How do you track InstancedMeshed instance so that they can be interacted with?

Hi! I have a scene with about 150 instanced meshes, each representing 10-20 instances. I need to track the instances, and follow up with some action (e.g. if the user clicks an instance, I need to do something with data related to that specific instance)

With normal geometry I would set the userData object on the mesh, and then retrieve it when a user clicks the scene (using a raytracer)

How would I do this with InstancedMeshes? can I set the userData object specifically for an instance?

2 Likes

I found out that the intersection has a property called instanceId, and I created a dictionary of the mesh id and the instanceId to get the data I need. This works for me and I hope its the right way.

4 Likes

Related example: three.js webgl - instancing - raycast

1 Like