gkjohnson / three-mesh-bvh

A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.
https://gkjohnson.github.io/three-mesh-bvh/example/bundle/raycast.html
MIT License
2.4k stars 248 forks source link

Can I get which mesh is intersecting, when use staticGeometryGenerator with multi meshes. #449

Closed DoMoCo closed 1 year ago

DoMoCo commented 1 year ago

I just want to get intersected mesh not triangle. I don't get any idea about it after reading a lot of issues.

Thanks a lot.

gkjohnson commented 1 year ago

Hello! What's your use case? Why are you using the static geometry generator if you need to identify which geometry has been intersected with?

If you really need to use the static geometry generator and still identify the intersected geometry I recommend adding a vertex attribute for each triangle with a mesh index so you can dereference to the associated geometry later.

DoMoCo commented 1 year ago

Thank you for your attention!

My use case is: There are many planes in the scene and I want to click on a plane with the mouse. I can achieve this with the raycaster of three.js, but I want to accelerate it. Then I found three-mesh-bvh but I don't know how to use it even after many tries.

Why are you using the static geometry generator if you need to identify which geometry has been intersected with?

To answer this question that building bvh for a single plane doesn't seem to make sense.

gkjohnson commented 1 year ago

To answer this question that building bvh for a single plane doesn't seem to make sense.

Yes you're right - in the long term this is a use case that would be served best by a scene-level or instanced mesh acceleration structure.

I think right now this is probably your best bet:

If you really need to use the static geometry generator and still identify the intersected geometry I recommend adding a vertex attribute for each triangle with a mesh index so you can dereference to the associated geometry later.

DoMoCo commented 1 year ago

Thanks to face.materialIndex, I found the correspondence between intersected triangle and the related plane. Feel free to close this issue now.

I have already submitted another question, looking forward to the your answer.

Thanks again.