I'm trying to animate a rigged object by code. Well, after loading the modell (I used Blender, then exported to .x format, if this is important) and setting the EJUOR_CONTROL Mode I tried to move one bone for testing. However the mesh doesn't change but the bone does change it's position (That's checked by printing the local position of the bone). Am I missing a function call? Please help if someone knows a possible solution.
Here's the code:
Code: Select all
class Graphic {
public:
Graphic(std::string mainobj, std::wstring title) {
device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(640, 480), 8, false, true); //Weitere spezialisierungen möglich
if (!device) throw "ERR_CREATE_DEVICE";
device->setWindowCaption(title.c_str());
videodriver = device->getVideoDriver();
smgr = device->getSceneManager();
mainobjNode = smgr->addAnimatedMeshSceneNode(smgr->getMesh(io::path(mainobj.c_str())));
smgr->addCameraSceneNode(0, core::vector3df(0, 0, -2), core::vector3df(0, 0, 0));
lamp = smgr->addLightSceneNode(0, core::vector3df(0, 1, -1), video::SColorf(0.3, 0.3, 0.1));
mainobjNode->setMaterialFlag(video::EMF_LIGHTING, true);
mainobjNode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
mainobjNode->setPosition(core::vector3df(0, -2.8, 1));
mainobjNode->setJointMode(scene::EJUOR_CONTROL);
smgr->setAmbientLight(video::SColorf(0.1, 0.1, 0.1));
image = device->getGUIEnvironment()->addImage(core::rect<s32>(0, 0, 320, 480), 0, 1, 0, false);
videodriver->beginScene(true, true, video::SColor(0, 0, 0, 0));
videodriver->endScene();
}
bool isRunning() {
return device->run();
}
void render() {
videodriver->beginScene(true, true, video::SColor(0, 0, 0, 0));
smgr->drawAll();
smgr->getGUIEnvironment()->drawAll();
videodriver->endScene();
}
void moveBone(std::string which, core::vector3df pos) {
mainobjNode->animateJoints();
mainobjNode->getJointNode(which.c_str())->setPosition(pos);
}
core::vector3df getBonePosition(std::string which) {
return mainobjNode->getJointNode(which.c_str())->getPosition();
}
private:
IrrlichtDevice *device;
scene::ISceneManager *smgr;
video::IVideoDriver *videodriver;
scene::IAnimatedMeshSceneNode *mainobjNode;
scene::ILightSceneNode *lamp;
gui::IGUIImage *image;
};
Code: Select all
int main() {
Graphic gcl("h1.x", L"Kugeltest");
unsigned long long st = 0;
while (gcl.isRunning()) {
gcl.render();
st++;
if (st % 300 == 0) {
std::cout << gcl.getBonePosition("Armature_Eyebrow1_L").X << " " << gcl.getBonePosition("Armature_Eyebrow1_L").Y
<< " " << gcl.getBonePosition("Armature_Eyebrow1_L").Z << std::endl;
gcl.moveBone("Armature_Eyebrow1_L", gcl.getBonePosition("Armature_Eyebrow1_L") + irr::core::vector3df(0.1, 0, 0));
}
}
return 0;
}