Blender V4.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").field_source();
14 b.add_output<decl::Int>("Point Count").field_source();
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>::ForFunc(curves.curves_num(), count_fn);
29 }
30 if (domain == AttrDomain::Point) {
31 VArray<int> count = VArray<int>::ForFunc(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 }
44
46 const AttrDomain domain,
47 const IndexMask & /*mask*/) const final
48 {
49 return construct_curve_point_count_gvarray(curves, domain);
50 }
51
52 uint64_t hash() const override
53 {
54 /* Some random constant hash. */
55 return 456364322625;
56 }
57
58 bool is_equal_to(const fn::FieldNode &other) const override
59 {
60 return dynamic_cast<const SplineCountFieldInput *>(&other) != nullptr;
61 }
62
63 std::optional<AttrDomain> preferred_domain(const bke::CurvesGeometry & /*curves*/) const final
64 {
65 return AttrDomain::Curve;
66 }
67};
68
70{
71 Field<float> spline_length_field{std::make_shared<bke::CurveLengthFieldInput>()};
72 Field<int> spline_count_field{std::make_shared<SplineCountFieldInput>()};
73
74 params.set_output("Length", std::move(spline_length_field));
75 params.set_output("Point Count", std::move(spline_count_field));
76}
77
78static void node_register()
79{
80 static blender::bke::bNodeType ntype;
81 geo_node_type_base(&ntype, GEO_NODE_INPUT_SPLINE_LENGTH, "Spline Length", NODE_CLASS_INPUT);
83 ntype.declare = node_declare;
85}
87
88} // namespace blender::nodes::node_geo_input_spline_length_cc
Low-level operations for curves.
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static VArray ForFunc(const int64_t size, GetFunc get_func)
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
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
int count
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static VArray< int > construct_curve_point_count_gvarray(const bke::CurvesGeometry &curves, const AttrDomain domain)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
__int64 int64_t
Definition stdint.h:89
unsigned __int64 uint64_t
Definition stdint.h:90
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