[Bf-extensions-cvs] [a0e8b8b7] blender-v2.91-release: Fix T82830: Handle limit for vertex color and uv layers in importer

Robert Guetzkow noreply at git.blender.org
Mon Nov 23 13:39:49 CET 2020


Commit: a0e8b8b7875ba1eb883a714344d6fbace6259b4f
Author: Robert Guetzkow
Date:   Mon Nov 23 13:32:38 2020 +0100
Branches: blender-v2.91-release
https://developer.blender.org/rBAa0e8b8b7875ba1eb883a714344d6fbace6259b4f

Fix T82830: Handle limit for vertex color and uv layers in importer

Blender has a limit for both vertex color layers and UV layers. The
functions `bpy.types.Mesh.vertex_colors.new()` and
`bpy.types.Mesh.uv_layers.new()` will return `None` once the limit
is reached. The FBX importer and glTF importer didn't handle this
case before and attempted to access the `data`, which failed. This
patch adds the missing checks. In case no vertex colors or uv map
can be created, the assignment of colors or uv coordinates is
skipped.

Reviewed By: mont29, julien

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

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

M	io_scene_fbx/import_fbx.py
M	io_scene_gltf2/blender/imp/gltf2_blender_mesh.py

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

diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 319c4972..ec16b6d1 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -1079,6 +1079,12 @@ def blen_read_geom_layer_color(fbx_obj, mesh):
 
             # Always init our new layers with full white opaque color.
             color_lay = mesh.vertex_colors.new(name=fbx_layer_name, do_init=False)
+
+            if color_lay is None:
+                print("Failed to add {%r %r} vertex color layer to %r (probably too many of them?)"
+                      "" % (layer_id, fbx_layer_name, mesh.name))
+                continue
+
             blen_data = color_lay.data
 
             # some valid files omit this data
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
index 09ec325b..0311c3b0 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
@@ -275,12 +275,22 @@ def do_primitives(gltf, mesh_idx, skin_idx, mesh, ob):
     for uv_i in range(num_uvs):
         name = 'UVMap' if uv_i == 0 else 'UVMap.%03d' % uv_i
         layer = mesh.uv_layers.new(name=name)
+
+        if layer is None:
+            print("WARNING: UV map is ignored because the maximum number of UV layers has been reached.")
+            break
+
         layer.data.foreach_set('uv', squish(loop_uvs[uv_i]))
 
     for col_i in range(num_cols):
         name = 'Col' if col_i == 0 else 'Col.%03d' % col_i
         layer = mesh.vertex_colors.new(name=name)
 
+        if layer is None:
+            print("WARNING: Vertex colors are ignored because the maximum number of vertex color layers has been "
+                  "reached.")
+            break
+
         layer.data.foreach_set('color', squish(loop_cols[col_i]))
 
     # Skinning



More information about the Bf-extensions-cvs mailing list