Gltf Import: Camera usage

Hi! I Loaded a glb File from Blender with an Camera. So I wanted to use this camera in the Three.js viewer and add some OrbitControls.
The Camera is not moving. But when I use my own Perspective Cam everything is ok. But I cant get this cam to the Position if the one in the glb.

When I use
this.camera=gltf.cameras[0];
in the loader.load then I see the correct Object but cant move.

When I use
this.camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
this.scene.add(this.camera);

And In the Loader.load
this.camera.position.set(gltf.cameras[0].position);
or this.camera.copy(gltf.cameras[0]);
I get a moving Camera which is completly wrong. Position of the gltf.cameras[0] is (0,0,0).

I found the Bug. And it was in Blender. Blender uses an Object and parents the camera to it. So the Camera will always have 0,0,0 because it is on the same place as the Object. Found the Solution when I was browsing the scene in the Javascript browser of chrome. The Camera had a parent and this had all needed Information.

Now with
this.camera.position.copy(gltf.cameras[0].parent.position);
this.camera.quaternion.copy(gltf.cameras[0].parent.quaternion);
this.camera.scale.copy(gltf.cameras[0].parent.scale);
Everything works. copy of the Object does not work, because the parent is no Camera

Hope someone else will need this Info in the Future!

4 Likes

If the camera has rotation, still need to get the product of two quaternion
const newQuaternion = camera.parent.quaternion.multiply(camera.quaternion)
and then send to camera quaternion
this.camera.quaternion.copy(newQuaternion);