Blender  V3.3
node_geo_input_spline_length.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "node_geometry_util.hh"
4 
5 #include "BKE_curves.hh"
6 
8 
10 {
11  b.add_output<decl::Float>(N_("Length")).field_source();
12  b.add_output<decl::Int>(N_("Point Count")).field_source();
13 }
14 
15 /* --------------------------------------------------------------------
16  * Spline Count
17  */
18 
20  const eAttrDomain domain)
21 {
22  if (!component.has_curves()) {
23  return {};
24  }
25  const Curves &curves_id = *component.get_for_read();
27 
28  auto count_fn = [curves](int64_t i) { return curves.points_for_curve(i).size(); };
29 
30  if (domain == ATTR_DOMAIN_CURVE) {
31  return VArray<int>::ForFunc(curves.curves_num(), count_fn);
32  }
33  if (domain == ATTR_DOMAIN_POINT) {
34  VArray<int> count = VArray<int>::ForFunc(curves.curves_num(), count_fn);
35  return component.attributes()->adapt_domain<int>(
37  }
38 
39  return {};
40 }
41 
43  public:
44  SplineCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Spline Point Count")
45  {
47  }
48 
50  const eAttrDomain domain,
51  IndexMask UNUSED(mask)) const final
52  {
53  if (component.type() == GEO_COMPONENT_TYPE_CURVE) {
54  const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
55  return construct_curve_point_count_gvarray(curve_component, domain);
56  }
57  return {};
58  }
59 
60  uint64_t hash() const override
61  {
62  /* Some random constant hash. */
63  return 456364322625;
64  }
65 
66  bool is_equal_to(const fn::FieldNode &other) const override
67  {
68  return dynamic_cast<const SplineCountFieldInput *>(&other) != nullptr;
69  }
70 };
71 
73 {
74  Field<float> spline_length_field{std::make_shared<bke::CurveLengthFieldInput>()};
75  Field<int> spline_count_field{std::make_shared<SplineCountFieldInput>()};
76 
77  params.set_output("Length", std::move(spline_length_field));
78  params.set_output("Point Count", std::move(spline_count_field));
79 }
80 
81 } // namespace blender::nodes::node_geo_input_spline_length_cc
82 
84 {
86 
87  static bNodeType ntype;
91  nodeRegisterType(&ntype);
92 }
eAttrDomain
Definition: BKE_attribute.h:25
@ ATTR_DOMAIN_CURVE
Definition: BKE_attribute.h:31
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:27
Low-level operations for curves.
@ GEO_COMPONENT_TYPE_CURVE
#define GEO_NODE_INPUT_SPLINE_LENGTH
Definition: BKE_node.h:1440
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define final(a, b, c)
Definition: BLI_hash.h:21
#define UNUSED(x)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
static VArray ForFunc(const int64_t size, GetFunc get_func)
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
GVArray get_varray_for_context(const GeometryComponent &component, const eAttrDomain domain, IndexMask UNUSED(mask)) const final
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
int count
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
static void node_declare(NodeDeclarationBuilder &b)
static VArray< int > construct_curve_point_count_gvarray(const CurveComponent &component, const eAttrDomain domain)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_input_spline_length()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
__int64 int64_t
Definition: stdint.h:89
unsigned __int64 uint64_t
Definition: stdint.h:90
CurvesGeometry geometry
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)