Hi community!
For years I’ve been dreaming about an instrument, that would allow me to fill a mesh with points, so I could create cool things.
My own attempt, based on default raycasting with counting of intersections, was very slow.
But everything changed since @gkjohnson released his awesome plugin: Three-mesh-bvh: A plugin for fast geometry raycasting and spatial queries!
Now, I want to show you my new attempt on the field of filling meshes with points. The core of the method is simple: using that plugin, cast a ray from a point, get first intersection, check the dot-product of intersected face’s normal and raycaster’s ray, and if it’s greater than zero, we’re inside of the mesh, otherwise, we’re outside.
Picture:
Demo: https://xykxn.csb.app/
First time using of CodeSandbox, as Codepen doesn’t allow too long loops (it limits approximately to 10000 iterations) and I wanted to have hundreds of thousands of points
Source code: great-http-xykxn - CodeSandbox
PS Three-mesh-bvh is one of the best things for me, that ever happened to three.js, since .onBeforeCompile
, selective bloom and MeshSurfaceSampler