Moving Joints in Skinned Mesh

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.
andreasky
Posts: 30
Joined: Tue Jun 09, 2009 2:36 pm

Moving Joints in Skinned Mesh

Post by andreasky »

Hi,

after looking at this demo:

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=32709

I created a 3D model with joints wthout animation. Then, I exported the model as ".X" file and loaded into Irrlicht. I added code to try to move joints through Irrlicht API. However, when I ran the program, the joints did not animate.

Does anyone know what I made wrong?

Thank you in adavance.

Bye-bye,

Andrea
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Yes you got the if statement in line 238 wrong...

Without code we can't tell you if you did anything wrong.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Maybe wrong Joint Mode? Read the Wiki page on the new animation system.
andreasky
Posts: 30
Joined: Tue Jun 09, 2009 2:36 pm

Post by andreasky »

hybrid wrote:Maybe wrong Joint Mode? Read the Wiki page on the new animation system.
I tried with "EJUOR_CONTROL" , as follows:

CharNode->setJointMode(EJUOR_CONTROL);

THis shpuld be used to control nodel positions. Is it right?
andreasky
Posts: 30
Joined: Tue Jun 09, 2009 2:36 pm

Post by andreasky »

Sylence wrote:Yes you got the if statement in line 238 wrong...

Without code we can't tell you if you did anything wrong.
Please, could yu tell me how to change th ewrong if-statement in line 238?

Thank you
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

lol, that was irony xD
you havent show us nothing, just asked whats wrong, how should we answer? :D
Image
Image
andreasky
Posts: 30
Joined: Tue Jun 09, 2009 2:36 pm

Post by andreasky »

B@z wrote:lol, that was irony xD
you havent show us nothing, just asked whats wrong, how should we answer? :D
I did not show any code, simply becasue in my first message I added a link where one can see the code I used.

However, here it is:


======================================
// Irrlicht
#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif


// MAIN

int main()
{
// create Irrlicht device
IrrlichtDevice* device = createDevice( video::EDT_OPENGL, dimension2d<s32>(800, 600), 32,
false, false);

if (device == 0)
return 1; // could not create selected driver.

video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();

// create camera
smgr->addCameraSceneNodeFPS(0, 100.0f, .1f);

// Load Char
IAnimatedMesh* CharMesh = smgr->getMesh("../../media/dwarf.X");
if (!CharMesh) return 1;

IAnimatedMeshSceneNode* CharNode = smgr->addAnimatedMeshSceneNode( CharMesh );
if (!CharNode) return 1;

// Initilise
CharNode->setMaterialFlag(EMF_LIGHTING, false);
CharNode->setAnimationSpeed(10);

// Prepare for Joint Control
CharNode->setJointMode(EJUOR_CONTROL); //To write positions to the mesh on render



int lastFPS = -1;


f32 headRotation = 0;
f32 headPosition = 0;


while(device->run())
{

// Animate character manually
CharNode->animateJoints();


// Get the Joint you want to MANIPULATE, and its Parent
IBoneSceneNode* thisJoint = CharNode->getJointNode("head");

if( thisJoint )
{
ISceneNode* parentJoint = thisJoint->getParent();

if( parentJoint )
{
// Get the default (animated) Joint's position and rotation
vector3df jointPos = thisJoint->getAbsolutePosition();
vector3df jointRot = thisJoint->getAbsoluteTransformation().getRotationDegrees();

// Get the absolute INVERSE Transformation matrix of the parent
matrix4 iparentTransform = parentJoint->getAbsoluteTransformation();
iparentTransform.makeInverse();

// Set the Absolute Position or Rotation of the Joint without fear!
vector3df newJointPos = jointPos + vector3df( 0, 1+(sin(headPosition)*2), 0 );
vector3df newJointRot = vector3df( 0, headRotation, 0 );

// Transform the Position by the Parent's Inverse matrix before applying it
iparentTransform.transformVect( newJointPos );

// APPLY
thisJoint->setPosition( newJointPos );
thisJoint->setRotation( newJointRot );
}
}


// funny
headPosition += 0.01f;
if( headPosition > 2*PI ){ headPosition -= 0; }

headRotation += 0.5f;
if( headRotation > 360 ){ headRotation -= 360; }


// do Irrlicht stuff

driver->beginScene(true, true, video::SColor(255,113,113,133));

smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)

driver->endScene();

int fps = driver->getFPS();

if (lastFPS != fps)
{
core::stringw tmp(L"fmx's funny dwarf head joint manipulation demo! [");
tmp += driver->getName();
tmp += L"] fps: ";
tmp += fps;

device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
}


// show cursor
// device->getCursorControl()->setVisible(true);



device->drop();

return 0;
}
======================================

My problem is: I would like to use Irrlicht API to control joints' position and rotation. I found this sample and it works fine.
For this reason, I created a simple 3D model with some joints and exported it as ".X" file. In the 3D modelling software, I called a node "head". I did not create any animation, since I wanted to control it via Irrlicht API, as in the sample.

However, after buildng the code, the joint position and rotation do not change.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Did you check that you actuall got a skeleton in your file?
andreasky
Posts: 30
Joined: Tue Jun 09, 2009 2:36 pm

Post by andreasky »

Do you mean in Irrlicht?
In case, please, could you tell me how to do that?
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

if irrlicht didnt find the joint it should write to the console.

but you have functions like IAnimatedMeshSceneNode::getJointCount and getJointNode( ID)

just make a for loop, print out all the joints to the console, and you will see if you have that bone or not :P
Image
Image
andreasky
Posts: 30
Joined: Tue Jun 09, 2009 2:36 pm

Post by andreasky »

I tried with IAnimatedMeshSceneNode::getJointCount and getJointNode( ID).

I do not know why, but IAnimatedMeshSceneNode::getJointCount returns me one joint more than the right value. For example if the actual joint number is "15", IAnimatedMeshSceneNode::getJointCount returns "16".
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

try

Code: Select all

for (int i = 0; i < node->getJointCount(); i++)
{
   IBoneSceneNode* joint = node->getJointNode(i);
}
and write out the name, maybe there is a function for getName?
anyway, just write out the names, and check if there is a joint called "head"
(maybe there is some problem with naming, or when exported, it renamed the joint or something)

and the plus one, i dunno why. printing out the names should answer this question too :P
Image
Image
andreasky
Posts: 30
Joined: Tue Jun 09, 2009 2:36 pm

Post by andreasky »

Do you know how to get a "getName" function for skeletal joints?
andreasky
Posts: 30
Joined: Tue Jun 09, 2009 2:36 pm

Post by andreasky »

Hi,

I found out why "getJointCount()" retrieves one joint more than the actual number: it retrieves also the shape node for the 3D model I created.

I used "IBoneSceneNode::getBoneName()" function to get joints name.

Here is the result of my example:


===========================
The number of Joint is: 21

The name of the bone is: pCube1
The name of the bone is: joint1
The name of the bone is: joint2
The name of the bone is: joint3
The name of the bone is: joint4
The name of the bone is: joint5
The name of the bone is: joint6
The name of the bone is: joint7
The name of the bone is: joint8
The name of the bone is: joint9
The name of the bone is: joint15
The name of the bone is: joint16
The name of the bone is: joint17
The name of the bone is: joint10
The name of the bone is: joint11
The name of the bone is: joint12
The name of the bone is: joint13
The name of the bone is: joint14
The name of the bone is: joint18
The name of the bone is: joint19
The name of the bone is: joint20
===========================
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

so, actually you dont have a bone called "head"
maybe it had been removed when exported, or you just forgot to set it up.
anyway, search for that head bone, get its real name, and try with that :D
Image
Image
Post Reply