From 53366cc71d86a1f9488d713dd18aed7325daff03 Mon Sep 17 00:00:00 2001 From: Michel Fedde <35878897+Neintonine@users.noreply.github.com> Date: Tue, 30 Jan 2024 17:20:59 +0100 Subject: [PATCH] adds option to color attribute to override the attribute --- src/properties/bake_to_id.py | 5 +++++ src/types/targets/vertex_colors.py | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/properties/bake_to_id.py b/src/properties/bake_to_id.py index 019941a..30bfa5b 100644 --- a/src/properties/bake_to_id.py +++ b/src/properties/bake_to_id.py @@ -29,6 +29,11 @@ class BakeToIDProperties(PropertyGroup): name="Color Attribute", default="ID_MASK", ) + target_vertex_color_override_attribute: BoolProperty( + name="Override Color Attribute", + default=True, + description="If set true, the attribute will be deleted and recreated, if it already exists. If set false, the data will just be overwritten." + ) adv_total_hues: IntProperty( name="Total Hues", diff --git a/src/types/targets/vertex_colors.py b/src/types/targets/vertex_colors.py index f77a718..91480e3 100644 --- a/src/types/targets/vertex_colors.py +++ b/src/types/targets/vertex_colors.py @@ -3,7 +3,8 @@ name = 'Color Attribute / Vertex Color' description = 'Bakes the ID onto a color attribute (previously known as Vertex Color)' connected_properties = [ - 'target_vertex_color_attribute_name' + 'target_vertex_color_attribute_name', + 'target_vertex_color_override_attribute' ] @@ -21,12 +22,22 @@ def paint_targets(props, targets, colors): layer_name = props.target_vertex_color_attribute_name for mesh in sorted_targets: + if layer_name in mesh.attributes: mesh.attributes.remove(mesh.attributes[layer_name]) - color_attribute = mesh.attributes.new(name=layer_name, type='FLOAT_COLOR', domain='CORNER') + color_attribute = get_color_attribute(props, mesh.attributes, layer_name) for (indecies, color) in sorted_targets[mesh]: for polygon in indecies: for idx in polygon.loop_indices: - color_attribute.data[idx].color = (color[0], color[1], color[2], 1.0) \ No newline at end of file + color_attribute.data[idx].color = (color[0], color[1], color[2], 1.0) + +def get_color_attribute(props, attributes, layer_name): + if layer_name in attributes: + if not props.target_vertex_color_override_attribute: + return attributes[layer_name] + + attributes.remove(attributes[layer_name]) + + return attributes.new(name=layer_name, type='FLOAT_COLOR', domain='CORNER') \ No newline at end of file