• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當自強而不息

            Working with skeletal animation(7)

            Updating the Skinned Mesh

            When your skeletal structure is in the pose you desire, it's time to update (or rebuild) the skinned mesh to match. Before you rebuild the skinned mesh, you must make sure you have constructed the secondary mesh container and updated the frame hierarchy. To review how to construct the mesh container, consult the "Creating a Secondary Mesh Container" section earlier in this chapter. To refresh your memory about how to update the frame hierarchy, review the "Updating the Hierarchy" section earlier in this chapter. After you're sure of these two things, you can continue.

            To update the skinned mesh, you must first lock the vertex buffers of the skinned mesh and the secondary mesh. This is critical because DirectX will pull the vertex data from the skinned mesh object, apply the bone transformations, and write the resulting vertex data to the secondary mesh object.

            First, though, you need to copy the transformations from the frames to the array of matrices(pBoneMatrices) stored in the mesh container. At the same time, you have to combine the transformations  with the bones' inversed transformations. The inversed bone transformations are responsible for moving the mesh's vertices to the origin of the mesh before you apply the actual transformation. To better understand this, take a look at Figure 4.4

            The mesh in Figure 4.4 is composed of three bones (frames) and a number of vertices. To apply a transformation to any frame, you must move the vertices belonging to the frame to the origin and then apply the transformations.

            You move the vertices around the origin of the mesh before you apply a transformation because a rotation matrix simply rotates vertices around an origin. If you were to rotate a vertex belonging to any bone, the vertex would rotate around the origin of the mesh instead of the bone's joint. For example, if your body was a mesh and you bent your elbow, the vertices constructing your arm's mesh would rotate around your elbow, not the center of your body. After the vertices are moved to the center of the mesh, the transformation is applied (thus rotating the vertices to match the rotation of the bone) and finally translated into position.

            Normally, these inversed bone transformations are stored in the .X file by the 3D modeler used to create the meshes. If you don't have access to this information from an .X file, you can compute it yourself by first updating the frame hierarchy, and then inverting each frame's combined transformation using the D3DXMatrixInverse function. Here's a quick example.

            // pRoot = root D3DXFRAME_EX object
            // pMesh = D3DXMESHCONTAINER_EX object w/mesh data
            // Update the frame hierarchy
            pRoot−>UpdateHierarchy();
            // Go through each bone and calculate the inverse
            for(DWORD i=0;i<NumBones;i++)
            {
            // Grab the transformation using the bone matrix
            D3DXMATRIX matBone = (*pMesh−>ppFrameMatrices);
            	// Invert the matrix
            D3DXMatrixInverse(&matBone, NULL, &matBone);
            	// Store the inversed bone transformation somewhere
            }

            Instead of going through all the trouble of calculating the inversed bone transformations yourself, however, you can rely on the skinned mesh object to supply that information. By calling ID3DXSkinInfo::GetBoneOffsetMatrix, you'll get the inversed bone transformation matrix pointer. Multiply this matrix by a frame transformation matrix, and you're set!

            Using what you just learned, iterate through all the bones, grab the inversed bone transformation, combine it with the frame transformation, and store the result in the pBoneMatrices array.

            for(DWORD i=0;i<pSkinInfo−>GetNumBones();i++) 
            {
            // Set the inversed bone transformation
            pMesh−>pBoneMatrices[i]=(*pSkinInfo−>GetBoneOffsetMatrix(i));
            	// Apply frame transformation
            if(pMesh−>ppFrameMatrices[i])
            pMesh−>pBoneMatrices[i] *= (*pMesh−>ppFrameMatrices[i]);
            }

            Now that you've copied the bones' transformations into the pBoneMatrices array, you can move on to updating the skinned mesh by first locking the vertex buffers for the skinned mesh and the secondary mesh.

            // pSkinMesh = skinned mesh container
            // pMesh = secondary mesh container

            // Lock the meshes' vertex buffers
            void *SrcPtr, *DestPtr;

            pSkinMesh−>LockVertexBuffer(D3DLOCK_READONLY,(void**)&SrcPtr);
            pMesh−>LockVertexBuffer(0, (void**)&DestPtr);

            After you lock the vertex buffers, you need to perform a call to ID3DXSkinInfo::UpdateSkinnedMesh to apply all the bones' transformations to the vertices and write the resulting data to the secondary mesh container.

            Applies software skinning to the target vertices based on the current matrices.

            HRESULT UpdateSkinnedMesh(
            CONST D3DXMATRIX * pBoneTransforms,
            CONST D3DXMATRIX * pBoneInvTransposeTransforms,
            LPCVOID pVerticesSrc,
            PVOID pVerticesDst
            );

            Parameters

            pBoneTransforms
            [in] Bone transform matrix.
            pBoneInvTransposeTransforms
            [in] Inverse transpose of the bone transform matrix.
            pVerticesSrc
            [in] Pointer to the buffer containing the source vertices.
            pVerticesDst
            [in] Pointer to the buffer containing the destination vertices.

            Return Values

            If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

            Remarks

            When used to skin vertices with two position elements, this method skins the second position element with the inverse of the bone instead of the bone itself.

            To finish, you simply unlock the vertex buffers, and you're ready to render!

            // pSkinInfo = skinned mesh info object

            // Update the skinned mesh using provided transformations
            pSkinInfo−>UpdateSkinnedMesh(pBoneMatrices, NULL, SrcPtr, DestPtr);

            // Unlock the meshes vertex buffers
            pSkinMesh−>UnlockVertexBuffer();
            pMesh−>UnlockVertexBuffer();

             

            Rendering the Skinned Mesh

            Now comes the good part−rendering your secondary mesh and showing the world what it's like to play with powerthe power of skeletal animation and skinned meshes, that is. You only need to depend on the typical mesh−rendering functions to render the secondary mesh. Loop through each material, set the material and texture, and call the ID3DXMesh::DrawSubset function. Loop and continue until all of the subsets have been drawn.

            // pMesh = D3DXMESHCONTAINER_EX object with material data
            // pMeshToDraw = secondary mesh pointer to render
            for(DWORD i=0;i<pMesh−>NumMaterials;i++)
            {
            // Set material and texture
            pD3DDevice−>SetMaterial(&pMesh−>pMaterials[i].MatD3D);
            pD3DDevice−>SetTexture(0, pMesh−>pTextures[i]);
            	// Draw the mesh subset
            pMeshToDraw−>DrawSubset(i);
            }

            posted on 2008-04-23 20:06 lovedday 閱讀(456) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            日韩AV无码久久一区二区| 久久无码专区国产精品发布| 久久久久亚洲AV无码麻豆| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 国产免费久久精品99久久| 久久久久亚洲AV无码专区网站| 久久亚洲国产最新网站| 国产午夜久久影院| 欧美亚洲日本久久精品| 精品久久777| 色狠狠久久综合网| 一本伊大人香蕉久久网手机| 久久综合亚洲鲁鲁五月天| 国产高清美女一级a毛片久久w| 伊人久久成人成综合网222| 青青草国产精品久久久久| 久久久久久久女国产乱让韩| 亚洲精品高清国产一久久| 亚洲伊人久久精品影院 | 四虎影视久久久免费| .精品久久久麻豆国产精品| 中文字幕无码久久精品青草| 国产99久久九九精品无码| 国产亚洲精品自在久久| 亚洲精品美女久久777777| 久久中文字幕人妻丝袜| 午夜精品久久久久成人| 久久精品成人免费观看97| 亚洲国产成人久久综合碰碰动漫3d| 精品久久久久久无码不卡| 久久国产成人午夜aⅴ影院| 久久久中文字幕| 欧美精品一本久久男人的天堂| 久久国产色AV免费看| 久久一日本道色综合久久| 香蕉久久av一区二区三区| 久久妇女高潮几次MBA| 狠狠综合久久AV一区二区三区| 99久久国产亚洲综合精品| 少妇人妻综合久久中文字幕| 热久久最新网站获取|