Skip to content

Commit

Permalink
Merge pull request #2233 from KhronosGroup/VC_next
Browse files Browse the repository at this point in the history
Option to export VC even if not used in node tree
  • Loading branch information
julienduroure authored May 24, 2024
2 parents 7666b48 + 3aec730 commit 6198a41
Show file tree
Hide file tree
Showing 20 changed files with 2,082 additions and 899 deletions.
55 changes: 52 additions & 3 deletions addons/io_scene_gltf2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,33 @@ class ExportGLTF2_Base(ConvertGLTF2_Base):
),
default=False)

export_colors: BoolProperty(
name='Dummy',
description='Keep for compatibility only',

export_vertex_color: EnumProperty(
name='Use Vertex Color',
items=(
('MATERIAL', 'Material',
'Export vertex color when used by material'),
('ACTIVE', 'Active',
'Export active vertex color'),
('NONE', 'None',
'Do not export vertex color')),
description='How to export vertex color',
default='MATERIAL'
)

export_all_vertex_colors: BoolProperty(
name='Export all vertex colors',
description=(
'Export all vertex colors, even if not used by any material. '
'If no Vertex Color is used in the mesh materials, a fake COLOR_0 will be created, '
'in order to keep material unchanged'
),
default=True
)

export_active_vertex_color_when_no_material: BoolProperty(
name='Export active vertex color when no material',
description='When there is no material on object, export active vertex color.',
default=True
)

Expand Down Expand Up @@ -1058,6 +1082,14 @@ def execute(self, context):
export_settings['gltf_attributes'] = self.export_attributes
export_settings['gltf_cameras'] = self.export_cameras

export_settings['gltf_vertex_color'] = self.export_vertex_color
if self.export_vertex_color == 'NONE':
export_settings['gltf_all_vertex_colors'] = False
export_settings['gltf_active_vertex_color_when_no_material'] = False
else:
export_settings['gltf_all_vertex_colors'] = self.export_all_vertex_colors
export_settings['gltf_active_vertex_color_when_no_material'] = self.export_active_vertex_color_when_no_material

export_settings['gltf_unused_textures'] = self.export_unused_textures
export_settings['gltf_unused_images'] = self.export_unused_images

Expand Down Expand Up @@ -1353,6 +1385,23 @@ def export_panel_data_mesh(layout, operator):
col = body.column()
col.prop(operator, 'export_shared_accessors')

header, sub_body = body.panel("GLTF_export_data_material_vertex_color", default_closed=True)
header.label(text="Vertex Colors")
if sub_body:
row = sub_body.row()
row.prop(operator, 'export_vertex_color')
if operator.export_vertex_color == "ACTIVE":
row = sub_body.row()
row.label(text="Note that fully compliant glTF 2.0 engine/viewer will use it as multiplicative factor for base color.", icon='ERROR')
row = sub_body.row()
row.label(text="If you want to use VC for any other purpose than vertex color, you should use custom attributes.")
row = sub_body.row()
row.active = operator.export_vertex_color != "NONE"
row.prop(operator, 'export_all_vertex_colors')
row = sub_body.row()
row.active = operator.export_vertex_color != "NONE"
row.prop(operator, 'export_active_vertex_color_when_no_material')


def export_panel_data_material(layout, operator):
header, body = layout.panel("GLTF_export_data_material", default_closed=True)
Expand Down
6 changes: 4 additions & 2 deletions addons/io_scene_gltf2/blender/com/gltf2_blender_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def get_component_type(attribute_component_type):
"FLOAT_VECTOR_4": gltf2_io_constants.ComponentType.Float,
"INT": gltf2_io_constants.ComponentType.Float, # No signed Int in glTF accessor
"FLOAT": gltf2_io_constants.ComponentType.Float,
"BOOLEAN": gltf2_io_constants.ComponentType.Float
"BOOLEAN": gltf2_io_constants.ComponentType.Float,
"UNSIGNED_BYTE": gltf2_io_constants.ComponentType.UnsignedByte
}.get(attribute_component_type)

def get_channel_from_target(target):
Expand Down Expand Up @@ -147,7 +148,8 @@ def get_numpy_type(attribute_component_type):
"FLOAT_VECTOR_4": np.float32,
"INT": np.float32, #signed integer are not supported by glTF
"FLOAT": np.float32,
"BOOLEAN": np.float32
"BOOLEAN": np.float32,
"UNSIGNED_BYTE": np.uint8,
}.get(attribute_component_type)

def get_attribute_type(component_type, data_type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,28 @@ def __gather_attribute(blender_primitive, attribute, export_settings):
)
}

elif attribute.startswith("COLOR_") and blender_primitive["attributes"][attribute]['component_type'] == gltf2_io_constants.ComponentType.UnsignedByte:
# We are in special case where we fake a COLOR_0 attribute with UNSIGNED_BYTE
# We need to normalize it

export_user_extensions('gather_attribute_change', export_settings, attribute, data, True)

return { attribute : gltf2_io.Accessor(
buffer_view=gltf2_io_binary_data.BinaryData(data['data'].tobytes(), gltf2_io_constants.BufferViewTarget.ARRAY_BUFFER),
byte_offset=None,
component_type=data['component_type'],
count=len(data['data']),
extensions=None,
extras=None,
max=None,
min=None,
name=None,
normalized=True,
sparse=None,
type=data['data_type'],
)
}

elif attribute.startswith("JOINTS_") or attribute.startswith("WEIGHTS_"):
return __gather_skins(blender_primitive, export_settings)

Expand Down
Loading

0 comments on commit 6198a41

Please sign in to comment.