Blender  V3.3
node_geo_input_curve_handles.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 
6 
8 {
9  b.add_input<decl::Bool>(N_("Relative"))
10  .default_value(false)
11  .supports_field()
12  .description(N_("Output the handle positions relative to the corresponding control point "
13  "instead of in the local space of the geometry"));
14  b.add_output<decl::Vector>(N_("Left")).field_source();
15  b.add_output<decl::Vector>(N_("Right")).field_source();
16 }
17 
19  Field<bool> relative_;
20  bool left_;
21 
22  public:
24  : GeometryFieldInput(CPPType::get<float3>(), "Handle"), relative_(relative), left_(left)
25  {
26  }
27 
29  const eAttrDomain domain,
30  IndexMask mask) const final
31  {
32  if (component.type() != GEO_COMPONENT_TYPE_CURVE) {
33  return {};
34  }
35 
37  fn::FieldEvaluator evaluator(field_context, &mask);
38  evaluator.add(relative_);
39  evaluator.evaluate();
40  const VArray<bool> relative = evaluator.get_evaluated<bool>(0);
41 
42  const AttributeAccessor attributes = *component.attributes();
43 
44  VArray<float3> positions = attributes.lookup_or_default<float3>(
45  "position", ATTR_DOMAIN_POINT, {0, 0, 0});
46 
47  StringRef side = left_ ? "handle_left" : "handle_right";
48  VArray<float3> handles = attributes.lookup_or_default<float3>(
49  side, ATTR_DOMAIN_POINT, {0, 0, 0});
50 
51  if (relative.is_single()) {
52  if (relative.get_internal_single()) {
54  for (const int i : positions.index_range()) {
55  output[i] = handles[i] - positions[i];
56  }
57  return attributes.adapt_domain<float3>(
59  }
60  return attributes.adapt_domain<float3>(handles, ATTR_DOMAIN_POINT, domain);
61  }
62 
64  for (const int i : positions.index_range()) {
65  if (relative[i]) {
66  output[i] = handles[i] - positions[i];
67  }
68  else {
69  output[i] = handles[i];
70  }
71  }
72  return component.attributes()->adapt_domain<float3>(
74  }
75 
76  uint64_t hash() const override
77  {
78  return get_default_hash_2(relative_, left_);
79  }
80 
81  bool is_equal_to(const fn::FieldNode &other) const override
82  {
83  if (const HandlePositionFieldInput *other_handle =
84  dynamic_cast<const HandlePositionFieldInput *>(&other)) {
85  return relative_ == other_handle->relative_ && left_ == other_handle->left_;
86  }
87  return false;
88  }
89 };
90 
92 {
93  Field<bool> relative = params.extract_input<Field<bool>>("Relative");
94  Field<float3> left_field{std::make_shared<HandlePositionFieldInput>(relative, true)};
95  Field<float3> right_field{std::make_shared<HandlePositionFieldInput>(relative, false)};
96 
97  params.set_output("Left", std::move(left_field));
98  params.set_output("Right", std::move(right_field));
99 }
100 
101 } // namespace blender::nodes::node_geo_input_curve_handles_cc
102 
104 {
106 
107  static bNodeType ntype;
109  &ntype, GEO_NODE_INPUT_CURVE_HANDLES, "Curve Handle Positions", NODE_CLASS_INPUT);
113  nodeRegisterType(&ntype);
114 }
eAttrDomain
Definition: BKE_attribute.h:25
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:27
@ GEO_COMPONENT_TYPE_CURVE
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4408
#define GEO_NODE_INPUT_CURVE_HANDLES
Definition: BKE_node.h:1449
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
@ NODE_SIZE_MIDDLE
Definition: BKE_node.h:366
#define final(a, b, c)
Definition: BLI_hash.h:21
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
static VArray ForContainer(ContainerT container)
int add(GField field, GVArray *varray_ptr)
Definition: field.cc:731
const GVArray & get_evaluated(const int field_index) const
Definition: FN_field.hh:431
GVArray get_varray_for_context(const GeometryComponent &component, const eAttrDomain domain, IndexMask mask) const final
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
static int left
static void node_declare(NodeDeclarationBuilder &b)
uint64_t get_default_hash_2(const T1 &v1, const T2 &v2)
Definition: BLI_hash.hh:223
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
MutableSpan< float3 > positions
void register_node_type_geo_input_curve_handles()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
unsigned __int64 uint64_t
Definition: stdint.h:90
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
ParamHandle ** handles
#define N_(msgid)