DataTexture3D Generation (three-mesh-bvh)

@Usnul

(sigh) I would like to have your ability to explain things :sweat_smile:

  1. Having a mesh, build a Box3 object from it.

  2. Having that box and using Raycaster, in the triple loop (x, y, z), cast rays, where ray’s origin is the current position inside the box in accordance to values of the loop (x, y, z), and ray’s direction is a random normalized vector.
    2.1. Check the result of raycast against the mesh. The same way, described here: Sand Nefertiti (three-mesh-bvh) (first hit + dot-product of raycaster’s ray and mesh’s normal). If we’re inside of the mesh, push 1 into data array, otherwise push 0.

  3. Having filled data array, create DataTexture3D object.

  4. Having that 3D texture, do/create cool/awesome stuff :slight_smile: I used this texture with 3d grid of lines, discarding the parts, that is not in the model. I modified the example, added one more uniform to cancel the discarding. When you set noDiscard to true, you’ll see full cubic grid of magenta. Set it to false, and lines will remain only inside of the dragon.

2 Likes