Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2020-09-05 16:41:05 +0300
committerJulien Duroure <julien.duroure@gmail.com>2020-09-05 16:41:05 +0300
commit0c2ff8fa7c7266de4349fb38c8b59b7678755ded (patch)
tree16b4ffa79a36b289c2278e7dc79fb6443a2e4d10 /io_scene_gltf2/blender
parent5118d312b7a5b760897ec69ffdab56888e0b7678 (diff)
glTF exporter: store vertex colors as normalized ushorts
Diffstat (limited to 'io_scene_gltf2/blender')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_primitive_attributes.py30
1 files changed, 25 insertions, 5 deletions
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