Blender  V3.3
node_geo_input_mesh_face_neighbors.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 Count"))
15  .field_source()
16  .description(N_("Number of edges or points in the face"));
17  b.add_output<decl::Int>(N_("Face Count"))
18  .field_source()
19  .description(N_("Number of faces which share an edge with the face"));
20 }
21 
23  const eAttrDomain domain)
24 {
25  const Mesh *mesh = component.get_for_read();
26  if (mesh == nullptr) {
27  return {};
28  }
29 
30  Array<int> edge_count(mesh->totedge, 0);
31  for (const int i : IndexRange(mesh->totloop)) {
32  edge_count[mesh->mloop[i].e]++;
33  }
34 
35  Array<int> poly_count(mesh->totpoly, 0);
36  for (const int poly_num : IndexRange(mesh->totpoly)) {
37  MPoly &poly = mesh->mpoly[poly_num];
38  for (const int loop_num : IndexRange(poly.loopstart, poly.totloop)) {
39  poly_count[poly_num] += edge_count[mesh->mloop[loop_num].e] - 1;
40  }
41  }
42 
43  return component.attributes()->adapt_domain<int>(
44  VArray<int>::ForContainer(std::move(poly_count)), ATTR_DOMAIN_FACE, domain);
45 }
46 
48  public:
50  : GeometryFieldInput(CPPType::get<int>(), "Face Neighbor Count Field")
51  {
53  }
54 
56  const eAttrDomain domain,
57  IndexMask UNUSED(mask)) const final
58  {
59  if (component.type() == GEO_COMPONENT_TYPE_MESH) {
60  const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
61  return construct_neighbor_count_gvarray(mesh_component, domain);
62  }
63  return {};
64  }
65 
66  uint64_t hash() const override
67  {
68  /* Some random constant hash. */
69  return 823543774;
70  }
71 
72  bool is_equal_to(const fn::FieldNode &other) const override
73  {
74  return dynamic_cast<const FaceNeighborCountFieldInput *>(&other) != nullptr;
75  }
76 };
77 
79  const eAttrDomain domain)
80 {
81  const Mesh *mesh = component.get_for_read();
82  if (mesh == nullptr) {
83  return {};
84  }
85 
86  return component.attributes()->adapt_domain<int>(
88  [mesh](const int i) -> float { return mesh->mpoly[i].totloop; }),
90  domain);
91 }
92 
94  public:
95  FaceVertexCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Vertex Count Field")
96  {
98  }
99 
101  const eAttrDomain domain,
102  IndexMask UNUSED(mask)) const final
103  {
104  if (component.type() == GEO_COMPONENT_TYPE_MESH) {
105  const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
106  return construct_vertex_count_gvarray(mesh_component, domain);
107  }
108  return {};
109  }
110 
111  uint64_t hash() const override
112  {
113  /* Some random constant hash. */
114  return 236235463634;
115  }
116 
117  bool is_equal_to(const fn::FieldNode &other) const override
118  {
119  return dynamic_cast<const FaceVertexCountFieldInput *>(&other) != nullptr;
120  }
121 };
122 
124 {
125  Field<int> vertex_count_field{std::make_shared<FaceVertexCountFieldInput>()};
126  Field<int> neighbor_count_field{std::make_shared<FaceNeighborCountFieldInput>()};
127  params.set_output("Vertex Count", std::move(vertex_count_field));
128  params.set_output("Face Count", std::move(neighbor_count_field));
129 }
130 
131 } // namespace blender::nodes::node_geo_input_mesh_face_neighbors_cc
132 
134 {
136 
137  static bNodeType ntype;
139  &ntype, GEO_NODE_INPUT_MESH_FACE_NEIGHBORS, "Face Neighbors", NODE_CLASS_INPUT);
143  nodeRegisterType(&ntype);
144 }
eAttrDomain
Definition: BKE_attribute.h:25
@ ATTR_DOMAIN_FACE
Definition: BKE_attribute.h:29
@ GEO_COMPONENT_TYPE_MESH
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4408
#define GEO_NODE_INPUT_MESH_FACE_NEIGHBORS
Definition: BKE_node.h:1481
#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
#define UNUSED(x)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
static VArray ForContainer(ContainerT container)
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_vertex_count_gvarray(const MeshComponent &component, const eAttrDomain domain)
static VArray< int > construct_neighbor_count_gvarray(const MeshComponent &component, const eAttrDomain domain)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_input_mesh_face_neighbors()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
unsigned __int64 uint64_t
Definition: stdint.h:90
unsigned int e
int totedge
struct MLoop * mloop
int totpoly
int totloop
struct MPoly * mpoly
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)