• <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>

            天行健 君子當(dāng)自強(qiáng)而不息

            D3D Animation Basis(7)

            Updating Skinned Meshes

            A skinned mesh works like this: Each vertex is attached to an imaginary bone (which is specified by a frame object). As these frames move, so do the vertices attached to them. To update the coordinates of the vertices as the bones move, you need to call a special function that takes the source vertex data, transforms it according to the bones' transformations, and stores the results in a second mesh object. This special function is called ID3DXSkinInfo::UpdateSkinnedMesh.

            Whenever you load a mesh using the D3DXLoadSkinMeshFromXof function (which is what the second LoadMesh function does), you get a pointer to an ID3DXSkinInfo object. This object contains the information about which vertices are attached to which bones. This way, the object knows which transformations to apply to the vertices.

            To update the vertices, you must first lock the mesh's vertex buffer (which contains the source vertex coordinates), as well as the destination mesh's vertex buffer. The destination mesh will receive the updated vertices as they are transformed. Once locked, you need to call UpdateSkinnedMesh, also specifying a series of transformation matrices (stored as D3DXMATRIX objects) that represent the various bone transformations.

            For now, just check out the update_skin_mesh helper function code to see how it updates the skinned meshes for you.

            HRESULT update_skin_mesh(D3DXMESHCONTAINER_EX* mesh_container)
            {
                
            if(mesh_container == NULL)
                    
            return E_FAIL;

                
            if(mesh_container->MeshData.pMesh == NULL || mesh_container->skin_mesh == NULL || mesh_container->pSkinInfo == NULL)
                    
            return E_FAIL;

                
            if(mesh_container->bone_matrices == NULL || mesh_container->frame_matrices == NULL)
                    
            return E_FAIL;

                
            // copy the bone matrices over (must have been combined before call draw_mesh)
                for(DWORD i = 0; i < mesh_container->pSkinInfo->GetNumBones(); i++)
                {
                    
            // start with bone offset matrix
                    mesh_container->bone_matrices[i] = *(mesh_container->pSkinInfo->GetBoneOffsetMatrix(i));

                    
            // apply frame transformation
                    if(mesh_container->frame_matrices[i])
                        mesh_container
            ->bone_matrices[i] *= (*mesh_container->frame_matrices[i]);
                }

                
            void* src_vertices;
                
            void* dest_vertices;

                mesh_container
            ->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&src_vertices);
                mesh_container
            ->skin_mesh->LockVertexBuffer(0, (void**)&dest_vertices);

                
            // update the skinned mesh using provided transformations
                mesh_container->pSkinInfo->UpdateSkinnedMesh(mesh_container->bone_matrices, NULL, src_vertices, dest_vertices);

                mesh_container
            ->MeshData.pMesh->UnlockVertexBuffer();
                mesh_container
            ->skin_mesh->UnlockVertexBuffer();    

                
            return S_OK;
            }

             

            Aside from the typical error−checking code, the update_skin_mesh function starts by looping through each bone contained within the ID3DXSkinInfo object (stored in the D3DXMESHCONTAINER_EX object you've already loaded). For each bone, the original transformation matrix from the .X file is grabbed and stored in an array of matrices used in the call to UpdateSkinnedMesh.

            From here the bone's transformation, as stored in the bone's respective frame object, is applied to the transformation matrix. This process continues until all transformation matrices are set up

            At this point, you are ready to lock the vertex buffers and call the UpdateSkinnedMesh function.

            The function is finished by unlocking the buffers and returning a success code.

            And once again speaking of rendering, it is finally time to see the helper functions I created to get those
            meshes on screen!


            posted on 2008-04-15 10:22 lovedday 閱讀(313) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評(píng)論

            色综合久久中文色婷婷| 亚洲精品无码久久久久AV麻豆| 亚洲乱码中文字幕久久孕妇黑人| 久久久一本精品99久久精品88| 久久久久av无码免费网| 久久se精品一区二区| 久久国产乱子伦精品免费午夜| 婷婷久久综合九色综合绿巨人 | 亚洲国产高清精品线久久 | 国产一区二区三精品久久久无广告| 91精品国产91热久久久久福利| 久久夜色精品国产亚洲| 久久免费视频观看| 亚洲伊人久久大香线蕉综合图片| 久久被窝电影亚洲爽爽爽| 久久久噜噜噜久久中文字幕色伊伊 | 99久久国产免费福利| 亚洲精品第一综合99久久| 国产精品久久久久久福利漫画| 久久大香萑太香蕉av| 国产精品免费久久| 国产成人久久精品一区二区三区| 亚洲欧美成人久久综合中文网| 色综合久久中文综合网| 久久人妻少妇嫩草AV无码专区| 亚洲综合久久夜AV | 久久精品国产99国产精品| 青青青青久久精品国产 | 青青热久久国产久精品| 久久久中文字幕| 久久国产热精品波多野结衣AV| 波多野结衣AV无码久久一区| 久久久久久久综合狠狠综合| 亚洲人成无码网站久久99热国产| 久久综合欧美成人| 国产精品免费久久| 久久综合九色综合久99| 久久人人爽人人爽人人片AV东京热| 91精品国产色综久久| 精品国产91久久久久久久a| 久久精品无码免费不卡|