Mesher ~ another iteration
isosurfaces contouring FEM
Felt my meshing tool needed another rewrite; getting trickier though.
The idea behind the tool is to construct a mesh using smaller simpler building blocks; kind of like a purely additive CSG modeller. I started out with a Marching Cubes implementation, but I really wanted it to be able to capture sharp edges in the base geometry. Also the triangle quality of the generated meshes needed improving. I prefer to bake data as vertex maps whenever I can, but shading based on interpolation between per-vertex values on awkwardly shaped triangles can quickly give poor results.
Scene are built using standard non-self intersecting meshes as basic building blocks. The advantage of this is that I can use any existing modeller to set these scenes up while allowing for a lot less linear workflow. Blocks are modelled once and can then be instantiated/transformed multiple times into the scene.
The algorithm then starts out by turning the bounding box of the mesh into a set of connected tetrahedrons. From there it keeps sampling the background mesh and using that data to refine the tetrahedral grid until it resembles the original mesh. It ends up with a big blob of tetrahedrons with a single connected triangle manifold on the surface.
What's nice about tetrahedrons is that they're guaranteed to be convex objects, so you basically get a convex decomposition (for collision detection) for free. Though I do a quick merge-pass to see if individual tets can be clustered together to form larger convex chunks. A volumetric description of the mesh allows for more robust intersection testing, but I only really need to keep the outer "crust" of tetrahedrons around, so I discard the inner ones to save on memory,
Any vertex weight map applied to the base mesh is projected back onto the resulting triangle mesh. I use these as masks for textures and density maps for surface particle replication (foliage etc.).
Two Catmull-Rom curves projected as road uv-maps. Locally the vertex resolution needs to be uniform and high enough to capture the curvature of the road. The green weight map masks a grass texture while also modulating the alpha channel of the road:
And the final scene textured and baked in Modo. Modo allows you to set up a pre-shaded environment into which you can simply drop newly generated meshes to have them automatically have their materials etc. applied.