Skip to content

Commit

Permalink
Fix & improve glTF loader matrix decomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
appgurueu authored and sfan5 committed Feb 27, 2025
1 parent d74af2f commit 90121dc
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions irr/src/CGLTFMeshFileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,16 +546,6 @@ void SelfType::MeshExtractor::deferAddMesh(
});
}

// Base transformation between left & right handed coordinate systems.
// This just inverts the Z axis.
static const core::matrix4 leftToRight = core::matrix4(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, -1, 0,
0, 0, 0, 1
);
static const core::matrix4 rightToLeft = leftToRight;

static core::matrix4 loadTransform(const tiniergltf::Node::Matrix &m, SkinnedMesh::SJoint *joint)
{
// Note: Under the hood, this casts these doubles to floats.
Expand All @@ -570,14 +560,7 @@ static core::matrix4 loadTransform(const tiniergltf::Node::Matrix &m, SkinnedMes

auto scale = mat.getScale();
joint->Animatedscale = scale;
core::matrix4 inverseScale;
inverseScale.setScale(core::vector3df(
scale.X == 0 ? 0 : 1 / scale.X,
scale.Y == 0 ? 0 : 1 / scale.Y,
scale.Z == 0 ? 0 : 1 / scale.Z));

core::matrix4 axisNormalizedMat = inverseScale * mat;
joint->Animatedrotation = axisNormalizedMat.getRotationDegrees();
joint->Animatedrotation = mat.getRotationRadians(scale);
// Invert the rotation because it is applied using `getMatrix_transposed`,
// which again inverts.
joint->Animatedrotation.makeInverse();
Expand Down

0 comments on commit 90121dc

Please sign in to comment.