[Original] detailed explanation of the mathematical calculation process of bone movement Transformation

Source: Internet
Author: User

1. Coordinate Transformation of nodes in the static state of bones (reference posture)

For example, there are three coordinate systems nested with each other: Child skeleton coordinate system, parent skeleton coordinate system, and world coordinate system. First, we do not consider the movement of bones.VCIs VertexVPosition in the Local Coordinate System of the Child skeletonWhen the bones are still:

From child coordinate to parent coordinate:VP=VC*ML-> P
From parent coordinate to world coordinate:Vw = VP * MP-> W

Therefore, the process of directly converting child skeleton coordinates to world coordinates is:Vw = VC * Mc-> P * MP-> W

Where,VCIt can be expressed as a row vector:VC = (XC, YC, ZC,1)AndMc-> P,MP-> WIs two translation arrays, where (Dxp, dyp, dzp),(Dxc, dyc, DZCThe coordinates of the Parent and Child bones in the world coordinate system:


Note! In the example,Mc-> P,MP-> WIt's just two translation matrices. This is the most common simple case. However, in actual situations, the local coordinate axes of each skeleton do not need to be consistent with those of the world. Therefore,Mc-> P,MP-> WIt may also contain complex transformations such as rotation and scaling, but the basic principle is the same.

2. Calculation of skeleton movement accumulation Transformation

Next we will further consider the bone movement. The most typical method to describe a bone movement is to break down its motionCompared with its local coordinate systemRotation and translation (usually first rotating and then translating), the rotation and translation can be expressed simply by a rotating quarternion and a translation vector translation. For the sake of simplicity, We will unify the two into a single form of transformation matrix.

Let's assume that the child skeleton is transformed from its local coordinate systemMTCAnd the parent skeleton is transformed from its local coordinate systemMTP, Then there is: after the transformation, from the local child skeleton coordinate transformation to the parent skeleton coordinate:V 'P = VC * MTC * Mc-> P;V'pAfter the world coordinate system is transformed,VCNew location in the world:V 'W = V' p * MTP * MP-> W

In short,V' W = VC *[MTC * Mc-> P * (MTP * MP-> W)]

Why do we see the rule? For any skeleton,Based on the position of the vertex in the Local Coordinate System of the skeleton, we can find a new position in the global coordinate system after the skeleton moves.The process is a (transformation in the local coordinate system) * (transformation to the parent Coordinate System) * (transformation in the parent Coordinate System) * (transformation to the parent Coordinate System )*.... Until the process is changed to the world coordinate system. If we convert "(transform in the parent Coordinate System) * (transform to the parent Coordinate System )*.... Until the transformation to the world coordinate system "is regarded as the accumulation transformation of the parent skeleton, then the accumulation transformation of its child skeleton is" (local transformation) * (transformation to the parent Coordinate System) * (accumulation and transformation of parent bones )".

In other words, as long as you know the current skeletonAccumulation TransformationThen, we can quicklyLocal coordinates of the current skeleton VertexQuickly convert to the transformedWorld coordinate system. For the second-legged animals, calculating their respective accumulation transformations Based on the parent-child relationship of the skeleton is just a simple tree-type sequential traversal process. This is the update process of the skeleton transformation.

3. Coordinate Calculation of mesh nodes associated with the skeleton

OK. Now we can update the nodes on the skinned mesh. Here we will continue to use that example. Now our problem is: the nodes on the mesh are knownWorld coordinates, accumulation transformation matrix of various bones, and position of the Local Coordinate System Origin of each bone in the world system, Find the mesh nodesCoordinates of the world after the skeleton Movement.

The only thing to note here is that in order to apply the skeleton accumulation transformation to obtain the new world coordinates of nodes, we must first convert the world coordinates of the node into the local coordinates under the associated skeleton coordinate system. In other words, a nodeVIt is connected to the Child skeleton. What we know isVWorld coordinatesVWAnd the child skeleton accumulation transformation matrix, after obtaining the motionVThe coordinates of the New World. The key here is howVWTo obtain the local coordinates of the sub-skeleton coordinate system.VC. In our exampleVW-> VCThe process is simply too simple.VWMinus (Dxc, dyc, DZC.

This process is worth understanding, because the understanding and expression of this process is the most confusing in the online materials. First, let's consider the static skeleton, that is, the initial State of all bones, which is called"Reference posture(Reference pose ). An initial matrix is associated with each skeleton. This transformation is calledReference the initial inverse transformation of the skeleton in the postureIt coordinates the world coordinates of the nodes associated with the skeleton in the reference posture into the local coordinates of the skeleton.VWConvertVC.

For example, in the above example, the initial inverse transformation of the Child skeleton in the reference posture isMW-> C, There are:

Of course, this is just the simplest example of translation. IfMc-> WContains complex transformations,MW-> CThe format is more complex. Generally, the initial inverse transformation of each skeleton under the reference posture is provided directly in the model file to facilitate the users of the model. (Note:MW-> CIt is actually the information returned by getboneoffsetmatrix in direct3d API)

Okay. Now, we have all connected to Ren Du's second pulse in mathematics. Let's take a look at the full computing process of the skeleton Transformation:

1. Read mesh nodes (in the form of world coordinates) and the initial inverse transformation of all bones in the reference posture
2. traverse the tree structure of the skeleton to calculate the movement accumulation transformation of all bones
3. traverse the skeletonCFor allCAssociated mesh nodesV(The coordinates of the world areVW):
3.1. ExploitationCObtained by the initial inverse transformationVLocal coordinates in the skeleton Coordinate SystemVC, Which is equivalent to offsetting the reference posture
3.2. ExploitationCTransformation andVCTo obtain the skeleton MovementVCoordinates of the New World
4. Now, after all the nodes in the mesh are updated, we have finally obtained a new model after the skeletal movement.

4. Smooth weighted calculation of mesh nodes during skeleton Transformation

In this article, we only consider the situation where "the position of a node is determined by only one bone. In the complex skeleton transformation process, the new position of a skin node may be determined by several root bones, such as the elbow node, the movement of the bones in the forearm and upper arm may affect its position.

In this case, we can defineSmooth weightConcept, consider the nodeV, The associatedNRoot bone isBi(1 <=I<=N) For each bone.Bi, Each has a corresponding weight.AIAnd allAIAnd 1. For each skeletonBiWe can all achieve a correspondingVNew coordinates of nodesVI, New coordinates like this will be sharedN. Then we can use the weightAITo smooth the weighting of these new coordinates, that isVThe new coordinates ultimately unique to the node are:Vw = sum (ai * VI)

This process is calledVertex Mixing(Vertex blending), because of its standardized computing method and large computing workload, most of them are currently implemented using hardware. Generally, 3D acceleration hardware supportsN= 4 vertex hybrid computing. It's a simple idea, isn't it?

5. Problems specific to skeleton transformation in Allied 2

The skeleton transformation process in Allied 2 is roughly similar to the above example. The general situation is:

1. The initial inverse transformation of all bones is a translation array, similar to the example above.
2. The movement of all bones is described as a rotation (quad-tuples) and a shift (vector) relative to the local coordinates)
3. vertex mixing is not used, that isN= 1. The position of a vertex in the model is determined by and only by one bone.
4. In the data file, all coordinate systems and related data use the right hand system.

The first three points are nothing more than the first three points. The only 4th points are a headache. Why? Because the Allied skeleton movement uses the right hand system similar to OpenGL, And the direct3d (Including its mathematical functionsIs left-hand. It doesn't matter who is brutal. What matters is that this has actually caused a lot of confusion and trouble. How can direct3d be used to calculate and render right-hand data? Obviously, it is the computing disorder caused by the confusion of symbols, which eventually leads to the confusion of the model.

After carefully analyzing the above process, the problems we face can be divided into two layers: one is the skeleton computing layer, and the other is the model drawing layer. The correct method is: the process must be strictly differentiated from the two, that is, the problems related to the left and right hand series during plotting should not be considered during calculation, and vice versa. That is to say, the clearest idea is to unify the computation into the same coordinate system (left or right hand), and convert the computation into another coordinate system for operation, the two are irrelevant. In this case, the most appropriate method is that all model computing uses the Right Hand System of its data. As for how to draw the right-hand data model with d3d in the left-hand system, it is pediatrics. The simplest way is to exchange y-zcoordinate data of vertices, the conversion from the right-hand model to the left-hand model is achieved. The corresponding transformation matrix is:

OK. The goal is clear:We want to use the ready-made left-hand mathematical functions of d3d for substantive right-hand model calculation.. Let's take a look at the computing process and think about which operations are affected by the left and right hands. In fact, normal operations such as matrix and vector multiplication addition are fixed and will not be affected by coordinate system settings. In the three basic transformations (rotation, translation, and scaling), the latter two will not be affected, rotation alone is critical, because the specific description depends on the various coordinate systems we actually use.

Now that the initiator is locked, consider how to describe this angle-displacement. First, we can exclude the rotation description in the form of a matrix. The reason is very simple: 4*4, which is complicated. Second, we can also eliminate the problem of a large number of ouarla angles. The most appropriate analysis method should be to rotate the four tuples in the form of axis-angle, that is, quaternion. According to the geometric meaning of the four tuples, we can see that in different coordinate systems, the definitions are as follows:

A. in the left-hand system, the rotation axis vector isN,Shunshi clockRotateT, There are:
Q =[Cos (T/2) sin (T/2) N]
Q =
[Cos (T/2) sin (T/2) NX sin (T/2) ny sin (T/2) NZ]
Q =
[W x Y Z]

B. In the Right Hand System, the rotation axis vector is n,Reverse clockIf you rotate t, the following operations are available:
Q =[Cos (T/2) sin (T/2) N]
Q =
[Cos (T/2) sin (T/2) NX sin (T/2) ny sin (T/2) NZ]
Q =
[W x Y Z]

We can find that the only difference is that the angle of the left and right hands isTThe definition of rotation is the opposite. Quarternion, followedX/y/zThe three components should be reversed by symbols in different coordinate systems.

OK. Now we have understood the nature of the problem:The quaternion stored in the Allied data file is right-handed., So,In order to be able to use the left-hand function in DX for substantial right-hand computation, WeThe right hand of quarternion must beX, Y, ZPerform a symbol flipNote that this is a permanent operation: After a symbol is flipped, you no longer need to consider the computing problem of the left and right hand series related to Quaternion. The "left-hand functions" here include d3d functions related to all rotation, such as "converting tuples into Matrices" and "four-dimensional spherical interpolation slerp". Before using these functions, first, we must ask ourselves: has its data input undergone a symbol flip during its initialization? If yes, congratulations. The calculated result is correct (that is, the correct right hand is the calculation result), even though you are using the d3d function in the left hand.

The above is a special problem encountered during the calculation of the Allied 2 skeleton. To put it bluntly, the essence of the trouble is that the data we have is inconsistent with the coordinate system used by the 3D API, which affects our computing. In the above article, I have provided the key ideas and methods to solve this problem, hoping to help my friends who encounter similar problems.

References:

[1] Death Squad 2-3D model/Action browser, neoragex2002's Weblog

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.