Rag Doll

Discuss any questions about BEPUphysics or problems encountered.
BoltonBeedz
Posts: 45
Joined: Fri Dec 07, 2007 12:58 am

Rag Doll

Post by BoltonBeedz »

Hi.
I'm implementing rag doll physics in XNA using BallSocketJoint class, and Skinned Model Sample from Microsoft.

I created Cylinders from my Bones and hey presto. I also used collision filter to allow the cylinders to occupy the same space. Does anyone know how to use constraints in BEPU to make joints behave properly, in particular with a model exported from blender?
Image
BoltonBeedz
Posts: 45
Joined: Fri Dec 07, 2007 12:58 am

Re: Rag Doll

Post by BoltonBeedz »

Also, if I create a new cylinder, is there a way to
1>position it with a rotating transating world matrix,
2>get the end points?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rag Doll

Post by Norbo »

Here's a quick checklist:

Are the cylinders sized correctly and positioned correctly according to the model?
Is the BallSocketJoint's anchor positioned between the cylinders such that it is a logical joint position?
Is the "softness" set to a good value? Softness removes a little bit of rigidity while improved stability in some situations. Try 0 or another small number (below 0.3) to begin with.
Is the "biasFactor" set to a good value? This value represents how much of the joint's position error to try and correct per second. Try 0.2 to begin with.

The source format is generally irrelevant; so long as the correct joint positions are extracted, it should work.

I'm currently working on the constraint overhaul of v0.11.0 as well. It will include quite a lot of fancy new things that will help with making ragdolls, like new constraint types, joint friction and joint limits. When it's ready, I'll probably release a demo partially based on the microsoft sample to show one way of integrating it.
Also, if I create a new cylinder, is there a way to
1>position it with a rotating transating world matrix,
2>get the end points?
1) If you're using v0.10.0 and up, entities have worldTransform and internalWorldTransform properties.
2) There's no explicitly implemented getEndPoints method, but you could retrieve the cylinder.orientationMatrix.Up property. This vector points along the lengthwise axis of the cylinder. If you multiply this vector by half the cylinder length and add it to the cylinder's centerPosition, you can get the top point and similarly for the bottom point.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rag Doll

Post by Norbo »

As an addendum to 1), you can also create an entity in v0.10.0 and above using a MotionState in the constructor.
BoltonBeedz
Posts: 45
Joined: Fri Dec 07, 2007 12:58 am

Re: Rag Doll

Post by BoltonBeedz »

Thanks for the info. It took a while but I got it to work. lesson learned: scale matrices cause work.
As you see I am still unable to calculate the bone lengths. I'll keep trying. The framerate of this stuff is insane by the way.
Image
BoltonBeedz
Posts: 45
Joined: Fri Dec 07, 2007 12:58 am

Re: Rag Doll

Post by BoltonBeedz »

I'm now thinking that getting the bone lengths is Advanced so I give up and decide to use objects defined in blender instead. I guess i'm thinking of how constraints in blender relate to rags. They can't be imported easily but it would be nice to define them in Blender to animate the model. Are you by any chance going to write blender specific documentation on the subject of transfering constraints from blender? Or let me know sometime. Cheers
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rag Doll

Post by Norbo »

I might actually have some sample code laying around from back when I was testing some skeleton-to-entities stuff. It calculated bone lengths and some other information. I'll see what I can dig up. It's not blender specific though; it was built on top of the same bone system ideas as the skinned model sample (using its dude.fbx as well).

I'm not a blender expert, but I'll see what I can do when I get to the documentation-making stage for constraints.

By the way, when you said insane framerate, you don't mean insanely bad do you? Just making sure there's not something bad going on :D
BoltonBeedz
Posts: 45
Joined: Fri Dec 07, 2007 12:58 am

Re: Rag Doll

Post by BoltonBeedz »

Insane as in good.
Forget the bone length it's doing my head in trying to work it out. I'll do boxes in blender. You know what.. is there a thickness setting on a triangle mesh and terrain please?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rag Doll

Post by Norbo »

You can adjust the collision margin of terrain and triangle meshes, yes.

The terrain has a "margin" field, while StaticTriangleGroups get their margin from the TriangleMesh that was passed into the constructor. The TriangleMesh.hierarchy object has a margin field as well which you can set. Be sure to call refit or reconstructHierarchy on the hierarchy after changing the hierarchy's margin (refit should do the trick).

The margin expands the triangle to be a bit fatter, as shown in this thread: http://bepu-games.com/forums/viewtopic.php?f=4&t=409

Terrains also have a rescueDepth field. This will pull any entity that's fallen beneath the terrain (to a certain distance) back to the surface.
BoltonBeedz
Posts: 45
Joined: Fri Dec 07, 2007 12:58 am

Re: Rag Doll

Post by BoltonBeedz »

Image
Thanks for helping me with this
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rag Doll

Post by Norbo »

That's certainly some nice progress since the first picture!

I wish I could get these joint enhancements out quicker. It would really help to be able to easily stop the excessive twisting/bending.
BoltonBeedz
Posts: 45
Joined: Fri Dec 07, 2007 12:58 am

Re: Rag Doll

Post by BoltonBeedz »

This is good fun actually.. but..
I cranked up the terrain margin to 1.0f but it just goes weird.
I imagine some feature where the terrain can be considered solid underneath: infinately or to a fixed height Y value, while the top remains unchanged.
Also, for getting better small objects interacting with big-triangles would be a similar setting where the face of the triangle is extruded inwards what
That would be sweet if you aren't busy. Cheers.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rag Doll

Post by Norbo »

The problem with big triangles is that the collision detection system's stability starts to fail. Creating an automated re-triangulation system would be quite tricky to perfect. In a simple extrusion case, there would be long sliver-like triangle created which are also unstable. Someday there may be a bit of built-in help for this, but until then, the collision model needs to be well-formatted and correctly sized. Keeping objects on the same order of magnitude of 1 unit = 1 meter generally works. Try to avoid having individual triangles with low width to length ratios (somewhere around 1:5 or less works) or excessive overall size (less than 20 works well).

The 'solid underground' effect is simulated by using the terrain's rescueDepth field. While it won't 'collide' with objects below the surface, it will teleport them back to the surface. I chose this system as opposed to a 'thick' terrain composed of a bunch of separate thick entities extending downward due to the possibility that an entity could get stuck between the boundaries of two entities, bouncing back and forth until it dropped out of the bottom of the terrain.

In the future, perhaps in v0.11.0 if it won't delay the version too much (v0.12.0 otherwise), I will be doing an overhaul of the collision detection pipeline. A part of this overhaul is some speed and functionality enhancements for the StaticTriangleGroup and Terrain. Ideally, a more robust 'thick terrain' system could be implemented alongside the rest of the changes. However, the same fundamental size restrictions will exist.
BoltonBeedz
Posts: 45
Joined: Fri Dec 07, 2007 12:58 am

Re: Rag Doll

Post by BoltonBeedz »

Image
This is how it looks now by the way. I still can't calculate the bone lengths though.
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Re: Rag Doll

Post by jstroh »

WTB contraints and ragdoll example from Norbo!
Post Reply