我正在尝试在我的 3D Enigne (DX 11) 上实现骨骼动画。蒙皮部分工作正常,但骨矩阵转换几乎没有问题。我正在使用基于 Valve 的 SMD 并已转换为左手坐标系(YZ 交换)的自制二进制格式。所以有我的骨头到世界的代码:
for(int i = 0; i < Model->numJoints; i++)
{
Bones[i].WorldPos = XMFLOAT3(0.0f, 0.0f, 0.0f);
Joint tmpJoint = Model->joints[i]; //bind-pose bone data (translation + orientation)
//Rotation matrix calculation
XMMATRIX RotX = XMMatrixRotationX(-tmpJoint.orientation.x);
XMMATRIX RotY = XMMatrixRotationY(-tmpJoint.orientation.y);
XMMATRIX RotZ = XMMatrixRotationZ(-tmpJoint.orientation.z);
//Rot * Translation
XMMATRIX Local = RotX * RotY * RotZ * XMMatrixTranslation(tmpJoint.pos.x, tmpJoint.pos.y, tmpJoint.pos.z);
XMMATRIX tmp;
if (Model->Skeleton.parentID[i] != -1)
{
Bones[i].global = Local * Bones[Model->Skeleton.parentID[i]].global;
}
else
Bones[i].global = Local;
XMVECTOR temp;
XMStoreFloat3(&Bones[i].WorldPos, XMVector3Transform(temp, Bones[i].global));
}
//line between 2 connected bones (aka skeleton)
bonePoints[i] = Bones[i].WorldPos; //bone position in world
bonePoints[i+1] = Bones[Model->Skeleton.parentID[i]].WorldPos; //parent bone position in world
正如您在下面的图片中看到的那样,计算出的骨架看起来变形了。我认为旋转计算部分有问题,可能遗漏了一些额外的转置。我试图改变矩阵乘法顺序但没有任何成功。