Particle Systems for Real-Time Rigid-body, Fluid, and Flocking simulations
Voxlelize the Mesh
Smoothed particle hydrodynamics (SPH) simulations have an unstructured mesh composed of many particles. Representing rigid-bodies as a set of particles will greatly simplify the calculation of interaction forces between fluids and rigid- bodies. Unfortunately, Rigid-bodies are typically represented as triangular meshes. One would like to have a technique which turns a triangular mesh into a particle representation of that same shape.
The process of creating a particle representation from a triangular mesh is called voxelization. Using OpenGL, one can render a mesh in slices. Initialize the first framebuffer to zeros. Then render the mesh to the depth of one slice of the mesh. For each successive slice, switch the OpenGL blending mode to XOR. Doing so will change pixels which are “on” to “off” only if the incoming signal is “off”. Likewise pixels that are “off” change to “on” only if the incoming signal is “on”. Effectively, the process turns on when it passes through the surface and only turns off again once it passes through th other side of the mesh.
The voxelization process outputs a 3D Texture where a red pixel indicates the voxel belongs to the inside of the mesh. Therefore, one must iterate over all the voxels adding particles to the domain at a position relative to the r,s, and t indices of the 3D Texture. The user must decide provide a global offset and rotation when actually adding the particles to the domain.