Fix #104665: FBX Export: Duplicate materials cause material indices to be offset
commit0a4e4f27043ce86c8eb885d8534cab5df30e8b54
authorThomas Barlow <github@mysterymayhem.co.uk>
Fri, 2 Jun 2023 14:31:30 +0000 (2 15:31 +0100)
committerGitea <gitea@fake.local>
Tue, 6 Jun 2023 15:36:12 +0000 (6 17:36 +0200)
tree403d91ef1ed265f3b3755257018de3c58caddbf5
parent0086ce9d67048900bcc09e05202bd574961d7b85
Fix #104665: FBX Export: Duplicate materials cause material indices to be offset

The export of duplicate materials was changed to skip incrementing the
material index for each duplicate in [0], however the connection was
still being added for each duplicate. Because the connections to
materials are what are indexed by the material indices, the material
indices would no longer match up with the materials, resulting in
incorrect exports.

The original code before the change in [0] was actually exporting FBX
files that worked in external software. The issue was instead in the
FBX importer where it removed duplicate materials without updating the
material indices. Changing the exporter in [0] appeared to fix the issue
because the importer would cause the duplicate materials and material
indices to realign.

Reverting [0] would also have fixed the export issue, however, removing
both the duplicate materials and their connections additionally avoids
the importer issue when these exported files are imported back into
Blender, and makes more sense because only one of each duplicate would
have been used by the exported file in the first place.

[0]: 5c9ecad1d29edd8ba9ebaaad8f71839bd5d88324

Pull Request: https://projects.blender.org/blender/blender-addons/pulls/104667
io_scene_fbx/export_fbx_bin.py