In this minimal react-three-fiber App I am trying to load and include the same GLTF model twice:
import React, { Suspense } from "react";
import { Canvas } from "@react-three/fiber";
import { useGLTF } from "@react-three/drei";
function MyContent() {
const firstGltf = useGLTF("/eye/scene.gltf");
const secondGltf = useGLTF("/eye/scene.gltf");
return (
<>
<primitive object={firstGltf.scene} position={[-200, 0, -400]} />
<primitive object={secondGltf.scene} position={[200, 0, -400]} />
</>
);
}
export default function App() {
return (
<Canvas>
<ambientLight color="white" intensity={0.5} />
<Suspense fallback={null}>
<MyContent />
</Suspense>
</Canvas>
);
}
See this codesandbox
However only the second <primitive>
is visible. If i remove the second <primitive>
, then the first one is visible.
I'm struggling to understand why this happens and how to do it better.
(Is it because the second call to useGLTF
remembers that "/eye/scene.gltf"
has already been loaded and returns the same object? And is this somehow messing up the usage with <primitive>
, maybe because materials/geometries haven't been re-created a second time and exist only once?)
In particular, this is what I want to achieve:
- use a gltf model multiple times on my canvas
- ideally, load the gltf only once
On top of that, maybe you can help me to clarify these questions as well so I get a better understanding what's actually going on here:
- Since I only want a 3D model, is it the right approach to work with a
gltf.scene
object? - Is
<primitive>
actually the correct approach to show the 3D model? Or should I somehow extract the geometries/textures from the scene and render them?
Thank you!