Blender V4.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").supported_type(
16 b.add_output<decl::Float>("Length");
17}
18
19static float curves_total_length(const bke::CurvesGeometry &curves)
20{
21 const VArray<bool> cyclic = curves.cyclic();
22 curves.ensure_evaluated_lengths();
23
24 float total_length = 0.0f;
25 for (const int i : curves.curves_range()) {
26 total_length += curves.evaluated_length_total_for_curve(i, cyclic[i]);
27 }
28 return total_length;
29}
30
32{
33 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
34 float length = 0.0f;
35 if (geometry_set.has_curves()) {
36 const Curves &curves_id = *geometry_set.get_curves();
37 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
38 length += curves_total_length(curves);
39 }
40 else if (geometry_set.has_grease_pencil()) {
41 using namespace bke::greasepencil;
42 const GreasePencil &grease_pencil = *geometry_set.get_grease_pencil();
43 for (const int layer_index : grease_pencil.layers().index_range()) {
44 const Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
45 if (drawing == nullptr) {
46 continue;
47 }
48 const bke::CurvesGeometry &curves = drawing->strokes();
49 length += curves_total_length(curves);
50 }
51 }
52 else {
53 params.set_default_remaining_outputs();
54 return;
55 }
56
57 params.set_output("Length", length);
58}
59
60static void node_register()
61{
62 static blender::bke::bNodeType ntype;
63
64 geo_node_type_base(&ntype, GEO_NODE_CURVE_LENGTH, "Curve Length", NODE_CLASS_GEOMETRY);
65 ntype.declare = node_declare;
68}
70
71} // 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:418
#define NOD_REGISTER_NODE(REGISTER_FUNC)
const bke::CurvesGeometry & strokes() const
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
CurvesGeometry geometry
const GreasePencil * get_grease_pencil() const
const Curves * get_curves() const
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347