Fix T41015: FBX importer does not check material indices of polygons are valid.

We have to validate this once materials are linked to meshes!

(Knowing whether it is expected to have invalid indices in FBX data is irrelevant -
there is nothing valid really in this file format!
In this case, looks like all models have an ultimate, cryptic 'default' material
(only defined by some sort of ugly long UUID key)).
This commit is contained in:
Bastien Montagne 2014-07-12 18:37:06 +02:00
parent 0e4f0c2ee8
commit 15054752be
Notes: blender-bot 2023-02-14 20:05:21 +01:00
Referenced by issue #41015, FBX importer does not check material indices of polygons are valid.
1 changed files with 11 additions and 0 deletions

View File

@ -1294,6 +1294,17 @@ def load(operator, context, filepath="",
fbx_lnk_material_type) in connection_filter_reverse(fbx_lnk_uuid, b'Material'):
mesh.materials.append(material)
# We have to validate mesh polygons' mat_idx, see T41015!
# Some FBX seem to have an extra 'default' material which is not defined in FBX file.
max_idx = max(0, len(mesh.materials) - 1)
has_invalid_indexes = False
for p in mesh.polygons:
if p.material_index > max_idx:
has_invalid_indexes = True
p.material_index = 0
if has_invalid_indexes:
print("WARNING: mesh '%s' had invalid material indices, those were rest to first material" % mesh.name)
_(); del _
def _():