Blender V5.3
node_geo_curve_length.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
11
13{
14 b.add_input<decl::Geometry>("Curve"_ustr)
16 .description("Curve to compute the length of");
17 b.add_output<decl::Float>("Length"_ustr);
18}
19
21{
22 const VArray<bool> cyclic = curves.cyclic();
23 curves.ensure_evaluated_lengths();
24
25 float total_length = 0.0f;
26 for (const int i : curves.curves_range()) {
27 total_length += curves.evaluated_length_total_for_curve(i, cyclic[i]);
28 }
29 return total_length;
30}
31
33{
34 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve"_ustr);
35 float length = 0.0f;
36 if (geometry_set.has_curves()) {
37 const Curves &curves_id = *geometry_set.get_curves();
38 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
40 }
41 else if (geometry_set.has_grease_pencil()) {
42 using namespace bke::greasepencil;
43 const GreasePencil &grease_pencil = *geometry_set.get_grease_pencil();
44 for (const int layer_index : grease_pencil.layers().index_range()) {
45 const Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
46 if (drawing == nullptr) {
47 continue;
48 }
49 const bke::CurvesGeometry &curves = drawing->strokes();
51 }
52 }
53 else {
55 return;
56 }
57
58 params.set_output("Length"_ustr, length);
59}
60
61static void node_register()
62{
63 static bke::bNodeType ntype;
64
65 geo_node_type_base(&ntype, "GeometryNodeCurveLength"_ustr, GEO_NODE_CURVE_LENGTH);
66 ntype.ui_name = "Curve Length";
67 ntype.ui_description = "Retrieve the length of all splines added together";
68 ntype.enum_name_legacy = "CURVE_LENGTH";
70 ntype.declare = node_declare;
73}
75
76} // namespace blender::nodes::node_geo_curve_length_cc
Low-level operations for curves.
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_CURVE_LENGTH
#define NOD_REGISTER_NODE(REGISTER_FUNC)
const bke::CurvesGeometry & strokes() const
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
float length(VecOp< float, D >) RET
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_declare(NodeDeclarationBuilder &b)
static float curves_total_length(const bke::CurvesGeometry &curves)
static void node_geo_exec(GeoNodeExecParams params)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const GreasePencil * get_grease_pencil() const
const Curves * get_curves() const
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