Skeleton with Assimp skeletal animation resolved

Skeleton with Assimp skeletal animation resolved

Skeletal animation is very common graphics applications a wide range of technology, but also the more basic content as graphics engineers need to sort out this part of the content is clear, the key is the main points: first, to distinguish bone , nodes two concept; second, familiar with Assimp (or other) of the analytical methods, and analytical programming and animation of the skeleton of play.

Understanding bones

First of all, why is there such a thing exists skeletal animation it? If we look from our own bodies, we can see that part of our body can be active, it has a major base inside the bones, such as the swing arm, forearm skin all the muscles and bones together all sports. Looking back 3D rendering, we need to draw is usually a mesh, which is part of the surface of the object can be considered a skin. We want to draw objects also can do some actions like the human body the same. Then the same, we will this skin above each of the smallest units, such as the vertex (vertex) are bound up a bone, how the bones move, how to move on the skin. This section, called skins (Skin Rigging) , is the [1] done by the artist (real situation, a point may be affected by multiple bone influences need to identify specific weights). In this way, we only need to consider the limited movement of several bones of the human body can describe the whole movement, simplifying a lot, but also to simulate the laws of nature.

That node then what is?

Node is a point, in the context of the bone, it may be referred to as "joint", but unlike the bone joints. Keep in mind: the skeleton is the length of the line, only the position of a point in space can not describe the bones . Only two points to make up a line, the line can represent only the bones. Even in Unity or other software, with a node, node, joint representative of the bones, but my heart is to be aware of this. The following figure, RA is a skeleton, RB, BC were all bones, but we can not say that A is a skeleton, lifting A alone does not make sense, it is only a point.

The artist's work, all the vertices, and rigging are, apparently, matching the figure below the upper part of the skeleton of the vertices of the mesh, are bound up with the RA bone, and in the lower left and right vertices basically bound to the BC and DE two bones. In these apex node, and more will be rigging, each bone has a certain weight. At the same time, the artist will provide attitude of a skeleton key frame animation, that is, when the key frame, each bone position.


  A -
     \
      \
       \
  B---- R ----- D
  |             |
  |             |
  |             |
  C             E

------------------

R -> A
R -> B -> C
R -> D -> E

According to data provided by the artist, exactly how do we determine the location of each point of it? First, there is a parent-child relationship between the structure of the bone, the bone is on the map of RB BC skeleton father. We can also be described by a node, then that point is the R point B father, point B is the point C father (as shown by arrow). The relationship between father and son at the level of the bone, or we can use nodes are described, it describes essentially the same bone, as is shown in the cartoon. Assimp used to help resolve FBX file, we get all the information from Assimp in. For the position of bones at any time, Assimp provide each bone relative to the upper-level transformation to transform matrix representation, traversing from the root, you can get every bone relative root transformation, if the root is considered the world the center of the coordinate system, which is the bone space -> world space is transformed. bone space is at a point in which the bones as the origin of the coordinate system, which is a specific point, in fact, we are not learned, this information is not important to calculate and understand, just know that bone space is the local coordinate bones Department bind know every point of this bone, can be in this position among the local coordinate system. For every point of this bind bone, set in its position in the bone space is bone_pos, then, its position in the world coordinate system is bone_posmultiplied by the transformation matrix calculated.

Assimp resolve Guide

Use Assimp load the FBX file get aiSceneThis is the entry of all data.

Bone

aiBone *bone = aiScene->mMeshes[]->mBones[];

mBones array which stores all of the bones, the bones stored corresponding to the weight of each vertex and the vertex binding weight, and a mOffsetMatrixthis matrix is useful, mentioned later.

Node

aiNode *root_node = aiScene->mRootNode  // root node
aiNode *child_node = root_node->mChildren[i]  // get child node

In addition to the parent-child relationship aiNode related information storage, the most important attribute is that mTransformationthis is a transformation matrix relative to the node.

Here we see the two statements node and bone, in the prescribed Assimp, each bone must have a corresponding node of the same name, in turn, does not hold. Every bone transformation matrix is ​​a transformation matrix of the same name node.

Bind Pose

Bind Pose is a mesh vertex information, regardless of the bones, the direct drawing result obtained, i.e. an initial drawing state of an object. Further, also can be used to read out the data Assimp verified. [2]

As mentioned before, the vertex position bone space is a prerequisite for the calculation, but in fact, to the mesh vertex position we read, that is based on model space model to describe the space, and as such, we can draw directly model to the initial state. How do I get the position of bone space it? In theory, sequential traversal get BoneToWorld transform matrix, the inverse matrix is ​​WorldToBone transform matrix, namely:

final_pos = (transform_matrix) * (transform_matrix)^(-1) * world_pos;  // means: final_pos = world_pos;

Seems pointless, because in a stepwise matrix inversion and then this operation is really complex, Assimp directly to this inverse matrix, that is mOffsetMatrix, the equation can be written as:

final_pos = (transform_matrix) * (offset_matrix) * world_pos; // means: final_pos = world_pos;

FBX can use this method to verify the correct reading and calculation. Under normal circumstances should be drawn as a direct result of, if not the same, that is, something goes wrong (most likely to go wrong is progressively traversing the node computing transformation matrix).

Animation

After getting bone space position, each frame is calculated attitude is straightforward. aiSceneIt contains several aiAnimation, each representing a group of animation, each aiAnimationcomprising an aiNodeAnimarray called mChannels, according to aiNodeAnim->mNodeNamefind the corresponding node, then the node in the transform matrix can be a specific moment by Position, Rotation and Scaling of out interpolation calculation, which still represent only relative transformation matrix parent node still obtained, AnimationBoneToWorldTransformMatrix final calculation at a particular time each node by progressively traversing:

final_pos = (animation_transform_matrix) * (offset_matrix) * world_pos;

Reference

[1] Skeletal Animation With Assimp

[2] can't get bones/skinning to work

Asset-Importer-Lib Documentation

Bones Animation - Matrices and calculations

Guess you like

Origin www.cnblogs.com/psklf/p/11613676.html