[Bf-extensions-cvs] [072073e4] master: Fix T75982: FBX export with empty material swapps materials around

Mysteryem noreply at git.blender.org
Mon Jan 23 15:47:30 CET 2023


Commit: 072073e40108b674088e5e604e9108902d212c29
Author: Mysteryem
Date:   Mon Jan 23 15:38:37 2023 +0100
Branches: master
https://developer.blender.org/rBA072073e40108b674088e5e604e9108902d212c29

Fix T75982: FBX export with empty material swapps materials around

FBX exporter code was creating the list used for mapping material indices to FBX indices from only the materials being exported.

Since there is no material for empty material slots, the list used for mapping would be reduced in length by one for each empty material slot.

The mesh's material indices would remain unaffected by the reduction in length of the mapping list, causing any material indices after an empty material slot to be mapped to the wrong FBX index.

This patch changes the creation of the mapping list so that any material slots with a material that is not being exported are mapped to the default material instead of being excluded.

Reviewed By: mont29

Maniphest Tasks: T75982

Differential Revision: https://developer.blender.org/D17034

===================================================================

M	io_scene_fbx/export_fbx_bin.py

===================================================================

diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index 75d8529f..0be94223 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -1199,10 +1199,9 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes):
 
                 # We have to validate mat indices, and map them to FBX indices.
                 # Note a mat might not be in me_fbxmats_idx (e.g. node mats are ignored).
-                blmaterials_to_fbxmaterials_idxs = [me_fbxmaterials_idx[m]
-                                                    for m in me_blmaterials if m in me_fbxmaterials_idx]
+                def_ma = next(me_fbxmaterials_idx[m] for m in me_blmaterials if m in me_fbxmaterials_idx)
+                blmaterials_to_fbxmaterials_idxs = [me_fbxmaterials_idx.get(m, def_ma) for m in me_blmaterials]
                 ma_idx_limit = len(blmaterials_to_fbxmaterials_idxs)
-                def_ma = blmaterials_to_fbxmaterials_idxs[0]
                 _gen = (blmaterials_to_fbxmaterials_idxs[m] if m < ma_idx_limit else def_ma for m in t_pm)
                 t_pm = array.array(data_types.ARRAY_INT32, _gen)



More information about the Bf-extensions-cvs mailing list