MD2 Animation Not Playing Correctly

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
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

MD2 Animation Not Playing Correctly

Post by AshmenGlue »

This is so much of a programming question rather than a modelling one. I've created a custom MD2 model and exported it. When I load it into my program. It seems to just playthrough all the animations available, and not just the STAND animation like it's supposed to. When I hit the run button, it jumps to the first frame of the run animation and pauses there.

I've looked at the model using MD2Viewer and the animations are FINE. I've only animated 12 frames even though the qc file states up to 200 frames. I'm not sure what is causing the animation errors on my model. Is there something extra that needs to be done?

This is my qc:

// Sample MD2 config, copy into export directory
$modelname faerie.md2
$origin 0.0 0.0 0.0

// sequences
$sequence stand 0 9
$sequence run 10 12
$sequence attack 16 25
$sequence paint1 26 32
$sequence jump 33 40
$sequence flip 41 50
$sequence salute 51 57
$sequence taunt 58 65
$sequence wave 66 70
$sequence point 90 130
$sequence crstnd 131 140
$sequence crwalk 141 150
$sequence crattak 151 160
$sequence crpain 161 165
$sequence crdeath 166 170
$sequence death1 171 180
$sequence death2 181 190
$sequence death3 191 200




I exported the model with the same name as in the qc. The thing that bugs me is that it shows up fine in MD2Viewer. The Stand and Run animations are there. But in-game the model just plays all the animations.
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post by dhenton9000 »

Irrlicht animation play back has to be told when to start and stop, otherwise default behavior is what you see. Its like a tape recorder, you have to wind it to the animation you want.

heres a code snippet I use to play an .X animation

Code: Select all



	personNode->setAnimationSpeed(25);
	personNode->setLoopMode(true);
	personNode->setFrameLoop(startAnimidx,stopAnimidx); 


look at the help file for setFrameLoop, and the MD2 object
for:

virtual bool irr::scene::IAnimatedMeshMD2::getFrameLoop ( const c8 * name,
s32 & outBegin,
s32 & outEnd,
s32 & outFps
) const [pure virtual]

hth
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

I know what you mean. The thing is, it works when I put like faerie.md2 or sydney.md2 in. It's this model. I'm not sure what exactly I have to do for the model to work in Irrlicht. As far as I know now, the MD2 model has it's animation names correct, but it just doesn't play correctly when loaded in Irrlicht.

EDIT: Also, I am using setMD2Animation.

EDIT2: I've uploaded the model to my website if anyone wants to try to see what's wrong.

http://www.samuelheng.com/faerie.md2

It's called faerie because I'm lazy to rename my source.
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

dhenton9000, I've tried your way of setting the FrameLoops. It doesn't work either. The result I get is still the model playing through all its animations.
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

Ashmen: what program are you using to make the model?
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

I used MilkShape3D. Modelled it, then added my own joints to the mesh, assigned them to vertices, and did some simple animations. Then I made the md2.qc and exported it as an MD2.
Guest

Post by Guest »

scene::IAnimatedMeshSceneNode* anmh = smgr->addAnimatedMeshSceneNode(
smgr->getMesh("Media\\horse.md2"));
scene::ISceneNodeAnimator* anim2 = smgr->createFollowSplineAnimator(device->getTimer()->getTime(),
points);

anmh->addAnimator(anim2);
anim2->drop();
anmh->setMaterialFlag(video::EMF_LIGHTING, false);
anmh->setFrameLoop(8, 96);
anmh->setAnimationSpeed(60);
anmh->setRotation(core::vector3df(0.0f,90.0f,0.0f));
anmh->setScale(core::vector3df(0.1750f,0.175f,0.1750f));
anmh->setMaterialTexture(0, driver->getTexture("Media\\horse.pcx"));



This code plays the first 12 frames of the horse animation
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

I don't think you understand. My code works with the md2 models included with irrlicht. There's wrong with this new model I made and I'm trying to find out why.
Guest

Post by Guest »

#include <stdio.h>
#include <wchar.h>
#include <irrlicht.h>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
bool IsStanding ;
scene::ISceneNode* node = 0;
IrrlichtDevice* device = 0;
int main()
{
device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480),32, false, false, false );
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
IsStanding = true; // change this value to change the animation frames!
scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(smgr->getMesh("faerie.md2"));
anms->setMaterialFlag(video::EMF_LIGHTING, false);
if(IsStanding)
anms->setFrameLoop(0, 72);
else
anms->setFrameLoop(80, 96);
anms->setAnimationSpeed(30);
anms->setRotation(core::vector3df(0,180.0f,0));
smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
device->getCursorControl()->setVisible(false);
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,113,113,133));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

Nono, my code WORKS. When I use the default faerie.md2 the CODE WORKS.

It's when I use my new model that the animation doesn't play.
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

Sorry dude, it was my bad.
I was using setMD2Animation(scene::EMAT_STAND); and RUN and whatsoever to call my animations. Turns out it only works with the default models in Irrlicht. When I used setMD2Animation("stand"); it works perfect. Also, I've found out through some searching on the forums that if I want to use setFrameLoop(begin, end), I have to multiply the frame numbers by 8.

Can anyone tell me if I need to do the same for getFrameNr()? As in if I want to detect if a node's animation is at frame 10 do I need to write:

if (node->getFrameNr() == 80) {

//blah

}

?
michael520
Posts: 230
Joined: Mon Oct 10, 2005 2:24 am

Post by michael520 »

AshmenGlue wrote:Nono, my code WORKS. When I use the default faerie.md2 the CODE WORKS.

It's when I use my new model that the animation doesn't play.

Hello, my situation is just the same as yours!
by the way, what export program do you use?
And do you have any link about how to make md2 models?
Thanks!
Post Reply