diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index 0e7fccb90cc6bb110c7a730d190373b480cbcd47..35380dd9d994485be20dcaa978df5940c5026e41 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 e6a5881fc4b2cb8b79bcfc478263dac2c17291da..bdfa4e5e669acba514a9f341e3356f6672770010 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