从FBX文件中提取皮肤数据

时间:2015-09-30 17:43:07

标签: c++ animation directx fbx

我需要将动画数据从Autodesk的FBX文件格式转换为与DirectX兼容的格式;具体来说,我需要计算我的蒙皮网格的偏移矩阵。我已经编写了一个转换器(在这种情况下将.fbx转换为我自己的'场景'格式),其中我想为我的网格计算偏移矩阵。这是代码:

//
//  Skin
//
if(bHasDeformer)
{
    // iterate deformers( TODO: ACCOUNT FOR MULTIPLE DEFORMERS )
    for(int i = 0; i < ncDeformers && i < 1; ++i)
    {
        // skin
        FbxSkin *pSkin = (FbxSkin*)pMesh->GetDeformer(i, FbxDeformer::eSkin);
        if(pSkin == NULL)
            continue;

        // bone count
        int ncBones = pSkin->GetClusterCount();

        // iterate bones
        for (int boneIndex = 0; boneIndex < ncBones; ++boneIndex)
        {                       
            // cluster
            FbxCluster* cluster = pSkin->GetCluster(boneIndex);

            // bone ref
            FbxNode* pBone = cluster->GetLink();

            // Get the bind pose
            FbxAMatrix bindPoseMatrix, transformMatrix;
            cluster->GetTransformMatrix(transformMatrix);
            cluster->GetTransformLinkMatrix(bindPoseMatrix);

            // decomposed transform components
            vS = bindPoseMatrix.GetS();
            vR = bindPoseMatrix.GetR();
            vT = bindPoseMatrix.GetT();

            int *pVertexIndices = cluster->GetControlPointIndices();
            double *pVertexWeights = cluster->GetControlPointWeights();

            // Iterate through all the vertices, which are affected by the bone
            int ncVertexIndices = cluster->GetControlPointIndicesCount();

            for (int iBoneVertexIndex = 0; iBoneVertexIndex < ncVertexIndices; iBoneVertexIndex++) 
            {
                // vertex
                int niVertex = pVertexIndices[iBoneVertexIndex];

                // weight
                float fWeight = (float)pVertexWeights[iBoneVertexIndex];
            }
        }
    }

如何将fbx变换转换为骨骼偏移矩阵?

0 个答案:

没有答案