Fix #104737: FBX: Materials missing from linked duplicates #104738

Merged
Bastien Montagne merged 1 commits from Mysteryem/blender-addons:fix_dupli_mats_pr into main 2023-07-06 10:15:56 +02:00
Member

Exporting meshes with duplicate materials combines them into a single
material slot (Material->Model connection) when exporting as FBX because
the material indices dict is keyed by materials. This resulted in unused
duplicate material slots being included in the export.

1 removed these unused duplicate material slots, however, because the
materials for each object are keyed by the object's mesh, this meant
that linked duplicates sharing the same mesh (aside from the first
linked duplicate processed) would not get any material slots because
their materials would already be present in their mesh's dict that
mapped from materials to material indices.

Without larger changes to how materials and material slots are exported,
it is not currently possible to simultaneously remove the unused
duplicate material slots and support linked duplicates. The code for
exporting materials and material slots needs some redesigning anyway so
that linked duplicates with differing materials are actually exported as
linked duplicates instead of duplicating their meshes on export, but
this would be more of a target for 4.0.

As noted in 1, reverting 0 was also an option, so this patch does as
noted and reverts the functional changes of 0, but keeps the comment
because it's still relevant.

This patch changes the export of meshes containing duplicate materials
to export unused duplicate material slots as they did before 1.
Note that because of 2, these unused duplicate material slots are
visible to users when importing the .fbx back into Blender, just like
any meshes with duplicate materials exported as .fbx by Blender 3.5 and
earlier.

Exporting meshes with duplicate materials combines them into a single material slot (Material->Model connection) when exporting as FBX because the material indices dict is keyed by materials. This resulted in unused duplicate material slots being included in the export. [1] removed these unused duplicate material slots, however, because the materials for each object are keyed by the object's mesh, this meant that linked duplicates sharing the same mesh (aside from the first linked duplicate processed) would not get any material slots because their materials would already be present in their mesh's dict that mapped from materials to material indices. Without larger changes to how materials and material slots are exported, it is not currently possible to simultaneously remove the unused duplicate material slots and support linked duplicates. The code for exporting materials and material slots needs some redesigning anyway so that linked duplicates with differing materials are actually exported as linked duplicates instead of duplicating their meshes on export, but this would be more of a target for 4.0. As noted in [1], reverting [0] was also an option, so this patch does as noted and reverts the functional changes of [0], but keeps the comment because it's still relevant. This patch changes the export of meshes containing duplicate materials to export unused duplicate material slots as they did before [1]. Note that because of [2], these unused duplicate material slots are visible to users when importing the .fbx back into Blender, just like any meshes with duplicate materials exported as .fbx by Blender 3.5 and earlier. [0]: commit/5c9ecad1d29edd8ba9ebaaad8f71839bd5d88324 [1]: commit/0a4e4f27043ce86c8eb885d8534cab5df30e8b54 [2]: commit/80db34b208f7a575aa86b06cfc8ee98cb11a1280
Thomas Barlow changed title from Fix 104737: FBX: Materials missing from linked duplicates to Fix #104737: FBX: Materials missing from linked duplicates 2023-07-05 16:30:41 +02:00
Thomas Barlow force-pushed fix_dupli_mats_pr from c109923d78 to b5a42a499a 2023-07-05 16:31:32 +02:00 Compare
Thomas Barlow requested review from Bastien Montagne 2023-07-05 16:37:10 +02:00
Author
Member

I think it would be a good idea for this to also get into 3.6 LTS.

I think it would be a good idea for this to also get into 3.6 LTS.
Bastien Montagne approved these changes 2023-07-06 10:14:55 +02:00
Bastien Montagne left a comment
Owner

Thanks for the fix, also it's unfortunate the change has to be reverted in the end. But this is definitely the only option at this point for 3.6 (will add the commit to the list of backports in the relevant task, blender/blender#109399).

Thanks for the fix, also it's unfortunate the change has to be reverted in the end. But this is definitely the only option at this point for 3.6 (will add the commit to the list of backports in the relevant task, blender/blender#109399).
Bastien Montagne merged commit 65ef64dd01 into main 2023-07-06 10:15:56 +02:00
Bastien Montagne deleted branch fix_dupli_mats_pr 2023-07-06 10:15:56 +02:00
First-time contributor

We wrote a python tool for collapsing duplicating materials for different purposes, including that one.

We wrote a python tool for collapsing duplicating materials for different purposes, including that one.
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#104738
No description provided.