Blender  V3.3
node_geo_set_spline_resolution.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 {
9  b.add_input<decl::Geometry>(N_("Geometry")).supported_type(GEO_COMPONENT_TYPE_CURVE);
10  b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
11  b.add_input<decl::Int>(N_("Resolution")).min(1).default_value(12).supports_field();
12  b.add_output<decl::Geometry>(N_("Geometry"));
13 }
14 
16  const Field<bool> &selection_field,
17  const Field<int> &resolution_field)
18 {
19  const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_CURVE);
20  if (domain_size == 0) {
21  return;
22  }
23  MutableAttributeAccessor attributes = *component.attributes_for_write();
24 
26 
27  AttributeWriter<int> resolutions = attributes.lookup_or_add_for_write<int>("resolution",
29 
30  fn::FieldEvaluator evaluator{field_context, domain_size};
31  evaluator.set_selection(selection_field);
32  evaluator.add_with_destination(resolution_field, resolutions.varray);
33  evaluator.evaluate();
34 
35  resolutions.finish();
36 }
37 
39 {
40  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
41  Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
42  Field<int> resolution_field = params.extract_input<Field<int>>("Resolution");
43 
44  geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
46  geometry_set.get_component_for_write<CurveComponent>(), selection_field, resolution_field);
47  });
48 
49  params.set_output("Geometry", std::move(geometry_set));
50 }
51 
52 } // namespace blender::nodes::node_geo_set_spline_resolution_cc
53 
55 {
57 
58  static bNodeType ntype;
59 
61  &ntype, GEO_NODE_SET_SPLINE_RESOLUTION, "Set Spline Resolution", NODE_CLASS_GEOMETRY);
64  nodeRegisterType(&ntype);
65 }
@ ATTR_DOMAIN_CURVE
Definition: BKE_attribute.h:31
@ GEO_COMPONENT_TYPE_CURVE
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
#define GEO_NODE_SET_SPLINE_RESOLUTION
Definition: BKE_node.h:1457
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
GAttributeWriter lookup_or_add_for_write(const AttributeIDRef &attribute_id, const eAttrDomain domain, const eCustomDataType data_type, const AttributeInit &initializer=AttributeInitDefault())
void set_selection(Field< bool > selection)
Definition: FN_field.hh:366
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void set_resolution_in_component(GeometryComponent &component, const Field< bool > &selection_field, const Field< int > &resolution_field)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_set_spline_resolution()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition: sort.c:35
GeometryComponent & get_component_for_write(GeometryComponentType component_type)
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)