Cleanup: Use enum class for boolean operation
Similar to the recently introduced `Solver` enum. This is just friendlier and doesn't require including `DNA_node_types.h` in the geometry module header. There's no strong benefit to declaring these enums in DNA in practice.
This commit is contained in:
@@ -8,8 +8,6 @@
|
||||
#include "BLI_math_matrix_types.hh"
|
||||
#include "BLI_span.hh"
|
||||
|
||||
#include "DNA_node_types.h"
|
||||
|
||||
struct Mesh;
|
||||
|
||||
namespace blender::geometry::boolean {
|
||||
@@ -25,6 +23,12 @@ enum class Solver {
|
||||
Float = 1,
|
||||
};
|
||||
|
||||
enum class Operation {
|
||||
Intersect = 0,
|
||||
Union = 1,
|
||||
Difference = 2,
|
||||
};
|
||||
|
||||
/**
|
||||
* BooleanOpParameters bundles together the global parameters for the boolean operation.
|
||||
* As well as saying which particular operation (intersect, difference, union) is desired,
|
||||
@@ -32,7 +36,7 @@ enum class Solver {
|
||||
* (e.g., whether or not there are any self intersections).
|
||||
*/
|
||||
struct BooleanOpParameters {
|
||||
GeometryNodeBooleanOperation boolean_mode;
|
||||
Operation boolean_mode;
|
||||
/** Can we assume there are no self-intersections in any of the operands? */
|
||||
bool no_self_intersections = true;
|
||||
/** Can we assume there are no nested components (e.g., a box inside a box) in any of the
|
||||
|
||||
@@ -807,13 +807,27 @@ static Mesh *imesh_to_mesh(meshintersect::IMesh *im, MeshesToIMeshInfo &mim)
|
||||
|
||||
#endif // WITH_GMP
|
||||
|
||||
static meshintersect::BoolOpType operation_to_mesh_arr_mode(const Operation operation)
|
||||
{
|
||||
switch (operation) {
|
||||
case Operation::Intersect:
|
||||
return meshintersect::BoolOpType::Intersect;
|
||||
case Operation::Union:
|
||||
return meshintersect::BoolOpType::Union;
|
||||
case Operation::Difference:
|
||||
return meshintersect::BoolOpType::Difference;
|
||||
}
|
||||
BLI_assert_unreachable();
|
||||
return meshintersect::BoolOpType::None;
|
||||
}
|
||||
|
||||
static Mesh *mesh_boolean_mesh_arr(Span<const Mesh *> meshes,
|
||||
Span<float4x4> transforms,
|
||||
const float4x4 &target_transform,
|
||||
Span<Array<short>> material_remaps,
|
||||
const bool use_self,
|
||||
const bool hole_tolerant,
|
||||
const int boolean_mode,
|
||||
const meshintersect::BoolOpType boolean_mode,
|
||||
Vector<int> *r_intersecting_edges)
|
||||
{
|
||||
#ifdef WITH_GMP
|
||||
@@ -839,14 +853,8 @@ static Mesh *mesh_boolean_mesh_arr(Span<const Mesh *> meshes,
|
||||
}
|
||||
return int(mim.mesh_face_offset.size()) - 1;
|
||||
};
|
||||
meshintersect::IMesh m_out = boolean_mesh(m_in,
|
||||
static_cast<meshintersect::BoolOpType>(boolean_mode),
|
||||
meshes.size(),
|
||||
shape_fn,
|
||||
use_self,
|
||||
hole_tolerant,
|
||||
nullptr,
|
||||
&arena);
|
||||
meshintersect::IMesh m_out = boolean_mesh(
|
||||
m_in, boolean_mode, meshes.size(), shape_fn, use_self, hole_tolerant, nullptr, &arena);
|
||||
if (dbg_level > 0) {
|
||||
std::cout << m_out;
|
||||
write_obj_mesh(m_out, "m_out");
|
||||
@@ -1052,11 +1060,25 @@ static BMesh *mesh_bm_concat(Span<const Mesh *> meshes,
|
||||
return bm;
|
||||
}
|
||||
|
||||
static int operation_to_float_mode(const Operation operation)
|
||||
{
|
||||
switch (operation) {
|
||||
case Operation::Intersect:
|
||||
return BMESH_ISECT_BOOLEAN_ISECT;
|
||||
case Operation::Union:
|
||||
return BMESH_ISECT_BOOLEAN_UNION;
|
||||
case Operation::Difference:
|
||||
return BMESH_ISECT_BOOLEAN_DIFFERENCE;
|
||||
}
|
||||
BLI_assert_unreachable();
|
||||
return BMESH_ISECT_BOOLEAN_NONE;
|
||||
}
|
||||
|
||||
static Mesh *mesh_boolean_float(Span<const Mesh *> meshes,
|
||||
Span<float4x4> transforms,
|
||||
const float4x4 &target_transform,
|
||||
Span<Array<short>> material_remaps,
|
||||
int boolean_mode,
|
||||
const int boolean_mode,
|
||||
Vector<int> * /*r_intersecting_edges*/)
|
||||
{
|
||||
BLI_assert(meshes.size() == transforms.size() || transforms.size() == 0);
|
||||
@@ -1159,7 +1181,7 @@ Mesh *mesh_boolean(Span<const Mesh *> meshes,
|
||||
transforms,
|
||||
target_transform,
|
||||
material_remaps,
|
||||
op_params.boolean_mode,
|
||||
operation_to_float_mode(op_params.boolean_mode),
|
||||
r_intersecting_edges);
|
||||
case Solver::MeshArr:
|
||||
return mesh_boolean_mesh_arr(meshes,
|
||||
@@ -1168,7 +1190,7 @@ Mesh *mesh_boolean(Span<const Mesh *> meshes,
|
||||
material_remaps,
|
||||
!op_params.no_self_intersections,
|
||||
!op_params.watertight,
|
||||
op_params.boolean_mode,
|
||||
operation_to_mesh_arr_mode(op_params.boolean_mode),
|
||||
r_intersecting_edges);
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
|
||||
@@ -2655,12 +2655,6 @@ typedef enum GeometryNodeProximityTargetType {
|
||||
GEO_NODE_PROX_TARGET_FACES = 2,
|
||||
} GeometryNodeProximityTargetType;
|
||||
|
||||
typedef enum GeometryNodeBooleanOperation {
|
||||
GEO_NODE_BOOLEAN_INTERSECT = 0,
|
||||
GEO_NODE_BOOLEAN_UNION = 1,
|
||||
GEO_NODE_BOOLEAN_DIFFERENCE = 2,
|
||||
} GeometryNodeBooleanOperation;
|
||||
|
||||
typedef enum GeometryNodeCurvePrimitiveCircleMode {
|
||||
GEO_NODE_CURVE_PRIMITIVE_CIRCLE_TYPE_POINTS = 0,
|
||||
GEO_NODE_CURVE_PRIMITIVE_CIRCLE_TYPE_RADIUS = 1
|
||||
|
||||
@@ -478,10 +478,8 @@ static Mesh *exact_boolean_mesh(BooleanModifierData *bmd,
|
||||
|
||||
const bool use_self = (bmd->flag & eBooleanModifierFlag_Self) != 0;
|
||||
const bool hole_tolerant = (bmd->flag & eBooleanModifierFlag_HoleTolerant) != 0;
|
||||
const GeometryNodeBooleanOperation op = static_cast<GeometryNodeBooleanOperation>(
|
||||
bmd->operation);
|
||||
blender::geometry::boolean::BooleanOpParameters op_params;
|
||||
op_params.boolean_mode = op;
|
||||
op_params.boolean_mode = blender::geometry::boolean::Operation(bmd->operation);
|
||||
op_params.no_self_intersections = !use_self;
|
||||
op_params.watertight = !hole_tolerant;
|
||||
op_params.no_nested_components = false;
|
||||
|
||||
@@ -47,8 +47,8 @@ struct AttributeOutputs {
|
||||
|
||||
static void node_update(bNodeTree *ntree, bNode *node)
|
||||
{
|
||||
GeometryNodeBooleanOperation operation = (GeometryNodeBooleanOperation)node->custom1;
|
||||
geometry::boolean::Solver solver = geometry::boolean::Solver(node->custom2);
|
||||
const geometry::boolean::Operation operation = geometry::boolean::Operation(node->custom1);
|
||||
const geometry::boolean::Solver solver = geometry::boolean::Solver(node->custom2);
|
||||
|
||||
bNodeSocket *geometry_1_socket = static_cast<bNodeSocket *>(node->inputs.first);
|
||||
bNodeSocket *geometry_2_socket = geometry_1_socket->next;
|
||||
@@ -56,12 +56,12 @@ static void node_update(bNodeTree *ntree, bNode *node)
|
||||
bNodeSocket *intersecting_edges_socket = static_cast<bNodeSocket *>(node->outputs.last);
|
||||
|
||||
switch (operation) {
|
||||
case GEO_NODE_BOOLEAN_INTERSECT:
|
||||
case GEO_NODE_BOOLEAN_UNION:
|
||||
case geometry::boolean::Operation::Intersect:
|
||||
case geometry::boolean::Operation::Union:
|
||||
bke::nodeSetSocketAvailability(ntree, geometry_1_socket, false);
|
||||
node_sock_label(geometry_2_socket, "Mesh");
|
||||
break;
|
||||
case GEO_NODE_BOOLEAN_DIFFERENCE:
|
||||
case geometry::boolean::Operation::Difference:
|
||||
bke::nodeSetSocketAvailability(ntree, geometry_1_socket, true);
|
||||
node_sock_label(geometry_2_socket, "Mesh 2");
|
||||
break;
|
||||
@@ -73,7 +73,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
|
||||
|
||||
static void node_init(bNodeTree * /*tree*/, bNode *node)
|
||||
{
|
||||
node->custom1 = GEO_NODE_BOOLEAN_DIFFERENCE;
|
||||
node->custom1 = int16_t(geometry::boolean::Operation::Difference);
|
||||
node->custom2 = int16_t(geometry::boolean::Solver::Float);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ static Array<short> calc_mesh_material_map(const Mesh &mesh, VectorSet<Material
|
||||
static void node_geo_exec(GeoNodeExecParams params)
|
||||
{
|
||||
#ifdef WITH_GMP
|
||||
GeometryNodeBooleanOperation operation = (GeometryNodeBooleanOperation)params.node().custom1;
|
||||
geometry::boolean::Operation operation = geometry::boolean::Operation(params.node().custom1);
|
||||
geometry::boolean::Solver solver = geometry::boolean::Solver(params.node().custom2);
|
||||
const bool use_self = params.get_input<bool>("Self Intersection");
|
||||
const bool hole_tolerant = params.get_input<bool>("Hole Tolerant");
|
||||
@@ -103,7 +103,7 @@ static void node_geo_exec(GeoNodeExecParams params)
|
||||
Vector<Array<short>> material_remaps;
|
||||
|
||||
GeometrySet set_a;
|
||||
if (operation == GEO_NODE_BOOLEAN_DIFFERENCE) {
|
||||
if (operation == geometry::boolean::Operation::Difference) {
|
||||
set_a = params.extract_input<GeometrySet>("Mesh 1");
|
||||
/* Note that it technically wouldn't be necessary to realize the instances for the first
|
||||
* geometry input, but the boolean code expects the first shape for the difference operation
|
||||
@@ -220,13 +220,17 @@ static void node_geo_exec(GeoNodeExecParams params)
|
||||
static void node_rna(StructRNA *srna)
|
||||
{
|
||||
static const EnumPropertyItem rna_node_geometry_boolean_method_items[] = {
|
||||
{GEO_NODE_BOOLEAN_INTERSECT,
|
||||
{int(geometry::boolean::Operation::Intersect),
|
||||
"INTERSECT",
|
||||
0,
|
||||
"Intersect",
|
||||
"Keep the part of the mesh that is common between all operands"},
|
||||
{GEO_NODE_BOOLEAN_UNION, "UNION", 0, "Union", "Combine meshes in an additive way"},
|
||||
{GEO_NODE_BOOLEAN_DIFFERENCE,
|
||||
{int(geometry::boolean::Operation::Union),
|
||||
"UNION",
|
||||
0,
|
||||
"Union",
|
||||
"Combine meshes in an additive way"},
|
||||
{int(geometry::boolean::Operation::Difference),
|
||||
"DIFFERENCE",
|
||||
0,
|
||||
"Difference",
|
||||
@@ -253,7 +257,7 @@ static void node_rna(StructRNA *srna)
|
||||
"",
|
||||
rna_node_geometry_boolean_method_items,
|
||||
NOD_inline_enum_accessors(custom1),
|
||||
GEO_NODE_BOOLEAN_INTERSECT);
|
||||
int(geometry::boolean::Operation::Intersect));
|
||||
|
||||
RNA_def_node_enum(srna,
|
||||
"solver",
|
||||
|
||||
Reference in New Issue
Block a user