Skip to content

Commit 8d41b4f

Browse files
ochafikkintel
andauthored
Add backend setting / flag to enable manifold in prod builds (openscad#5235)
Co-authored-by: Marius Kintel <marius@kintel.net>
1 parent d3d32fe commit 8d41b4f

File tree

68 files changed

+180
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+180
-81
lines changed

.github/workflows/linux-build-matrix.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ jobs:
1414
os: [ ubuntu-latest ]
1515
headless: [ ON, OFF ]
1616
enable_tests: [ ON, OFF ]
17+
enable_manifold: [ ON, OFF ]
1718

1819
runs-on: ${{ matrix.os }}
1920

20-
name: ${{ matrix.os }}:HEADLESS=${{ matrix.headless }},ENABLE_TESTS=${{ matrix.enable_tests }}
21+
name: ${{ matrix.os }}:HEADLESS=${{ matrix.headless }},ENABLE_TESTS=${{ matrix.enable_tests }},ENABLE_MANIFOLD=${{ matrix.enable_manifold }}
2122

2223
steps:
2324
- uses: actions/checkout@v4
@@ -30,6 +31,7 @@ jobs:
3031
cmake -S . -B build -GNinja \
3132
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
3233
-DHEADLESS=${{ matrix.headless }} \
34+
-DENABLE_MANIFOLD=${{ matrix.enable_manifold }} \
3335
-DENABLE_TESTS=${{ matrix.enable_tests }}
3436
- name: Build OpenSCAD
3537
run: cmake --build build

CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ option(ENABLE_SPNAV "Enable support for libspnav input driver." ON)
5555
option(ENABLE_HIDAPI "Enable support for HIDAPI input driver." ON)
5656
option(ENABLE_TBB "Enable support for oneAPI Threading Building Blocks." ON)
5757
option(ENABLE_CGAL "Enable CGAL." ON)
58+
option(ENABLE_MANIFOLD "Enable Manifold." ON)
5859
option(ALLOW_BUNDLED_HIDAPI "Allow usage of bundled HIDAPI library (Windows only)." OFF)
5960
option(ENABLE_PYTHON "Enable experimental Python Interpreter" OFF)
6061
option(BUILD_SHARED_LIBS "Build shared library" OFF)
@@ -944,7 +945,7 @@ if(EXPERIMENTAL AND ENABLE_TBB)
944945
target_link_libraries(OpenSCAD PRIVATE TBB::tbb)
945946
endif()
946947

947-
if(EXPERIMENTAL)
948+
if(ENABLE_MANIFOLD)
948949

949950
# Hack to find our wanted version of Python before Manifold's included googletest finds Python2
950951
find_package(Python3 3.4 COMPONENTS Interpreter REQUIRED)
@@ -970,12 +971,6 @@ if(EXPERIMENTAL)
970971
target_link_libraries(OpenSCAD PRIVATE manifold polygon cross_section)
971972
add_sanitizers(manifold)
972973

973-
target_compile_definitions(OpenSCAD PRIVATE ENABLE_MANIFOLD)
974-
list(APPEND Sources ${MANIFOLD_SOURCES})
975-
if (ENABLE_CGAL)
976-
list(APPEND Sources ${MANIFOLD_CGAL_SOURCES})
977-
endif()
978-
979974
if (USE_MANIFOLD_TRIANGULATOR)
980975
target_compile_definitions(OpenSCAD PRIVATE USE_MANIFOLD_TRIANGULATOR)
981976
endif()
@@ -1193,9 +1188,16 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
11931188
set_source_files_properties("src/ext/polyclipping/clipper.cpp" PROPERTIES COMPILE_FLAGS "-Wno-class-memaccess")
11941189
endif()
11951190

1191+
if (ENABLE_MANIFOLD)
1192+
target_compile_definitions(OpenSCAD PRIVATE ENABLE_MANIFOLD)
1193+
list(APPEND Sources ${MANIFOLD_SOURCES})
1194+
endif()
11961195
if (ENABLE_CGAL)
11971196
list(APPEND Sources ${CGAL_SOURCES})
11981197
endif()
1198+
if (ENABLE_MANIFOLD AND ENABLE_CGAL)
1199+
list(APPEND Sources ${MANIFOLD_CGAL_SOURCES})
1200+
endif()
11991201
list(APPEND Sources src/openscad.cc ${CORE_SOURCES} ${OFFSCREEN_SOURCES})
12001202

12011203
set_source_files_properties(

src/Feature.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Feature::list_t Feature::feature_list; // Double-listed values. --^
3131
const Feature Feature::ExperimentalFastCsg("fast-csg", "Enable much faster CSG operations with corefinement instead of nef when possible.");
3232
const Feature Feature::ExperimentalFastCsgSafer("fast-csg-safer", "Don't use corefinement in cases it doesn't supports and risks crashing. This will fallback to slower operations on Nef polyhedra.");
3333
const Feature Feature::ExperimentalFastCsgDebug("fast-csg-debug", "Debug mode for fast-csg: adds logs with extra costly checks and dumps .off files with the last corefinement operands.");
34-
const Feature Feature::ExperimentalManifold("manifold", "Use the Manifold library (https://github.com/elalish/manifold) for CSG operations instead of CGAL.");
3534
const Feature Feature::ExperimentalRoof("roof", "Enable <code>roof</code>");
3635
const Feature Feature::ExperimentalInputDriverDBus("input-driver-dbus", "Enable DBus input drivers (requires restart)");
3736
const Feature Feature::ExperimentalLazyUnion("lazy-union", "Enable lazy unions.");

src/Feature.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class Feature
1717
static const Feature ExperimentalFastCsg;
1818
static const Feature ExperimentalFastCsgSafer;
1919
static const Feature ExperimentalFastCsgDebug;
20-
static const Feature ExperimentalManifold;
2120
static const Feature ExperimentalRoof;
2221
static const Feature ExperimentalInputDriverDBus;
2322
static const Feature ExperimentalLazyUnion;

src/geometry/GeometryEvaluator.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "utils/printutils.h"
2626
#include "utils/calc.h"
2727
#include "io/DxfData.h"
28+
#include "glview/RenderSettings.h"
2829
#include "utils/degree_trig.h"
2930
#include <list>
3031
#include <utility>
@@ -161,7 +162,7 @@ GeometryEvaluator::ResultObject GeometryEvaluator::applyToChildren3D(const Abstr
161162
if (actualchildren.empty()) return {};
162163
if (actualchildren.size() == 1) return ResultObject::constResult(actualchildren.front().second);
163164
#ifdef ENABLE_MANIFOLD
164-
if (Feature::ExperimentalManifold.is_enabled()) {
165+
if (RenderSettings::inst()->backend3D == RenderBackend3D::ManifoldBackend) {
165166
return ResultObject::mutableResult(ManifoldUtils::applyOperator3DManifold(actualchildren, op));
166167
}
167168
#endif
@@ -178,7 +179,7 @@ GeometryEvaluator::ResultObject GeometryEvaluator::applyToChildren3D(const Abstr
178179
default:
179180
{
180181
#ifdef ENABLE_MANIFOLD
181-
if (Feature::ExperimentalManifold.is_enabled()) {
182+
if (RenderSettings::inst()->backend3D == RenderBackend3D::ManifoldBackend) {
182183
return ResultObject::mutableResult(ManifoldUtils::applyOperator3DManifold(children, op));
183184
}
184185
#endif
@@ -964,7 +965,7 @@ std::shared_ptr<const Geometry> GeometryEvaluator::projectionCut(const Projectio
964965
std::shared_ptr<const Geometry> newgeom = applyToChildren3D(node, OpenSCADOperator::UNION).constptr();
965966
if (newgeom) {
966967
#ifdef ENABLE_MANIFOLD
967-
if (Feature::ExperimentalManifold.is_enabled()) {
968+
if (RenderSettings::inst()->backend3D == RenderBackend3D::ManifoldBackend) {
968969
auto manifold = ManifoldUtils::createManifoldFromGeometry(newgeom);
969970
auto poly2d = manifold->slice();
970971
return std::shared_ptr<const Polygon2d>(ClipperUtils::sanitize(poly2d));
@@ -987,7 +988,7 @@ std::shared_ptr<const Geometry> GeometryEvaluator::projectionCut(const Projectio
987988
std::shared_ptr<const Geometry> GeometryEvaluator::projectionNoCut(const ProjectionNode& node)
988989
{
989990
#ifdef ENABLE_MANIFOLD
990-
if (Feature::ExperimentalManifold.is_enabled()) {
991+
if (RenderSettings::inst()->backend3D == RenderBackend3D::ManifoldBackend) {
991992
std::shared_ptr<const Geometry> newgeom = applyToChildren3D(node, OpenSCADOperator::UNION).constptr();
992993
if (newgeom) {
993994
auto manifold = ManifoldUtils::createManifoldFromGeometry(newgeom);

src/geometry/GeometryUtils.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "libtess2/Include/tesselator.h"
1313
#include "utils/printutils.h"
1414
#include "geometry/Reindexer.h"
15+
#include "glview/RenderSettings.h"
1516
#include "Feature.h"
1617
#include "geometry/PolySet.h"
1718

@@ -521,7 +522,7 @@ Transform3d GeometryUtils::getResizeTransform(const BoundingBox &bbox, const Vec
521522
std::shared_ptr<const Geometry> GeometryUtils::getBackendSpecificGeometry(const std::shared_ptr<const Geometry>& geom)
522523
{
523524
#if ENABLE_MANIFOLD
524-
if (Feature::ExperimentalManifold.is_enabled()) {
525+
if (RenderSettings::inst()->backend3D == RenderBackend3D::ManifoldBackend) {
525526
if (const auto ps = std::dynamic_pointer_cast<const PolySet>(geom)) {
526527
return ManifoldUtils::createManifoldFromPolySet(*ps);
527528
} else if (auto mani = std::dynamic_pointer_cast<const ManifoldGeometry>(geom)) {

src/geometry/Polygon2d.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ std::unique_ptr<PolySet> Polygon2d::tessellate() const
177177
{
178178
PRINTDB("Polygon2d::tessellate(): %d outlines", this->outlines().size());
179179
#if defined(ENABLE_MANIFOLD) && defined(USE_MANIFOLD_TRIANGULATOR)
180-
if (Feature::ExperimentalManifold.is_enabled()) {
180+
if (RenderSettings::inst()->backend3D == RenderBackend3D::ManifoldBackend) {
181181
return ManifoldUtils::createTriangulatedPolySetFromPolygon2d(*this);
182182
}
183183
else

src/geometry/boolean_utils.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#endif // ENABLE_MANIFOLD
2525

2626
#include "Feature.h"
27+
#include "glview/RenderSettings.h"
2728
#include "geometry/PolySet.h"
2829
#include "utils/printutils.h"
2930
#include "core/progress.h"
@@ -112,7 +113,7 @@ std::unique_ptr<PolySet> applyHull(const Geometry::Geometries& children)
112113
std::shared_ptr<const Geometry> applyMinkowski(const Geometry::Geometries& children)
113114
{
114115
#if ENABLE_MANIFOLD
115-
if (Feature::ExperimentalManifold.is_enabled()) {
116+
if (RenderSettings::inst()->backend3D == RenderBackend3D::ManifoldBackend) {
116117
return ManifoldUtils::applyMinkowskiManifold(children);
117118
}
118119
#endif // ENABLE_MANIFOLD

src/geometry/linear_extrude.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#include <boost/logic/tribool.hpp>
1010

1111
#include "geometry/GeometryUtils.h"
12+
#include "glview/RenderSettings.h"
1213
#include "core/LinearExtrudeNode.h"
1314
#include "geometry/PolySet.h"
1415
#include "geometry/PolySetBuilder.h"
1516
#include "geometry/PolySetUtils.h"
1617
#include "utils/calc.h"
1718
#include "utils/degree_trig.h"
18-
#include "Feature.h"
1919

2020
namespace {
2121

@@ -510,7 +510,7 @@ std::unique_ptr<Geometry> extrudePolygon(const LinearExtrudeNode& node, const Po
510510
// the polyset from vertices using PolySetBuilder
511511

512512
#ifdef ENABLE_MANIFOLD
513-
if (Feature::ExperimentalManifold.is_enabled()) {
513+
if (RenderSettings::inst()->backend3D == RenderBackend3D::ManifoldBackend) {
514514
return assemblePolySetForManifold(polyref, vertices, indices,
515515
node.convexity, isConvex, slice_stride * num_slices);
516516
}

src/glview/RenderSettings.cc

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
#include "glview/RenderSettings.h"
2+
#include "utils/printutils.h"
23

3-
RenderSettings *RenderSettings::inst(bool erase)
4-
{
4+
std::string renderBackend3DToString(RenderBackend3D backend) {
5+
switch (backend) {
6+
case RenderBackend3D::CGALBackend:
7+
return "CGAL";
8+
case RenderBackend3D::ManifoldBackend:
9+
return "Manifold";
10+
default:
11+
throw std::runtime_error("Unknown rendering backend");
12+
}
13+
}
14+
15+
RenderBackend3D renderBackend3DFromString(std::string backend) {
16+
boost::algorithm::to_lower(backend);
17+
if (backend == "cgal") {
18+
return RenderBackend3D::CGALBackend;
19+
} else if (backend == "manifold") {
20+
return RenderBackend3D::ManifoldBackend;
21+
} else {
22+
if (!backend.empty()) {
23+
LOG(message_group::Warning,
24+
"Unknown rendering backend '%1$s'. Using default '%2$s'.",
25+
backend.c_str(),
26+
renderBackend3DToString(DEFAULT_RENDERING_BACKEND_3D).c_str());
27+
}
28+
return DEFAULT_RENDERING_BACKEND_3D;
29+
}
30+
}
31+
32+
RenderSettings *RenderSettings::inst(bool erase) {
533
static auto instance = new RenderSettings;
634
if (erase) {
735
delete instance;
@@ -10,8 +38,8 @@ RenderSettings *RenderSettings::inst(bool erase)
1038
return instance;
1139
}
1240

13-
RenderSettings::RenderSettings()
14-
{
41+
RenderSettings::RenderSettings() {
42+
backend3D = DEFAULT_RENDERING_BACKEND_3D;
1543
openCSGTermLimit = 100000;
1644
far_gl_clip_limit = 100000.0;
1745
img_width = 512;

0 commit comments

Comments
 (0)