I did a search for IAnimatedMeshX and .x file

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
andy0482
Posts: 23
Joined: Mon Sep 13, 2004 6:22 pm

I did a search for IAnimatedMeshX and .x file

Post by andy0482 »

I did a search for IAnimatedMeshX and .x file and I found somewhere that someone else was trying to animate an .x file. I tried to use the function setMD2Animation and it works fine. But now I have two questions.

1. How can I get the animation to loop? If I could tell when the animation was over then I could set it to the first frame if I knew how to get that. A nice little code block would be nice.

2. It does seem strange not to use the IAnimatedMeshX member functions. Does anyone have any code on how to use the IAnimatedMeshX class?

Also once again I am going to sleep. :( Its past 2am and I have a Calc 2 Exam in the morning. Wish me luck.

Thanks again
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

setMD2Animation is exclusively for .md2 files (hence the MD2 in the name).
Do u want looping behavior or non-looping behavior? If all you want is looped animation then IAnimatedMeshSceneNode::setFrameLoop(in the API docs). If you don't want things to loop it's a little more difficult. I made a mod that allowed you to set the animation as non-looping. See the FAQ forum, though you'll prob need search as the thread is a bit old. madinitaly also made a modification that's a bit less powerful in some respects than mine, but is more straight-forward to use and allows easily chained animations. See his .md3 loader thread in FAQ.

Using IAnimatedMeshX member functions affects all nodes with that mesh (though scene manager functions could be modified so each new node gets a new mesh) and also requires that you have a pointer to the mesh, not just the node.
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
andy0482
Posts: 23
Joined: Mon Sep 13, 2004 6:22 pm

thanks but

Post by andy0482 »

The reason I used the MD2 function was because of a prior post where someone showed a work around using it. But thanks I should have stated that more clearly.

Do you or anyone else have a sample code bit to show me how to load a .x file and get the pointer to the IAnimatedMeshX?

Thanks
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Code: Select all

IAnimatedMesh *mesh=smgr->getMesh("filename.x");
IAnimatedMeshX *xmesh=dynamic_cast<IAnimatedMeshX*>(mesh);
if(!xmesh)
{
   cout<<"this is not a .x mesh\n";
}
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Ryoga2k
Posts: 21
Joined: Mon May 03, 2004 6:59 pm
Location: Asturias, Spain

Post by Ryoga2k »

I was the one originally (I think) interested in that question :P
The code to load an .X file is quite simple:

Code: Select all

//Load the X file
IAnimatedMesh *pMesh = pSceneMng->getMesh("my_model.x");
if (pMesh == NULL)
{
  //error
}

// Add the model to the scene
IAnimatedMeshSceneNode *pNode = pSceneMng->addAnimatedMeshSceneNode(pMesh,parent,id);
if (pNode == NULL)
{
  //error
}
So you only have to keep both pointers to pMesh and pNode. You can use the same pMesh to create several identic actors (characters, objects, etc...) in your scene. When you enable an animation using the pMesh, all the actors related to that mesh show the same animation. Then you can use the pNode of each actor to displace them or some other actions.
The problem I had was that I only kept the pointer to the SceneNodes, and I asked for a way to obtain the pointer to the Mesh :shock:
Anyway, you can animate your X models without the IAnimatedMesh, using the setFrameLoop and setAnimationSpeed methods of the IAnimatedMeshSceneNode class.
"There's always a way, if desire meets courage"
Conan of Cimmeria
andy0482
Posts: 23
Joined: Mon Sep 13, 2004 6:22 pm

Now an error

Post by andy0482 »

Code: Select all

scene::IAnimatedMesh* iZombieMesh = smgr->getMesh("Zombie.x");
scene::IAnimatedMeshX *xmesh=dynamic_cast<scene::IAnimatedMeshX*>(iZombieMesh);	
if(!xmesh) 
{ 
cout<<"this is not a .x mesh\n"; 
}
Now when I get to this code section I get an error that says abnormal program termination.

Also Ryoga2k could you send me a more complete sample of what you did to get your .x file loaded and animated? Thanks
Ryoga2k
Posts: 21
Joined: Mon May 03, 2004 6:59 pm
Location: Asturias, Spain

Post by Ryoga2k »

I think a correct way to do it could be:

Code: Select all

scene::IAnimatedMesh* iZombieMesh = smgr->getMesh("Zombie.x"); 
scene::IAnimatedMeshX *xmesh;
if (xmesh = dynamic_cast<scene::IAnimatedMeshX*>(iZombieMesh))    
{ 
  // ... 
}
else
{
  cout<<"this is not a .x mesh\n";
}
"There's always a way, if desire meets courage"
Conan of Cimmeria
andy0482
Posts: 23
Joined: Mon Sep 13, 2004 6:22 pm

Still get error

Post by andy0482 »

I still get an error that gives me "abnormal program termination"

I tried DX and OpenGL but both have this issue. Does anyone have a code bit that shows how to load the .x file and then set the animation by calling the animation name and not the the key frames?

Thanks
andy0482
Posts: 23
Joined: Mon Sep 13, 2004 6:22 pm

OK Fixed one problem and now another :)

Post by andy0482 »

OK I took the code above and had the crash issue. So I did a static cast and that worked.

Code: Select all

scene::IAnimatedMesh* iZombieMesh = smgr->getMesh("Zombie.x"); 
IAnimatedMeshX *xmesh = static_cast<IAnimatedMeshX*>(iZombieMesh);
Now my problem is how to I get xmesh into the scene manager?

This is the code I was using when I was using the IAnimatedMesh

Code: Select all

scene::IAnimatedMeshSceneNode* iZombieNode = smgr->addAnimatedMeshSceneNode(iZombieMesh, 0, -1, core::vector3df(0, 0, 0), core::vector3df(0, 0, 0), core::vector3df(200, 200, 200)); 

iZombieNode->setMD2Animation("Idle");
iZombieNode->setAnimationSpeed(1000);

iZombieNode->setMaterialFlag(EMF_LIGHTING, false);
What call do I need to make to the scene manager? I tried to change the call to addMeshSceneNode and passing the mesh from xmesh but then all I get is a static mesh when I call xmesh->setCurrentAnimation() function.

Any Help

Thanks as always
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

static_cast? That's odd. A static cast shouldn't work for upcasting as a static_cast is supposed to work only with safe casts. Upcasting from a base class is not a safe cast. I'm not sure why your compiler allows that. Maybe I'm missing something?
The reason I used the MD2 function was because of a prior post where someone showed a work around using it.
above you say that, and you still seem to be using the md2 function. I cannot help you with that part, because as far as I know the md2 function works only with md2 files.


Now my problem is how to I get xmesh into the scene manager?
smgr->addAnimatedMeshSceneNode(iZombieMesh,etc) should work. Your code there appears correct.

You can set the frame loop with IAnimatedMeshSceneNode::SetFrameLoop
Which animation (of however many seperate animation there are in the .x file) is determined by xmesh->setAnimation (or maybe it's setCurrentAnimation, but it's something like that)
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Post Reply