Skinned Mesh, (Global) Bone Transformation

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

Skinned Mesh, (Global) Bone Transformation

Postby Max Power » Wed Mar 14, 2012 10:54 am

Hi, I have been using Irrlicht (along with PhysX) for over a year now, but only the most basic features. Now I want to implement skinned meshes and ragdolls into my simulation. The first thing i want to do is create a working ragdoll using a .x-mesh that I originally exported from MakeHuman, imported into blender, rotated (both mesh and armature) to match Y = up, Z = forward and finally exported as .x for a right-handed CS.

The first step is to allow bones to move independently from the parent in the global reference frame, so I can attach each of them to a PhysX-actor.
For applying transformations from PhysX-actors to Irrlicht-nodes I call this on every frame:

cpp Code: Select all
void applyPose (const PxRigidActor *fromPx, ISceneNode *toIrr)
{
    PxTransform posePx = fromPx->getGlobalPose();
    matrix4 matIrr = quaternion(posePx.q.x,posePx.q.y,posePx.q.z,posePx.q.w).makeInverse().getMatrix();
    matIrr.setTranslation(vector3df(posePx.p.x,posePx.p.y,posePx.p.z));
    if (toIrr->getParent() != gScene->getRootSceneNode())// this would work with rootSceneNode as parent as well
    {
        matrix4 pTrans;
        toIrr->getParent()->getAbsoluteTransformation().getInverse(pTrans);
        matIrr = pTrans*matIrr;
    }
    toIrr->setPosition(matIrr.getTranslation());
    vector3df rot = matIrr.getRotationDegrees();
    toIrr->setRotation(rot);
    toIrr->updateAbsolutePosition();
}


... and it seems to work fine with nodes I manually "parented" - they move with their attached actor like they don't have a parent-node at all.

When I try the same with BoneSceneNodes I get weird behaviour and Axes don't seem to match, even though the whole .x-mesh orientation is as it should be. I set JointMode to EJUOR_CONTROL, but bones don't really move independently. I can't help thinking the problem is somehow related to the armature (and maybe the way I aligned it before export?...), but I don't know what to do... Any help?
Max Power
 
Posts: 23
Joined: Wed Mar 14, 2012 10:09 am

Re: Skinned Mesh, (Global) Bone Transformation

Postby Max Power » Thu Mar 22, 2012 9:53 am

anybody?...

maybe someone has a working example of how to directly position BoneNodes in global space? i guess that might help me.
Max Power
 
Posts: 23
Joined: Wed Mar 14, 2012 10:09 am

Re: Skinned Mesh, (Global) Bone Transformation

Postby Nadro » Thu Mar 22, 2012 10:45 pm

Hi, You can directly set a bone position in this way (code isn't fully optimized):
cpp Code: Select all
IBoneSceneNode* Bone = Node->getJointNode("Your_Bone");
 
ISceneNode* tempNode = Bone;
std::vector<ISceneNode*> Parents;
 
while(Node != tempNode)
{
    tempNode = tempNode->getParent();
    Parents.push_back(tempNode);
}
 
for(int i = Parents.size() - 1; i >= 0; --i)
    Parents[i]->updateAbsolutePosition();
 
Parents.clear();
 
if(Bone)
{
    matrix4 ParentTransform = Bone->getParent()->getAbsoluteTransformation();
    ParentTransform.makeInverse();
 
    vector3df Position = Your_Position;
 
    ParentTransform.transformVect(Position);
 
    Bone->setPosition(Position);
}

I hope this helps :)
NBK Game Studio - Official Site:
http://www.nbkgamestudio.pl/
Nadro
 
Posts: 1000
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Skinned Mesh, (Global) Bone Transformation

Postby Max Power » Fri Mar 23, 2012 8:45 am

Thanks a lot, after updating all the parent-nodes' transformations from last to first it works as it should!
That means many update-calls though, if I do the same with 10+ bones per ragdoll. Maybe I could optimize by trying to avoid duplicate calls for shared parents.

The only thing that still irritates me is that bone-forward-directions point to the back of the mesh, as if z-axis was reversed. That's not really a problem though, at least not yet - and maybe that's just a "feature" of the mesh/armature I am using.

Thanks again!
Max Power
 
Posts: 23
Joined: Wed Mar 14, 2012 10:09 am

Re: Skinned Mesh, (Global) Bone Transformation

Postby Max Power » Fri Mar 23, 2012 12:23 pm

bit off-topic, but: can I switch visibility of individual bones somehow to replace them with attached meshes for clothing etc. or is it necessary to split the node into different parts(=nodes) for that and attach them to a "meshless" skeleton? If so, what about the border regions, where polygones belong to vertices of different adjacent bones? How would I keep those?
Max Power
 
Posts: 23
Joined: Wed Mar 14, 2012 10:09 am

Re: Skinned Mesh, (Global) Bone Transformation

Postby Nadro » Sat Mar 24, 2012 1:55 pm

You have to use different nodes for each character element in Your case.
NBK Game Studio - Official Site:
http://www.nbkgamestudio.pl/
Nadro
 
Posts: 1000
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest