Blender  V2.93
node_geo_attribute_remove.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #include "node_geometry_util.hh"
18 
20  {SOCK_GEOMETRY, N_("Geometry")},
21  {SOCK_STRING,
22  N_("Attribute"),
23  0.0f,
24  0.0f,
25  0.0f,
26  1.0f,
27  -1.0f,
28  1.0f,
29  PROP_NONE,
31  {-1, ""},
32 };
33 
35  {SOCK_GEOMETRY, N_("Geometry")},
36  {-1, ""},
37 };
38 
39 namespace blender::nodes {
40 
43  Span<std::string> attribute_names)
44 {
45  for (std::string attribute_name : attribute_names) {
46  if (attribute_name.empty()) {
47  continue;
48  }
49 
50  if (!component.attribute_try_delete(attribute_name)) {
51  params.error_message_add(NodeWarningType::Error,
52  TIP_("Cannot delete attribute with name \"") + attribute_name +
53  "\"");
54  }
55  }
56 }
57 
59 {
60  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
61  Vector<std::string> attribute_names = params.extract_multi_input<std::string>("Attribute");
62 
63  geometry_set = geometry_set_realize_instances(geometry_set);
64 
65  if (geometry_set.has<MeshComponent>()) {
67  geometry_set.get_component_for_write<MeshComponent>(), params, attribute_names);
68  }
69  if (geometry_set.has<PointCloudComponent>()) {
71  geometry_set.get_component_for_write<PointCloudComponent>(), params, attribute_names);
72  }
73 
74  params.set_output("Geometry", geometry_set);
75 }
76 } // namespace blender::nodes
77 
79 {
80  static bNodeType ntype;
81 
83  &ntype, GEO_NODE_ATTRIBUTE_REMOVE, "Attribute Remove", NODE_CLASS_ATTRIBUTE, 0);
86  nodeRegisterType(&ntype);
87 }
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
#define GEO_NODE_ATTRIBUTE_REMOVE
Definition: BKE_node.h:1406
#define NODE_CLASS_ATTRIBUTE
Definition: BKE_node.h:360
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define TIP_(msgid)
#define N_(msgid)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:126
@ SOCK_MULTI_INPUT
@ SOCK_GEOMETRY
@ SOCK_STRING
@ PROP_NONE
Definition: RNA_types.h:113
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
GeometrySet geometry_set_realize_instances(const GeometrySet &geometry_set)
static void geo_node_attribute_remove_exec(GeoNodeExecParams params)
static void remove_attribute(GeometryComponent &component, GeoNodeExecParams &params, Span< std::string > attribute_names)
static bNodeSocketTemplate geo_node_attribute_remove_in[]
void register_node_type_geo_attribute_remove()
static bNodeSocketTemplate geo_node_attribute_remove_out[]
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
GeometryComponent & get_component_for_write(GeometryComponentType component_type)
bool has(const GeometryComponentType component_type) const
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:327