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.5k stars 261 forks source link

How to quickly check which points of pointcloud are inside a oriented box #451

Closed DoMoCo closed 2 years ago

DoMoCo commented 2 years ago

use case:

I want to use a box to select points from pointcloud.

How can I achieve this in three-mesh-bvh ? is there a solution? If judge point one by one, it should be very slow, so I want to use acceleration structure to speed up. But after many tries, I only found the realated interset function.

The example Lasso selection maybe helpful, but I didn't see a relation for my question.

Thanks.

gkjohnson commented 2 years ago

You'll want to use the shapecast function to perform a custom shape query against a shape, though it's not the most intuitive function to wrap your head around. The point cloud example will show you how to store points as degenerate triangles in the BVH in addition to using shapecast for raycasting. And the triangle painting demo may be closer to your use case of checking for intersections against a BVH.

The first step will be making sure you can testing whether a point is contained in an OBB. And then that can be used in the spatial query to test points.

Beyond that I'll need more specific questions to help.