3Д БУМ

3Д принтеры и всё что с ними связано

Attaching the Mesh

When your joints are animating smoothly, it is time to attach the mesh. The mesh is what makes up the shape of the model. It is a group of vertices and triangles that help the model have volume and detail. Without the mesh, a skeletally animated model would simply be a

skeleton. Each mesh vertex stores an index into the joint array to signify that it is attached to a certain bone. Now, the way the joints were stored determines the method of transforming and rendering these vertices.

If the joints are stored with each having its parent index, and you have already gone through and calculated the final absolute matrices, attach­ing the mesh is simple. Each vertex must be transformed by its joint’s absolute matrix. Be sure to store your transformed vertex in a special place; do not overwrite your original vertex. This is done because in most formats, the boneframes are not cumulative. Each frame stores the rotation and translation of a specific joint from the starting point. If you do not go back to the original vertices when calculating new vertex positions each time, the model will behave erratically. Figure 5.8 shows what it means to attach individual vertices to a joint.

Attaching the Mesh

Figure 5.8 Attaching vertices to joints.

Now you are probably thinking to yourself, “well, I can animate a model’s vertices, but what about triangles, normals, and texture coor­dinates”? This is where skeletal animation really starts to shine. Each model contains just one set of texture coordinates and triangle infor­mation. Just because the positions of the vertices change does not mean the triangle indexes and texture coordinates have to. This means you don’t have to worry about them once you set them up.

Normals are another story. Because the orientation of the polygons and vertices change, so will the normals. If you are using just face normals, you need to recalculate them manually every frame before sending them to the renderer. However, if you calculated vertex

normals at the beginning, you are in luck. Vertex normals do not have to be completely recalculated after transformation. They can be transformed by the same matrix as the vertices were. The only differ­ence here is that you do not take in account translation. Using the Transform3() function of the matrix class will rotate your vertex normal, while still retaining its original magnitude.

If the joints store child indexes and you are pushing the current transformation matrix onto the stack using glPushMatrix, rendering your model becomes really easy. In this case, it is not necessary to transform each vertex before displaying it. No changes are necessary for rendering anything. Everything you render now will be trans­formed properly, even face normals. Another issue to consider is how vertices are attached to more than one bone. In this case, each bone will have an assigned weight that tells you how much it will affect the joint. The final transformation is the weighted average of all of the transformations of the attached bones.

Для любых предложений по сайту: [email protected]