6 Replies - 450 Views - Last Post: 06 August 2013 - 09:30 AM Rate Topic: -----

#1 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,299
  • Joined: 22-October 08

How are animations bound to meshes

Posted 05 August 2013 - 04:58 AM

Hey guys,

I am trying to create a havok animation via code(So I get it working), and I have come to the conclusion that I know very little about the inner workings of animation. I keep seeing these words come up a lot:

  • Bones
  • Skeleton
  • Animation Container
  • Pose
  • Blend
  • Rig


I know what Bones are(In Blender). But in code I have no idea. All the documentation in havok says is the bones class stores the name of the bone + whether or not the bones moves relative to the parent.

When I created my rig in bslender a while ago, I added bones and allocated those bones to certain parts of my mesh(What is this called ?), and then added in the animation.

How is the animation linked to certain areas of a mesh?

Sorry if I seem vague, it's my BDay and I've had a few.

Is This A Good Question/Topic? 0
  • +

Replies To: How are animations bound to meshes

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How are animations bound to meshes

Posted 05 August 2013 - 07:00 AM

Happy Birthday, aaron1178! :)

The theory is that the joins have certain properties, like range of motion, weights, etc. How specifically it is implemented for various engines varies depending on coordinate system and sophistication.
Was This Post Helpful? 1
  • +
  • -

#3 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 581
  • View blog
  • Posts: 1,290
  • Joined: 24-April 12

Re: How are animations bound to meshes

Posted 05 August 2013 - 07:08 AM

Happy belated birthday!

This is an especially weak area in my game programming knowledge. I've been considering working on it next, possibly even next weekend as I'm wrapping up some other things. So, I'll share what I "think" I know out of my incomplete experience.


I've worked with 3D Studio Max and Blender, but more with Max. I've also been doing animation in XNA. I have written a small tutorial program on rigid animation in XNA that I have to put together a full tutorial on (hopefully in the next week or two since the program is already written). I've ran through a few tutorials on doing skinned animation, but I'm still very weak in my understanding of this and that's where I hope to focus my learning in upcoming weeks.

So, here's my understanding. First of all, there are two separate approaches (at least two) that you can take. The first is rigid animation and the second is skinned animation.

With rigid animation you create your model, for example in Max, as separate meshes called objects in Max. For example, you might create a car and you want the wheels to spin and the doors to open. So, you create the car body and then the wheels and doors as separate objects in Max. Then you do what Max calls "linking objects" where you define a parent/child relationship where the car body is the parent and the wheels and doors are children. Children can have children. For example, the door might have windows that roll down. In that case the window would be a child of the door which is a child of the car body. I don't think there is a limit to how deep this relationship can go, or at least it can go as deep as you're likely to need.

In this case of rigid animation, what I've seen is the world matrices of the objects and sub-objects in this hierarchy referred to as "bones". The bones have the same relationships as the objects, or meshes. (Note: this has absolutely nothing to do with the bones you see in Max or Blender and is really just the object link relationship and their transformation matrices.) But the way the relationship is maintained is through "transformation matrices". Each "bone" has a world matrix. When the model is drawn The parent's world matrix is applied, then every single child's world matrix is applied to the parent until the world/transformation matrix of the child currently being drawn is applied to the model.

I refer to them as children world matrices, but I think the correct term is "the child's transformation matrix". Because all the matrices in that branch of the hierarchy are applied, it makes the child relative to all of it's "forefathers". For example, if you translate the car body by its world matrix, the door moves with the car because the translation is in the body's matrix, not the door's matrix. But since the body matrix and the door matrix are combined before drawing, the door moves with the car. Likewise, the window will move too, even though you haven't changed the window's world/transformation matrix, because you combine the body then the door to the window's world/transformation matrix. If you translate the window downward to "roll it down" that info will only be in the window's matrix. It will still be relative to the rest of the car, but only the window will move. So moving the parent automatically moves all the children, but moving a child only affects the child - unless the child has children that will be affected. (Move a child in the middle of the hierarchy and its parents will not be affected, but it's children's children will be.)

I believe this hierarchy of transformation matrices is referred to as "bones" in rigid animation. You can translate, rotate, or scale, any of the children (which will affect any of its children automatically because their matrix will be combined with their parents' matrices) and this will not affect the parents. So you can rotate the wheel matrices and do separate rotations for the door hinges and perhaps a translation to roll the window down.

And that's basically how you do rigid animation. It's called "rigid" animation because all of the pieces, like the doors and wheels, are rigid and do not bend.

Rigid animation is handled in your program as your code simply applies translations, scaling, and rotations to the individual matrices of the hierarchy as needed. It works great for objects like cars.

However, people and creatures are not rigid. A robot might be made of metal and might be a rigid model, but a person bends and stretches. This is done with "skinned animation".

Now skinned animation is something I admittedly know too little about. I've done the animations from the art side. I think I've even skinned and rigged a model years ago. And I remember animating a couple different models years ago. The part that I don't know is how to use this information in your program, as I've only run through a couple of tutorials on writing such code so far. But I have done at least that.

Ok. So here's what I know. You go into your program - like Max, Maya, or Blender - and you create your model as a single mesh. You create what Max would call "bones". The distinction is that Max would have called what we had in rigid animation as "linked objects". Here Max actually has a "model", for lack of a better word, that represents a bone of a skeleton. These bones are supposed to somewhat imitate the bones of a creature. We often think of a human skeleton, but you could create such a bone structure for a horse too, for example.

These bones are placed inside your model in a way to sort of simulate the creature's actual skeleton. Then these bones are attached to individual vertices in a process known as "rigging". When you rig your model, you are attaching this skeleton of bones to your model at each vertex. This is going to give all of the vertices a similar parent/child relationship to what we had before.

Now, when you rig your skeleton to your model, it may cause the model to bend in an odd way that doesn't look right. So you can "weight" your vertices to the skeleton so that different vertices move differently in relation to the skeleton. This helps clear up problems with the mesh not deforming correctly and textures stretching in odd ways.

So, a rigged model has a skeleton of bones that are attached to the vertices of the model. This allows you to move the model by simply moving the bones. Move an upper arm bone and the forearm and hand bones will move with it even though the clavicle bone that it is attached to does not move.

The process of weighting the vertices to the bones, after rigging, is called "skinning".

So, once you have your model and its rigged and skinned, it becomes super easy to animate. I don't know if you can animate such a model in your code, or if you would even want to. Instead, you usually produce an animation file, or otherwise, store an animation in the model's file.

I've used Poser, which is a program that lets you bring in the skeleton of bones and produce an animation file for it. That was years ago, but I thought it was a pretty good program.

But I think you can do all your animation inside of Blender, and probably Max for that matter.

You mentioned "poses". I don't think that has anything to do with us. You have to remember that all these programs - Maya, Max, Blender, etc. - were not designed to make games. The various model files they export were not designed for that either. If anything, these programs tend to focus on producing animated movies or still shots for a single art picture. Many many artists use these programs for art that has nothing to do with games (or maybe its art for the game's cover or something). I believe a pose is just adjusting the model's skeleton to put it in a particular pose. But that, by definition, means that you are not animating it.

I suppose its possible that a single animation might be referred to as a pose, but I don't think that's correct. A model or animation file can contain many separate animations for that model.

Ok. So we have our rigged and skinned model and we're ready to do our animation. The first thing you need to know is that the model has what is referred to as a "bind pose". This is the pose that the model is in when it was created, rigged, and skinned. This is the pose of the model before it is adjusted in any way. This pose is stored in the model's file and "I believe" that any adjustments are actually relative to this pose. I'm a little shaky on how a bind pose is actually used in code.

So, in our animation program, we adjust our model to what I will call a "starting pose". (I said we don't use poses and now I keep saying the word over and over. lol Maybe its just been a really long time since I've done any of this.) For the starting pose, we want a pose where the model is "at rest". For a human, this would likely just be standing with arms hanging comfortably at the side and looking forward.

In your game, or whatever, you need all of your animations to be "connected" to one another. If your model runs, it needs to start at the rest position, do running, and then slow down until it is back in the rest position. Otherwise there is a huge visual leap in the animation where the model is running and then suddenly and violently goes back to the rest position in the middle of a run as soon as you stop. All animations have to transform out of this rest position and transform back into it when they are done. Your rest pose is totally different than your bind pose unless you created your model in a nice rest pose. A lot of times people create the character's arms straight out like Vitruvian man. This is not an "at rest" pose and obviously not one that you want to start and end every animation with.

So, in our animation program, we save our at rest pose. Then we can begin to animate. The first animation you want to do is probably "Standing Still". You may think we already have that in the "at rest" pose. But no human stands perfectly still when "at rest". We start with the "at rest" pose.

You figure out how long you want the animation to be. Maybe its 5 seconds for the "Standing Still" animation. You move the time line to different spots and record what we call "key frames". So, maybe we have a key frame every half second in our "Standing Still" animation. We copy the "at rest" pose as the first and last pose in our animation. Then we move the timeline to every half second. At each half second we might want to do a key frame. The key frames are poses that we want the model to be in at that point in the animation. So, we move the time line to that key frame, pose the model using the bones. Move it to the next key frame and pose again. And so on so that every key frame has a pose in it starting and ending "at rest". We might want our "Standing Still" animation to have some shifting of the character's weight from one leg to the other ever so slightly, almost imperceptivity. Maybe some swinging of the arms. Maybe a slight turning of the head back and forth as if looking around. All the motions for this animation need to be subtle because, after all, it's "Standing Still".

This is already a long explanation; so I won't go into detail on key frames. But suffice it to say that your model will be animated between the key frames. It will move smoothly from key frame to key frame which produces the overall animation effect. So, your key frames may be "jumpy", but the end result will not be. You don't have to animate through every motion; rather you simply pose the model into various key frames and the rest is taken care of for you.

Now I assume that your program (code that you write or your engine) has to be written so that it fills in the animation between key frames. I believe that only the key frames are stored in the animation file. I think your code has to do interpolation every video, or game, frame in order to calculate the model's pose for that drawing frame. I assume that the bones have transformation matrices in the bind pose, and transformation matrices applied against that for each key frame. I assume your code creates two poses that you are attempting to interpolate between which are two hierarchies of transformation matrices. So, every bone has a matrix for the start pose and another for the end pose. The timeline tells which pose is supposed to occur at what time and so you interpolate between the two matrices based on the amount of time that has passed between the two key frame poses. At least this is my foggy understanding of what needs to happen based on my very limited run through a couple of tutorials which I may or may not have actually understood.

Perhaps this interpolation between key frame poses is what is being called "blending". I'm not sure I've ever heard the term "blend".

I'm not really sure what an "animation container" is. I know that in Poser I was producing .bvh files to contain the animation that were completely separate from the model itself. I know that the model class in XNA has the mesh and children meshes stored separately from the bone structure. I think you have to extend that class to store animations, because skinned animation is not directly supported in XNA (without extending the model class and the Content pipeline).

So, hopefully that clears things up a bit. I've done the animation and modeling before. It's really how the code plays back the animation where I'm really unsure of how it works for skinned animation.

This post has been edited by BBeck: 05 August 2013 - 10:22 AM

Was This Post Helpful? 2
  • +
  • -

#4 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,299
  • Joined: 22-October 08

Re: How are animations bound to meshes

Posted 05 August 2013 - 02:29 PM

I will reply better when I get home, but I would like to say BBeck, for your birthday, I'm going to buy you a bulk stack of keyboards ;)
Was This Post Helpful? 0
  • +
  • -

#5 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 581
  • View blog
  • Posts: 1,290
  • Joined: 24-April 12

Re: How are animations bound to meshes

Posted 05 August 2013 - 09:21 PM

Aw! How thoughtful!

I like the kind with the really snappy keys that give you instant feedback when you click them. And I prefer wireless with glow in the dark keys for typing my "novels" at 3AM when I can't sleep.

Although, you may want to coordinate with Butch because he may have the bulk keyboards already claimed for my birthday gift. (I'm pretty certain he's planning on buying me that for my birthday.)

This post has been edited by BBeck: 05 August 2013 - 09:23 PM

Was This Post Helpful? 0
  • +
  • -

#6 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How are animations bound to meshes

Posted 06 August 2013 - 09:15 AM

I've reserve the Best Buy entire stock for you, BBeck. ;)
Was This Post Helpful? 0
  • +
  • -

#7 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 581
  • View blog
  • Posts: 1,290
  • Joined: 24-April 12

Re: How are animations bound to meshes

Posted 06 August 2013 - 09:30 AM

View PostButchDean, on 06 August 2013 - 11:15 AM, said:

I've reserve the Best Buy entire stock for you, BBeck. ;)/>


You guys are so thoughtful! I don't know what to say. :-)

I won't ruin the moment by telling you that I've been continuing my evil plot to convert all game programmers to the dark side and to follow the ways of XNA in another post ... again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1