Cloth - rigid body collision detection in C++

   5107   4   2
User Avatar
Member
4 posts
Joined: March 2012
Offline
Hello all,

I'm currently experimenting with implementing a cloth simulation algorithm as a Houdini plug-in in C++. Rather than writing my own collision detection algorithm (or using an external library) I would like to use Houdini's built in collision detection routines, but I'm not sure where to start. It seems that the SIM_ColliderBFA class is what I should be using, but I can't figure out what do with it.

In outline, my solver implementation is currently based on the SIM_SingleSolver (so only one cloth object can be solved at time) class. This implements the virtual function

SIM_Solver:IM_Result solveSingleObjectSubclass(SIM_Engine &engine,
SIM_Object &object,
SIM_ObjectArray &feedbacktoobjects,
const SIM_Time &timestep,
bool newobject);

My guess is that I should be doing something like:
SIM_ColliderBFA* clothCollider = SIM_DATA_CREATE(object, “Collider”, SIM_ColliderBFA, 0);
once I get to the collision detection step, but this always seems to return NULL (presumably because object is missing some required sub-data).

Any advice on this matter would be greatly appreciated!
User Avatar
Member
4 posts
Joined: March 2012
Offline
Slight update: I just found out about the SIM_ColliderInfo class, along with SIM_ColliderLabel and the SIM_Object::getCollider function. It appears that these (in particular SIM_ColliderInfo) are the key entry points of the collision detection functionality. I will explore these and post the results of my investigation.

I also forgot to mention in my first post that I'm using Houdini 11 at the moment.
User Avatar
Member
4 posts
Joined: March 2012
Offline
I have investigated the API components I mentioned in my previous message, but still don't understand enough to make use of them. Here are some further comments and questions:

1. I believe I understand how to make use of SIM_Solver::getDefaultColliderSubclass, SIM_Solver::getDefaultColliderSubclass, and SIM_ColliderLabel for assigning which colliders the solver should use. However, I still don't understand how to actually make use of built-in collider classes (e.g. what sub-data does each object need, etc.).

2. It seems that SIM_ColliderBFA is used for cloth-cloth collision (or thin-plate rigid body collision), but not for volume-cloth. Furthermore, it can't be instantiated via SIM_DATA_CREATE as it isn't “registered” (it doesn't appear to have a data factory). I have managed to create instances of some other colliders.

3. How is volume-cloth collision done? Is it with one of the available SIM_Collider subclasses, and if so, which one? How can I set up my own objects to make use of this collider?

4. Which solver is responsible for the various collisions when multiple solvers are involved? For example, if I set up a collision relation between a static rigid body and an active one, what are the collision resolution responsibilities of the static solver and what are the responsibilities of the active solver?
User Avatar
Staff
429 posts
Joined: June 2007
Offline
Questions 1 & 2:
If you want to implement collisions for a custom cloth simulator in DOPs, then I recommend directly accessing the simulation geometry of any Static or RBD objects that you want to collide with. You can then do the collision detection against that geometry. For example, if you have a reference “object” to a SIM_Object, you can get the geometry by calling: SIM_DATA_GETCONST(object, “Geometry”, SIM_Geometry);
For continuous collision detection you will need the geometry from the objects at both the previous and the current frame times (using the method SIM_Engine::getObjectAtTime).

Question 3: Cloth-volume collisions can be done using SDFs. The methods getDistance and getGradient of GU_SDF should suffice for a basic implementation that collides only the cloth vertices. If you want to compute accurate friction for collisions against geometry that is not moving like a rigid object (i.e., deforming), you may need to generate some kind of velocity field in addition to the SDF. If the collision geometry is deforming fast, you will want to generate SDFs at many small time intervals to get accurate results.

Question 4: You can do all collision handling between cloth and RBD/Static in your cloth solver, where the cloth responds to collisions with the RBD/Static objects and generates impulses to the RBD/Static object that can be processed and applied at a later stage by the RBD solver.

Michiel
User Avatar
Member
4 posts
Joined: March 2012
Offline
Michiel,

Thank you for your helpful reply. The cloth solver that I am implementing is based on a paper that does not explain the collision resolution step (the algorithm is meant to be used together with other existing components), so my goal was to try to use Houdini's built in collision algorithms somehow (for example classes such as RBD_ColliderSDF), together with some additional custom logic, rather than creating collision handlers from scratch. I don't know if this is even possible (I can't quite figure it out from the HDK documentation).

I think perhaps as an alternative I might try to plug in an existing collision detection library such as Bullet.
  • Quick Links