Blender V5.0
node_geo_set_spline_resolution.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
5#include "BKE_curves.hh"
7
9
10#include "node_geometry_util.hh"
11
13
15{
16 b.use_custom_socket_order();
17 b.allow_any_socket_order();
18 b.add_input<decl::Geometry>("Curve", "Geometry")
19 .supported_type({GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil})
20 .description("Curves to change the resolution of");
21 b.add_output<decl::Geometry>("Curve", "Geometry").propagate_all().align_with_previous();
22 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
23 b.add_input<decl::Int>("Resolution").min(1).default_value(12).field_on_all();
24}
25
27 const fn::FieldContext &field_context,
28 const Field<bool> &selection,
29 const Field<int> &resolution)
30{
32 field_context,
33 "resolution",
34 AttrDomain::Curve,
35 selection,
36 resolution);
37}
38
39static void set_grease_pencil_resolution(GreasePencil &grease_pencil,
40 const Field<bool> &selection,
41 const Field<int> &resolution)
42{
43 using namespace blender::bke::greasepencil;
44 for (const int layer_index : grease_pencil.layers().index_range()) {
45 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
46 if (drawing == nullptr) {
47 continue;
48 }
50 drawing->strokes_for_write(),
51 bke::GreasePencilLayerFieldContext(grease_pencil, AttrDomain::Curve, layer_index),
52 selection,
53 resolution);
54 drawing->tag_topology_changed();
55 }
56}
57
59{
60 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
61 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
62 const Field<int> resolution = params.extract_input<Field<int>>("Resolution");
63
64 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
65 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
66 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
67 const bke::CurvesFieldContext field_context(*curves_id, AttrDomain::Curve);
68 set_curve_resolution(curves, field_context, selection, resolution);
69 }
70 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
71 set_grease_pencil_resolution(*grease_pencil, selection, resolution);
72 }
73 });
74
75 params.set_output("Geometry", std::move(geometry_set));
76}
77
78static void node_register()
79{
80 static blender::bke::bNodeType ntype;
81
82 geo_node_type_base(&ntype, "GeometryNodeSetSplineResolution", GEO_NODE_SET_SPLINE_RESOLUTION);
83 ntype.ui_name = "Set Spline Resolution";
84 ntype.ui_description =
85 "Control how many evaluated points should be generated on every curve segment";
86 ntype.enum_name_legacy = "SET_SPLINE_RESOLUTION";
89 ntype.declare = node_declare;
91}
93
94} // namespace blender::nodes::node_geo_set_spline_resolution_cc
Low-level operations for curves.
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_SET_SPLINE_RESOLUTION
#define NOD_REGISTER_NODE(REGISTER_FUNC)
MutableAttributeAccessor attributes_for_write()
bke::CurvesGeometry & strokes_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)
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
static void set_curve_resolution(bke::CurvesGeometry &curves, const fn::FieldContext &field_context, const Field< bool > &selection, const Field< int > &resolution)
static void set_grease_pencil_resolution(GreasePencil &grease_pencil, const Field< bool > &selection, const Field< int > &resolution)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:36
GreasePencil * get_grease_pencil_for_write()
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