Blender  V3.3
node_geo_input_mesh_edge_vertices.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "DNA_mesh_types.h"
4 #include "DNA_meshdata_types.h"
5 
6 #include "BKE_mesh.h"
7 
8 #include "node_geometry_util.hh"
9 
11 
13 {
14  b.add_output<decl::Int>(N_("Vertex Index 1"))
15  .field_source()
16  .description(N_("The index of the first vertex in the edge"));
17  b.add_output<decl::Int>(N_("Vertex Index 2"))
18  .field_source()
19  .description(N_("The index of the second vertex in the edge"));
20  b.add_output<decl::Vector>(N_("Position 1"))
21  .field_source()
22  .description(N_("The position of the first vertex in the edge"));
23  b.add_output<decl::Vector>(N_("Position 2"))
24  .field_source()
25  .description(N_("The position of the second vertex in the edge"));
26 }
27 
29 
31  const VertexNumber vertex,
32  const eAttrDomain domain)
33 {
34  const Mesh *mesh = component.get_for_read();
35  if (mesh == nullptr) {
36  return {};
37  }
38  if (domain == ATTR_DOMAIN_EDGE) {
39  if (vertex == VERTEX_ONE) {
41  [mesh](const int i) -> int { return mesh->medge[i].v1; });
42  }
44  [mesh](const int i) -> int { return mesh->medge[i].v2; });
45  }
46  return {};
47 }
48 
50  private:
51  VertexNumber vertex_;
52 
53  public:
55  : GeometryFieldInput(CPPType::get<int>(), "Edge Vertices Field"), vertex_(vertex)
56  {
58  }
59 
61  const eAttrDomain domain,
62  IndexMask UNUSED(mask)) const final
63  {
64  if (component.type() == GEO_COMPONENT_TYPE_MESH) {
65  const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
66  return construct_edge_vertices_gvarray(mesh_component, vertex_, domain);
67  }
68  return {};
69  }
70 
71  uint64_t hash() const override
72  {
73  return vertex_ == VERTEX_ONE ? 23847562893465 : 92384598734567;
74  }
75 
76  bool is_equal_to(const fn::FieldNode &other) const override
77  {
78  if (const EdgeVerticesFieldInput *other_field = dynamic_cast<const EdgeVerticesFieldInput *>(
79  &other)) {
80  return vertex_ == other_field->vertex_;
81  }
82  return false;
83  }
84 };
85 
87  const VertexNumber vertex,
88  const eAttrDomain domain)
89 {
90  const Mesh *mesh = component.get_for_read();
91  if (mesh == nullptr) {
92  return {};
93  }
94 
95  if (vertex == VERTEX_ONE) {
96  return component.attributes()->adapt_domain<float3>(
98  mesh->totedge,
99  [mesh](const int i) { return float3(mesh->mvert[mesh->medge[i].v1].co); }),
101  domain);
102  }
103  return component.attributes()->adapt_domain<float3>(
105  mesh->totedge,
106  [mesh](const int i) { return float3(mesh->mvert[mesh->medge[i].v2].co); }),
108  domain);
109 }
110 
112  private:
113  VertexNumber vertex_;
114 
115  public:
117  : GeometryFieldInput(CPPType::get<float3>(), "Edge Position Field"), vertex_(vertex)
118  {
120  }
121 
123  const eAttrDomain domain,
124  IndexMask UNUSED(mask)) const final
125  {
126  if (component.type() == GEO_COMPONENT_TYPE_MESH) {
127  const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
128  return construct_edge_positions_gvarray(mesh_component, vertex_, domain);
129  }
130  return {};
131  }
132 
133  uint64_t hash() const override
134  {
135  return vertex_ == VERTEX_ONE ? 987456978362 : 374587679866;
136  }
137 
138  bool is_equal_to(const fn::FieldNode &other) const override
139  {
140  if (const EdgePositionFieldInput *other_field = dynamic_cast<const EdgePositionFieldInput *>(
141  &other)) {
142  return vertex_ == other_field->vertex_;
143  }
144  return false;
145  }
146 };
147 
149 {
150  Field<int> vertex_field_1{std::make_shared<EdgeVerticesFieldInput>(VERTEX_ONE)};
151  Field<int> vertex_field_2{std::make_shared<EdgeVerticesFieldInput>(VERTEX_TWO)};
152  Field<float3> position_field_1{std::make_shared<EdgePositionFieldInput>(VERTEX_ONE)};
153  Field<float3> position_field_2{std::make_shared<EdgePositionFieldInput>(VERTEX_TWO)};
154 
155  params.set_output("Vertex Index 1", std::move(vertex_field_1));
156  params.set_output("Vertex Index 2", std::move(vertex_field_2));
157  params.set_output("Position 1", std::move(position_field_1));
158  params.set_output("Position 2", std::move(position_field_2));
159 }
160 
161 } // namespace blender::nodes::node_geo_input_mesh_edge_vertices_cc
162 
164 {
166 
167  static bNodeType ntype;
171  nodeRegisterType(&ntype);
172 }
eAttrDomain
Definition: BKE_attribute.h:25
@ ATTR_DOMAIN_EDGE
Definition: BKE_attribute.h:28
@ GEO_COMPONENT_TYPE_MESH
#define GEO_NODE_INPUT_MESH_EDGE_VERTICES
Definition: BKE_node.h:1479
#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
static VArray ForFunc(const int64_t size, GetFunc get_func)
GVArray get_varray_for_context(const GeometryComponent &component, const eAttrDomain domain, IndexMask UNUSED(mask)) const final
GVArray get_varray_for_context(const GeometryComponent &component, const eAttrDomain domain, IndexMask UNUSED(mask)) const final
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
static VArray< int > construct_edge_vertices_gvarray(const MeshComponent &component, const VertexNumber vertex, const eAttrDomain domain)
static VArray< float3 > construct_edge_positions_gvarray(const MeshComponent &component, const VertexNumber vertex, const eAttrDomain domain)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_input_mesh_edge_vertices()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
unsigned __int64 uint64_t
Definition: stdint.h:90
int totedge
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)