Blender V5.3
node_geo_set_curve_normal.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
8#include "RNA_enum_types.hh"
9
11
12#include "node_geometry_util.hh"
13
15
17{
18 b.use_custom_socket_order();
19 b.allow_any_socket_order();
20 b.add_input<decl::Geometry>("Curve"_ustr)
22 .description("Curves to change the normals on");
23 b.add_output<decl::Geometry>("Curve"_ustr).propagate_all_geometry().align_with_previous();
24 b.add_input<decl::Bool>("Selection"_ustr)
25 .default_value(true)
26 .hide_value()
27 .evaluated_geometry_field();
28 b.add_input<decl::Menu>("Mode"_ustr)
31 .description("Mode for curve normal evaluation");
32 b.add_input<decl::Vector>("Normal"_ustr)
33 .default_value({0.0f, 0.0f, 1.0f})
34 .subtype(PROP_XYZ)
35 .evaluated_geometry_field()
36 .usage_by_single_menu(NORMAL_MODE_FREE);
37}
38
40 const NormalMode mode,
41 const fn::FieldContext &curve_context,
42 const fn::FieldContext &point_context,
43 const Field<bool> &selection_field,
44 const Field<float3> &custom_normal)
45{
46 /* First evaluate the normal modes without changing the geometry, since that will influence the
47 * result of the "Normal" node if used in the input to the custom normal field evaluation. */
48 fn::FieldEvaluator evaluator(curve_context, curves.curves_num());
49 evaluator.set_selection(selection_field);
50 evaluator.evaluate();
51 const IndexMask curve_mask = evaluator.get_evaluated_selection_as_mask();
52
53 if (mode == NORMAL_MODE_FREE) {
55 curves.attributes_for_write(),
56 point_context,
57 "custom_normal",
58 AttrDomain::Point,
59 Field<bool>::from_input<bke::EvaluateOnDomainInput>(selection_field, AttrDomain::Curve),
60 custom_normal);
61 }
62
63 index_mask::masked_fill(curves.normal_mode_for_write(), int8_t(mode), curve_mask);
64
65 curves.tag_normals_changed();
66}
67
69 const NormalMode mode,
70 const Field<bool> &selection_field,
71 const Field<float3> &custom_normal)
72{
73 using namespace blender::bke::greasepencil;
74 for (const int layer_index : grease_pencil.layers().index_range()) {
75 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
76 if (drawing == nullptr) {
77 continue;
78 }
80 drawing->strokes_for_write(),
81 mode,
84 selection_field,
85 custom_normal);
86 }
87}
88
90{
91 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve"_ustr);
92 Field<bool> selection_field = params.extract_input<Field<bool>>("Selection"_ustr);
93 const NormalMode mode = params.get_input<NormalMode>("Mode"_ustr);
94 Field<float3> custom_normal;
95 if (mode == NORMAL_MODE_FREE) {
96 custom_normal = params.extract_input<Field<float3>>("Normal"_ustr);
97 }
98
99 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
100 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
101 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
103 mode,
106 selection_field,
107 custom_normal);
108 }
110 set_grease_pencil_normal(*grease_pencil, mode, selection_field, custom_normal);
111 }
112 });
113
114 params.set_output("Curve"_ustr, std::move(geometry_set));
115}
116
117static void node_register()
118{
119 static bke::bNodeType ntype;
120 geo_node_type_base(&ntype, "GeometryNodeSetCurveNormal"_ustr, GEO_NODE_SET_CURVE_NORMAL);
121 ntype.ui_name = "Set Curve Normal";
122 ntype.ui_description = "Set the evaluation mode for curve normals";
123 ntype.enum_name_legacy = "SET_CURVE_NORMAL";
125 ntype.declare = node_declare;
127
129}
131
132} // namespace blender::nodes::node_geo_set_curve_normal_cc
Low-level operations for curves.
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_SET_CURVE_NORMAL
#define NOD_REGISTER_NODE(REGISTER_FUNC)
bke::CurvesGeometry & strokes_for_write()
void set_selection(Field< bool > selection)
IndexMask get_evaluated_selection_as_mask() const
static Field from_input(Args &&...args)
T extract_input(const UString identifier)
T get_input(const UString identifier) const
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)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
static void set_curve_normal(bke::CurvesGeometry &curves, const NormalMode mode, const fn::FieldContext &curve_context, const fn::FieldContext &point_context, const Field< bool > &selection_field, const Field< float3 > &custom_normal)
static void node_declare(NodeDeclarationBuilder &b)
static void set_grease_pencil_normal(GreasePencil &grease_pencil, const NormalMode mode, const Field< bool > &selection_field, const Field< float3 > &custom_normal)
static void node_geo_exec(GeoNodeExecParams params)
const EnumPropertyItem rna_enum_curve_normal_mode_items[]
Definition rna_curves.cc:58
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
signed char int8_t
Definition BKE_text.h:76
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
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393