At work, I used instancedmesh to improve program performance. Sometimes you need to know the ID of each instance by picking, such as this problem #17906 .
I made a demo about getting instance ID by raycast not gpu picking. In this demo, clicking the instance will rotate to indicate that it is selected.
And I have done more about the raycast of multi instance rendering of morphTargets , which seems to work well.
This is an online demo of Demo:
This is the demo code:
https://github.com/webglzhang/three.js/blob/dev/src/objects/Mesh.js
https://github.com/webglzhang/three.js/blob/dev/src/objects/InstancedMesh.js
https://github.com/webglzhang/three.js/blob/dev/examples/webgl_instancing_raycast.html
How about this case? We can discuss whether three.js needs this function. If so, I can make this pr. thanks.
I think it would be great to call Mesh.raycast() in some way instead of copying it into InstancedMesh.raycast(). Do you think this is possible?
After you respond to @Mugen87, I think a PR would be nice. Be sure to avoid calling new THREE.Matrix4() inside the render loop; create one instance and reuse it.
I think it would be great to call
Mesh.raycast()in some way instead of copying it intoInstancedMesh.raycast(). Do you think this is possible?
This is a very good idea. I'm trying to realize it these days and see how it works.
After you respond to @Mugen87, I think a PR would be nice. Be sure to avoid calling
new THREE.Matrix4()inside the render loop; create one instance and reuse it.
I will pay attention to this situation, thank you for your reminding!
@Mugen87 @WestLangley Hey, I remade the demo and further extend this approach to the deformation target. It looks good. I updated the question. How does it look?
I suggest you make a PR so it's easier to identify the diff.