• <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)而不息

            Working with skeletal animation(6)

            Mapping Bones to Frames

            If you peruse an .X file, you might notice some similarities between the Frame data objects and the SkinWeights objects. For every bone in your skeletal structure, there is a matching SkinWeights object embedded inside a Mesh object that contains the name of a Frame object (or a reference to a Frame object). That's right−each bone is named after its corresponding Frame data object!

            After you load your skinned mesh, you need to connect each bone to its corresponding frame. This is simply a matter of iterating all bones, getting the name of each, and searching the list of frames for a match. Each matching frame pointer is stored in a special bone structure of your design.

            I embedded the bone−mapping data in the D3DXMESHCONTAINER_EX structure. The D3DXMESHCONTAINER_EX structure adds an array of texture objects, a secondary mesh container object, and the bone−mapping data to the D3DXMESHCONTAINER structure.

            struct D3DXMESHCONTAINER_EX : D3DXMESHCONTAINER
            {
              IDirect3DTexture9 **pTextures;
              ID3DXMesh *pSkinMesh;
              D3DXMATRIX **ppFrameMatrices;
              D3DXMATRIX *pBoneMatrices;

              // .. extra data and functions to follow
            };

            For this chapter, the important variables are ppFrameMatrices and pBoneMatrices. The pBoneMatrices array contains the transformations from your bone hierarchy; one transformation matrix is applied to each vertex belonging to the appropriate bone. The only problem is, the transformations from your bones are not stored in an array; they're stored as a hodgepodge of single transformations spread throughout the hierarchy.

            The D3DXMESHCONTAINER_EX structure provides a pointer to each bone transformation matrix contained within the hierarchy of D3DXFRAME_EX objects inside an array of pointers (ppFrameMatrices). Using these pointers, you can pull each bone transformation and place it into the pBoneMatrices array you'll create and use during the call to update your skinned mesh.

            You can create the array of pointers and the array of matrices after you load the bone hierarchy by taking the number of bones from the hierarchy and allocating an array of D3DXMATRIX pointers and D3DXMATRIX objects, like this:

            // pSkinInfo = skinned mesh object

            // Get the number of bones in the hierarchy
            DWORD NumBones = pSkinInfo−>GetNumBones();

            // Allocate an array of D3DXMATRIX pointers to point to each bones' transformation.
            D3DXMATRIX *ppFrameMatrices = new D3DXMATRIX*[NumBones];

            // Allocate an array of D3DXMATRIX matrix objects to contain the actual transformations
            // used to update the skinned mesh.
            D3DXMATRIX *pBoneMatrices = new D3DXMATRIX[NumBones];

            After you load your skinned mesh, you can set up the pointers to each bone transformation by querying the skinned mesh info object for each bone name. Using that, you can scan the list of frames for a match. For each matched bone, set the pointer to that frame's transformation matrix. When all bones and frames are matched up, you can then iterate the entire list and copy the matrices to the pBoneMatrices array.

            First let me show you how to match up the bones and frames. Remember that earlier in this chapter I mentioned that the bones are named after the frames. Using the ID3DXSkinInfo::GetBoneName function, you can obtain the name of the bone and frame to match.

            // Go through each bone and grab the name of each to work with
            for(DWORD i=0;i<pSkinInfo−>GetNumBones();i++) {
              // Get the bone name
              const char *BoneName = pSkinInfo−>GetBoneName(i);

            When you have the bone's name, you can scan through the list of frames in the hierarchy to look for a match. To do so, you use the recursive FindFrame function developed in the "Modifying Bone Orientation" section earlier in this chapter, as follows.

            // pRootFrame = D3DXFRAME_EX root frame object

            // Find matching name in frames
            D3DXFRAME_EX *pFrame = pRootFrame−>Find(BoneName);

            If a frame with the name provided by the bone is found, you can link to the frame's combined transformation matrix. If no match is found, then the link is set to NULL.

            // Match frame to bone
            if(pFrame)
              pMesh−>ppFrameMatrices[i] = &pFrame−>matCombined;
            else
              pMesh−>ppFrameMatrices[i] = NULL;
            }

            You might not understand the exact reasons for mapping the bones to the frame at this moment, but it will make more sense when you get into manipulating the skinned mesh and rebuilding the mesh to render it. For now, take each step in stride, and start by learning how to manipulate the skinned mesh.

             

            Manipulating the Skinned Mesh

            Now nothing is stopping you from twisting up that skeletal structure and going crazy. Just make sure it's your mesh's imaginary skeletal structure you're manipulating and not your own−I just hate it when I accidentally manipulate my bones into a pose I can't get out of for an hour! Kidding aside, you can now alter the frame orientations in your frame hierarchy. It's those frames that represent your bones.

            Speaking of altering the frame orientations, be aware that you should only rotate your bones; you should never translate them. Scaling is acceptable, but be careful−remember that all transformations propagate throughout the hierarchy. If you were to scale your character's upper arm, the lower arm would be scaled as well.

            I covered changing the orientations of the various bones earlier in this chapter, in the "Modifying Bone Orientation" section, so I won't rehash anything here. After you've loaded the skeletal structure and skinned mesh, feel free to start working with the bone transformations using those techniques covered earlier. When you're ready, you can update the skinned mesh and prepare it for rendering.


            posted on 2008-04-23 19:39 lovedday 閱讀(264) 評(píng)論(0)  編輯 收藏 引用


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


            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(lèi)(178)

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

            搜索

            最新評(píng)論

            久久综合狠狠综合久久激情 | 青青久久精品国产免费看| 亚洲午夜福利精品久久| 精品久久久久成人码免费动漫| 久久天天躁夜夜躁狠狠躁2022| 新狼窝色AV性久久久久久| 99久久成人国产精品免费| 久久国产精品免费一区二区三区| 三级片免费观看久久| 久久精品人人做人人爽97| 久久91这里精品国产2020| 99久久国产精品免费一区二区| 成人免费网站久久久| 婷婷久久综合九色综合九七| 人妻精品久久久久中文字幕69| 国产精品免费久久久久影院| 亚洲午夜久久久久久噜噜噜| 91亚洲国产成人久久精品网址 | 久久精品国产亚洲av高清漫画| 99久久精品免费国产大片| 一本色道久久HEZYO无码| 久久久精品国产Sm最大网站| 久久精品无码专区免费东京热| 免费精品久久久久久中文字幕| AV无码久久久久不卡蜜桃| 日产精品久久久久久久| 久久精品亚洲男人的天堂| 成人久久久观看免费毛片| 久久永久免费人妻精品下载| 久久精品国产亚洲AV蜜臀色欲| 亚洲欧美一级久久精品| 国产精品熟女福利久久AV| 2020最新久久久视精品爱| 99久久无色码中文字幕| 99久久精品费精品国产一区二区| 7777久久久国产精品消防器材| 怡红院日本一道日本久久 | 天天躁日日躁狠狠久久| 伊人久久精品影院| 中文字幕无码久久精品青草| 一级做a爰片久久毛片看看|