[Bf-extensions-cvs] [1505475] master: Fix T41015: FBX importer does not check material indices of polygons are valid.

Bastien Montagne noreply at git.blender.org
Sat Jul 12 18:49:00 CEST 2014


Commit: 15054752be43a3b66743fcd4f9702a43c0b6a99a
Author: Bastien Montagne
Date:   Sat Jul 12 18:37:06 2014 +0200
https://developer.blender.org/rBA15054752be43a3b66743fcd4f9702a43c0b6a99a

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

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

M	io_scene_fbx/import_fbx.py

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

diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 2f20212..91ac89c 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -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 _():



More information about the Bf-extensions-cvs mailing list