Skip to content

Switching between shared materials #789

Answered by drcmda
Datanizze asked this question in Q&A
Discussion options

You must be logged in to vote

in threejs one child can not be in two parents. primitive is an escape hatch that allows you to dump a readymade object into a scene, but unfortunately it is inviting to try what you did. though i don't quite understand why you want to make it so complicated: https://codesandbox.io/s/funny-greider-x97rs

<Box
  position={[-100, 0, 0]}
  args={[100, 100, 100]}
  onClick={() => setUseRed((s) => !s)}
  material={useRed ? materialRed : materialBlue} />

rule of thumb: you can freely share geometries and materials (in the same canvas!) but you can't have one mesh or any object in two places.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@gsimone
Comment options

@Datanizze
Comment options

Answer selected by Datanizze
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants