Mesh: Move flip faces function to blenkernel

The aim is to replace the `BKE_mesh_faces_flip` functions with
this newer C++ function using the attribute API. But that is must
be called by RNA, so move this to blenkernel to avoid a circular
dependency between the geometry module and RNA.
This commit is contained in:
Hans Goudey
2023-08-01 13:08:52 -04:00
parent 9048bf6ffd
commit 40de15d521
6 changed files with 23 additions and 51 deletions

View File

@@ -8,10 +8,12 @@
* \ingroup bke
*/
#include "BLI_index_mask.hh"
#include "BKE_mesh.h"
namespace blender::bke::mesh {
namespace blender::bke {
namespace mesh {
/* -------------------------------------------------------------------- */
/** \name Polygon Data Evaluation
* \{ */
@@ -270,7 +272,11 @@ inline int edge_other_vert(const int2 &edge, const int vert)
/** \} */
} // namespace blender::bke::mesh
} // namespace mesh
void mesh_flip_faces(Mesh &mesh, const IndexMask &selection);
} // namespace blender::bke
/* -------------------------------------------------------------------- */
/** \name Inline Mesh Data Access

View File

@@ -202,6 +202,7 @@ set(SRC
intern/mesh_debug.cc
intern/mesh_evaluate.cc
intern/mesh_fair.cc
intern/mesh_flip_faces.cc
intern/mesh_iterators.cc
intern/mesh_legacy_convert.cc
intern/mesh_mapping.cc

View File

@@ -2,8 +2,6 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "GEO_mesh_flip_faces.hh"
#include "DNA_mesh_types.h"
#include "BLI_task.hh"
@@ -12,9 +10,9 @@
#include "BKE_attribute_math.hh"
#include "BKE_mesh.hh"
namespace blender::geometry {
namespace blender::bke {
void flip_faces(Mesh &mesh, const IndexMask &selection)
void mesh_flip_faces(Mesh &mesh, const IndexMask &selection)
{
if (mesh.faces_num == 0 || selection.is_empty()) {
return;
@@ -61,4 +59,4 @@ void flip_faces(Mesh &mesh, const IndexMask &selection)
BKE_mesh_tag_face_winding_changed(&mesh);
}
} // namespace blender::geometry
} // namespace blender::bke

View File

@@ -16,7 +16,6 @@ set(SRC
intern/curve_constraints.cc
intern/fillet_curves.cc
intern/mesh_copy_selection.cc
intern/mesh_flip_faces.cc
intern/mesh_merge_by_distance.cc
intern/mesh_primitive_cuboid.cc
intern/mesh_split_edges.cc
@@ -37,7 +36,6 @@ set(SRC
GEO_curve_constraints.hh
GEO_fillet_curves.hh
GEO_mesh_copy_selection.hh
GEO_mesh_flip_faces.hh
GEO_mesh_merge_by_distance.hh
GEO_mesh_primitive_cuboid.hh
GEO_mesh_split_edges.hh

View File

@@ -1,19 +0,0 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "BLI_index_mask.hh"
struct Mesh;
namespace blender::geometry {
/**
* Reverse the order of the vertices in the selected faces. This effectively changes the
* direction of the face normal.
*/
void flip_faces(Mesh &mesh, const IndexMask &selection);
} // namespace blender::geometry

View File

@@ -2,14 +2,7 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BLI_task.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_runtime.h"
#include "BKE_attribute_math.hh"
#include "GEO_mesh_flip_faces.hh"
#include "node_geometry_util.hh"
@@ -22,20 +15,6 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>("Mesh").propagate_all();
}
static void mesh_flip_faces(Mesh &mesh, const Field<bool> &selection_field)
{
if (mesh.faces_num == 0) {
return;
}
const bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_FACE};
fn::FieldEvaluator evaluator{field_context, mesh.faces_num};
evaluator.add(selection_field);
evaluator.evaluate();
const IndexMask selection = evaluator.get_evaluated_as_mask(0);
geometry::flip_faces(mesh, selection);
}
static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
@@ -44,7 +23,16 @@ static void node_geo_exec(GeoNodeExecParams params)
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
mesh_flip_faces(*mesh, selection_field);
const bke::MeshFieldContext field_context(*mesh, ATTR_DOMAIN_FACE);
fn::FieldEvaluator evaluator(field_context, mesh->faces_num);
evaluator.add(selection_field);
evaluator.evaluate();
const IndexMask selection = evaluator.get_evaluated_as_mask(0);
if (selection.is_empty()) {
return;
}
bke::mesh_flip_faces(*mesh, selection);
}
});