Skip to content

Fix GLTF bind matrix remapping#5782

Merged
akleshchev merged 1 commit into
secondlife:developfrom
gaiaclary:fix-gltf-bind-matrix-remap
May 18, 2026
Merged

Fix GLTF bind matrix remapping#5782
akleshchev merged 1 commit into
secondlife:developfrom
gaiaclary:fix-gltf-bind-matrix-remap

Conversation

@gaiaclary

Copy link
Copy Markdown
Contributor

Description

Fixes GLTF inverse bind matrix remapping for skeletons whose bind pose does not exactly match the viewer skeleton. This makes it possible to import GLB or DAE files created from the same model with identical vertex-level results. Edges may still vary depending on how each exporter calculates triangulation.

The previous code applied a per-joint world-space skeleton transform directly to each bind matrix. When a source parent joint carries bind-pose rotation that the viewer parent does not, that rotation can be baked into child inverse bind matrices, causing visible child joint twists.

This change remaps bind matrices by preserving each joint's bind-pose delta from its own GLTF rest matrix, then applying that local delta to the viewer override rest matrix. It also centralizes GLTF-to-viewer coordinate conversion for rest and bind matrix calculations.

Also adds .gitignore entries for generated local build folders:

  • /.autobuild-installables/
  • /.logs/

Related Issues

Issue Link: relates to https://feedback.secondlife.com/bug-reports/p/gltf-inverse-bind-matrix-remapping-bind-poses-not-fully-supported


Checklist

Please ensure the following before requesting review:

  • I have provided a clear title and detailed description for this pull request.
  • If useful, I have included media such as screenshots and video to show off my changes.
  • The PR is linked to a relevant issue with sufficient context.
  • I have tested the changes locally and verified they work as intended.
  • All new and existing tests pass.
  • Code follows the project's style guidelines.
  • Documentation has been updated if needed.
  • Any dependent changes have been merged and published in downstream modules
  • I have reviewed the contributing guidelines.

Additional Notes

1.) This is a bind-posed model in Blender with A-pose as rest pose:

Screenshot 2026-05-10 at 01 15 11

2.) This is how the SL preViewer displays the model with this fix applied:
Screenshot 2026-05-10 at 01 13 25

3.) This is how the official SL preViewer displays the same model without the fix:
Screenshot 2026-05-10 at 01 11 54

4.) Here are the DAE and GLB files, both exported from the same A-posed mesh:

glb_and_dae.zip

Important: When both files are loaded with the patched viewer, both meshes are identical at vertex level. Edges may differ due to different triangulation between GLB and DAE exports.

Local build verification:

  • llgltfloader.cpp was compiled through the Xcode secondlife-bin target in Release.
  • The compile used the project warning settings including -Wall and -Werror.
  • No compiler diagnostics were emitted for llgltfloader.cpp.

Disclaimer

This patch fixes the issue in our tests, but there may be a better approach. Please feel free to adjust the implementation as needed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the GLTF skin import path to remap inverse bind matrices in a joint-local way (instead of applying a world-space skeleton transform directly), improving rig parity between GLB and DAE imports when bind poses differ from the viewer skeleton. It also adds ignores for locally generated build/log output folders.

Changes:

  • Precomputes rotated bind matrices in viewer space and remaps each joint’s bind matrix using a per-joint rest→bind delta applied onto the viewer override rest matrix.
  • Adds helper APIs to centralize GLTF→viewer coordinate rotation for bind/rest computations.
  • Updates .gitignore to exclude additional generated folders.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
indra/newview/gltf/llgltfloader.h Declares new helper methods for coordinate conversion and bind-matrix remapping.
indra/newview/gltf/llgltfloader.cpp Implements joint-local bind remapping (computeViewerBindMatrix) and uses it during skin processing.
.gitignore Adds ignore rules for local build/install/log directories.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1725 to +1730
if (bind_iter == rotated_bind_matrices.end() || !node_data.mIsOverrideValid)
{
converted_bind_matrices[gltf_node_index] = node_data.mOverrideRestMatrix;
return node_data.mOverrideRestMatrix;
}

@akleshchev akleshchev May 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like copilot got the right idea here. mOverrideRestMatrix isn't initialized by default so code should either check it, assert or have other sort of 'don't run before buildOverrideMatrix' security.

But it does look like mOverrideRestMatrix would be initialized because buildOverrideMatrix gets called first for every joint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaiaclary can you check that ^^ please?

Comment on lines +1687 to +1689
// skeleton override and bind-pose calculations. Keeping this conversion in
// one helper ensures bind and rest matrices use the same rotation path,
// including the optional XY rotation applied for compatible uploads.
@DarlCat

DarlCat commented May 11, 2026

Copy link
Copy Markdown
Contributor

Question: Do meshes uploaded utilizing this feature with this patch look correct to unpatched viewers?

Does this open the door to a breaking change in the mesh upload pipeline just to add support for an optional part of the glTF spec?

Screenshot 2026-05-11 at 11 53 20 AM

@akleshchev

Copy link
Copy Markdown
Contributor

Thank you.
I run this throught a dozen gltf rigged meshes, no issues surfaced. Merging.

@akleshchev akleshchev merged commit 447f307 into secondlife:develop May 18, 2026
16 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GLTF inverse bind matrix remapping (bind poses) not fully supported

4 participants