Ray intersection on instencedMesh that has multiple morph targets

I would like to create an instancedMesh that can handle morphing. I need morph targets because each instance should have different shape so morph targets seems handy. Also each instance should detect rays because I need mouse events on each instance.

instancedMesh is needed because I want to draw large number of objects with the same material but different size.

Mesh approach

First I create a mesh with a geometry that has morph targets to make sure the morphing works as it expected.

mesh_morph

The base geometry have four morph targets top, bottom, left and right. Each morph target just move the edges in the given direction.

I manually calculated the boundingBox and boundingSphere to be able to detect cursor on the morphed parts.

InstancedMesh approach

With a single mesh works well the morphing however if I try to use the same geometry it does not work the same.

First issue

Only the original geometry can detect ray intersection. It was a problem on the first example as well but I manually calculated the boundingBox and boundingSphere which is fixed the problem. On instancedMesh does not matter if I change the bounds or not it will work the same.

instanced_mesh_01

The first rectangle is the original geometry shape. The second rectangle top and bottom morph targets is 0.5. That means moves the top and bottom edges with 0.5 on the y axes.

Second issue

When I move the second instance out of the original bounding box it somehow still detects ray in the original geometry shape.

instanced_mesh_02

My question is how can I detect rays on instancedMesh in morphed parts? My desired result should be a solution that works the same as the first example.


DEMO


My stackoverflow question: https://stackoverflow.com/q/79566244/19284873

Morph targets and instancing don’t work together. Edit: I’m wrong! Thanks @agargaro for pointing it out to me!

1 Like