Way to get mesh instance?

Here is my scene, the user can move the pot on the floor by mouse or touches.

The scene model has the following mesh instances:

  • wall1
  • wall2
  • wall3
  • railing
  • floor
  • ceiling

I am finding a way to get the mesh instance where the user clicked / tapped.

The physics way by app.systems.rigidbody.raycastFirst only return the entity, normal, point, not including the mesh instance…

The picker way by pc.Picker can return mesh instances, however when the user move the pot, the mouse/touches will always on the pot, so the picker only return the pots’ mesh instances, not the scene model’s mesh instances. what’s more, the picker way should not be used on mobile devices because of the performance.

The bounding box way by boudingbox.intersectsRay will do the trick in simple scenes, when usint it in a complex scene model, it sucks. See the following scene:

When I click the floor, as the floor’s bounding box and the railing’s bounding box intersects, I can always get them, but this is not what I want.

What I want is Raycaster.intersectObject in three.js…
Is there any way to do this ?
Thanks!

@will @max @yaustar
These days I dive into THREE.js’s Raycaster.intersectObject source code, and I make a demo by the engine.
The implementation is migrated from THREE.js :grinning:

I think we can add an api for these kind of issues:

app.systems.camera.raycastMeshinstances(ray, entity.model.model.meshInstances);
// if the ray do not intersects, return null;
// if the ray intersects anything, return the following data structure
[
    {
        distance: distance to triangle,
        index: triangle index,
        meshIntance: the mesh instance of triangle,
        point: hit point
    }
]
4 Likes