diff options
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc index 1780ec69df2..17718949de3 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc @@ -202,19 +202,40 @@ static void do_math_operation(Span<float> span_input, UNUSED_VARS_NDEBUG(success); } +static AttributeDomain get_result_domain(const GeometryComponent &component, + const GeoNodeExecParams ¶ms, + const NodeMathOperation operation, + 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 highest priority domain from existing input attributes, or the default. */ + const AttributeDomain default_domain = ATTR_DOMAIN_POINT; + if (operation_use_input_b(operation)) { + if (operation_use_input_c(operation)) { + return params.get_highest_priority_input_domain({"A", "B", "C"}, component, default_domain); + } + return params.get_highest_priority_input_domain({"A", "B"}, component, default_domain); + } + return params.get_highest_priority_input_domain({"A"}, component, default_domain); +} + static void attribute_math_calc(GeometryComponent &component, const GeoNodeExecParams ¶ms) { const bNode &node = params.node(); const NodeAttributeMath *node_storage = (const NodeAttributeMath *)node.storage; const NodeMathOperation operation = static_cast<NodeMathOperation>(node_storage->operation); + const std::string result_name = params.get_input<std::string>("Result"); /* The result type of this node is always float. */ const CustomDataType result_type = CD_PROP_FLOAT; - /* The result domain is always point for now. */ - const AttributeDomain result_domain = ATTR_DOMAIN_POINT; + const AttributeDomain result_domain = get_result_domain( + component, params, operation, result_name); - /* Get result attribute first, in case it has to overwrite one of the existing attributes. */ - const std::string result_name = params.get_input<std::string>("Result"); OutputAttributePtr attribute_result = component.attribute_try_get_for_output( result_name, result_domain, result_type); if (!attribute_result) { |