Faster Ray Intersects Mesh For Those with Many Facets

See demo at BVH from Morton Codes

I am happy to continue working on this and making a PR if it is a feature that is needed. Please let me know your views.

For usage my thinking is along these lines

You can create a BVH with mesh.createBVH(), SPS.createBVH(), meshes.createBVH(), scene.createBVH(), the latter for all meshes in a scene.

From here mesh means any of mesh, SPS, meshes or scene.

All can be serialized and exported along with the mesh. This is because for very very large number of objects (50k + ) the construction of a BVH can begin to move into minutes rather than seconds. This sort of number also causes the browser to produce the wait or stop option, so maybe needs to be done with the help of a worker.

When mesh.useBVH is true then mesh.intersects(ray) can

  1. (for a small mesh, <20K facets) create a BVH if necessary or
  2. use the one already created

and will return the pickingInfo for the facet, particle or mesh hit in the case of mesh, SPS or meshes respectively.

All primitives of an object must be static, ie the mesh, SPS or group of meshes can move and rotate as a whole but the vertices, particles or individual mesh must retain their individual positions and rotations respectively.

4 Likes

This is something worth pursing I think My only question is more about: is there a need?