我正在从http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html完成本教程 不幸的是,它没有解释 Assimp 如何获得它的骨骼数据。我知道全局逆变换是一个默认的矩阵值混合器,用于将 y 值设置为 z 值,将 z 值设置为 -y。(或者至少这是我的测试 md5 模型使用的)
GlobalInverseTransform = aiScene->mRootNode->mTransformation;
我试图了解 Assimp 如何从 MD5 文件中导出偏移矩阵或反向绑定姿势。例如BobLampClean.md5mesh有 32 个关节和 32 个偏移矩阵
aiMesh->mBones[i]->mOffsetMatrix;
根据我在网上看到的其他样本,他们计算偏移矩阵,它是这样的......
void ComputeQuatW(glm::quat& quat)
{
float t = 1.0f - (quat.x * quat.x) - (quat.y * quat.y) - (quat.z * quat.z);
if (t < 0.0f)
quat.w = 0.0f;
else
quat.w = -sqrtf(t);
}
glm::mat4 rotation, rotationInv, translationInv, offsetmatrix;
glm::quat MyQuaternion;
//here I chose an arbitrary joint and hard coded its orientation and position
MyQuaternion = glm::quat(glm::quat(-0.535591, -0.462288, -0.534983, 1));
ComputeQuatW(MyQuaternion);
glm::mat4 RotationMatrix = glm::toMat4(MyQuaternion);
rotationInv = glm::transpose(RotationMatrix);
translationInv = glm::translate(translationInv, glm::vec3(-0.014076, -2.592741, -30.241238));
offsetmatrix = rotationInv*translationInv;
我已经输出了这些偏移矩阵中的每一个以与 Assimp 的骨骼矩阵进行比较,但无济于事。我不太确定我做错了什么......
编辑更新:好的,所以我的操作不正确,我正在调试一个不使用 Assimp 的工作代码示例,它可以复制与 Assimp 数据相同的值。我将更新如何正确计算数据。