From 28e19c5a5f175757343fdaf2fe5c45cb4fde8f6f Mon Sep 17 00:00:00 2001 From: Lukas Cone Date: Sun, 18 Aug 2024 17:45:11 +0200 Subject: [PATCH] fix coord system --- md5anim/md5anim_to_gltf.cpp | 5 +++-- md5mesh/md5mesh_to_gltf.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/md5anim/md5anim_to_gltf.cpp b/md5anim/md5anim_to_gltf.cpp index c2c6cb3..207ec09 100644 --- a/md5anim/md5anim_to_gltf.cpp +++ b/md5anim/md5anim_to_gltf.cpp @@ -55,7 +55,8 @@ struct GLTFAni : GLTF { int32 aniStream = -1; }; -static const es::Matrix44 corMat({0, 0, -1, 0}, {-1, 0, 0, 0}, {0, 1, 0, 0}, +static const float IN_TO_M = 0.0254 * 0.9144; // inch to yard to meter +static const es::Matrix44 corMat({0, 0, 1, 0}, {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}); void LoadAnim(GLTFAni &main, std::istream &istr, std::string animName) { @@ -343,7 +344,7 @@ void LoadAnim(GLTFAni &main, std::istream &istr, std::string animName) { sampl.output = accid; auto WriteTranslation = [&](Vector pos_) { - Vector4A16 pos(pos_); + Vector4A16 pos(pos_ * IN_TO_M); if (b.parentId < 0) { pos = pos * corMat; diff --git a/md5mesh/md5mesh_to_gltf.cpp b/md5mesh/md5mesh_to_gltf.cpp index 2534a2b..cd68ad5 100644 --- a/md5mesh/md5mesh_to_gltf.cpp +++ b/md5mesh/md5mesh_to_gltf.cpp @@ -78,8 +78,9 @@ struct GLTFMain : GLTF { int32 vtStream = -1; }; -static const es::Matrix44 corMat({0, 0, -1, 0}, {-1, 0, 0, 0}, {0, 1, 0, 0}, - {0, 0, 0, 1}); +static const float IN_TO_M = 0.0254 * 0.9144; // inch to yard to meter +static const es::Matrix44 corMat({0, 0, IN_TO_M, 0}, {IN_TO_M, 0, 0, 0}, + {0, IN_TO_M, 0, 0}, {0, 0, 0, 1}); inline bool fltcmp(float f0, float f1, float epsilon = 0.0001) { return (f1 <= f0 + epsilon) && (f1 >= f0 - epsilon); @@ -307,7 +308,7 @@ void AppProcessFile(AppContext *ctx) { gNode.name = b.name; Vector4A16 quat(b.rotation); quat.QComputeElement(); - Vector4A16 pos(b.position, 1); + Vector4A16 pos(b.position * IN_TO_M, 1); b.tm = quat; b.tm.r4() = pos; b.tm.Transpose(); @@ -361,7 +362,7 @@ void AppProcessFile(AppContext *ctx) { Bone &bone = bones.at(mWeight.boneId); vert.boneIds[w] = mWeight.boneId; vert.boneWeights[w] = std::round(mWeight.weight * 0xff); - Vector4A16 tpos(Vector4A16(mWeight.position, 1) * bone.tm); + Vector4A16 tpos(Vector4A16(mWeight.position * IN_TO_M, 1) * bone.tm); Vector bPos(Vector4A16(tpos * mWeight.weight)); vert.position += bPos; }