Introduction to bone Animation

Source: Internet
Author: User
First, I will explain this article about the fifth chapter of bone animation translated from Evan pipho's <focus on 3D models>, removed the previous instructions and the last demo instructions, including all theoretical content. For more information, see the source. Thank you!

Understand that a skeleton animation uses a "bone" to motion a model, rather than an animation by manually editing and moving each vertex or surface. each vertex is attached to a bone (or sometimes multiple bones ). A bone or joint is just a control point of a set of vertices. these concepts are similar to the joints in our bodies, such as our knee joints or wrist joints. when the bone moves, each vertex attached to it also follows the motion, as shown in 5.2. even the movement of the bone itself can lead to the movement of other bones. this makes the model more appropriate and reasonable, because in real life, part of the physical exercise affects other parts of the body. therefore, programmers need to be able to use the bone to calculate the transformation of a single vertex. although this will bring a lot of work, The results prove that this is worthwhile.
<! -- [If! VML] --> <! -- [Endif] -->
Figure 5.2 vertex animation requires you to move each vertex, while the bone animation allows you to move only one bone in the model and the vertex will change accordingly.
Bone animation has many advantages over traditional vertex transform animation, as you can see in the previous chapter.
First, the most intuitive aspect for players is to increase the realism. the role based on the skeleton movement tends to be more authentic and often appears in places where the traditional model requires stronger interaction with the surrounding things. to make the model more realistic, it is really simple for the skeleton-based model. in the traditional key frame animation, the game performs linear interpolation between two locations. however, in this case, the joints do not actually rotate, which is a problem for the body to rotate.
This is not so obvious for users, but it is very important for programmers to see whether such animations occupy less storage space. instead of storing a new set of vertices for each frame of animation, all we need to store is the rotation and Heping information of the bones. this saves a lot of storage space. You only need to add the bone and vertex-bone attachment information.
A little more storage space is required for bone animation to save more detailed models, add additional motion frames, or even use them elsewhere in the game after appropriate improvements. you can add more details to the game world and improve. i. to provide a more exciting game, or to add some cool stuff or Easter eggs. These are the ones that you would like to join but cannot join due to space problems.
Another advantage is the creation of 3D game content by the artist. A good bone animation system will reduce the time for us to make model animations. almost every good animation program has used bone animation to ensure the smooth transition from the artist to the programmer, to the game, and finally to the player. this accelerates the creation of game content and ensures that there is no animation or feature distortion when the model is exported to the format used by the game.
A longer-term advantage is another benefit to programmers (which is getting better and better, isn't it ?). Because of the flexibility of the bones, you can locate them in real time as you like, or create an animation at runtime. it is equivalent to providing a more diverse animation library. you can even let the game control the movements when the body encounters an object, or slide down from a slope. this technology is produced instantly during play, and there is such a noteworthy example in the Unreal Tournament 2003's physics system (http://www.epicgames.com. real interaction between roles and models in the environment, including slide down from the slope and moving slowly on the top.
Compared with the traditional key frame animation, bone animation is not easy to understand and implement. This chapter will help you ease any worries about bone animation.
First, let's look at your arm. show your arm in your chest and observe it. your arm has many bones, two main ones, and the palm of your hand) and some bones on your fingers.
Are you sure you want to move your fingers? Only move your fingers, and the rest of your arm does not. now bending your elbow not only does your arm move, but also your fingers and Palm move. if not, your arm is broken from your palm and fingers, and each part is isolated and hung in the air.
How can we associate this arm with a skeleton animation? Your arm represents a part of the 3D model. Your fingers, palm, and upper and lower parts of the arm are part of the model. different joints and bones run through your arm, such as the shoulder joint, elbow joint, wrist joint, and finger joint.
That is to say, when you move a bone in the arm's "upstream", any downstream part of the bone will also move. This is the most basic concept of bone animation.
In this way, there is a wonderful thing: it allows you to move any bone on the model and penetrate into the following movement, apply to any things that take this movement as the origin. for example, this allows you to move the shoulder of a role without worrying about moving the elbows and hands, because they will automatically move to the correct position. you can also reset them to make sure they are automatically updated. figure 5.3 shows an example of a joint and a vertex attached to the joint.
<! -- [If! VML] --> <! -- [Endif] -->
Figure 5.3 When executing a skeleton animation, you don't have to worry about joints or points of points between bones. Each vertex is actually attached (associated) to a Guan node, not a bone.
The root joint is the terminal joint in a model. any other joint is eventually associated with the root joint in its own path. any operation on the Root joint, such as translation or rotation, will affect each vertex in the model. you can think that the root joint is the joint that controls all other joints. simply modify the root joint, you can make the role walk upright, or rotate it to let him move upside down on the ceiling-All you do is a simple call.
There is only one root joint in each model, and it does not have a parent joint. the root joint is usually a place where many bones are connected, rather than a small animation. for example, it includes the middle part and the lower part, but it is not explicitly required that the root joint must be in an accurate position in the model. every model can be different as long as you want. figure 5.4 shows the changes that occur when the position and orientation of the root node are modified.
<! -- [If! VML] --> <! -- [Endif] -->
Figure 5.4 rotating or translating the root joint affects all other joints and entries in the model.
Because of the log capacity limit of the xisai blog, I had to split it into two articles to describe them first, this article is translated from Evan pipho's <focus on 3D models> book about chapter 5 of bone animation, removing the previous instructions and the last demo instructions, contains all the theoretical content. For more information, see the source. Thank you!
A parent joint and a child joint can have a parent joint and a child joint. its Parent joint will affect its ability to do anything. the rotation and movement of the parent joint affect the calculation of the new position of the current joint. taking the arm as an example, the elbow joint is the parent joint of the palm. moving the elbow affects the palm of your hand. in a simple skeleton animation, each joint has only one parent joint, if any.
However, a joint can have many subjoints. the subjoint is relative to the parent joint. anything you do to the parent joint will penetrate into the Child joint. in other words, the current joint is the parent joint of all the joints under it.
<! -- [If! VML] --> <! -- [Endif] -->
Figure 5.5 relationship between parent and child Joints
The key frame animation of the skeleton animation saves multiple copies of vertices, And the skeleton animation system also has key frames. The reproduction of key frames is the instantaneous state of a model position.
However, unlike the method in which each key frame contains copies of all its own vertices, the key frame or boneframe of the skeleton animation contains the rotation and the transformation information of the moving, generally, the translation is in the form of X, Y, and Z values, and the three contain the values rotated by X, Y, and Z axes respectively. like conventional vertex key frames, these skeleton frames must be interpolated to provide smooth animation effects.
The position or translation value can be linearly interpolated between the two, just as you operate on vertices in a traditional key frame animation. but there is a problem with rotation. Simply performing the interpolation like translating between two values will produce a strange effect. the rotation will not be smooth. It may accelerate and slow down, depending on its own position. if there is a large difference between the two rotation information, the model may appear as ooze in the square that is glued together )". this is because linear interpolation is used, and everything is interpolated along a straight line. If this method is used for rotation, it will produce a strange effect, because the rotation is interpolation along the arc rather than the straight line. the arc path will generate a "seepage" effect when the two ends of the path are in a straight line rather than along the arc path.
The best way to solve this problem is to use the Quaternary element. you learned this in Chapter 2. "Introduction to the Quaternary concepts", one of the biggest advantages of the Quaternary concepts is that they can easily perform interpolation. it is not only easy to interpolation, but also easy to perform spherical linear interpolation.
Spherical linear interpolation is performed before two points on the spherical surface. however, as compared to approaching in a straight line between two points, the spherical linear interpolation is along the surface of the ball. you can imagine picking up a ball, such as a basketball, and marking two points on it. Then, use your fingers to find the shortest path between the two points. because your finger cannot enter the inside of the ball, the path between two points will be an arc. this is the slerp processing method. by using the slerp function, you can perform interpolation along the arc to create a smooth and pleasing-eye effect.
The computing position uses the information you have read above, and you may want to try to implement the skeleton animation. however, you have not learned how parent joints affect subjoints. the simple use of the key frame will make each joint move independently, which may produce a strange, distorted mesh.
This section will show you how to change it so that normal motion between joints can be achieved. the first thing you need to do is create a transformation matrix for each (Key Frame) point that uses different rotating and moving key frame data. this transformation matrix can be converted into three rotation matrices (the rotation matrices in the three directions of annotation: x, y, and z) and the moving matrices. This has been learned in Chapter 1, then multiply the three matrices to generate the final transformation matrix. you can also use the setrotation and settranslation functions of the matrix class to avoid matrix multiplication by yourself. the generated matrix is called relative matrix ).
Next, you need to calculate an absolute matrix (absolute matrix ). the absolute matrix is obtained by multiplying the relative matrix of the joint by the absolute matrix of its parent joint. the absolute matrix tells you the absolute transformation of the joint ). this includes its own relative transformations. In addition, all the transformations of the joints before the Hierarchy have been calculated. this allows the movement of other joints as a result of moving the upstream joints of the joint chain. think about how your elbow moves when you move your shoulders. This raises the question: How do you calculate the initial absolute matrix? Remember, the root joint has no parent joint. Therefore, its absolute matrix is its relative matrix.
If you traverse each joint in the correct order and calculate each absolute matrix in this order, each joint (the absolute matrix) will contain the transformation of its parent joint, and the transformation of the parent joint of its parent joint. figure 5.6 shows what happens when you consider all previous (joint) transformations before changing a joint.
<! -- [If! VML] --> <! -- [Endif] -->
Figure 5.6 traverses the joints and takes into account all the previous transformations. note that even if only one joint is to be moved, the joints under it also need to move. This is like moving your hips, so your knees and ankles have to move.
Do you only store the index of the sub-joint, but not the parent joint index of the joint? The index set you want to access immediately depends on the model format. some formats, such as ms3d, give you a parent joint index for each joint at the same time. Other formats may give you a subjoint index. using a subjoint index requires a much different method than using a parent index, but it is no more difficult than the latter. you start from the root joint again. After calculating the transformation matrix of the root joint, press a new matrix into the stack using a command similar to glpushmatrix. A new copy of the world matrix is created. This world transformation matrix is a matrix that executes all geometric transformations before being displayed. use your new matrix to multiply the local matrix of the root joint. the result is the world transformation matrix, which places everything in the correct position before the next bone is drawn, and the transformation of the parent joint is also taken into account. for example, the rotation of the role's buttocks may be the sum of some actions. because the knee and ankle are the sub-joints of the hip joint, they will also be rotated.
The rendering function is recursive like this. It continues to call the rendering function for its subjoints, and each subjoint calls the rendering function for its subjoints, and so on until the terminal joint is reached (the joint without the sub-joint), the reset stack uses a command such as glpopmatrix. for example, when a role's leg is to be drawn, the new matrix is pushed into the stack to calculate the knee joint, ankle joint, and ankle joint. however, if you want to start calculating the arm, you should get out of the stack status before processing the leg. Otherwise, whenever you move the leg, the arm will also move.
Figure 5.7 shows a recursive rendering function.
<! -- [If! VML] --> <! -- [Endif] -->
Figure 5.7 Replace the parent index storage joint with a sub-index for rendering
Attach the mesh to the skeleton. When your joints are smooth, it is also time to attach the mesh to the skeleton. mesh forms the shape of a model. It is composed of a group of vertices and triangles that make the model stereoscopic and detailed. There is no mesh, the model based on the skeleton movement is just a simple skeleton. each mesh vertex stores an index pointing to the joint array to indicate that it is attached to a bone. now, the method of storing joints determines the transformation and rendering methods of these vertices.
If each joint is stored with an index of its parent joint and you have traversed and calculated the final absolute matrix, it is very easy to attach the mesh. make sure that the transformed vertex is saved to a special place. Do not overwrite the original vertex. this is because in most formats, the skeleton frames are not accumulated, and each frame stores the rotation and peaceful movement of specific joints starting from the starting point. if you do not roll back to the original vertex, the model will be subject to erratic motion every time you calculate the position of the new vertex. figure 5.8 shows how each vertex is attached to a joint.
<! -- [If! VML] --> <! -- [Endif] -->
Figure 5.8 attaching a vertex to a joint

Now you may say to yourself, "Okay, how can I move the vertex of a model, the triangle, the normal, and the texture coordinates "? This is exactly where the skeleton model really starts to flash. each model contains a set of texture coordinates and a set of triangle information. because the vertex position changes, the triangle vertex index and texture coordinates also change. this means that when you set them for the first time, you don't need to worry about them.
The normal is another thing. Because the orientation of the polygon and the position of the vertex are changed, the normal is changed accordingly. if you are using a plane normal, you need to re-calculate them before each frame passes them to the Renderer. however, if you calculate the vertex normal at the beginning, you are lucky that the vertex normal does not have to be completely re-computed after the transformation. They can be transformed with the same transformation matrix of the vertex. the only difference is that you do not need to consider translation. use the transform3 () function of the matrix class to rotate your vertex normal vector while retaining its original size.
If the joint stores the index of the subjoint and you press the current transformation matrix into the stack using glpushmatrix, rendering the model will become very easy. in this case, there is no need to transform each vertex before the display. no matter what rendering, there is no need to change. anything you want to render will now be properly transformed, or even face normal. another question to consider is how the vertex is attached to more than one bone. in this case, each bone is assigned a weight, which determines the weight of the key node. the final transformation is the weighted average of the transformations of all these attached bones.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.