diff options
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc index fc5fb4c5488..0309fb83bd7 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc @@ -42,27 +42,44 @@ static void geo_node_attribute_color_ramp_layout(uiLayout *layout, namespace blender::nodes { +static AttributeDomain get_result_domain(const GeometryComponent &component, + StringRef input_name, + StringRef result_name) +{ + /* Use the domain of the result attribute if it already exists. */ + ReadAttributePtr result_attribute = component.attribute_try_get_for_read(result_name); + if (result_attribute) { + return result_attribute->domain(); + } + + /* Otherwise use the input attribute's domain if it exists. */ + ReadAttributePtr input_attribute = component.attribute_try_get_for_read(input_name); + if (input_attribute) { + return input_attribute->domain(); + } + + return ATTR_DOMAIN_POINT; +} + static void execute_on_component(const GeoNodeExecParams ¶ms, GeometryComponent &component) { const bNode &bnode = params.node(); NodeAttributeColorRamp *node_storage = (NodeAttributeColorRamp *)bnode.storage; + const std::string result_name = params.get_input<std::string>("Result"); + const std::string input_name = params.get_input<std::string>("Attribute"); /* Always output a color attribute for now. We might want to allow users to customize. * Using the type of an existing attribute could work, but does not have a real benefit * currently. */ const CustomDataType result_type = CD_PROP_COLOR; + const AttributeDomain result_domain = get_result_domain(component, input_name, result_name); - const std::string result_name = params.get_input<std::string>("Result"); - /* Once we support more domains at the user level, we have to decide how the result domain is - * chosen. */ - const AttributeDomain result_domain = ATTR_DOMAIN_POINT; OutputAttributePtr attribute_result = component.attribute_try_get_for_output( result_name, result_domain, result_type); if (!attribute_result) { return; } - const std::string input_name = params.get_input<std::string>("Attribute"); FloatReadAttribute attribute_in = component.attribute_get_for_read<float>( input_name, result_domain, 0.0f); |