Moving Joints in Skinned Mesh
Moving Joints in Skinned Mesh
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
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
I did not show any code, simply becasue in my first message I added a link where one can see the code I used.B@z wrote:lol, that was irony xD
you havent show us nothing, just asked whats wrong, how should we answer?
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.
try
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
Code: Select all
for (int i = 0; i < node->getJointCount(); i++)
{
IBoneSceneNode* joint = node->getJointNode(i);
}
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
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
===========================
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
===========================

