Blender V5.3
node_geo_input_spline_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
6
7#include "BKE_curves.hh"
8
10
12{
13 b.add_output<decl::Float>("Length"_ustr).structure_type(StructureType::Field);
14 b.add_output<decl::Int>("Point Count"_ustr).structure_type(StructureType::Field);
15}
16
17/* --------------------------------------------------------------------
18 * Spline Count
19 */
20
22 const AttrDomain domain)
23{
24 const OffsetIndices points_by_curve = curves.points_by_curve();
25 auto count_fn = [points_by_curve](int64_t i) { return points_by_curve[i].size(); };
26
27 if (domain == AttrDomain::Curve) {
28 return VArray<int>::from_func(curves.curves_num(), count_fn);
29 }
30 if (domain == AttrDomain::Point) {
31 VArray<int> count = VArray<int>::from_func(curves.curves_num(), count_fn);
32 return curves.adapt_domain<int>(std::move(count), AttrDomain::Curve, AttrDomain::Point);
33 }
34
35 return {};
36}
37
39 public:
40 SplineCountFieldInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Spline Point Count") {}
41
43 const AttrDomain domain,
44 const IndexMask & /*mask*/) const final
45 {
47 }
48
49 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
50 {
51 static constexpr int8_t id = 0;
52 hash.add(&id);
53 }
54
55 std::optional<AttrDomain> preferred_domain(const bke::CurvesGeometry & /*curves*/) const final
56 {
57 return AttrDomain::Curve;
58 }
59};
60
66
67static void node_register()
68{
69 static bke::bNodeType ntype;
70 geo_node_type_base(&ntype, "GeometryNodeSplineLength"_ustr, GEO_NODE_INPUT_SPLINE_LENGTH);
71 ntype.ui_name = "Spline Length";
72 ntype.ui_description =
73 "Retrieve the total length of each spline, as a distance or as a number of points";
74 ntype.enum_name_legacy = "SPLINE_LENGTH";
77 ntype.declare = node_declare;
79}
81
82} // namespace blender::nodes::node_geo_input_spline_length_cc
Low-level operations for curves.
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_INPUT_SPLINE_LENGTH
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static VArray from_func(const int64_t size, GetFunc get_func)
uint64_t hash() const
Definition field.cc:185
static Field from_input(Args &&...args)
void set_output(const UString identifier, T &&value)
GVArray get_varray_for_context(const bke::CurvesGeometry &curves, const AttrDomain domain, const IndexMask &) const final
std::optional< AttrDomain > preferred_domain(const bke::CurvesGeometry &) const final
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &) const override
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static VArray< int > construct_curve_point_count_gvarray(const bke::CurvesGeometry &curves, const AttrDomain domain)
__int64 int64_t
Definition BKE_text.h:90
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
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