Skip to content

Commit

Permalink
fix coord system
Browse files Browse the repository at this point in the history
  • Loading branch information
PredatorCZ committed Aug 18, 2024
1 parent 55953fd commit 28e19c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions md5anim/md5anim_to_gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions md5mesh/md5mesh_to_gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 28e19c5

Please sign in to comment.