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.39k stars 247 forks source link

How to get a bounding volume at level=x (where x can be 20 ) while raycasting to a BVH #383

Closed SrinivasPrabhu794 closed 2 years ago

SrinivasPrabhu794 commented 2 years ago

Hi @gkjohnson ,

I have a use case where I need to raycast to a BVH and find a Bounding volume at say level=20, enclosing that intersection point only so that I can do some intersection checks myself. Is that possible to do this at the moment?

USE_CASE: There are multiple complex geometries in the scene and the objects need to be placed/stacked on top of each other. The top surface of one object acts as the ground/base for another object that will be placed on it. For this, I first shapecast and find the top most Y position at any point of intersection. Sometimes for concave objects there are certain hole sections where I need to place the object. In such a case I thought of doing a raycast intersection in -Y direction from the main object in question to the BVH of the geometry below it. If I can get a BV at level=20 for example then I can check if the object is already on the top surface of an object right below it or floating in the air.

Let me know if this is possible.

Thanks!

gkjohnson commented 2 years ago

I'm not fully following what your strategy is here. If you'd like to place something on the surface and find the highest point over a certain section of the mesh you can use the shapecast function to check the height of the triangles in your target region.

Either way generally the structural properties of the BVH should not be relied upon because the depth, organization, etc can change dramatically depending on the options used during construction.

SrinivasPrabhu794 commented 2 years ago

Hi @gkjohnson

If you'd like to place something on the surface and find the highest point over a certain section of the mesh you can use the shapecast function to check the height of the triangles in your target region.

Do you mean by using the "intersectsTriangle" callback in the shapecast function? Do you have any examples that I can take a look at that does this ? Basically, what I want to implement is basic physics where if a drop an object it should fall on the surface of the mesh below it.

Either way generally the structural properties of the BVH should not be relied upon because the depth, organization, etc can change dramatically depending on the options used during construction.

Ok I understand.

gkjohnson commented 2 years ago

If you look in the examples files there are a couple demos that show to to implement basic physics: