How to switch to a camera defined in a loaded glTF scene? #1999
-
I'm trying to:
I didn't find a way to do this in the documentation, nor in Github issues and discussions. I tried using a primitive and the const Scene = ({ ...rest }) => {
const gltf = useLoader(GLTFLoader, sceneUrl);
return (
<>
<ambientLight intensity={0.5} />
<primitive object={gltf.scene} />
<primitive object={gltf.cameras[0]} makeDefault />
</>
);
}; My scene displays just fine and I can see my camera in Any tips on the cleanest way to control gltf animations in the context of r3f (such as to start my camera animation, say, as soon as the scene is displayed) would also be appreciated :) Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Okay, so I figured it out from the following snippet #181 (comment) and the My solution to switch to the gltf camera is this: useEffect(() => set({ camera: gltf.cameras[0] }), [gltf.cameras, set]); Now to get the camera animation playing! |
Beta Was this translation helpful? Give feedback.
Okay, so I figured it out from the following snippet #181 (comment) and the
useThree
documentation. Maybe this should be documented in the GLTF section of the documentation?My solution to switch to the gltf camera is this:
Now to get the camera animation playing!