【发布时间】:2023-04-04 17:17:01
【问题描述】:
我正在尝试遵循here ( at ogldev ) 提到的in this answer 的教程。
然而,我面临一些我认为与 Assimp 的行主要订单与 GLM 的列主要订单有关的问题,尽管我不太确定。
我尝试了一些变体和命令以查看其中任何一个是否有效,但无济于事。
Here ( Gist ) 是我用来加载完整 MD5 文件的类。还有我目前的结果。
而且,当我尝试更新骨骼变换矩阵时,这是我认为出错的部分。
void SkeletalModel::ReadNodeHierarchyAnimation(float _animationTime, const aiNode* _node,
const glm::mat4& _parentTransform)
{
std::string node_name = _node->mName.data;
const aiAnimation * p_animation = scene->mAnimations[0];
glm::mat4 node_transformation(1.0f);
convert_aimatrix_to_glm(node_transformation, _node->mTransformation);
// Transpose it.
node_transformation = glm::transpose(node_transformation);
const aiNodeAnim * node_anim = FindNodeAnim(p_animation, node_name);
if (node_anim) {
//glm::mat4 transformation_matrix(1.0f);
glm::mat4 translation_matrix(1.0f);
glm::mat4 rotation_matrix(1.0f);
glm::mat4 scaling_matrix(1.0f);
aiVector3D translation;
CalcInterpolatedPosition(translation, _animationTime, node_anim);
translation_matrix = glm::translate(translation_matrix, glm::vec3(translation.x, translation.y, translation.z));
aiQuaternion rotation;
CalcInterpolatedRotation(rotation, _animationTime, node_anim);
// Transpose the matrix after this.
convert_aimatrix_to_glm(rotation_matrix, rotation.GetMatrix());
//rotation_matrix = glm::transpose(rotation_matrix);
aiVector3D scaling;
CalcInterpolatedScaling(scaling, _animationTime, node_anim);
scaling_matrix = glm::scale(scaling_matrix, glm::vec3(scaling.x, scaling.y, scaling.z));
node_transformation = scaling_matrix * rotation_matrix * translation_matrix;
//node_transformation = translation_matrix * rotation_matrix * scaling_matrix;
}
glm::mat4 global_transformation = node_transformation * _parentTransform;
if (boneMapping.find(node_name) != boneMapping.end()) {
// Update the Global Transformation.
auto bone_index = boneMapping[node_name];
//boneInfoData[bone_index].finalTransformation = globalInverseTransform * global_transformation * boneInfoData[bone_index].boneOffset;
boneInfoData[bone_index].finalTransformation = boneInfoData[bone_index].boneOffset * global_transformation * globalInverseTransform;
//boneInfoData[bone_index].finalTransformation = globalInverseTransform;
}
for (auto i = 0; i < _node->mNumChildren; i++) {
ReadNodeHierarchyAnimation(_animationTime, _node->mChildren[i], global_transformation);
}
}
我当前的输出:
我尝试通过代码中使用的每个矩阵来检查是否应该转置它。我是否应该更改矩阵乘法顺序。我找不到我的问题。
如果有人能在此处指出我的错误或将我引导至其他教程以帮助我加载动画,那就太好了。
另外,我看到建议在学习的初始阶段使用基本模型。但有人告诉我 Obj 格式不支持动画,在此之前我一直在使用 Obj。我是否可以使用 Blender 以类似于本教程中所示的 MD5 的方式导出的任何其他格式?
【问题讨论】:
标签: c++ opengl glm-math assimp