Sign in to follow this  
CodaKiller

Has anyone ever done ragdolls with a soft skinning shader?

Recommended Posts

Has anyone ever done ragdolls with a soft skinning shader? I'm desperate, I'll take any information I can get, please help me! Anyone who has done this in any form please post source, I don't care what language you wrote the code in, I'll figure it out and I don't care what Physics API or Graphics API you used. I've been having a problem getting my ragdolls to work with my soft skinning shader, I've been working on it for 2 weeks with little to no success and it seems so simple yet I can't figure it out! I basically need to convert the world matrices that I get from the physics engine in to local matrices that would effect the vertices in the correct way. I've not just been working on this part time I've been working on it for 10 hours a day, every day and some times longer without a break! There is only so much I can take, help me please!!!

Share this post


Link to post
Share on other sites

int bone_parents[NUM_BONES] = {-1, 0, 0, 1 ..... };
Matrix world_tms[NUM_BONES] = { /* from physics */ };
Matrix local_tms[NUM_BONES] = {};

for(int i=0;i<NUM_BONES;++i)
{
if(bone_parents[i]==-1)
{
local_tms[i] = world_tms[i];
}
else
{
Matrix parent_inverse = world_tms[ bone_parents[i] ];
parent_inverse.Invert();
local_tms[i] = world_tms[i] * parent_inverse;
}
}

Share this post


Link to post
Share on other sites

/**
* Updates the world transforms for this bone.
*/

void updateWorldVectors(){
if (parent != null){
// worldRot = localRot * parentWorldRot
worldRot = parent.worldRot.mult(localRot);

// worldPos = parentWorldPos + (parentWorldRot * localPos)
worldPos = parent.worldRot.mult(localPos);
worldPos.addLocal(parent.worldPos);
}else{
worldRot.set(localRot);
worldPos.set(localPos);
}
}



This computes the worldBindInverse transforms

/**
* Saves the current bone state as it's binding pose, including it's children.
*/

void setBindingPose(){
initialPos.set(localPos);
initialRot.set(localRot);

// Save inverse derived position/scale/orientation, used for calculate offset transform later
worldBindInversePos.set(worldPos);
worldBindInversePos.negateLocal();

worldBindInverseRot.set(worldRot);
worldBindInverseRot.inverseLocal();

for (Bone b : children)
b.setBindingPose();
}




And this computes the matrix you should multiply your verticies by in the shader.

/**
* Stores the skinning transform in the specified Matrix4f.
* The skinning transform applies the animation of the bone to a vertex.
* @param m
*/

void getOffsetTransform(Matrix4f m){
Quaternion rotate = worldRot.mult(worldBindInverseRot);
Vector3f translate = worldPos.add(rotate.mult(worldBindInversePos));

m.loadIdentity();
m.setTranslation(translate);
m.setRotationQuaternion(rotate);
}


(Full source: http://code.google.com/p/radakan/source/browse/trunk/ogreloader/src/com/radakan/jme/mxml/anim/Bone.java)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this