Blender V4.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")
14 .translation_context(BLT_I18NCONTEXT_AMOUNT)
15 .field_source()
16 .description("The surface area of each of the mesh's faces");
17}
18
19static VArray<float> construct_face_area_varray(const Mesh &mesh, const AttrDomain domain)
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>::ForFunc(faces.size(), area_fn), AttrDomain::Face, domain);
31}
32
34 public:
35 FaceAreaFieldInput() : bke::MeshFieldInput(CPPType::get<float>(), "Face Area Field")
36 {
38 }
39
41 const AttrDomain domain,
42 const IndexMask & /*mask*/) const final
43 {
44 return construct_face_area_varray(mesh, domain);
45 }
46
47 uint64_t hash() const override
48 {
49 /* Some random constant hash. */
50 return 1346334523;
51 }
52
53 bool is_equal_to(const fn::FieldNode &other) const override
54 {
55 return dynamic_cast<const FaceAreaFieldInput *>(&other) != nullptr;
56 }
57
58 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
59 {
60 return AttrDomain::Face;
61 }
62};
63
65{
66 params.set_output("Area", Field<float>(std::make_shared<FaceAreaFieldInput>()));
67}
68
69static void node_register()
70{
71 static blender::bke::bNodeType ntype;
72 geo_node_type_base(&ntype, GEO_NODE_INPUT_MESH_FACE_AREA, "Face Area", NODE_CLASS_INPUT);
73 ntype.declare = node_declare;
76}
78
79} // namespace blender::nodes::node_geo_input_mesh_face_area_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#define BLT_I18NCONTEXT_AMOUNT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:138
static VArray ForFunc(const int64_t size, GetFunc get_func)
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &) const final
std::optional< AttrDomain > preferred_domain(const Mesh &) const override
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static char faces[256]
float face_area_calc(Span< float3 > vert_positions, Span< int > face_verts)
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static VArray< float > construct_face_area_varray(const Mesh &mesh, const AttrDomain domain)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
unsigned __int64 uint64_t
Definition stdint.h:90
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347