Physics simulation for character hair

Hi all,

I needed a break from postprocessing, so I decided I’d look into re-implementing my hair physics simulator in C++.

At this point I think I need some help with Panda’s C++/Python integration. I understand Panda includes a tool called interrogate that will generate Python bindings for a C++ module, but I’m having trouble finding documentation (or even relatively recent forum posts - I suspect posts from 2006 or 2007 such as [url]Cracking open Python objects in C++], [url][Solved] Mixing C++/Python, accessing the engine in parallel] or [url]Interrogate questions] may be out of date by now :slight_smile: ).

Basically, I want to make a C++ extension for Panda that takes in a multipart actor and some extra information, takes control of a subset of the actor’s joints, and then runs a custom physics simulation to animate those joints procedurally (while letting everything else in the actor to be animated normally).

I think a custom simulation is the way to go for two reasons: getting the Bullet or ODE features to take control of a subset of an actor’s joints seems painful, and at least to me it seems that Bullet’s softbody rope does not have support for bending rigidity (nor is it easy to extract its shape to apply it to a sequence of joints). (For example, sewing thread has almost no bending rigidity, while a guitar string does. In a character’s hair, it seems to me that e.g. braids should be more resistant to bending than free bunches of hair. Hence, user-settable bending rigidity for artistic control.)

As stated earlier in this thread, I have already made a working prototype in Python, but the physics simulation needs C++ for speed. I’m familiar with both languages, but aside from some simple experiments with Cython, I have never integrated the two.

So, I have some questions:

  1. Where do I start if I want to make a C++ extension for Panda that plugs into the makepanda build system? Are there examples? (I’d like to build this in a way that it can be included into Panda if the quality is sufficient.)

  2. What is the preferred way for passing Python objects and strings from Python to a C++ Panda extension? I think I saw a simple example somewhere last year (and can’t find it now that I’d need it!), but it was passing only an integer, whereas I would need to pass more complex data types, like Python lists (of strings) and Panda objects such as Actor.

  3. The simulation needs to update the controlled joints at each frame. What is the preferred way of implementing update tasks in C++ extensions?

  4. The final version of the simulation will need motion information in order to implement fictitious forces arising from non-inertial motion of the Actor (see e.g. http://en.wikipedia.org/wiki/Fictitious_force#Mathematical_derivation_of_fictitious_forces).

Is there a more preferred, general way to extract this information in Panda, than using finite differences based on the last known position(s)? The simulation needs the local acceleration at each joint that is generated by the combined effect of non-inertial rigid-body motion (i.e. acceleration and rotation) and any prerecorded animation that may be simultaneously playing on the Actor (affecting the hair parent joint or its ancestors). Linear velocity may also be useful for a crude simulation of air resistance based on the local velocity plus some random noise.

Finite differences should work, but will cause a one-frame lag in angular velocity and a two-frame lag in linear acceleration, even when inaccurate first-order backward differences are used. Higher accuracy would require even more points and thus more lag; see e.g. http://www.geometrictools.com/Documentation/FiniteDifferences.pdf.

Thus, if the motion information is somehow directly available, it would be better to use that in order to avoid the lag. But it depends on how game models are usually animated and moved - if there is no velocity and acceleration information, then position-based finite differences are the only option. (A hybrid that calculates velocity from position and acceleration from velocity is possible - and works better if the framerate varies - but this does not remove the problem.)

As usual, any help would be appreciated :slight_smile: