Blender V5.3
node_geo_input_mesh_face_area.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_mesh.hh"
6
8
10
12{
13 b.add_output<decl::Float>("Area"_ustr)
14 .translation_context(BLT_I18NCONTEXT_AMOUNT)
15 .structure_type(StructureType::Field)
16 .description("The surface area of each of the mesh's faces");
17}
18
20{
21 const Span<float3> positions = mesh.vert_positions();
22 const OffsetIndices faces = mesh.faces();
23 const Span<int> corner_verts = mesh.corner_verts();
24
25 auto area_fn = [positions, faces, corner_verts](const int i) -> float {
26 return bke::mesh::face_area_calc(positions, corner_verts.slice(faces[i]));
27 };
28
29 return mesh.attributes().adapt_domain<float>(
30 VArray<float>::from_func(faces.size(), area_fn), AttrDomain::Face, domain);
31}
32
34 public:
35 FaceAreaFieldInput() : bke::MeshFieldInput(CPPType::get<float>(), "Face Area Field") {}
36
38 const AttrDomain domain,
39 const IndexMask & /*mask*/) const final
40 {
41 return construct_face_area_varray(mesh, domain);
42 }
43
44 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
45 {
46 static constexpr int8_t id = 0;
47 hash.add(&id);
48 }
49
50 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
51 {
52 return AttrDomain::Face;
53 }
54
55 bke::NativeFieldDomain native_domain_info(const Mesh & /*mesh*/) const override
56 {
57 return bke::NativeFieldDomain::Domain{AttrDomain::Face};
58 }
59};
60
62{
64}
65
66static void node_register()
67{
68 static bke::bNodeType ntype;
69 geo_node_type_base(&ntype, "GeometryNodeInputMeshFaceArea"_ustr, GEO_NODE_INPUT_MESH_FACE_AREA);
70 ntype.ui_name = "Face Area";
71 ntype.ui_description = "Calculate the surface area of a mesh's faces";
72 ntype.enum_name_legacy = "MESH_FACE_AREA";
74 ntype.declare = node_declare;
77}
79
80} // namespace blender::nodes::node_geo_input_mesh_face_area_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_INPUT_MESH_FACE_AREA
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define BLT_I18NCONTEXT_AMOUNT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
static VArray from_func(const int64_t size, GetFunc get_func)
uint64_t hash() const
Definition field.cc:185
static Field from_input(Args &&...args)
void set_output(const UString identifier, T &&value)
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &) const final
std::optional< AttrDomain > preferred_domain(const Mesh &) const override
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &) const override
float face_area_calc(Span< float3 > vert_positions, Span< int > face_verts)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static VArray< float > construct_face_area_varray(const Mesh &mesh, const AttrDomain domain)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
signed char int8_t
Definition BKE_text.h:76
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393