Skip to content

is there a way to pass a seperate userData to every mesh in instanced mesh? #1543

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

You must be logged in to vote

instancedmesh is a single object/mesh - the instances are virtual, they are not real meshes. but if you look at these https://codesandbox.io/s/instances-h873k and https://codesandbox.io/s/instanced-vertex-colors-8fo01 you'll see that you always have data to describe each instance. you can put anything in there, positions, color, sizes, ...

const data = [...Array(count)].map((_, i) => ({
  position: ...,
  color: ...,
  text: ....,
  data: ....,
})

useFrame(() => {
  for (let i = 0; i < data.length; i++) {
    const item = data[i]
    ...
    ref.current.setInstanceAt(i, ...)

Replies: 1 comment 2 replies

Comment options

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

@bhushan6
Comment options

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