Is there any way to attach mesh to bone? For example I load animated .js character and i want to attach weapon to it's hand.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
It is possible using a few simple hacks on the Bone and Object3D prototype. Since bones inherit from Object3D, they may have children, so we can easily .add() a mesh to any bone.
However, the SkinnedMesh will only call updateMatrixWorld() on non-Bone children, and update() for Bone children. Additionally, bones call update() for each of its children (regardless of wether it is a bone or not). The following snippets change that behavior:
Three.js Version 68 handles this out of the box, but a bit different. No changing of internal functions is required.
It now works like this:
the bone hierarchy is now found in the children of the SkinnedMesh.
Find the bone in the children list and simply attach the object to it:
Note: If you have a bone hierarchy (for example in your exported blender model) then this is represented in three.js too. If you target bone has a parent bone it will look like this: