Differential D13228 Diff 44828 source/blender/nodes/geometry/nodes/legacy/node_geo_attribute_compare.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/legacy/node_geo_attribute_compare.cc
| Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | static void geo_node_attribute_compare_layout(uiLayout *layout, | ||||
| uiItemR(layout, ptr, "input_type_a", 0, IFACE_("A"), ICON_NONE); | uiItemR(layout, ptr, "input_type_a", 0, IFACE_("A"), ICON_NONE); | ||||
| uiItemR(layout, ptr, "input_type_b", 0, IFACE_("B"), ICON_NONE); | uiItemR(layout, ptr, "input_type_b", 0, IFACE_("B"), ICON_NONE); | ||||
| } | } | ||||
| static void geo_node_attribute_compare_init(bNodeTree *UNUSED(tree), bNode *node) | static void geo_node_attribute_compare_init(bNodeTree *UNUSED(tree), bNode *node) | ||||
| { | { | ||||
| NodeAttributeCompare *data = (NodeAttributeCompare *)MEM_callocN(sizeof(NodeAttributeCompare), | NodeAttributeCompare *data = (NodeAttributeCompare *)MEM_callocN(sizeof(NodeAttributeCompare), | ||||
| __func__); | __func__); | ||||
| data->operation = NODE_FLOAT_COMPARE_GREATER_THAN; | data->operation = NODE_COMPARE_GREATER_THAN; | ||||
| data->input_type_a = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE; | data->input_type_a = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE; | ||||
| data->input_type_b = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE; | data->input_type_b = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE; | ||||
| node->storage = data; | node->storage = data; | ||||
| } | } | ||||
| static bool operation_tests_equality(const NodeAttributeCompare &node_storage) | static bool operation_tests_equality(const NodeAttributeCompare &node_storage) | ||||
| { | { | ||||
| return ELEM(node_storage.operation, NODE_FLOAT_COMPARE_EQUAL, NODE_FLOAT_COMPARE_NOT_EQUAL); | return ELEM(node_storage.operation, NODE_COMPARE_EQUAL, NODE_COMPARE_NOT_EQUAL); | ||||
| } | } | ||||
| static void geo_node_attribute_compare_update(bNodeTree *UNUSED(ntree), bNode *node) | static void geo_node_attribute_compare_update(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| NodeAttributeCompare *node_storage = (NodeAttributeCompare *)node->storage; | NodeAttributeCompare *node_storage = (NodeAttributeCompare *)node->storage; | ||||
| update_attribute_input_socket_availabilities( | update_attribute_input_socket_availabilities( | ||||
| *node, "A", (GeometryNodeAttributeInputMode)node_storage->input_type_a); | *node, "A", (GeometryNodeAttributeInputMode)node_storage->input_type_a); | ||||
| update_attribute_input_socket_availabilities( | update_attribute_input_socket_availabilities( | ||||
| *node, "B", (GeometryNodeAttributeInputMode)node_storage->input_type_b); | *node, "B", (GeometryNodeAttributeInputMode)node_storage->input_type_b); | ||||
| bNodeSocket *socket_threshold = (bNodeSocket *)BLI_findlink(&node->inputs, 9); | bNodeSocket *socket_threshold = (bNodeSocket *)BLI_findlink(&node->inputs, 9); | ||||
| nodeSetSocketAvailability(socket_threshold, operation_tests_equality(*node_storage)); | nodeSetSocketAvailability(socket_threshold, operation_tests_equality(*node_storage)); | ||||
| } | } | ||||
| static void do_math_operation(const VArray<float> &input_a, | static void do_math_operation(const VArray<float> &input_a, | ||||
| const VArray<float> &input_b, | const VArray<float> &input_b, | ||||
| const FloatCompareOperation operation, | const NodeCompareOperation operation, | ||||
| MutableSpan<bool> span_result) | MutableSpan<bool> span_result) | ||||
| { | { | ||||
| const int size = input_a.size(); | const int size = input_a.size(); | ||||
| if (try_dispatch_float_math_fl_fl_to_bool( | if (try_dispatch_float_math_fl_fl_to_bool( | ||||
| operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) { | operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) { | ||||
| for (const int i : IndexRange(size)) { | for (const int i : IndexRange(size)) { | ||||
| const float a = input_a[i]; | const float a = input_a[i]; | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | static AttributeDomain get_result_domain(const GeometryComponent &component, | ||||
| /* Otherwise use the highest priority domain from existing input attributes, or the default. */ | /* Otherwise use the highest priority domain from existing input attributes, or the default. */ | ||||
| return params.get_highest_priority_input_domain({"A", "B"}, component, ATTR_DOMAIN_POINT); | return params.get_highest_priority_input_domain({"A", "B"}, component, ATTR_DOMAIN_POINT); | ||||
| } | } | ||||
| static void attribute_compare_calc(GeometryComponent &component, const GeoNodeExecParams ¶ms) | static void attribute_compare_calc(GeometryComponent &component, const GeoNodeExecParams ¶ms) | ||||
| { | { | ||||
| const bNode &node = params.node(); | const bNode &node = params.node(); | ||||
| NodeAttributeCompare *node_storage = (NodeAttributeCompare *)node.storage; | NodeAttributeCompare *node_storage = (NodeAttributeCompare *)node.storage; | ||||
| const FloatCompareOperation operation = static_cast<FloatCompareOperation>( | const NodeCompareOperation operation = static_cast<NodeCompareOperation>( | ||||
| node_storage->operation); | node_storage->operation); | ||||
| const std::string result_name = params.get_input<std::string>("Result"); | const std::string result_name = params.get_input<std::string>("Result"); | ||||
| const AttributeDomain result_domain = get_result_domain(component, params, result_name); | const AttributeDomain result_domain = get_result_domain(component, params, result_name); | ||||
| OutputAttribute_Typed<bool> attribute_result = component.attribute_try_get_for_output_only<bool>( | OutputAttribute_Typed<bool> attribute_result = component.attribute_try_get_for_output_only<bool>( | ||||
| result_name, result_domain); | result_name, result_domain); | ||||
| if (!attribute_result) { | if (!attribute_result) { | ||||
| Show All 13 Lines | static void attribute_compare_calc(GeometryComponent &component, const GeoNodeExecParams ¶ms) | ||||
| } | } | ||||
| MutableSpan<bool> result_span = attribute_result.as_span(); | MutableSpan<bool> result_span = attribute_result.as_span(); | ||||
| /* 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_COMPARE_EQUAL) { | ||||
| if (input_data_type == CD_PROP_FLOAT) { | if (input_data_type == CD_PROP_FLOAT) { | ||||
| do_equal_operation_float( | do_equal_operation_float( | ||||
| attribute_a->typed<float>(), attribute_b->typed<float>(), threshold, result_span); | attribute_a->typed<float>(), attribute_b->typed<float>(), threshold, result_span); | ||||
| } | } | ||||
| else if (input_data_type == CD_PROP_FLOAT3) { | else if (input_data_type == CD_PROP_FLOAT3) { | ||||
| do_equal_operation_float3( | do_equal_operation_float3( | ||||
| attribute_a->typed<float3>(), attribute_b->typed<float3>(), threshold, result_span); | attribute_a->typed<float3>(), attribute_b->typed<float3>(), threshold, result_span); | ||||
| } | } | ||||
| else if (input_data_type == CD_PROP_COLOR) { | else if (input_data_type == CD_PROP_COLOR) { | ||||
| do_equal_operation_color4f(attribute_a->typed<ColorGeometry4f>(), | do_equal_operation_color4f(attribute_a->typed<ColorGeometry4f>(), | ||||
| attribute_b->typed<ColorGeometry4f>(), | attribute_b->typed<ColorGeometry4f>(), | ||||
| threshold, | threshold, | ||||
| result_span); | result_span); | ||||
| } | } | ||||
| else if (input_data_type == CD_PROP_BOOL) { | else if (input_data_type == CD_PROP_BOOL) { | ||||
| do_equal_operation_bool( | do_equal_operation_bool( | ||||
| attribute_a->typed<bool>(), attribute_b->typed<bool>(), threshold, result_span); | attribute_a->typed<bool>(), attribute_b->typed<bool>(), threshold, result_span); | ||||
| } | } | ||||
| } | } | ||||
| else if (operation == NODE_FLOAT_COMPARE_NOT_EQUAL) { | else if (operation == NODE_COMPARE_NOT_EQUAL) { | ||||
| if (input_data_type == CD_PROP_FLOAT) { | if (input_data_type == CD_PROP_FLOAT) { | ||||
| do_not_equal_operation_float( | do_not_equal_operation_float( | ||||
| attribute_a->typed<float>(), attribute_b->typed<float>(), threshold, result_span); | attribute_a->typed<float>(), attribute_b->typed<float>(), threshold, result_span); | ||||
| } | } | ||||
| else if (input_data_type == CD_PROP_FLOAT3) { | else if (input_data_type == CD_PROP_FLOAT3) { | ||||
| do_not_equal_operation_float3( | do_not_equal_operation_float3( | ||||
| attribute_a->typed<float3>(), attribute_b->typed<float3>(), threshold, result_span); | attribute_a->typed<float3>(), attribute_b->typed<float3>(), threshold, result_span); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines | |||||