Skinning and Ragdoll Physics.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
stuff4mike
Posts: 7
Joined: Sat Jan 07, 2012 8:25 am

Skinning and Ragdoll Physics.

Post by stuff4mike »

Hi Everyone! =D

First off, I want to thank the creator(s) of BEPUPhysics as it is really a great library. I am having a problem with rendering ragdolls. I have my own rendering system I created for my game engine. I know this is a rendering problem, but it is heavily influenced by physics. I think I'm just a little burned out so I'm having trouble solving this issue.

I am having a problem with skinned meshes and ragdoll physics using BEPUPhysics in XNA 3.1. I am not a math expert, and the issue lies mostly in not understanding how to skin my meshes when physics is activated on a mesh (ie. ragdoll)

I already have skinned meshes rendering and animating. The problem lies when physics takes over in my game.

When I activate physics, whether in the T-Pose or in the middle of an animation on a mesh, I create a bunch of physics boxes using BEPU and add them to the physics space. They are positioned in world space given the animations current bone transformations and world transform. Using constraints, they seem to render fine using debug boxes I created, and fall/contort realistically.

First picture is T-Pose with user defined collision boxes. Second picture is when physics takes over and the physics objects laying on some steps below.

Image

Image

So, again I am not sure how to transform my vertices to match the ragdoll. I have a skinned shader which takes a world matrix and skeleton transforms, and then performs pretty standard hardware skinning. The skeleton transforms are calculated below for animations, which I believe is pretty standard.


for (int i = 0; i < bones.Count; i++)
{
Bone bone = bones;
bone.ComputeAbsoluteTransform();

m_boneTransforms = bone.AbsoluteTransform;
}

//
// Determine the skin transforms from the skeleton
//

for (int s = 0; s < m_modelExtra.Skeleton.Count; s++)
{
Bone bone = bones[m_modelExtra.Skeleton[s]];
skeleton[s] = bone.SkinTransform * bone.AbsoluteTransform;
}


public void ComputeAbsoluteTransform()
{
Matrix transform =
Matrix.CreateScale(Scale * bindScale) *
Matrix.CreateFromQuaternion(Rotation) *
Matrix.CreateTranslation(Translation) *
BindTransform;

if (Parent != null)
{
// This bone has a parent bone
AbsoluteTransform = transform * Parent.AbsoluteTransform;
}
else
{ // The root bone
AbsoluteTransform = transform;
}
}

I would appreciate some direction in how I need to calculate the skeleton matrices given box physics objects in world space. =) I am having lots of trouble understanding the concept and step-by-step instructions on how to proceed, especially after just wrapping my head around animation skinning. Thank you so much, I'm sure I'll need to elaborate more on certain things.

- Mike
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Skinning and Ragdoll Physics.

Post by Norbo »

To animate the skeleton with physical bodies, one option would be to create something analogous to the vertex->bone weightmap, but for animation bone->physics entity relationships instead. Parenting an animation bone directly to a single physics entity, as opposed to blending contributions from multiple entities, will probably be fine.

An animation bone knows its relationship to its parent physics entity (local offset and rotation). You already have some of these set up- the spawning locations of the physics bones on transition. Not all animation bones need to spawn individual physics entities, but every animation bone must know its local offset/rotation to its parent entity. Those local transforms can be transformed by the entity's own WorldTransform to get the world location of the bone. That final transformation is then given to the skinning system as if an animation and transform tree had computed it and all the vertices follow.
stuff4mike
Posts: 7
Joined: Sat Jan 07, 2012 8:25 am

Re: Skinning and Ragdoll Physics.

Post by stuff4mike »

Thanks so much for the quick and helpful reply! I have read it over and it is starting to sink in. I am going to work on it some more tonight, so we'll see how things go. =)

Thanks again and I'll update if I have any issues.

- Mike
coimbra79
Posts: 33
Joined: Thu Dec 29, 2011 12:42 am

Re: Skinning and Ragdoll Physics.

Post by coimbra79 »

HI!
Im using this discussion, because its the nearest to my problem.
Infact: I need to simulate cloth by using model joints, so this is my way:

1-realized the cloth... a skinnedModel (from Maya), with a bindPose and an animation keyfame only
2-export it on my project by FBX format.
3-in my 'CLOTHClass' load it and retrieve all joint the cloth contains
4-for each of them add a little sphere using position of bindPose
5-finally create the bepuJoints (ballsocket) using the bindPose bone hierarchy
Lets RUN it!!

The result is: The bepu structure joint works fine (i have a debug joint viewer), but the cloth drawing is bad.
I understeand the issue due to matrix transportation from bepu joint structure to skinnedModel. The problem infact is that bepuJoints dont have a true matrix (or not?). In ballSocketJoint i cant use the matrix of ball, they are free to rotate in some axis...
Trying with createWorld im able to retrieve the forward vector of joint (J.nttA.pos-J.nttB.pos), but the UP...

I know when all is tried and nobody can help me only a man ll save me... SUPERNORBO!!
Veri thanks in adance
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Skinning and Ragdoll Physics.

Post by Norbo »

The joints themselves don't have a single proper 'orientation', so they won't be very useful. You could change the anchors of the joints such that the spheres' rotation is meaningful, but this could reduce stability and the rotations might jerk around more than you want.

Instead, it may be best to just derive the orientations from adjacent sphere positions. For example, if the spheres are arranged in a grid, you can subtract the positions of the sphere above and below for one axis, then subtract the positions of the sphere to the left and right for another axis. Take the cross product to get a third axis perpendicular to the first, take the cross product of the first and third axes to complete an orthogonal basis. (This is similar to computing vertex normals on a terrain; googling that may make things clearer.) Normalize the basis vectors to get an orthonormal basis. Use that orthonormal basis to create the orientation matrix.

A couple of implementation notes:
-An orthonormal basis is a rotation matrix if the determinant is 1. Watch out- it's easy to accidentally construct the basis such that the determinant is -1 by negating a vector or reversing a cross product. An orthonormal matrix with a determinant of -1 is a reflection matrix, so things will flip. If this happens, you can play the tried and true 'flip signs until it works' game... or I guess go back and be careful about it, but...
-When building the orientation matrix from the basis, it's easy to accidentally transpose the orientation. Transposing a rotation matrix is equivalent to inverting a rotation matrix. If you are getting the opposite rotation from what you expect, this is probably happening- just transpose the matrix.

The above works even when the cloth isn't a perfect grid, so long as you have connectivity to build the basis from.
coimbra79
Posts: 33
Joined: Thu Dec 29, 2011 12:42 am

Re: Skinning and Ragdoll Physics.

Post by coimbra79 »

Image

the image rapresents the skinnedModel i project in Maya to performs cloth... It seem poor of joints but in reality they'r enough for my target.
To conform them with yours words i must replace that structure with a grid min 2XallVerticalJoints?... This way the physic balls will stay unrotate respect their anchor, and could i use the sphere matrix instead to calculate joit orientations by formulas?
Thanks!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Skinning and Ragdoll Physics.

Post by Norbo »

While it is possible to generate some bases that would work for a simple chain even without a grid, for this sort of thing I would advise actually creating entities that represent the bones' extents.

So, rather than a tiny sphere at the position of the joint, have a box which extends from the head to the tail of the bone. Then, create constraints between the box-bones which model the desired behavior, like a BallSocketJoint with a soft TwistJoint, or maybe a soft NoRotationJoint if you want to model cloth that resists bending more. The graphics transforms could be taken from the entities; just note that the center of the entity should be at the midpoint of the head and tail, so some offsets are required.

(This same approach can work for cloth with a large surface area, too. Check out the SelfCollidingClothDemo for an example of a bunch of boxes connected with constraints to form a semicontinuous surface.)
coimbra79
Posts: 33
Joined: Thu Dec 29, 2011 12:42 am

Re: Skinning and Ragdoll Physics.

Post by coimbra79 »

HI!...
Please Helpme!

As i already show in the picture im working on rigged cloth. Im very near to solve it in all...
Only i need to link all joint parented with the main (all joint with hierarky == 0) with a rigid joint.
The result must be: if i drag or rotate the main joint all the directly linked joints 'll follow his matrix.

I need to link them with a joint type have any degrees of freedom, and let the ancored entities maintain the same distance.
What do you suggest me?
very very thanks in advance!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Skinning and Ragdoll Physics.

Post by Norbo »

A BallSocketJoint combined with a NoRotationJoint would constrain all 6 degrees of freedom. (The WeldJoint is a convenience wrapper over these two constraints.)
coimbra79
Posts: 33
Joined: Thu Dec 29, 2011 12:42 am

Re: Skinning and Ragdoll Physics.

Post by coimbra79 »

thanks Norbo it work fine infact!
The last to be perfect in my cloth simulation is the inertia... the current look like huggest object then i need. I know (reading other threads), i must scale the inertia by using inertiahelper...
but modifing parameter it dont seem change...
Ill do other tryes, but if u have a flying suggest 4 me ill be happy to take it.
very thanks again.

Ill show u soon what i performed about rigged cloth.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Skinning and Ragdoll Physics.

Post by Norbo »

Scaling the inertia will just change the rotational behavior. The effect is usually pretty subtle, so it's probably not the best place to tune.

But I'm not entirely sure how it currently behaves, or how you want it to behave. Here are some possibilities:
1) If it tends to move very slowly, it may be that gravity is weak relative to the size of the objects. Or, LinearDamping and AngularDamping may be set to really high values.
2) If the objects swing around wildly for a long time after the character has stopped, increasing the LinearDamping and AngularDamping of the entities may help keep things under control.
3) If the cloth is so heavy that it's pushing other big objects out of the way, decreasing the cloth's mass would help.
coimbra79
Posts: 33
Joined: Thu Dec 29, 2011 12:42 am

Re: Skinning and Ragdoll Physics.

Post by coimbra79 »

can the inertia scale be called in any time of my simulation? becouse it really dont change nothink
i move his value from 0.001f to 5f.

Im trying every thinks (about your list of possibles reasons), but the impression is the same in all cases...
the cloth seem to be huggest than his graphic rappresentation.
coimbra79
Posts: 33
Joined: Thu Dec 29, 2011 12:42 am

Re: Skinning and Ragdoll Physics.

Post by coimbra79 »

i write this line:

Code: Select all

BEPUphysics.CollisionShapes.ConvexShapes.InertiaHelper.InertiaTensorScale = 5f;
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Skinning and Ragdoll Physics.

Post by Norbo »

Changing the InertiaHelper.InertiaScale only affects entities constructed after it is set (and only if those entities are not given a specific inertia tensor).

You can also scale an individual entity's inertia using its LocalInertiaTensor(Inverse) properties.
Post Reply