Fix: FBX fails to export materials on geometry nodes objects #104530

Merged
Bastien Montagne merged 1 commits from Mysteryem/blender-addons:fbx_fix_geometry_nodes_mat_export_pr into main 2023-04-12 11:27:03 +02:00
Member

For only the FBX exporter, fixes #104516.

The exporter would always get the materials to export from the original,
non-evaluated, object, but Geometry nodes, when applied, replace the
materials of the object and mesh/curve/etc., so the wrong materials
would be exported.

Now, when modifiers are applied on export, the materials of the
evaluated object are checked against the materials of the original
object. When the materials differ, the materials of the evaluated object
are set into the override_materials of the ObjectWrapper, causing its
materials property (refactored from the material_slots property) to
return them.

For only the FBX exporter, fixes #104516. The exporter would always get the materials to export from the original, non-evaluated, object, but Geometry nodes, when applied, replace the materials of the object and mesh/curve/etc., so the wrong materials would be exported. Now, when modifiers are applied on export, the materials of the evaluated object are checked against the materials of the original object. When the materials differ, the materials of the evaluated object are set into the `override_materials` of the ObjectWrapper, causing its `materials` property (refactored from the `material_slots` property) to return them.
Thomas Barlow added 1 commit 2023-04-05 15:06:06 +02:00
98017421b4 Fix: FBX fails to export materials on geometry nodes objects
For only the FBX exporter, fixes #104516.

The exporter would always get the materials to export from the original,
non-evaluated, object, but Geometry nodes, when applied, replace the
materials of the object and mesh/curve/etc., so the wrong materials
would be exported.

Now, when modifiers are applied on export, the materials of the
evaluated object are checked against the materials of the original
object. When the materials differ, the materials of the evaluated object
are set into the `override_materials` of the ObjectWrapper, causing its
`materials` property (refactored from the `material_slots` property) to
return them.
Author
Member

Initially I wanted to add an extra element to each tuple value in data_meshes that would specify the override materials to use, but another part of the code that finds all the materials to include in the export does so by iterating through each ObjectWrapper and I didn't want to add extra conditional behaviour in this loop depending on whether the ObjectWrapper is in data_meshes, when the ObjectWrapper is supposed to be a generic way to access data regardless of what type the Object is.

This led me to replace the material_slots property with materials because there's no easy way to create a sequence of fake material slots to be used as an override and all existing use of material_slots was just getting the materials of the slots.

Initially I wanted to add an extra element to each tuple value in `data_meshes` that would specify the override materials to use, but another part of the code that finds all the materials to include in the export does so by iterating through each ObjectWrapper and I didn't want to add extra conditional behaviour in this loop depending on whether the ObjectWrapper is in `data_meshes`, when the ObjectWrapper is supposed to be a generic way to access data regardless of what type the Object is. This led me to replace the `material_slots` property with `materials` because there's no easy way to create a sequence of fake material slots to be used as an override and all existing use of `material_slots` was just getting the materials of the slots.
Germano Cavalcante requested review from Bastien Montagne 2023-04-05 15:56:20 +02:00
Bastien Montagne approved these changes 2023-04-12 11:26:22 +02:00
Bastien Montagne left a comment
Owner

LGTM, nice and elegant solution!

LGTM, nice and elegant solution!
Bastien Montagne merged commit 893100d8e3 into main 2023-04-12 11:27:03 +02:00
Bastien Montagne deleted branch fbx_fix_geometry_nodes_mat_export_pr 2023-04-12 11:27:04 +02:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 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#104530
No description provided.