Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
| Show First 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | static void attribute_compare_calc(GeometryComponent &component, const GeoNodeExecParams ¶ms) | ||||
| /* The result type of this node is always float. */ | /* The result type of this node is always float. */ | ||||
| const CustomDataType result_type = CD_PROP_BOOL; | const CustomDataType result_type = CD_PROP_BOOL; | ||||
| /* The result domain is always point for now. */ | /* The result domain is always point for now. */ | ||||
| const AttributeDomain result_domain = ATTR_DOMAIN_POINT; | const AttributeDomain result_domain = ATTR_DOMAIN_POINT; | ||||
| /* Get result attribute first, in case it has to overwrite one of the existing attributes. */ | /* 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"); | const std::string result_name = params.get_input<std::string>("Result"); | ||||
| WriteAttributePtr attribute_result = component.attribute_try_ensure_for_write( | OutputAttributePtr attribute_result = component.attribute_try_get_for_output( | ||||
| result_name, result_domain, result_type); | result_name, result_domain, result_type); | ||||
| if (!attribute_result) { | if (!attribute_result) { | ||||
| return; | return; | ||||
| } | } | ||||
| const CustomDataType input_data_type = get_data_type(component, params, *node_storage); | const CustomDataType input_data_type = get_data_type(component, params, *node_storage); | ||||
| ReadAttributePtr attribute_a = params.get_input_attribute( | ReadAttributePtr attribute_a = params.get_input_attribute( | ||||
| "A", component, result_domain, input_data_type, nullptr); | "A", component, result_domain, input_data_type, nullptr); | ||||
| ReadAttributePtr attribute_b = params.get_input_attribute( | ReadAttributePtr attribute_b = params.get_input_attribute( | ||||
| "B", component, result_domain, input_data_type, nullptr); | "B", component, result_domain, input_data_type, nullptr); | ||||
| if (!attribute_a || !attribute_b) { | if (!attribute_a || !attribute_b) { | ||||
| /* Attribute wasn't found. */ | /* Attribute wasn't found. */ | ||||
| return; | return; | ||||
| } | } | ||||
| BooleanWriteAttribute attribute_result_bool = *attribute_result; | MutableSpan<bool> result_span = attribute_result->get_span_for_write_only<bool>(); | ||||
| MutableSpan<bool> result_span = attribute_result_bool.get_span_for_write_only(); | |||||
| /* Use specific types for correct equality operations, but for other operations we use implicit | /* Use specific types for correct equality operations, but for other operations we use implicit | ||||
| * conversions and float comparison. In other words, the comparison is not element-wise. */ | * conversions and float comparison. In other words, the comparison is not element-wise. */ | ||||
| if (operation_tests_equality(*node_storage)) { | if (operation_tests_equality(*node_storage)) { | ||||
| const float threshold = params.get_input<float>("Threshold"); | const float threshold = params.get_input<float>("Threshold"); | ||||
| if (operation == NODE_FLOAT_COMPARE_EQUAL) { | if (operation == NODE_FLOAT_COMPARE_EQUAL) { | ||||
| if (input_data_type == CD_PROP_FLOAT) { | if (input_data_type == CD_PROP_FLOAT) { | ||||
| do_equal_operation_float(*attribute_a, *attribute_b, threshold, result_span); | do_equal_operation_float(*attribute_a, *attribute_b, threshold, result_span); | ||||
| Show All 22 Lines | else if (operation == NODE_FLOAT_COMPARE_NOT_EQUAL) { | ||||
| do_not_equal_operation_bool(*attribute_a, *attribute_b, threshold, result_span); | do_not_equal_operation_bool(*attribute_a, *attribute_b, threshold, result_span); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| do_math_operation(*attribute_a, *attribute_b, operation, result_span); | do_math_operation(*attribute_a, *attribute_b, operation, result_span); | ||||
| } | } | ||||
| attribute_result_bool.apply_span(); | attribute_result.apply_span_and_save(); | ||||
| } | } | ||||
| static void geo_node_attribute_compare_exec(GeoNodeExecParams params) | static void geo_node_attribute_compare_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | ||||
| if (geometry_set.has<MeshComponent>()) { | if (geometry_set.has<MeshComponent>()) { | ||||
| attribute_compare_calc(geometry_set.get_component_for_write<MeshComponent>(), params); | attribute_compare_calc(geometry_set.get_component_for_write<MeshComponent>(), params); | ||||
| Show All 25 Lines | |||||