Skip to content

Commit 8a9f09e

Browse files
committed
#4109 #4080 Undistort GLTF rigged mesh in Z-up coordinate transformation
1 parent 71d543f commit 8a9f09e

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

indra/newview/gltf/llgltfloader.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,17 @@ bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh&
716716
LLMatrix4 gltf_transform(glm::value_ptr(rotated_inverse_bind_matrix));
717717
skin_info.mInvBindMatrix.push_back(LLMatrix4a(gltf_transform));
718718

719-
LL_INFOS("GLTF") << "mInvBindMatrix name: " << legal_name << " val: " << gltf_transform << LL_ENDL;
719+
LL_INFOS("GLTF_DEBUG") << "mInvBindMatrix name: " << legal_name << " val: " << gltf_transform << LL_ENDL;
720720

721-
// Translate based of mJointList
722-
gltf_transform.setTranslation(mJointList[legal_name].getTranslation()); // name is supposed to be in mJointList
723-
skin_info.mAlternateBindMatrix.push_back(LLMatrix4a(gltf_transform));
721+
// For alternate bind matrix, use the ORIGINAL joint transform (before rotation)
722+
// Get the original joint node and use its matrix directly
723+
S32 joint = gltf_skin.mJoints[i];
724+
LL::GLTF::Node& jointNode = mGLTFAsset.mNodes[joint];
725+
jointNode.makeMatrixValid();
726+
LLMatrix4 original_joint_transform(glm::value_ptr(jointNode.mMatrix));
727+
728+
LL_INFOS("GLTF_DEBUG") << "mAlternateBindMatrix name: " << legal_name << " val: " << original_joint_transform << LL_ENDL;
729+
skin_info.mAlternateBindMatrix.push_back(LLMatrix4a(original_joint_transform));
724730
}
725731
}
726732

@@ -750,6 +756,8 @@ void LLGLTFLoader::populateJointFromSkin(const LL::GLTF::Skin& skin)
750756
// Create coordinate system rotation matrix - GLTF is Y-up, SL is Z-up
751757
glm::mat4 coord_system_rotation = glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
752758

759+
LL_INFOS("GLTF_DEBUG") << "populateJointFromSkin: Processing " << skin.mJoints.size() << " joints" << LL_ENDL;
760+
753761
for (auto joint : skin.mJoints)
754762
{
755763
auto jointNode = mGLTFAsset.mNodes[joint];
@@ -768,15 +776,31 @@ void LLGLTFLoader::populateJointFromSkin(const LL::GLTF::Skin& skin)
768776

769777
jointNode.makeMatrixValid();
770778

771-
// Apply coordinate system rotation to joint transform
779+
// Debug: Log original joint matrix
772780
glm::mat4 gltf_joint_matrix = jointNode.mMatrix;
781+
LL_INFOS("GLTF_DEBUG") << "Joint '" << legal_name << "' original matrix:" << LL_ENDL;
782+
for(int i = 0; i < 4; i++)
783+
{
784+
LL_INFOS("GLTF_DEBUG") << " [" << gltf_joint_matrix[i][0] << ", " << gltf_joint_matrix[i][1]
785+
<< ", " << gltf_joint_matrix[i][2] << ", " << gltf_joint_matrix[i][3] << "]" << LL_ENDL;
786+
}
787+
788+
// Apply coordinate system rotation to joint transform
773789
glm::mat4 rotated_joint_matrix = coord_system_rotation * gltf_joint_matrix;
774790

791+
// Debug: Log rotated joint matrix
792+
LL_INFOS("GLTF_DEBUG") << "Joint '" << legal_name << "' rotated matrix:" << LL_ENDL;
793+
for(int i = 0; i < 4; i++)
794+
{
795+
LL_INFOS("GLTF_DEBUG") << " [" << rotated_joint_matrix[i][0] << ", " << rotated_joint_matrix[i][1]
796+
<< ", " << rotated_joint_matrix[i][2] << ", " << rotated_joint_matrix[i][3] << "]" << LL_ENDL;
797+
}
798+
775799
LLMatrix4 gltf_transform = LLMatrix4(glm::value_ptr(rotated_joint_matrix));
776800
mJointList[legal_name] = gltf_transform;
777801
mJointsFromNode.push_front(legal_name);
778802

779-
LL_DEBUGS("GLTF") << "mJointList name: " << legal_name << " val: " << gltf_transform << LL_ENDL;
803+
LL_INFOS("GLTF_DEBUG") << "mJointList name: " << legal_name << " val: " << gltf_transform << LL_ENDL;
780804
}
781805
}
782806

0 commit comments

Comments
 (0)