Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions indra/newview/gltf/llgltfloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh&
// Combine transforms: coordinate rotation applied to hierarchy transform
const glm::mat4 final_transform = coord_system_rotation * hierarchy_transform;

// Check if we have a negative scale (flipped coordinate system)
bool hasNegativeScale = glm::determinant(final_transform) < 0.0f;

// Pre-compute normal transform matrix (transpose of inverse of upper-left 3x3)
const glm::mat3 normal_transform = glm::transpose(glm::inverse(glm::mat3(final_transform)));

Expand Down Expand Up @@ -429,9 +432,22 @@ bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh&
vertices.push_back(vert);
}

for (U32 i = 0; i < prim.getIndexCount(); i++)
// When processing indices, flip winding order if needed
for (U32 i = 0; i < prim.getIndexCount(); i += 3)
{
indices.push_back(prim.mIndexArray[i]);
if (hasNegativeScale)
{
// Flip winding order for negative scale
indices.push_back(prim.mIndexArray[i]);
indices.push_back(prim.mIndexArray[i + 2]); // Swap these two
indices.push_back(prim.mIndexArray[i + 1]);
}
else
{
indices.push_back(prim.mIndexArray[i]);
indices.push_back(prim.mIndexArray[i + 1]);
indices.push_back(prim.mIndexArray[i + 2]);
}
}

// Check for empty vertex array before processing
Expand Down Expand Up @@ -572,6 +588,9 @@ bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh&
}
}

// Call normalizeVolumeFaces to compute proper extents
pModel->normalizeVolumeFaces();

// Fill joint names, bind matrices and prepare to remap weight indices
if (skinIdx >= 0)
{
Expand Down