Skip to content
Advertisement

Import camera from gltf

How to do I use camera from gltf in three-js? I am using the gltf loader as show in this example

Advertisement

Answer

As mentioned in the documentation, you extract the camera from the gltf.cameras array. It’s an array since it’s possible to export multiple cameras to glTF.

You normally want to assign the camera to a variable which is declared outside of the onLoad() scope so you can use it for rendering. Something like:

let camera;

const loader = new GLTFLoader();
loader.load( 'models/scene.gltf', function( gltf ) {

    scene.add( gltf.scene );
    camera = gltf.cameras[ 0 ];

} );
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement