Skip to content

Unable render muliple <primitive/> in one page #1199

Answered by partynikko
ida-fe asked this question in Q&A
Discussion options

You must be logged in to vote

Not sure how PCD works or is implemented, but a resource/object can only ever be mounted in one place at once. See here: https://github.com/pmndrs/react-three-fiber/blob/master/markdown/api.md#putting-already-existing-objects-into-the-scene-graph
To get around this, clone the loaded entity. For example, when loading GLTF scenes that I want to use multiple instances of, I do this:

export const useGltfScene = (model: string) => {
  const gltf = useGLTF(`${process.env.PUBLIC_URL}/models/${model}`);
  const scene = useMemo(() => gltf.scene.clone(), [gltf]); // Clone the scene to be able to use multiple instances.
  return scene;
};

Maybe (hopefully) that will work for PCD as well.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@ida-fe
Comment options

@drcmda
Comment options

@gong9
Comment options

Answer selected by ida-fe
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants