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
This commit is contained in:
Mysteryem 2023-01-23 15:38:37 +01:00 committed by Bastien Montagne
parent 5c9ecad1d2
commit 072073e401
Notes: blender-bot 2023-02-14 18:57:45 +01:00
Referenced by issue #75982, FBX export with empty material swapps materials around
1 changed files with 2 additions and 3 deletions

View File

@ -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)