• Advertisement
Sign in to follow this  

Skeletal Animation With Attachments (And Clothing)

This topic is 4703 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Skeletal Animation With Attachments Hello developers, For the last two weeks, I have been looking though books, searching the net, reading forums, and still have found nothing useful. I have even queried this form a few times with specific questions that have all received ridiculous, poor, or just plain arrogant responses. Responses along the lines of "It's easy", "Just google", and "No, do it this way." are not appreciated or helpful in the least bit. It's not easy, I have googled, and I don't want to hack it together because you think it's "easier". I apologize for the harshness of this little intro, but I'm sure many of you probably feel my frustrations. Anyway, I'm trying to learn about skeletal animation and item attachments. It might BE easy, but I have no idea where to start, and "skeletal animation" tutorials are not what I want. I am looking for someone to discuss attachments and model file type pros and cons and loading of the items and attaching them to points on the skeleton. Yes I know there are lots of skeletal animation tutorials, but once the guy is walking in a file format that is usually quite practically useless, I'm lost. Is there a tutorial about attaching two spheres to a cube so that when I move the cube around in its animation frames the spheres stay attached? How do "professionals" who know all these things learn it? There must be something out there. Does anyone here even know how to do such things? I know there are not many games that implement it, and I assume it is due to the difficulty. If anyone even knows of a book or anything that would go over these more advanced skeletal concepts, or is willing to help with creating a demo I would be MOST grateful. I usually program in C# but anything in C++ is fine as well, and I'm using DirectX. One of the biggest problems with doing skeletal animations for me is handling file formats. I can load a md2 consistently, but I've had little to no luck with other formats, and obviously md2s are rather useless for my current interests. So here's my summary of the think I'd like to know. 1. Model file type pros and cons (bones, animations, attachment points) 2. Converting to .x where to find converters, where to find and how to use loaders 3. Swapable parts (Clothing, weapons) 4. Detachable limbs? (removing bones, probably similar to swapable parts) Remember, getting to a point where I can load a single bone cube and attach two spheres would greatly brighten my day. Thank you in advance EDIT: Title change - GeekPlusPlus [Edited by - GeekPlusPlus on June 1, 2005 4:39:14 AM]

Share this post


Link to post
Share on other sites
Advertisement
Consider Half-Life 1's approach.

Each model has a number of attachment points defined. These are bone-relative positions, so as the bones move, the attachment points move too.

When rendering, you first use the current state of the bones to figure out where your attachment points are in worldspace (by applying the transforms from root bone down to the bone the point is attached to).

You then match that position to a key point on the attached model (e.g. the origin), by translating/orienting the attached model to match the attachment point.

Once you've got that, things like swappable parts should be obvious - use the same attachment point on the parent model, but different child models - though detachable limbs is a little harder (because you usually have to patch up the mesh a bit so as not to leave a hole). As far as file formats go, you can get it working by just providing a second file along with each md2 (.attach, maybe?) which contains human-readable bone indices + position for each attachment point.

Share this post


Link to post
Share on other sites
Hey GeekPlusPlus, I am after the same thing as you are, swapping body parts of a mesh etc... I just posted a new thread before reading urs... if you've found some answers please notify me here as well, thx in advance. I will do the same.

I'm not too familiar with attaching parts to a in the program, but to my understanding, the mesh itself will have to have some dummy frames defined, so when u load a mesh hierarchy (for x files), the frame will be there for u to use.

Share this post


Link to post
Share on other sites
I've just finished implementing my MD3 loader for my game engine and since I was after exactly what you after, it certainly gave me an introduction to skeletal animation (though some argue MD3 is not true skeleton animated).

The thing is, before I did this I knew how skeletal animation worked simply by understanding transformations and a hierarchy of matrices which I'm assuming you should know before attempting this.

To have two spheres follow a ball around its a matter of simply setting the cubes transformation then drawing its children whos transformations are their own combined with its parent (the cube) so that when the cube moves or rotates, the transformation of the spheres also move along with it.

I suggest implementing MD3 for a started. It shows how you attatch models at 'tag' points and interpolating key-frames of animation using quaternions which is all what you need to be implementing skeleton animation.
I can point you to links if you want to do it and even provide code if you ask.

Share this post


Link to post
Share on other sites
MeshMan:
I agree that MD3 could be a start for learning more about character animation, but as you say it's not really skeletal animation - in its best form (with interpolation betweeen key frames) it's more like a "mesh morphing" technique IMO.

GeekPlusPlus:
You're asking about a lot of different topics in your post and I don't have time to answer them all so I'll focus on the core question of attachment points and leave the other questions for yourself to figure out or for other people to answer :)

Anyway, attachments are certainly not trivial - but once you got a nice skeletal animation system up and running it's not that hard either, so don't give up!

You can think of a complete skeletal animation system as consisting of two parts

1) Animation: This part animates a hierachy of bones that shapes your "skeleton". Each bone is modelled as a kind of "tripod" or "basis" and consists of a *position* and an *orientation*. Combined, a bone can be represented as a 4x4 matrix - just like a world matrix in your rendering system.

2) Skinning: This part maps each vertex in your model to a bone (or more, if you're doing weighted skinning). Before rendering the mesh you apply to each vertex the corresponding bone. This sets up the pose of your character.

Lets assume that you have a working skeletal animation system up and running and wants to attach a gun to the hand of your character. What do you need to render the gun? You need a world matrix for it that will place the model at the correct position and orientation based on the animation of the character.

But that's really just the "hand bone" in the skeleton you just calculated for your animation system - combined with the overall world matrix for your character! This combined matrix will first position the gun at the correct position in model-space of the character, then transform it to the correct position in world-space based on the characters world matrix.

This is the first thing you should do - get this up and running and you'll see your gun model being rendered at the hand of the character and follow the hand as it's animated. First step of an attachment system!

Ok, now you'll probably find out that even though the gun is rendered at the approximately correct position it isn't really looking as good as you want - and the orientation is probably also wrong. This is because the "hand bone" of the character probably doesn't decribe a very good attachment point. This is where "tags", "attachment points" or "attachment bones" comes into the system. There are a number of ways to handle this problem:

- You could simply add a new "dummy" bone in MAX or whatever animation package you are using, link it to the hand bone and make sure it's at the correct position and orientation. Even though you are not skinning any vertices to this bone you can still use it for attaching the gun.

- You could somehow come up with a correct *relative* displacement and rotation and type it in a data file. At runtime you apply this relative transformation to the hand bone and use the result for the gun instead of using the hand bone directly. If you have your own editor for setting up characters you could add this functionality to it so you can adjust the attachment point visually and have the editor spit out the data you need for the game.

So to sum up the entire process:

1) Get a (any!) skeletal system working.
2) In your game engine, create a way to get a hold of the bone you want to attach to (look it up by name, bone index or whatever you want)
3) Use the bone combined with the character world matrix to render the gun

Hope this was helpful and good luck in getting the system up and running!

- Kasper Fauerby

Share this post


Link to post
Share on other sites
Skeletal animation is one of the most difficult subjects to find help on. I have no idea why. Lots of games impliment it, and it's not that hard to get working. But it is difficult to jump into an empty pool.

Quote:

1. Model file type pros and cons (bones, animations, attachment points)
2. Converting to .x where to find converters, where to find and how to use loaders
3. Swapable parts (Clothing, weapons)
4. Detachable limbs? (removing bones, probably similar to swapable parts)

1. I can't help, I've only used the x file format in my projects. I don't know of other formats which support skeletal animation.
2. What modeler do you use? You can export to x-files straight from the modeler if you choose to do so. I think Microsoft also has a 3ds converter, but I'm not sure where it is.
3. Weapons are easy (see source box below). Clothing is even easier to get working, but a bitch to get optimized. To put it bluntly, you simply render the character and his clothes as two seperate animated skinmeshes, both using the same skeleton and the same array of matrix states. The clothes will not magically fit. You have to make sure the weight envelopes match well enough in the modeling program. To optimize, you would have to hide all of the parts of the character's body and lower-clothing levels when something is equipped over it. That took me some time.
4. You wouldn't remove the bones. You would just avoid rendering anything where the bones used to be. If you're referring to severed limbs, you would need each limb as a seperate mesh subset. You would then need a replacement subset for that limb, such as a chopped shoulder (yummy). You then animate and render the chopped shoulder and character the same way you would as if the shoulder was a peice of clothing.

Quote:

Remember, getting to a point where I can load a single bone cube and attach two spheres would greatly brighten my day.

You need to practice playing with matrices. Using matrices, it's very simple to setup a hierarchy of states which control each other. The parent (cube) just ignores it's children and simply rotates or animates. The children (spheres) do the same thing. But once everything is animated, the spheres must multiply their parent's matrix with their own. But only to render. Something like this:

Matrix parent;
Matrix child;
Matrix child_offset; // the state where the sphere exists relative to the cube

// Update
parent.Rotate( 0, PI / 4, 0 );
child.Rotate( PI / 8, 0, 0 );

// Render
SetWorld( parent );
RenderCube();

Matrix child_state = child * child_offset * parent;
SetWorld( child_state );
RenderSphere();

Let me know if something needs more clarification.

edit: Edited #3 :)

[Edited by - Jiia on June 1, 2005 3:38:25 AM]

Share this post


Link to post
Share on other sites
EDIT: Kasper Fauerby and Jiia, I was typing while you posted so consider my post to be above yours. However, yours seem to be much more detailed so I'm looking them over now. Thanks!

Hello,

First of all I would just like to thank the current responders for their genuine assistance. =)

Ok, so what I understand about attachments is that when an an arm is told to do a "Wave" animation, it goes through a series of transformation over delta time. If this arm were holding a gun, then as a child to the arm (a pointer in some 'attached' variable for the arm) it would then also be put through these transformations, keeping it in the same position relative to the moving arm.

If that's the general idea, it seems pretty simple. Please correct me if I have something wrong.

Now clothing would be different. I think you would have all the relevant animations for that article right? For example pants need to walk, but don't need to wave. Now, lets say your model stats to run "Run". Then, you want to put on a pair of trousers. You wouldn't want to render the animated pants overtop of the legs, as that would be quite a waste of rendering power. So, you would have to detach from the hip downward on your model, then reattach the new legs modeled wearing trousers, and have them set to "Run" starting at the key frame you stopped the last legs at. If this is correct, I'm a little lost on how to "cut off the legs". I know if you are just changing pants, it would be possible to just re-skin the legs, but for something like plate mail, that wouldn't work.

I know some people model every part separately and then use an offset value from a point of reference, but then you would have problem with "scaling" our model, and attachment points wouldn't tween nicely since they a actually different models.

I hope there's some new information to add to this topic. I encourage anyone with some information to contribute it. If I can get something working, I would be more than willing to write a tutorial and share spread the wealth.

It's going well so far, lets keep up the quality responses.

- GeekPlusPlus

Share this post


Link to post
Share on other sites
Quote:
Original post by Jiia
Quote:

Remember, getting to a point where I can load a single bone cube and attach two spheres would greatly brighten my day.

You need to practice playing with matrices. Using matrices, it's very simple to setup a hierarchy of states which control each other. The parent (cube) just ignores it's children and simply rotates or animates. The children (spheres) do the same thing. But once everything is animated, the spheres must multiply their parent's matrix with their own. But only to render. Something like this:
*** Source Snippet Removed ***
Let me know if something needs more clarification.

edit: Edited #3 :)


I'm wondering how you put this all into a OOP kind of system? I've never fully understood how the render path looks. Like say you have a "class MeshNode" which essentialy is your mesh which contains - its local transform? If I also store a list of attatched MeshNode's, does it go something like:

if (pParent)
ApplyMyTransformWithCombinedParentTransform();
else
ApplyMyTransform();

RenderMesh();

For Each child in Children
RenderChild(child);

Pseudo code of course :)

Edit: I forgot to ask how you cascade the root matrix to the final child if the skeleton tree is say 5 levels.

Share this post


Link to post
Share on other sites
Quote:
Original post by GeekPlusPlus
You wouldn't want to render the animated pants overtop of the legs, as that would be quite a waste of rendering power. So, you would have to detach from the hip downward on your model, then reattach the new legs modeled wearing trousers, and have them set to "Run" starting at the key frame you stopped the last legs at.


Hmm, I have this picture in my head that I would have the parts I can attach to a model with the same skinning as the actual legs on the model and just draw the clothes on top of the legs.
Say like I have a pair of bear legs (woho!) that have the run animation and its composed of 5/4? bones. I play the animation of the legs and the vertices are affected by the transformations of the bones as usual, and now I want to attatch a pair of shorts or trousers (pants for you US people). I would just have the trousers have the same skinning as the legs themselves and attach them to the torso like the legs would be.
Would that work?

Share this post


Link to post
Share on other sites
Hello,

I think I get the clothing thing and now I think my lack of experience with bone animations might be the problem. Originally I thought it might be like 2d, where you had to animate every article of clothing. But with bone animations. All you need is a single skeleton that has all the motions. And then have the envelopes setup nicely so that no matter what mesh legs you use, or what mesh torso, or arms, they will always fit on the bones, inside the envelopes and animate nicely. And that is why Shadowbane does not have capes. They do not have bones and envelopes for a cape since could not make it look nice without lots of tiny bones animating (and we all know SB doesn't need more lag) or rag doll physics.

I have played with envelopes and animating bones in 3d Max. I didn't know that you could load a skeleton and then swap different meshes into the envelopes though. As I said this may have to do with my inexperience with skeletal models, but maybe you could give me some pseudo pointers as to how that's done?

Also, does anyone know where I could find a .x or a .max or .md3 that has bones and animations in it? Not up to paying for a model just for learning this technique. I have Max, if worse comes to worse I can run though a tutorial to make my own. However I can never get the knee to tween right where the envelopes overlap, but that's clearly off topic. =)

By the way, this is quite possibly the best discussion I've had on GD for a good while.

- GeekPlusPlus

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement