[Bf-extensions-cvs] [6087f4c2] master: glTF importer: fix bad vertex color alpha import

Julien Duroure noreply at git.blender.org
Sat Nov 30 15:53:51 CET 2019


Commit: 6087f4c26540b54ca164494ae46bb1cd1ec25446
Author: Julien Duroure
Date:   Sat Nov 30 15:53:22 2019 +0100
Branches: master
https://developer.blender.org/rBA6087f4c26540b54ca164494ae46bb1cd1ec25446

glTF importer: fix bad vertex color alpha import

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

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/imp/gltf2_blender_primitive.py

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

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index c3d2a9ff..01ac743b 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
 bl_info = {
     'name': 'glTF 2.0 format',
     'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
-    "version": (1, 1, 16),
+    "version": (1, 1, 17),
     'blender': (2, 81, 6),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
index 35e0d6d9..2a7eec17 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
@@ -132,24 +132,23 @@ class BlenderPrimitive():
             colors = BinaryData.get_data_from_accessor(gltf, attributes[layer_name], cache=True)
 
             # Check whether Blender takes RGB or RGBA colors (old versions only take RGB)
-            num_components = len(colors[0])
+            is_rgba = len(colors[0]) == 4
             blender_num_components = len(bme_verts[0].link_loops[0][layer])
-            if num_components == 3 and blender_num_components == 4:
-                # RGB -> RGBA
-                colors = [color+(1,) for color in colors]
-            if num_components == 4 and blender_num_components == 3:
-                # RGBA -> RGB
-                colors = [color[:3] for color in colors]
+            if is_rgba and blender_num_components == 3:
                 gltf2_io_debug.print_console("WARNING",
                     "this Blender doesn't support RGBA vertex colors; dropping A"
                 )
 
             for bidx, pidx in vert_idxs:
                 for loop in bme_verts[bidx].link_loops:
-                    loop[layer] = tuple(
-                        color_linear_to_srgb(c)
-                        for c in colors[pidx]
+                    color = colors[pidx]
+                    col = (
+                        color_linear_to_srgb(color[0]),
+                        color_linear_to_srgb(color[1]),
+                        color_linear_to_srgb(color[2]),
+                        color[3] if is_rgba else 1.0,
                     )
+                    loop[layer] = col[:blender_num_components]
 
             set_num += 1



More information about the Bf-extensions-cvs mailing list