Hi all,
The following is as much an is-there-interest-in-this-kind-of-feature question as a general posting.
I’m working on a character builder for an upcoming game project, and I’m also interested in doing physics-based procedural animation. Which brings us to the topic: physics-based procedural animation of a character’s hair.
When I started this project about a year ago, relatively extensive Googling showed that while Panda supports both Bullet and ODE, neither of them are connected to Panda’s logic in such a way as to easily make possible the procedural animation of a character’s hair or clothing.
The important property is that the logic needs to be able to use the physics engine only for some subset of the joints of a model (which is generally a multipart Actor for maximum runtime customizability), and the simulation must observe certain constraints (e.g. the length of each hair segment must not change).
Hence, having some background in classical mechanics, at this point I felt it was simpler to code a custom physics simulation and connect that to the procedural animation features of Panda3D than to try to adapt the existing integration to either Bullet or ODE to perform the calculations.
Whence, I have a working prototype:
Left: initial state from model file. Right: final state.
The simulation is initialized from the joint hierarchy in the model file, enabling the creation of different hairstyles in Blender:
However, the current prototype runs slowly, and is missing a couple of features that I still need to add to make a final usable version.
It turns out that NumPy is not very well suited for this particular task, as the chains of joints representing the hair segments have wildly differing lengths - or at least, it is very difficult to keep the calculation properly vectorized if chains of differing lengths are needed in the same simulation. (If multiple arrays are used, NumPy’s efficiency gain is lost.) Also, the calculation requires relatively many function calls, which are slow in Python.
Therefore, if I’m going to keep the custom code approach, the next logical step would be to move the slow stuff into a C or C++ extension module.
The question to the community is: does anyone else want this functionality, and especially, is there interest to include it in Panda if I implement a “procedural hair animation” module as a Panda C extension?
Specifically, the module would consist of a small physics code to perform the actual simulation, and auxiliary code to read in a model and animate a user-definable subset of its joints using the physics simulation.
The physics code simulates chains consisting of rigid rods, connected via ball-joint bending springs (with configurable stiffness). It will be possible to apply external forces such as gravity, air resistance, and the fictitious forces arising from inertial effects (when the simulation runs in a noninertial coordinate frame, such as the local coordinates of a character’s head). Some very basic collision shapes will be implemented, to prevent hair intersecting a character’s head or body. Collision detection with any external objects in the scene is NOT planned.
I might add support for branching chains in a later version; this would be useful for simulating the motions of trees subjected to wind. Combined with some small additional work in the fractal tree generator in the Panda examples, this might be useful for procedurally generated game level backgrounds.
As part of the system, there will be a thin logic layer that reads in a model, takes control of a subset of its joints, and then updates those joints procedurally based on the simulation. The neutral state of the joints can be initialized from the model (so the joint is not necessarily straight in the orientation where it applies zero force).
Note that the current Python-with-NumPy prototype already has most of this; the only parts missing are fictitious forces (inertial effects), collision detection and branching chains.
Mostly, the remaining work is a matter of implementing a more efficient (and slightly expanded) version in C/C++.
At least personally, I think a module like this would speed up game development, specifically making it much simpler to create characters with long, freely flowing hair.