Blender  V3.3
node_geo_input_mesh_edge_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_("Face Count"))
15  .field_source()
16  .description(N_("The number of faces that use each edge as one of their sides"));
17 }
18 
20  public:
22  : GeometryFieldInput(CPPType::get<int>(), "Edge Neighbor Count Field")
23  {
25  }
26 
28  const eAttrDomain domain,
29  IndexMask UNUSED(mask)) const final
30  {
31  if (component.type() == GEO_COMPONENT_TYPE_MESH) {
32  const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
33  const Mesh *mesh = mesh_component.get_for_read();
34  if (mesh == nullptr) {
35  return {};
36  }
37 
38  Array<int> face_count(mesh->totedge, 0);
39  for (const int i : IndexRange(mesh->totloop)) {
40  face_count[mesh->mloop[i].e]++;
41  }
42 
43  return mesh_component.attributes()->adapt_domain<int>(
44  VArray<int>::ForContainer(std::move(face_count)), ATTR_DOMAIN_EDGE, domain);
45  }
46  return {};
47  }
48 
49  uint64_t hash() const override
50  {
51  /* Some random constant hash. */
52  return 985671075;
53  }
54 
55  bool is_equal_to(const fn::FieldNode &other) const override
56  {
57  return dynamic_cast<const EdgeNeighborCountFieldInput *>(&other) != nullptr;
58  }
59 };
60 
62 {
63  Field<int> neighbor_count_field{std::make_shared<EdgeNeighborCountFieldInput>()};
64  params.set_output("Face Count", std::move(neighbor_count_field));
65 }
66 
67 } // namespace blender::nodes::node_geo_input_mesh_edge_neighbors_cc
68 
70 {
72 
73  static bNodeType ntype;
75  &ntype, GEO_NODE_INPUT_MESH_EDGE_NEIGHBORS, "Edge Neighbors", NODE_CLASS_INPUT);
78  nodeRegisterType(&ntype);
79 }
eAttrDomain
Definition: BKE_attribute.h:25
@ ATTR_DOMAIN_EDGE
Definition: BKE_attribute.h:28
@ GEO_COMPONENT_TYPE_MESH
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
#define GEO_NODE_INPUT_MESH_EDGE_NEIGHBORS
Definition: BKE_node.h:1484
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
const Mesh * get_for_read() const
std::optional< blender::bke::AttributeAccessor > attributes() const final
static VArray ForContainer(ContainerT container)
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 const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_input_mesh_edge_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 totloop
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)