Blender  V3.3
node_geo_remove_attribute.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "node_geometry_util.hh"
4 
6 
8 
10 {
11  b.add_input<decl::Geometry>(N_("Geometry"));
12  b.add_input<decl::String>(N_("Name")).is_attribute_name();
13  b.add_output<decl::Geometry>(N_("Geometry"));
14 }
15 
17 {
18  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
19  const std::string name = params.extract_input<std::string>("Name");
20  if (name.empty()) {
21  params.set_output("Geometry", std::move(geometry_set));
22  return;
23  }
26  params.set_output("Geometry", std::move(geometry_set));
27  return;
28  }
29 
30  std::atomic<bool> attribute_exists = false;
31  std::atomic<bool> cannot_delete = false;
32 
33  geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
38  if (geometry_set.has(type)) {
39  /* First check if the attribute exists before getting write access,
40  * to avoid potentially expensive unnecessary copies. */
41  const GeometryComponent &read_only_component = *geometry_set.get_component_for_read(type);
42  if (read_only_component.attributes()->contains(name)) {
43  attribute_exists = true;
44  }
45  else {
46  continue;
47  }
48 
50  if (!component.attributes_for_write()->remove(name)) {
51  cannot_delete = true;
52  }
53  }
54  }
55  });
56 
57  if (attribute_exists && !cannot_delete) {
58  params.used_named_attribute(name, eNamedAttrUsage::Remove);
59  }
60 
61  if (!attribute_exists) {
62  params.error_message_add(NodeWarningType::Info,
63  TIP_("Attribute does not exist: \"") + name + "\"");
64  }
65  if (cannot_delete) {
66  params.error_message_add(NodeWarningType::Warning,
67  TIP_("Cannot delete built-in attribute with name \"") + name + "\"");
68  }
69 
70  params.set_output("Geometry", std::move(geometry_set));
71 }
72 
73 } // namespace blender::nodes::node_geo_remove_attribute_cc
74 
76 {
78 
79  static bNodeType ntype;
80 
82  &ntype, GEO_NODE_REMOVE_ATTRIBUTE, "Remove Named Attribute", NODE_CLASS_ATTRIBUTE);
84  node_type_size(&ntype, 170, 100, 700);
86  nodeRegisterType(&ntype);
87 }
GeometryComponentType
@ GEO_COMPONENT_TYPE_MESH
@ GEO_COMPONENT_TYPE_POINT_CLOUD
@ GEO_COMPONENT_TYPE_INSTANCES
@ GEO_COMPONENT_TYPE_CURVE
void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth)
Definition: node.cc:4396
#define GEO_NODE_REMOVE_ATTRIBUTE
Definition: BKE_node.h:1499
#define NODE_CLASS_ATTRIBUTE
Definition: BKE_node.h:360
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define TIP_(msgid)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
in reality light always falls off quadratically Particle Info
virtual std::optional< blender::bke::AttributeAccessor > attributes() const
Definition: geometry_set.cc:75
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
bool allow_procedural_attribute_access(StringRef attribute_name)
const char * no_procedural_access_message
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_remove_attribute()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
GeometryComponent & get_component_for_write(GeometryComponentType component_type)
bool has(const GeometryComponentType component_type) const
const GeometryComponent * get_component_for_read(GeometryComponentType component_type) const
void modify_geometry_sets(ForeachSubGeometryCallback callback)
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)