1

我正在从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 数据相同的值。我将更新如何正确计算数据。

4

1 回答 1

1

答:为了创建绑定姿势,我使用了以下代码。数学类和函数是由本系列的作者创建的,这就是他创建 offsetMatrices 的方式,这也是 Assimp 构建它的骨骼偏移矩阵的方式。他的数学函数可以在这里https://www.youtube.com/watch?v=AqavYcdB7tg&t=3474s在评论部分找到。对于每个骨骼,您通过将四元数转换为旋转矩阵、转置它、然后通过位置的倒数平移平移矩阵,然后将两者结合来创建它。

"sheath"    0 ( 11.004813 -3.177138 31.702473 ) ( 0.307041 -0.578614 0.354181 )
//Example bone offset matrix.

四元数是最后一组 3 个数字,您计算 W 分量然后执行操作。

mlQuaternionToMat4(rotation, joint.orientation);
mlTransposeMat4(rotationInv, rotation);

在这里,您将使用第一组 3 个数字作为关节位置。

mlTranslationMat4(translationInv, -joint.position[0], -          
joint.position[1], -joint.position[2]);
mlMultiplyMat4_2(finalmatrix, rotationInv, translationInv);
//finalMatrix = aiMesh->bone[sheath]->offsetMatrix
于 2016-11-25T23:59:03.483 回答