Blender V5.3
node_geo_flip_faces.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
14{
15 b.use_custom_socket_order();
16 b.allow_any_socket_order();
17 b.add_input<decl::Geometry>("Mesh"_ustr)
18 .supported_type(GeometryComponent::Type::Mesh)
19 .description("Mesh to flip faces of");
20 b.add_output<decl::Geometry>("Mesh"_ustr).propagate_all_geometry().align_with_previous();
21 b.add_input<decl::Bool>("Selection"_ustr)
22 .default_value(true)
23 .hide_value()
24 .evaluated_geometry_field();
25}
26
28{
29 GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh"_ustr);
30
31 const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection"_ustr);
32
33 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
34 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
35 const bke::MeshFieldContext field_context(*mesh, AttrDomain::Face);
36 fn::FieldEvaluator evaluator(field_context, mesh->faces_num);
37 evaluator.add(selection_field);
38 evaluator.evaluate();
39 const IndexMask selection = evaluator.get_evaluated_as_mask(0);
40 if (selection.is_empty()) {
41 return;
42 }
43
44 bke::mesh_flip_faces(*mesh, selection);
45 }
46 });
47
48 params.set_output("Mesh"_ustr, std::move(geometry_set));
49}
50
51static void node_register()
52{
53 static bke::bNodeType ntype;
54
55 geo_node_type_base(&ntype, "GeometryNodeFlipFaces"_ustr, GEO_NODE_FLIP_FACES);
56 ntype.ui_name = "Flip Faces";
57 ntype.ui_description =
58 "Reverse the order of the vertices and edges of selected faces, flipping their normal "
59 "direction";
60 ntype.enum_name_legacy = "FLIP_FACES";
63 ntype.declare = node_declare;
65}
67
68} // namespace blender::nodes::node_geo_flip_faces_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_FLIP_FACES
#define NOD_REGISTER_NODE(REGISTER_FUNC)
int add(GField field, GVArray *varray_ptr)
IndexMask get_evaluated_as_mask(int field_index)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void mesh_flip_faces(Mesh &mesh, const IndexMask &selection)
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
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