Blender V4.5
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{
13 b.use_custom_socket_order();
14 b.allow_any_socket_order();
15 b.add_input<decl::Geometry>("Mesh").supported_type(GeometryComponent::Type::Mesh);
16 b.add_output<decl::Geometry>("Mesh").propagate_all().align_with_previous();
17 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
18}
19
21{
22 GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
23
24 const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
25
26 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
27 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
28 const bke::MeshFieldContext field_context(*mesh, AttrDomain::Face);
29 fn::FieldEvaluator evaluator(field_context, mesh->faces_num);
30 evaluator.add(selection_field);
31 evaluator.evaluate();
32 const IndexMask selection = evaluator.get_evaluated_as_mask(0);
33 if (selection.is_empty()) {
34 return;
35 }
36
37 bke::mesh_flip_faces(*mesh, selection);
38 }
39 });
40
41 params.set_output("Mesh", std::move(geometry_set));
42}
43
44static void node_register()
45{
46 static blender::bke::bNodeType ntype;
47
48 geo_node_type_base(&ntype, "GeometryNodeFlipFaces", GEO_NODE_FLIP_FACES);
49 ntype.ui_name = "Flip Faces";
50 ntype.ui_description =
51 "Reverse the order of the vertices and edges of selected faces, flipping their normal "
52 "direction";
53 ntype.enum_name_legacy = "FLIP_FACES";
56 ntype.declare = node_declare;
58}
60
61} // namespace blender::nodes::node_geo_flip_faces_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:447
#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:2748
void mesh_flip_faces(Mesh &mesh, const IndexMask &selection)
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)
void modify_geometry_sets(ForeachSubGeometryCallback callback)
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355