Sand Nefertiti (three-mesh-bvh)

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 :innocent:

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 :metal:

14 Likes

Wow, this is so cool :heart_eyes: :heart_eyes: :heart_eyes:

1 Like

Wow that even ran smoothly on mobile :hushed:

Btw csb can configure loop protection, when you add the codesandbox.json in the config files tab you’ll see the option.

1 Like

@looeee Yay! Thanks! :beers:

Yeah, that’s why the demo is on CSB, as it allows to manage long loops :slight_smile:

oh no, i read that wrong! because i ran into the problem before so often until i figured out it’s configurable. sorry. :face_with_thermometer:

@drcmda
Found it very friendly of CSB, when I bumped in that limitation of loops, that they told me I have to create that json to manage the problem :slight_smile:
And Codepen just said “We know better, what you need, so live with that limit” :sweat_smile:

1 Like

:star_struck:

it sounds like we need a “MeshVolumeSampler” volumetric alternative to “MeshSurfaceSampler” haha…

1 Like