From 1bbd19ab9a4294190f74becdc5a4e714f1c9c80b Mon Sep 17 00:00:00 2001 From: illua1 Date: Sat, 11 Feb 2023 02:54:46 +0300 Subject: [PATCH 1/2] init commit --- .../startup/bl_ui/node_add_menu_geometry.py | 1 + source/blender/blenkernel/BKE_node.h | 1 + source/blender/nodes/NOD_static_types.h | 1 + source/blender/nodes/geometry/CMakeLists.txt | 1 + .../nodes/geometry/node_geometry_register.cc | 1 + .../nodes/geometry/node_geometry_register.hh | 1 + .../nodes/node_geo_select_by_component.cc | 88 +++++++++++++++++++ 7 files changed, 94 insertions(+) create mode 100644 source/blender/nodes/geometry/nodes/node_geo_select_by_component.cc diff --git a/release/scripts/startup/bl_ui/node_add_menu_geometry.py b/release/scripts/startup/bl_ui/node_add_menu_geometry.py index 43fd87d0f83..6ecc99bb931 100644 --- a/release/scripts/startup/bl_ui/node_add_menu_geometry.py +++ b/release/scripts/startup/bl_ui/node_add_menu_geometry.py @@ -518,6 +518,7 @@ class NODE_MT_category_GEO_UTILITIES_FIELD(Menu): def draw(self, _context): layout = self.layout node_add_menu.add_node_type(layout, "GeometryNodeAccumulateField") + node_add_menu.add_node_type(layout, "GeometryNodeSelectByComponent") node_add_menu.add_node_type(layout, "GeometryNodeFieldAtIndex") node_add_menu.add_node_type(layout, "GeometryNodeFieldOnDomain") node_add_menu.draw_assets_for_catalog(layout, self.bl_label) diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index f387122079b..bfc8c9dab42 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1541,6 +1541,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, i #define GEO_NODE_IMAGE 1191 #define GEO_NODE_INTERPOLATE_CURVES 1192 #define GEO_NODE_EDGES_TO_FACE_GROUPS 1193 +#define GEO_NODE_SELECT_BY_COMPONENT 1194 /** \} */ diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index cb97e88ac9f..78e4fa49e38 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -286,6 +286,7 @@ DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_STATISTIC, def_geo_attribute_statistic, DefNode(GeometryNode, GEO_NODE_BLUR_ATTRIBUTE, def_geo_blur_attribute, "BLUR_ATTRIBUTE", BlurAttribute, "Blur Attribute", "Mix attribute values of neighboring elements") DefNode(GeometryNode, GEO_NODE_BOUNDING_BOX, 0, "BOUNDING_BOX", BoundBox, "Bounding Box", "Calculate the limits of a geometry's positions and generate a box mesh with those dimensions") DefNode(GeometryNode, GEO_NODE_CAPTURE_ATTRIBUTE, def_geo_attribute_capture,"CAPTURE_ATTRIBUTE", CaptureAttribute, "Capture Attribute", "Store the result of a field on a geometry and output the data as a node socket. Allows remembering or interpolating data as the geometry changes, such as positions before deformation") +DefNode(GeometryNode, GEO_NODE_SELECT_BY_COMPONENT, 0, "SELECT_BY_COMPONENT", SelectByComponent, "Select by Component", "") DefNode(GeometryNode, GEO_NODE_COLLECTION_INFO, def_geo_collection_info, "COLLECTION_INFO", CollectionInfo, "Collection Info", "Retrieve geometry instances from a collection") DefNode(GeometryNode, GEO_NODE_CONVEX_HULL, 0, "CONVEX_HULL", ConvexHull, "Convex Hull", "Create a mesh that encloses all points in the input geometry with the smallest number of points") DefNode(GeometryNode, GEO_NODE_CURVE_ENDPOINT_SELECTION, 0, "CURVE_ENDPOINT_SELECTION", CurveEndpointSelection, "Endpoint Selection", "Provide a selection for an arbitrary number of endpoints in each spline") diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt index 448a5e69de4..3ef1ce76031 100644 --- a/source/blender/nodes/geometry/CMakeLists.txt +++ b/source/blender/nodes/geometry/CMakeLists.txt @@ -149,6 +149,7 @@ set(SRC nodes/node_geo_sample_uv_surface.cc nodes/node_geo_scale_elements.cc nodes/node_geo_scale_instances.cc + nodes/node_geo_select_by_component.cc nodes/node_geo_self_object.cc nodes/node_geo_separate_components.cc nodes/node_geo_separate_geometry.cc diff --git a/source/blender/nodes/geometry/node_geometry_register.cc b/source/blender/nodes/geometry/node_geometry_register.cc index c6e0fc2697a..bdf66af4120 100644 --- a/source/blender/nodes/geometry/node_geometry_register.cc +++ b/source/blender/nodes/geometry/node_geometry_register.cc @@ -133,6 +133,7 @@ void register_geometry_nodes() register_node_type_geo_sample_uv_surface(); register_node_type_geo_scale_elements(); register_node_type_geo_scale_instances(); + register_node_type_geo_select_by_component(); register_node_type_geo_self_object(); register_node_type_geo_separate_components(); register_node_type_geo_separate_geometry(); diff --git a/source/blender/nodes/geometry/node_geometry_register.hh b/source/blender/nodes/geometry/node_geometry_register.hh index 900dd67cf71..4c7ef28108e 100644 --- a/source/blender/nodes/geometry/node_geometry_register.hh +++ b/source/blender/nodes/geometry/node_geometry_register.hh @@ -130,6 +130,7 @@ void register_node_type_geo_sample_nearest(); void register_node_type_geo_sample_uv_surface(); void register_node_type_geo_scale_elements(); void register_node_type_geo_scale_instances(); +void register_node_type_geo_select_by_component(); void register_node_type_geo_select_by_handle_type(); void register_node_type_geo_self_object(); void register_node_type_geo_separate_components(); diff --git a/source/blender/nodes/geometry/nodes/node_geo_select_by_component.cc b/source/blender/nodes/geometry/nodes/node_geo_select_by_component.cc new file mode 100644 index 00000000000..4ffa28de710 --- /dev/null +++ b/source/blender/nodes/geometry/nodes/node_geo_select_by_component.cc @@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "BKE_geometry_set.h" + +#include "BLI_index_mask.hh" + +#include "node_geometry_util.hh" + +namespace blender::nodes::node_geo_select_by_component_cc { + +static void node_declare(NodeDeclarationBuilder &b) +{ + b.add_output(N_("Is Mesh")).field_source_reference_all(); + b.add_output(N_("Is Curve")).field_source_reference_all(); + b.add_output(N_("Is Point Cloud")).field_source_reference_all(); + b.add_output(N_("Is Instances")).field_source_reference_all(); +} + +class SelectByComponentFieldInput final : public bke::GeometryFieldInput { + private: + const GeometryComponentType type_; + + public: + SelectByComponentFieldInput(const GeometryComponentType type) + : bke::GeometryFieldInput(CPPType::get(), "Select by Component"), type_(type) + { + } + + GVArray get_varray_for_context(const bke::GeometryFieldContext &context, + const IndexMask mask) const final + { + const GeometryComponentType context_component_type = context.type(); + return VArray::ForSingle(context_component_type == type_, mask.min_array_size()); + } + + uint64_t hash() const override + { + return type_; + } + + bool is_equal_to(const fn::FieldNode &other) const override + { + if (const SelectByComponentFieldInput *other_mask = + dynamic_cast(&other)) { + return other_mask->type_ == this->type_; + } + return false; + } +}; + +static void node_geo_exec(GeoNodeExecParams params) +{ + if (params.output_is_required("Is Mesh")) { + params.set_output( + "Is Mesh", + Field{std::make_shared(GEO_COMPONENT_TYPE_MESH)}); + } + if (params.output_is_required("Is Curve")) { + params.set_output( + "Is Curve", + Field{std::make_shared(GEO_COMPONENT_TYPE_CURVE)}); + } + if (params.output_is_required("Is Point Cloud")) { + params.set_output("Is Point Cloud", + Field{std::make_shared( + GEO_COMPONENT_TYPE_POINT_CLOUD)}); + } + if (params.output_is_required("Is Instances")) { + params.set_output( + "Is Instances", + Field{std::make_shared(GEO_COMPONENT_TYPE_INSTANCES)}); + } +} + +} // namespace blender::nodes::node_geo_select_by_component_cc + +void register_node_type_geo_select_by_component() +{ + namespace file_ns = blender::nodes::node_geo_select_by_component_cc; + + static bNodeType ntype; + + geo_node_type_base( + &ntype, GEO_NODE_SELECT_BY_COMPONENT, "Select by Component", NODE_CLASS_CONVERTER); + ntype.geometry_node_execute = file_ns::node_geo_exec; + ntype.declare = file_ns::node_declare; + nodeRegisterType(&ntype); +} -- 2.30.2 From 4c3dd830df4704f316e7a83163b98d0b7f711825 Mon Sep 17 00:00:00 2001 From: illua1 Date: Sat, 11 Feb 2023 03:27:49 +0300 Subject: [PATCH 2/2] add description to node, fix node position in some lists based on alphabet sort, use explicit cast for hash --- release/scripts/startup/bl_ui/node_add_menu_geometry.py | 2 +- source/blender/nodes/NOD_static_types.h | 2 +- .../nodes/geometry/nodes/node_geo_select_by_component.cc | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/release/scripts/startup/bl_ui/node_add_menu_geometry.py b/release/scripts/startup/bl_ui/node_add_menu_geometry.py index 6ecc99bb931..48f4e8be899 100644 --- a/release/scripts/startup/bl_ui/node_add_menu_geometry.py +++ b/release/scripts/startup/bl_ui/node_add_menu_geometry.py @@ -518,9 +518,9 @@ class NODE_MT_category_GEO_UTILITIES_FIELD(Menu): def draw(self, _context): layout = self.layout node_add_menu.add_node_type(layout, "GeometryNodeAccumulateField") - node_add_menu.add_node_type(layout, "GeometryNodeSelectByComponent") node_add_menu.add_node_type(layout, "GeometryNodeFieldAtIndex") node_add_menu.add_node_type(layout, "GeometryNodeFieldOnDomain") + node_add_menu.add_node_type(layout, "GeometryNodeSelectByComponent") node_add_menu.draw_assets_for_catalog(layout, self.bl_label) diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index 78e4fa49e38..5ce725b00cc 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -286,7 +286,6 @@ DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_STATISTIC, def_geo_attribute_statistic, DefNode(GeometryNode, GEO_NODE_BLUR_ATTRIBUTE, def_geo_blur_attribute, "BLUR_ATTRIBUTE", BlurAttribute, "Blur Attribute", "Mix attribute values of neighboring elements") DefNode(GeometryNode, GEO_NODE_BOUNDING_BOX, 0, "BOUNDING_BOX", BoundBox, "Bounding Box", "Calculate the limits of a geometry's positions and generate a box mesh with those dimensions") DefNode(GeometryNode, GEO_NODE_CAPTURE_ATTRIBUTE, def_geo_attribute_capture,"CAPTURE_ATTRIBUTE", CaptureAttribute, "Capture Attribute", "Store the result of a field on a geometry and output the data as a node socket. Allows remembering or interpolating data as the geometry changes, such as positions before deformation") -DefNode(GeometryNode, GEO_NODE_SELECT_BY_COMPONENT, 0, "SELECT_BY_COMPONENT", SelectByComponent, "Select by Component", "") DefNode(GeometryNode, GEO_NODE_COLLECTION_INFO, def_geo_collection_info, "COLLECTION_INFO", CollectionInfo, "Collection Info", "Retrieve geometry instances from a collection") DefNode(GeometryNode, GEO_NODE_CONVEX_HULL, 0, "CONVEX_HULL", ConvexHull, "Convex Hull", "Create a mesh that encloses all points in the input geometry with the smallest number of points") DefNode(GeometryNode, GEO_NODE_CURVE_ENDPOINT_SELECTION, 0, "CURVE_ENDPOINT_SELECTION", CurveEndpointSelection, "Endpoint Selection", "Provide a selection for an arbitrary number of endpoints in each spline") @@ -399,6 +398,7 @@ DefNode(GeometryNode, GEO_NODE_SAMPLE_NEAREST, def_geo_sample_nearest, "SAMPLE_N DefNode(GeometryNode, GEO_NODE_SAMPLE_UV_SURFACE, def_geo_sample_uv_surface, "SAMPLE_UV_SURFACE", SampleUVSurface, "Sample UV Surface", "Calculate the interpolated values of a mesh attribute at a UV coordinate") DefNode(GeometryNode, GEO_NODE_SCALE_ELEMENTS, def_geo_scale_elements, "SCALE_ELEMENTS", ScaleElements, "Scale Elements", "Scale groups of connected edges and faces") DefNode(GeometryNode, GEO_NODE_SCALE_INSTANCES, 0, "SCALE_INSTANCES", ScaleInstances, "Scale Instances", "Scale geometry instances in local or global space") +DefNode(GeometryNode, GEO_NODE_SELECT_BY_COMPONENT, 0, "SELECT_BY_COMPONENT", SelectByComponent, "Select by Component", "Find the type of the currently evaluated geometry") DefNode(GeometryNode, GEO_NODE_SELF_OBJECT, 0, "SELF_OBJECT", SelfObject, "Self Object", "Retrieve the object that contains the geometry nodes modifier currently being executed") DefNode(GeometryNode, GEO_NODE_SEPARATE_COMPONENTS, 0, "SEPARATE_COMPONENTS",SeparateComponents, "Separate Components","Split a geometry into a separate output for each type of data in the geometry") DefNode(GeometryNode, GEO_NODE_SEPARATE_GEOMETRY, def_geo_separate_geometry,"SEPARATE_GEOMETRY", SeparateGeometry, "Separate Geometry", "Split a geometry into two geometry outputs based on a selection") diff --git a/source/blender/nodes/geometry/nodes/node_geo_select_by_component.cc b/source/blender/nodes/geometry/nodes/node_geo_select_by_component.cc index 4ffa28de710..a69f8807a34 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_select_by_component.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_select_by_component.cc @@ -11,7 +11,7 @@ namespace blender::nodes::node_geo_select_by_component_cc { static void node_declare(NodeDeclarationBuilder &b) { b.add_output(N_("Is Mesh")).field_source_reference_all(); - b.add_output(N_("Is Curve")).field_source_reference_all(); + b.add_output(N_("Is Curves")).field_source_reference_all(); b.add_output(N_("Is Point Cloud")).field_source_reference_all(); b.add_output(N_("Is Instances")).field_source_reference_all(); } @@ -35,7 +35,7 @@ class SelectByComponentFieldInput final : public bke::GeometryFieldInput { uint64_t hash() const override { - return type_; + return uint64_t(type_); } bool is_equal_to(const fn::FieldNode &other) const override @@ -55,9 +55,9 @@ static void node_geo_exec(GeoNodeExecParams params) "Is Mesh", Field{std::make_shared(GEO_COMPONENT_TYPE_MESH)}); } - if (params.output_is_required("Is Curve")) { + if (params.output_is_required("Is Curves")) { params.set_output( - "Is Curve", + "Is Curves", Field{std::make_shared(GEO_COMPONENT_TYPE_CURVE)}); } if (params.output_is_required("Is Point Cloud")) { -- 2.30.2