Blender  V3.3
node_geo_separate_geometry.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "UI_interface.h"
4 #include "UI_resources.h"
5 
6 #include "node_geometry_util.hh"
7 
9 
11 
13 {
14  b.add_input<decl::Geometry>(N_("Geometry"));
15  b.add_input<decl::Bool>(N_("Selection"))
16  .default_value(true)
17  .hide_value()
18  .supports_field()
19  .description(N_("The parts of the geometry that go into the first output"));
20  b.add_output<decl::Geometry>(N_("Selection"))
21  .description(N_("The parts of the geometry in the selection"));
22  b.add_output<decl::Geometry>(N_("Inverted"))
23  .description(N_("The parts of the geometry not in the selection"));
24 }
25 
26 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
27 {
28  uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
29 }
30 
32 {
33  NodeGeometrySeparateGeometry *data = MEM_cnew<NodeGeometrySeparateGeometry>(__func__);
34  data->domain = ATTR_DOMAIN_POINT;
35 
36  node->storage = data;
37 }
38 
40 {
41  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
42 
43  const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
44 
45  const NodeGeometrySeparateGeometry &storage = node_storage(params.node());
46  const eAttrDomain domain = static_cast<eAttrDomain>(storage.domain);
47 
48  auto separate_geometry_maybe_recursively = [&](GeometrySet &geometry_set,
49  const Field<bool> &selection) {
50  bool is_error;
51  if (domain == ATTR_DOMAIN_INSTANCE) {
52  /* Only delete top level instances. */
54  geometry_set, domain, GEO_NODE_DELETE_GEOMETRY_MODE_ALL, selection, is_error);
55  }
56  else {
57  geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
59  geometry_set, domain, GEO_NODE_DELETE_GEOMETRY_MODE_ALL, selection, is_error);
60  });
61  }
62  };
63 
64  GeometrySet second_set(geometry_set);
65  if (params.output_is_required("Selection")) {
66  separate_geometry_maybe_recursively(geometry_set, selection_field);
67  params.set_output("Selection", std::move(geometry_set));
68  }
69  if (params.output_is_required("Inverted")) {
70  separate_geometry_maybe_recursively(second_set, fn::invert_boolean_field(selection_field));
71  params.set_output("Inverted", std::move(second_set));
72  }
73 }
74 
75 } // namespace blender::nodes::node_geo_separate_geometry_cc
76 
78 {
80 
81  static bNodeType ntype;
82 
84 
85  node_type_storage(&ntype,
86  "NodeGeometrySeparateGeometry",
89 
91 
95  nodeRegisterType(&ntype);
96 }
eAttrDomain
Definition: BKE_attribute.h:25
@ ATTR_DOMAIN_INSTANCE
Definition: BKE_attribute.h:32
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:27
#define NODE_STORAGE_FUNCS(StorageT)
Definition: BKE_node.h:1563
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
#define GEO_NODE_SEPARATE_GEOMETRY
Definition: BKE_node.h:1446
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
@ GEO_NODE_DELETE_GEOMETRY_MODE_ALL
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
OperationNode * node
void * tree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Field< bool > invert_boolean_field(const Field< bool > &field)
Definition: field.cc:521
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
void separate_geometry(GeometrySet &geometry_set, eAttrDomain domain, GeometryNodeDeleteGeometryMode mode, const Field< bool > &selection_field, bool &r_is_error)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node)
Definition: node.cc:1082
void register_node_type_geo_separate_geometry()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
void modify_geometry_sets(ForeachSubGeometryCallback callback)
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480