Blender V5.0
node_geo_set_id.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
8
10{
11 b.use_custom_socket_order();
12 b.allow_any_socket_order();
13 b.add_input<decl::Geometry>("Geometry").description("Geometry to update the ID attribute on");
14 b.add_output<decl::Geometry>("Geometry").propagate_all().align_with_previous();
15 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
16 b.add_input<decl::Int>("ID").implicit_field_on_all(NODE_DEFAULT_INPUT_INDEX_FIELD);
17}
18
20 const Field<bool> &selection_field,
21 const Field<int> &id_field)
22{
23 const AttrDomain domain = (component.type() == GeometryComponent::Type::Instance) ?
24 AttrDomain::Instance :
25 AttrDomain::Point;
26 const int domain_size = component.attribute_domain_size(domain);
27 if (domain_size == 0) {
28 return;
29 }
30 MutableAttributeAccessor attributes = *component.attributes_for_write();
31
32 const bke::GeometryFieldContext field_context{component, domain};
34 attributes, field_context, "id", domain, selection_field, id_field);
35}
36
38{
39 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
40 Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
41 Field<int> id_field = params.extract_input<Field<int>>("ID");
42
43 for (const GeometryComponent::Type type : {GeometryComponent::Type::Instance,
44 GeometryComponent::Type::Mesh,
45 GeometryComponent::Type::PointCloud,
46 GeometryComponent::Type::Curve})
47 {
48 if (geometry_set.has(type)) {
49 set_id_in_component(geometry_set.get_component_for_write(type), selection_field, id_field);
50 }
51 }
52
53 params.set_output("Geometry", std::move(geometry_set));
54}
55
56static void node_register()
57{
58 static blender::bke::bNodeType ntype;
59
60 geo_node_type_base(&ntype, "GeometryNodeSetID", GEO_NODE_SET_ID);
61 ntype.ui_name = "Set ID";
62 ntype.ui_description =
63 "Set the id attribute on the input geometry, mainly used internally for randomizing";
64 ntype.enum_name_legacy = "SET_ID";
67 ntype.declare = node_declare;
69}
71
72} // namespace blender::nodes::node_geo_set_id_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_SET_ID
#define NOD_REGISTER_NODE(REGISTER_FUNC)
int attribute_domain_size(AttrDomain domain) const
virtual std::optional< MutableAttributeAccessor > attributes_for_write()
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
bool try_capture_field_on_geometry(MutableAttributeAccessor attributes, const fn::FieldContext &field_context, const StringRef attribute_id, AttrDomain domain, const fn::Field< bool > &selection, const fn::GField &field)
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
static void set_id_in_component(GeometryComponent &component, const Field< bool > &selection_field, const Field< int > &id_field)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
GeometryComponent & get_component_for_write(GeometryComponent::Type component_type)
bool has(const GeometryComponent::Type component_type) const
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362