How to attach a camera to character's head?

I have an animated human character, created in Blender, exported in gltf and then used in three.js

I want a three.js camera to see the scene from the point of view of the character. I can do this in an approximate way:

character.add(camera);

Which works as expected. My problem is that I want to move the camera according to the head of the character, specifically the ‘head’ bone.

Looking at the json character.gltf file, it looks as if I might be able to get to the head bone and parent the camera to it or somehow discover its position and orientation and copy those values to the camera.

Is there any way of doing that?

I’ve found out how to do that.
In case anyone else has the same problem, code I’m using is like this:

(new GLTFLoader()).load(
        'character.gltf',
        function ( gltf ) {
          scene.add(gltf.scene);
          //loop through the bones
          gltf.scene.traverse(
            o => {
              if(o.isBone && o.name === 'head'){
                console.log('head found!');
                console.log(o instanceof THREE.Object3D); //true
                o.add(localCamera);
              }
            }
          );
        }
);
1 Like