Blender V5.0
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")
18 .supported_type(GeometryComponent::Type::Mesh)
19 .description("Mesh to flip faces of");
20 b.add_output<decl::Geometry>("Mesh").propagate_all().align_with_previous();
21 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
22}
23
25{
26 GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
27
28 const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
29
30 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
31 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
32 const bke::MeshFieldContext field_context(*mesh, AttrDomain::Face);
33 fn::FieldEvaluator evaluator(field_context, mesh->faces_num);
34 evaluator.add(selection_field);
35 evaluator.evaluate();
36 const IndexMask selection = evaluator.get_evaluated_as_mask(0);
37 if (selection.is_empty()) {
38 return;
39 }
40
41 bke::mesh_flip_faces(*mesh, selection);
42 }
43 });
44
45 params.set_output("Mesh", std::move(geometry_set));
46}
47
48static void node_register()
49{
50 static blender::bke::bNodeType ntype;
51
52 geo_node_type_base(&ntype, "GeometryNodeFlipFaces", GEO_NODE_FLIP_FACES);
53 ntype.ui_name = "Flip Faces";
54 ntype.ui_description =
55 "Reverse the order of the vertices and edges of selected faces, flipping their normal "
56 "direction";
57 ntype.enum_name_legacy = "FLIP_FACES";
60 ntype.declare = node_declare;
62}
64
65} // namespace blender::nodes::node_geo_flip_faces_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_FLIP_FACES
#define NOD_REGISTER_NODE(REGISTER_FUNC)
int add(GField field, GVArray *varray_ptr)
Definition field.cc:751
IndexMask get_evaluated_as_mask(int field_index)
Definition field.cc:804
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362