Blender V5.3
node_geo_set_nurbs_weight.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 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>("Curves"_ustr)
20 .description("Curves to set the weight on");
21 b.add_output<decl::Geometry>("Curves"_ustr).propagate_all_geometry().align_with_previous();
22 b.add_input<decl::Bool>("Selection"_ustr)
23 .default_value(true)
24 .hide_value()
25 .evaluated_geometry_field();
26 b.add_input<decl::Float>("Weight"_ustr).min(0.0f).default_value(1.0f).evaluated_geometry_field();
27}
28
30{
31 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curves"_ustr);
32 Field<bool> selection = params.extract_input<Field<bool>>("Selection"_ustr);
33
34 static auto clamp_negative = mf::build::SI1_SO<float, float>(
35 "Clamp Negative", [](float value) { return std::max(value, 0.0f); });
36 Field<float> weight(
37 FieldOperation::from(clamp_negative, {params.extract_input<Field<float>>("Weight"_ustr)}));
38
39 std::atomic<bool> has_curves = false;
40 std::atomic<bool> has_nurbs = false;
41
42 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
43 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
44 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
45 has_curves = true;
46 if (curves.has_curve_with_type(CURVE_TYPE_NURBS)) {
47 const bke::CurvesFieldContext field_context(*curves_id, AttrDomain::Point);
48 bke::try_capture_field_on_geometry(curves.attributes_for_write(),
49 field_context,
50 "nurbs_weight",
52 selection,
53 weight);
54 has_nurbs = true;
55 }
56 }
58 using namespace blender::bke::greasepencil;
59 for (const int layer_index : grease_pencil->layers().index_range()) {
60 Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
61 if (drawing == nullptr) {
62 continue;
63 }
64 has_curves = true;
66 if (curves.has_curve_with_type(CURVE_TYPE_NURBS)) {
68 curves.attributes_for_write(),
70 "nurbs_weight",
72 selection,
73 weight);
74 has_nurbs = true;
75 }
76 }
77 };
78 });
79
80 if (has_curves && !has_nurbs) {
81 params.error_message_add(NodeWarningType::Info, TIP_("Input curves do not have NURBS type"));
82 }
83
84 params.set_output("Curves"_ustr, std::move(geometry_set));
85}
86
87static void node_register()
88{
89 static bke::bNodeType ntype;
90
91 geo_node_type_base(&ntype, "GeometryNodeSetNURBSWeight"_ustr);
92 ntype.ui_name = "Set NURBS Weight";
93 ntype.ui_description =
94 "Control the influence of each NURBS control point on the curve by changing the "
95 "\"nurbs_weight\" attribute";
98 ntype.declare = node_declare;
100}
102
103} // namespace blender::nodes::node_geo_set_nurbs_weight_cc
Low-level operations for curves.
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define TIP_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
bke::CurvesGeometry & strokes_for_write()
static FieldOperationPtr from(std::shared_ptr< const mf::MultiFunction > fn, Vector< GField > inputs)
Definition field.cc:252
void error_message_add(const NodeWarningType type, StringRef message) const
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
bool try_capture_field_on_geometry(MutableAttributeAccessor attributes, const fn::FieldContext &field_context, const StringRef name, AttrDomain domain, const fn::Field< bool > &selection, const fn::GField &field)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:38
GreasePencil * get_grease_pencil_for_write()
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
NodeDeclareFunction declare
Definition BKE_node.hh:393