gltfjsx icon indicating copy to clipboard operation
gltfjsx copied to clipboard

Make output clonable by default?

Open wiredmatt opened this issue 2 years ago • 0 comments

Maybe I'm missing something but by using the generated JSX as is you can't create multiple instances of the same model.

This will just pick the last and render that one (the one with key 3), but not the others:

export const ModelViewer = () => {
  return (
    <>
      <OrbitControls />
      <group>
        {[1, 2, 3].map((i) => (
          <MyModel key={i} position={[i, i, i]} />
        ))}
      </group>
    </>
  );
};

Could be fixed by just changing these lines in the generated file:

const group = useRef<THREE.Group>();
  const { materials, animations, scene } = useGLTF(
    "/mymodel.glb"
  ) as GLTFResult;

const clone = useMemo(() => SkeletonUtils.clone(scene), [scene]);
const { nodes } = useGraph(clone) as GLTFResult;

I don't know if this wasn't included for some reason, but shouldn't it be a built-in option in the CLI?

Thanks

wiredmatt avatar May 27 '23 22:05 wiredmatt