three.jsskeletal-mesh

Three.js parenting mesh to bone


My goal is to attach separate objects (eg: wearable items) to an animated model, so that the bound objects are controlled by the models animation.

I have found these, but all seems outdated.

I experimenting with a character imported from blender that is skinned & rigged & animated.

My problem is: As I add a new mesh to a specific bone of the model (the commented out part in the code), the current animation clip is switched to the first one (t-pose), and the skinning get broken (model turns white). However the object is connects to the bone, and moves with it.

const {scene, animations} = await Utils.loadModel('model/someName.gltf');
const model = scene.children[0];

const material = new THREE.MeshBasicMaterial();
material.alphaTest = 0.5;
material.skinning = true;

model.traverse((child) => {     
    if (child.material) {
        material.map = child.material.map;
        child.material = material;
        child.material.needsUpdate = true;
    }
    if (child.isBone && child.name === 'RightHand') {
        // child.add(createMesh());
    }
});

gScene.add(model);

It dosen't work correctly, even if a simple cube is added, but it would be nice if I could add boots to a character, that is moves as its foot.


Solution

  • Looks like I have found a solution.

    I updated the demo (It's only a PoC) https://github.com/tomo0613/3d-animated-char-test

    first (in blender):

    then is JS code:

    I'm still curious, is there any intended /or better way doing this.?