[Bf-extensions-cvs] [0c2ff8fa] master: glTF exporter: store vertex colors as normalized ushorts
Julien Duroure
noreply at git.blender.org
Sat Sep 5 15:41:12 CEST 2020
Commit: 0c2ff8fa7c7266de4349fb38c8b59b7678755ded
Author: Julien Duroure
Date: Sat Sep 5 15:41:05 2020 +0200
Branches: master
https://developer.blender.org/rBA0c2ff8fa7c7266de4349fb38c8b59b7678755ded
glTF exporter: store vertex colors as normalized ushorts
===================================================================
M io_scene_gltf2/__init__.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_primitive_attributes.py
===================================================================
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 0e7fccb9..35380dd9 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, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
- "version": (1, 4, 17),
+ "version": (1, 4, 18),
'blender': (2, 90, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitive_attributes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitive_attributes.py
index e6a5881f..bdfa4e5e 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitive_attributes.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitive_attributes.py
@@ -135,12 +135,32 @@ def __gather_colors(blender_primitive, export_settings):
color_index = 0
color_id = 'COLOR_' + str(color_index)
while blender_primitive["attributes"].get(color_id) is not None:
- internal_color = blender_primitive["attributes"][color_id]
- attributes[color_id] = array_to_accessor(
- internal_color,
- component_type=gltf2_io_constants.ComponentType.Float,
- data_type=gltf2_io_constants.DataType.Vec4,
+ colors = blender_primitive["attributes"][color_id]
+
+ if type(colors) is not np.ndarray:
+ colors = np.array(colors, dtype=np.float32)
+ colors = colors.reshape(len(colors) // 4, 4)
+
+ # Convert to normalized ushorts
+ colors *= 65535
+ colors += 0.5 # bias for rounding
+ colors = colors.astype(np.uint16)
+
+ attributes[color_id] = gltf2_io.Accessor(
+ buffer_view=gltf2_io_binary_data.BinaryData(colors.tobytes()),
+ byte_offset=None,
+ component_type=gltf2_io_constants.ComponentType.UnsignedShort,
+ count=len(colors),
+ extensions=None,
+ extras=None,
+ max=None,
+ min=None,
+ name=None,
+ normalized=True,
+ sparse=None,
+ type=gltf2_io_constants.DataType.Vec4,
)
+
color_index += 1
color_id = 'COLOR_' + str(color_index)
return attributes
More information about the Bf-extensions-cvs
mailing list