From 2fcac97522dee91d8f444055b9a996fea7d36e40 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Wed, 13 Jul 2022 12:15:28 +0200 Subject: glTF exporter: Manage all 4 types of Vertex Colors (corner/point - byte/float) --- .../exp/gltf2_blender_gather_primitive_attributes.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_primitive_attributes.py') 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 72f0268c..f28a1f10 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 @@ -124,28 +124,34 @@ 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: - colors = blender_primitive["attributes"][color_id] + colors = blender_primitive["attributes"][color_id]["data"] 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) + if blender_primitive["attributes"][color_id]["norm"] is True: + comp_type = gltf2_io_constants.ComponentType.UnsignedShort + + # Convert to normalized ushorts + colors *= 65535 + colors += 0.5 # bias for rounding + colors = colors.astype(np.uint16) + + else: + comp_type = gltf2_io_constants.ComponentType.Float 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, + component_type=comp_type, count=len(colors), extensions=None, extras=None, max=None, min=None, name=None, - normalized=True, + normalized=blender_primitive["attributes"][color_id]["norm"], sparse=None, type=gltf2_io_constants.DataType.Vec4, ) -- cgit v1.2.3 From ef0027e72d295f5bbae1905c6260878851131eef Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Sat, 6 Aug 2022 12:11:15 +0200 Subject: glTF exporter: add bufferView Target at export --- .../blender/exp/gltf2_blender_gather_primitive_attributes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_primitive_attributes.py') 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 f28a1f10..8572d185 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 @@ -44,7 +44,7 @@ def array_to_accessor(array, component_type, data_type, include_max_and_min=Fals amin = np.amin(array, axis=0).tolist() return gltf2_io.Accessor( - buffer_view=gltf2_io_binary_data.BinaryData(array.tobytes()), + buffer_view=gltf2_io_binary_data.BinaryData(array.tobytes(), gltf2_io_constants.BufferViewTarget.ARRAY_BUFFER), byte_offset=None, component_type=component_type, count=len(array), @@ -142,7 +142,7 @@ def __gather_colors(blender_primitive, export_settings): comp_type = gltf2_io_constants.ComponentType.Float attributes[color_id] = gltf2_io.Accessor( - buffer_view=gltf2_io_binary_data.BinaryData(colors.tobytes()), + buffer_view=gltf2_io_binary_data.BinaryData(colors.tobytes(), gltf2_io_constants.BufferViewTarget.ARRAY_BUFFER), byte_offset=None, component_type=comp_type, count=len(colors), -- cgit v1.2.3 From 9638ec565580fd611577249fda938a5cd1146694 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Mon, 15 Aug 2022 10:22:13 +0200 Subject: glTF exporter: add comment --- .../blender/exp/gltf2_blender_gather_primitive_attributes.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_primitive_attributes.py') 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 8572d185..1af588b9 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 @@ -173,6 +173,13 @@ def __gather_skins(blender_primitive, export_settings): max_bone_set_index += 1 max_bone_set_index -= 1 + # Here, a set represents a group of 4 weights. + # So max_bone_set_index value: + # if -1 => No weights + # if 1 => Max 4 weights + # if 2 => Max 8 weights + # etc... + # If no skinning if max_bone_set_index < 0: return attributes -- cgit v1.2.3