How can I change parts of an animated mesh?

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
Smuel
Posts: 14
Joined: Fri Dec 08, 2006 10:50 am

How can I change parts of an animated mesh?

Post by Smuel »

Hi everyone.

I would like to be able to have animated characters in my game with body parts that I can change. For example, the hero would start off with bare feet and then when he finds a pair of cool boots with spikes on, the feet/ankle/lower-leg part of the mesh would get swapped out from the "bare feet" one to the "boots with spikes" one, and the texture along with it. I was not able to find any tutorial or sample code that showed how to do this. Is there a well known way to do this already in the Irrlicht engine, or am I treading new ground here?

I've been thinking about how it might be done, and the body-part changes would not happen very often, so I think it would be feasible from a computation standpoint to rebuild the mesh from constituent parts every time something changed, but I couldn't see how to do that with Irrlicht either, and I don't know if the animation system would cope with that method.

If it is possible I would also like some recommendations for a (free) 3D model editor / animation package that I could use to create the models and movements for it.

Thanks in advance...
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

You shouldn't try to change the model itself, but have a model without feet and then swap the model of the feet depending on what it is wearing. Another way of doing it would be to have bare feet on the main model and then when the player equips shoes place a shoe model over top. You should be able to attach these models to your bones.

As far as free 3D modelling for free most people like Blender.
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I guess it's even easier to only attach meshes to bones. That way the mesh is moved along with the feet and can be easily attached/removed.
Smuel
Posts: 14
Joined: Fri Dec 08, 2006 10:50 am

Post by Smuel »

So would it be possible to have a collection of meshes all attached to one skeleton? i.e. separate meshes for the torso, head, hands, and feet, but all animated as one? What would happen at the joints? Obviously I would make sure that the joins matched up in the modeller, but then when it is animated the vertices would actually be in different meshes, so wouldn't I end up with a 1-pixel line of empty space between them sometimes? I know that the real answer to all of this is "try it and see" but I'd rather someone told me "yes this is possible because I've done it" before I spend time trying to do it some way that has a known problem. Has anyone ever done this sort of thing with Irrlicht before?

Also, I thought about having the boots model just drawn over the top of the feet model, but I was worried that parts of the feet would show through - I mean the triangles in each model would be pretty close to each other, so the z-buffer (or whatever hidden-face removal algorithm Irrlicht uses) might not get it quite right. Perhaps you could assure me that this wouldn't be a problem? :)
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

There is no animation for the attached parts, they would only move in sync with the main mesh. And you might have z-buffer problems, that's almost always possible.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Why not create your original model without feet at all. Then you attach a node to the ankle joint, or maybe a joint that is at the center of where each foot would be. If you want the user to see bare feet, you attach a mesh scene node to those joints. The node would have a mesh that looks like a foot. If you want tennis shoes, you do the same but using a different mesh.

Travis
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

There is no animation for the attached parts, they would only move in sync with the main mesh.
I don't understand why this would be true. If you attach an animated mesh scene node to the joint of another animated mesh, the child node should move around as the joint moves, and you should be able to play an animation on the child node seperately.

This code works as expected. The animation state for the feet/hand nodes are obviously not connected to the animation state for the main model, but they are most definitely animated.

Code: Select all

  // beware: the dwarf has hands and feet that look like faeries!
  scene::IAnimatedMeshSceneNode* dwarf = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/dwarf.x")); 
  if (dwarf) 
  { 
    dwarf->setAnimationSpeed(2); 
    dwarf->setMaterialFlag(video::EMF_LIGHTING, false); 

    const char* joint_names[] = 
    { 
      "lwrist", 
      "rwrist", 
      "lankle", 
      "rankle", 
      0 
    }; 

    for (const char** joint_name = joint_names; *joint_name; ++joint_name) 
    { 
      scene::ISceneNode* joint = dwarf->getXJointNode(*joint_name); 
      if (joint) 
      { 
        scene::ISceneNode* child = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/faerie.md2"), joint); 
        child->setMaterialTexture(0, driver->getTexture("../../media/faerie2.bmp")); 
        child->setScale(core::vector3df(.5f, .3f, .5f)); 
        child->setMaterialFlag(video::EMF_LIGHTING, false); 
      } 
    } 
  } 
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, separate animations on child nodes work. But the previous posting sounded as if he wanted to define a controlling animation for the main node and the children. Just as the MD3/MD5 nodes. But that needs special handling inside special scene nodes.
Smuel
Posts: 14
Joined: Fri Dec 08, 2006 10:50 am

Post by Smuel »

Ah, I was a bit lost for a while there, but now I think understand what you're talking about. You're saying I could have a single animation with the component body-part meshes all attached to it, or I could have separate animations to go with each body part, the separate animations being attached to the main one.

Presumably having a separate animation for the lower legs makes it easier to make the character tap his foot independently of what his arms are doing, but it sounds like it would make it harder to do full-body movements, e.g. when he was running I would need to have "running body" and "running leg" animations proceeding in sync with each other. Is this as easy to do as vitek's code sample makes it look? My concerns are that creating the two animations might be more difficult in the editor (could I create it as one and then just split it into two files when saving?), and also hybrid's last comments "Just as the MD3/MD5 nodes. But that needs special handling inside special scene nodes." which I didn't really understand.
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I think you got it. If you have separate nodes for upper and lower part you have to keep them in sync manually. The md3/md5 meshes have this automatically done, but there is no proper support for those formats in Irrlicht, yet. However, Luke's new animation system might also help, but it's also under development.
So right now you can either choose to make one main character and add (animated) quipment to it or you add the parts together and enforce the synchronization on your own. If you develop the animations carefully it shoudl be quite easy to sync them. Just be careful that you don't create jumps in the animation and that you start the animations at the same frames together.
Smuel
Posts: 14
Joined: Fri Dec 08, 2006 10:50 am

Post by Smuel »

Great - thanks for the advice, guys.

I'll let you know how it turns out. It might be a while though... :)
Post Reply