Skip to content
Snippets Groups Projects
Commit 0c2ff8fa authored by Julien Duroure's avatar Julien Duroure
Browse files

glTF exporter: store vertex colors as normalized ushorts

parent 5118d312
Branches
Tags
No related merge requests found
......@@ -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',
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment