Skip to content

Minimal instancedMesh example #761

Answered by mattrossman
mattrossman asked this question in Q&A
Discussion options

You must be logged in to vote

Answering my own question for future readers:

A THREE.InstancedMesh stores all the 4x4 transformation matrices of all the instances inside a one flat Float32Array, which gets initialized to all zeros. A transformation matrix full of zeros means that the instances get squashed into the abyss, hence nothing gets rendered. To solve this you need to give the instances a more reasonable tranformation matrix, like an identity matrix. A THREE.Matrix4() will initialize to an identity matrix by default, so a minimal working version of the above example looks like:

function InstancedThing() {
  const ref = useRef()
  useEffect(() => {
    ref.current.setMatrixAt(0, new THREE.Matrix4())
  }, [])
  r…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@drcmda
Comment options

@mattrossman
Comment options

@sonisourabh
Comment options

Answer selected by mattrossman
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