Skeletal Animation (EJUOR_CONTROL)

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.
Post Reply
thenamename
Posts: 6
Joined: Thu Jan 12, 2017 6:51 pm

Skeletal Animation (EJUOR_CONTROL)

Post by thenamename »

Hello
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 :roll: (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;
};
and the main Function (just for testing)

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;
}
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Skeletal Animation (EJUOR_CONTROL)

Post by CuteAlien »

OK, no guarantees as I'm also not super familiar with animation code. But from a quick look at sources I think the updates from joints are done in OnAnimate() and on render() so you have to call either of those.

(I'm not sure why it's done twice - or even more often as render() can be called in several render passes. There seems to be some early out to prevent double-calculations for same frame for usual animations but not for EJUOR_CONTROL as far as I can see it. Those are not that expensive, but still looks strange - will have to check that some time).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
thenamename
Posts: 6
Joined: Thu Jan 12, 2017 6:51 pm

Re: Skeletal Animation (EJUOR_CONTROL)

Post by thenamename »

Ok thanks for your response but that wasn't the problem I found the solution now. The Code is ok - it's working on an other testobject, so I've just made an error when exporting
the Object (Maybe I forgot to activate with skinned weights)
Post Reply