Recently started to contact with computer animation, a blank, try to do a 3D skin, found that the math is really bad to imagine, the matrix of what all forgotten, it is really next to the foundation of the evil to mend ...
Keep a record of some of the problems encountered here.
Main bibliography: Computer animation algorithm and technology, 3D game (the English book is out of print) "3D game engine design-real-time computer graphics application Method"
A joint is a transformation matrix that, in hierarchical storage, typically begins with a layer of storage of the joint matrix from the root node:
So the matrix that each joint stores is built on top of the root joint.
Taking 3 joints as an example, the conversion is as follows:
-(T0 World Matrix)->link0-(T1 relative Link0 Link1 conversion, relative rotation R0)->link1-(T1.1 relative Link1 Link1.1 conversion, relative rotation R1)->link1.1
In addition, the transformation of each joint is nothing more than rotation and translation.
Therefore, with a vertex v in the coordinates of the Link1.1, then converting it to world coordinates V ' is:
V ' = t0*t1*r1*t1.1*r1*v (use column vectors here)
This is the fact that the vertices in the local coordinates are transformed into world coordinates through this series of matrices.
When the skin vertex mix because I write the program is still quite painful, I have to facilitate the import of a model into 3 models, and then the three model one by one to the world space, so as to avoid from the model space to the bone space calculation, but in the mixing of the bone to be loaded with the vertex to the corresponding bone space, These things are calculated in shader.
#version410Corelayout ( location=2)inchvec4 a_position;layout ( location=3)inchvec4 a_weight;uniform mat4 mv_matrix;uniform mat4 proj_matrix;uniform mat4 b1_matrix;uniform mat4 b2_matrix;uniform MAT4 B3_matrix;uniformintBone;//Bone LengthfloatBone_len =47.2441f;voidMain () {VEC4 new_a_position=a_position; VEC4 New_a_position1=a_position; //vertices that are offset upwardNEW_A_POSITION.Y + =Bone_len; //vertices that are shifted downwardNEW_A_POSITION1.Y-=Bone_len; //make different changes to different bones Switch(bone) { Case 1: Gl_position= proj_matrix*mv_matrix* (a_weight.x*b1_matrix*a_position+a_weight.y*b2_matrix*new_a_position1); Break; Case 2: Gl_position= proj_matrix*mv_matrix* (a_weight.x*b1_matrix*new_a_position+a_weight.y*b2_matrix*a_position+a_weight.z*b3_ matrix*new_a_position1); Break; Case 3: Gl_position= proj_matrix*mv_matrix* (a_weight.y*b2_matrix*new_a_position+a_weight.z*b3_matrix*a_position); Break; default: Break; } }
Then it is:
After blending vertices
"Computer animation" Skin notes