我正在尝试编写一个解析FBX文件并将其转换为我的自定义模型格式的解析器,以便在我的游戏引擎中使用,但我目前卡在提取每个骨骼所需的矩阵上。我认为我可能也迷失在蒙皮理论中了...
我已经成功地提取了网格的骨骼层次结构,并将变形集群的权重和索引附加到我的顶点上。现在我需要提取我在引擎中进行蒙皮所需的(两个?)矩阵。
基本上,在我的格式中,我希望它看起来像这样:
//骨骼ID
//父骨骼ID
//矩阵1
//矩阵2
现在是关于矩阵的问题... 我是否可以假设它们中至少有一个应该是“绑定姿势矩阵”,即我的骨架的默认位置?我如何从FBX中提取此矩阵?此矩阵对整个网格均匀吗?
至于第二个矩阵,我不太清楚,我尝试查看ViewScene和ImportScene示例,但我不理解。我读到了一些关于“本地空间矩阵”的内容,我猜这是每个骨骼的单独位置、旋转和缩放?
任何帮助或建议都将不胜感激,我现在很茫然,可能是因为一直盯着这个问题看而导致的。我快要放弃FBX,改用COLLADA了。
编辑1:引擎还没有绘图功能,因为我想先把这个搞定再做下一步。我找到了一个我认为我理解的例子,也许这里有人可以确认它是否正确。
//TEST CODE
//This lFbxLinkMatrix is the skeleton's transform when the binding happened.
//It is the same as the matrix in bindpose if the bindpose is complete.
// Multiply lClusterGlobalInitPosition by Geometric Transformation
FbxAMatrix clusterGlobalInitPosition;
cluster->GetTransformLinkMatrix(clusterGlobalInitPosition);
FbxAMatrix clusterGeometry = GetGeometry(cluster->GetLink());
clusterGlobalInitPosition *= clusterGeometry;
skeleton->at(boneListPosition).bindMatrix = clusterGlobalInitPosition;
// Compute the shift of the link relative to the reference.
//lVertexTransformMatrix = RGCP.Inverse() * CGCP * CGIP.Inverse() * RGIP * RG;
// CGCP = position of bone
// RGCP = mesh position
FbxAMatrix offsetMatrix;
FbxNode* boneNode = cluster->GetLink();
FbxAMatrix CGIP, RGIP, vertexTransformMatrix;
cluster->GetTransformLinkMatrix(CGIP);
cluster->GetTransformMatrix(RGIP);
vertexTransformMatrix = CGIP.Inverse() * RGIP;
skeleton->at(boneListPosition).localBoneMatrix = vertexTransformMatrix;
基本上,当我想计算我的动画时,我会获取网格世界矩阵的逆矩阵,将其乘以表示我的动画帧的矩阵,再乘以我的绑定矩阵的逆矩阵、该骨骼的父级绑定矩阵和最终父级变换矩阵。