1 Assimp的aiMatrix4x4与glm的mat4相互转换

在使用Assimp加载glb模型之后,将模型节点的mTransformation矩阵转换到glm中的mat4进行后续处理。Assimp的aiMatrix4x4与glm的mat4相关转换代码如下

#include "assimp/Importer.hpp"
#include "assimp/scene.h"
#include "assimp/postprocess.h"

#include "glm/glm.hpp"
#include "glm/core/type_mat4x4.hpp"

inline static glm::mat4 Assimp2Glm(const aiMatrix4x4& from)
{
    return glm::mat4(
        (double)from.a1, (double)from.b1, (double)from.c1, (double)from.d1,
        (double)from.a2, (double)from.b2, (double)from.c2, (double)from.d2,
        (double)from.a3, (double)from.b3, (double)from.c3, (double)from.d3,
        (double)from.a4, (double)from.b4, (double)from.c4, (double)from.d4
    );
}
inline static aiMatrix4x4 Glm2Assimp(const glm::mat4& from)
{
    return aiMatrix4x4(from[0][0], from[1][0], from[2][0], from[3][0],
        from[0][1], from[1][1], from[2][1], from[3][1],
        from[0][2], from[1][2], from[2][2], from[3][2],
        from[0][3], from[1][3], from[2][3], from[3][3]
    );
}

参考链接