A seldom update!
School is hogging all my time so there is not much time to do Max related stuff anymore. Nonetheless, I got three new things to show:
- Tetrahedralization in Max using TetGen
- A scripted procedural setup in particle flow for rigging ships plowing through ice.
- A 2D fluid solver implemented in XNA.
Tetrahedralization in Max using TetGen
I came over this article over at cgtalk and it was an interesting read. The tetrahedralization was new to me, and I started looking at TetGen and how I could interact with it using max. TetGen is a program to generate tetrahedral meshes of any 3D polyhedral domains. TetGen generates exact constrained Delaunay tetrahedralizations, boundary conforming Delaunay meshes, and Voronoi partitions. So I compiled the source files and wrote a maxscript that talks to the cmd line interface using dotNet. The scripts exports a mesh to the .off format, feeds it to TetGen who outputs a .ele and a .node file which Max reads and meshes. The bottleneck is creating the mesh in max. A tip is to check the “Single result mesh”. It gives you a single mesh where the tetrahedrons are created as elements and not as separate nodes. Creating 30K tetrahedrons takes about 4 seconds on my machine when creating as a single mesh. Creating separate nodes for each tetrahedron takes much longer; 4-5K nodes takes 4-5 seconds, 12K nodes takes 40 seconds. So there is a big overhead creating nodes using maxscript.
Cue boring video showing internall structure of a tetgen mesh:
Scripted procedural setup in particle flow for rigging ships plowing through ice.
Got hired to write some scripts to ease the setup and animation of ships plowing through ice.
Some key points for the system:
- Support huge scenes > 1k m.
- Arbitrary number of agents(boats)
- Quick setup/rigging
- Easy to make changes / easy iteration => procedural
I came up with some different solutions, but landed on particle flow mixed with agents with custom attributes, mainly because it made it easy to work fully procedural. Doing a rigid body system was out of the question due to the huge scales of the scenes and multiple interactions from the different boats. The user first specifies the number of agents in the system and the scripts creates them. An agent is a shape node with custom attributes linked to helpers for ice crack progagation, ice collision and ice deletion, and parameters for additional settings.
The heart of the system is the particle flow system. It is created after the user have specified the number of agents, which is the only requirement for it to be created. Everything else is customisable. The pflow system consist of mainly four parts: The particle creation, mesh cracking propagation, mesh collision and mesh deletion.
The particle creation is a scripted birth operator sampling mesh objects from the scene to particles. The user writes the common name of the mesh objects to be turned into particles in a custom attribute textfield found on the particle system. Scrubbing the slider now shows the mesh objects being controlled by particles. The original mesh objects are hidden and are not affected. This is because the system needs a reference point for sampling the mesh each time the slider is set back to the starting frame, thus restarting the system.
The next part of the system is the crack propagation check. Each of the agents has a node (by default a sphere deflector) that the pflow setup checks for collision against. If there is a collision the mesh is scaled based on it’s distance to the agent, creating larger cracks near the agents. This is done by a scripted operator.
The third part is the collision with the agent check. If a collision is detected the particles mesh is rotated perpendicular to the collision node referenced by the agent, this could be a custom mesh e.g. a ship hull. This gives the effect of the ice being cracked alongside the ships side. This is also done by a scripted operator.
The last part is the particle deletion check against the agent’s referenced delete node. Particles coming from the previous part are checked againts this node and deleted on collision.
Seeing it up close it may not look that impressive, but from a distance it gives a nice effect and it’s fully procedural. E.g. changing the path of the boats, changing the crack propagation size or any of the other custom properties are reflected in the system, and it is easy to add custom behavior using the particle view editor.
A little sample video of the system with two agents. I added some debris flying around and noisy push of the ground downwards creating a nice trail:
Some more tests here.
2D Fluid solver in XNA
Before the new semester started I decided to do something new and I ended up at looking at fluid solvers. Jos Stam gives this great presentation of his – now over 10 year old – implementation of stable 2D fluids. Converting the solver from C to C# was trivial, though I spent most of the time wrestling with XNA, since it was new to me, to get it to display the fluids correctly.