### Configure and Install PkgConfig File Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Generates the manifold.pc file from a template and installs it to the pkgconfig directory. ```cmake if(MANIFOLD_PAR) set(TEMPLATE_OPTIONAL_TBB "tbb") endif() configure_file( cmake/manifold.pc.in ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc @ONLY ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) ``` -------------------------------- ### Install Public Headers Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Defines the list of public headers and installs them to the include directory. ```cmake set( MANIFOLD_PUBLIC_HDRS common.h math.h mesh.h linalg.h manifold.h optional_assert.h polygon.h vec_view.h cross_section.h ) list(TRANSFORM MANIFOLD_PUBLIC_HDRS PREPEND include/manifold/) list( APPEND MANIFOLD_PUBLIC_HDRS ${CMAKE_CURRENT_BINARY_DIR}/include/manifold/version.h ) install( FILES ${MANIFOLD_PUBLIC_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold ) ``` -------------------------------- ### Install Python Bindings Source: https://github.com/elalish/manifold/blob/master/bindings/python/CMakeLists.txt Configures installation paths for the compiled module and generated stub files. ```cmake if(SKBUILD) set(MANIFOLD_PYBIND_LIBDIR ${SKBUILD_PLATLIB_DIR}) else() set(MANIFOLD_PYBIND_LIBDIR ${Python_SITEARCH}) endif() install( TARGETS manifold3d LIBRARY DESTINATION ${MANIFOLD_PYBIND_LIBDIR} COMPONENT bindings ) if(MANIFOLD_PYBIND_STUBGEN) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold3d.pyi DESTINATION ${MANIFOLD_PYBIND_LIBDIR} COMPONENT bindings ) endif() ``` -------------------------------- ### Install Python dependencies and run samples Source: https://github.com/elalish/manifold/blob/master/README.md Install required system packages and Python libraries to run exported samples. ```bash sudo apt install pkg-config libpython3-dev python3 python3-distutils python3-pip pip install trimesh pytest python3 run_all.py -e ``` -------------------------------- ### Configure Include Directories and Installation Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Sets public and private include directories and configures the installation target. ```cmake target_include_directories( manifold PUBLIC $ $ $ PRIVATE ${MANIFOLD_INCLUDE_DIRS} ) exportlib(manifold) install(TARGETS manifold EXPORT manifoldTargets) ``` -------------------------------- ### Install Manifold Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/documents/bindings.md Install the Manifold WASM library using npm. ```bash npm install --save manifold-3d ``` -------------------------------- ### Install WASM dependencies on Linux Source: https://github.com/elalish/manifold/blob/master/README.md Install Node.js and set up the Emscripten SDK on Linux systems. ```bash sudo apt install nodejs git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk install latest ./emsdk activate latest source ./emsdk/emsdk_env.sh ``` -------------------------------- ### Build Documentation with NPM Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/documents/contributing.md Install dependencies and build the TypeDoc documentation for the WASM bindings. The User and Developer docs will be generated in `docs/jsuser` and `docs/jsapi` respectively. ```bash cd bindings/wasm npm install npm run build npm run docs ``` -------------------------------- ### Install WASM dependencies on Mac Source: https://github.com/elalish/manifold/blob/master/README.md Use Homebrew to install Node.js and Emscripten on macOS. ```bash brew install nodejs brew install emscripten ``` -------------------------------- ### HTML Structure for Make Manifold GLTF Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/examples/make-manifold/make-manifold.html Sets up the basic HTML for the Make Manifold GLTF example, including the model-viewer element, download button, and checkbox for viewing manifold GLB. ```html

Drop a GLB here

``` -------------------------------- ### Install Manifold Targets and Config Files Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Exports the manifoldTargets and installs the generated CMake configuration files to the library directory. ```cmake set(EXPORT_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake) install( EXPORT manifoldTargets NAMESPACE manifold:: DESTINATION ${EXPORT_INSTALL_DIR}/manifold ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfig.cmake DESTINATION ${EXPORT_INSTALL_DIR}/manifold ) ``` -------------------------------- ### Configure RPath settings Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Sets up RPath for the build and installation process, ensuring correct library linking. ```cmake set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) list( FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} isSystemDir ) if("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) endif("${isSystemDir}" STREQUAL "-1") ``` -------------------------------- ### Run Development Server Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/examples/editor/README.md Starts a local development server that serves the editor pages and automatically rebuilds and refreshes on file changes. This command is useful for active development. ```bash npm run dev ``` -------------------------------- ### JavaScript for Make Manifold GLTF Example Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/examples/make-manifold/make-manifold.html Handles loading GLB files, processing them with the Manifold library, and enabling download functionality. It also manages the 'View Manifold GLB' checkbox. ```javascript import { ModelViewerElement } from '@google/model-viewer'; const viewer = document.getElementById('viewer'); const downloadButton = document.getElementById('download-button'); const viewManifoldGlbCheckbox = document.getElementById('view-manifold-glb'); const glbFile = document.getElementById('glb-file'); let manifold = null; let originalSrc = null; async function loadModel(src) { originalSrc = src; viewer.src = src; await viewer.componentReady(); const glTF = viewer.scene.getAsset('default'); if (!glTF) { console.error('No glTF asset found in the model.'); return; } const buffer = await fetch(src).then(res => res.arrayBuffer()); manifold = await Manifold.fromUSDZ(buffer); downloadButton.disabled = false; } glbFile.addEventListener('change', (event) => { const file = event.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = (e) => { const arrayBuffer = e.target.result; const blob = new Blob([arrayBuffer], { type: 'model/gltf-binary' }); const url = URL.createObjectURL(blob); loadModel(url); }; reader.readAsArrayBuffer(file); } }); downloadButton.addEventListener('click', async () => { if (!manifold || !originalSrc) { return; } const glTF = viewer.scene.getAsset('default'); if (!glTF) { console.error('No glTF asset found in the model.'); return; } const buffer = await Manifold.toGLTF(manifold); const blob = new Blob([buffer], { type: 'model/gltf-binary' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'manifold.glb'; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }); viewManifoldGlbCheckbox.addEventListener('change', async (event) => { if (!originalSrc) { return; } if (event.target.checked) { const buffer = await fetch(originalSrc).then(res => res.arrayBuffer()); const manifoldGlb = await Manifold.toGLTF(buffer, { viewManifold: true }); const blob = new Blob([manifoldGlb], { type: 'model/gltf-binary' }); const url = URL.createObjectURL(blob); viewer.src = url; } else { viewer.src = originalSrc; } }); // Example usage with a default model loadModel('https://modelviewer.dev/shared-assets/models/Astronaut.glb'); ``` -------------------------------- ### Build WASM in Debug Mode Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/documents/contributing.md Build the WASM project in debug mode for direct debugging in Chrome DevTools. Ensure the DWARF Chrome extension is installed. ```bash emcmake cmake -DCMAKE_BUILD_TYPE=Debug .. && emmake make ``` -------------------------------- ### Initialize Manifold WASM Module Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/documents/bindings.md Import and initialize the Manifold WASM module in your JavaScript project. This setup is required before using Manifold objects. ```javascript import Module from 'manifold-3d'; const wasm = await Module(); wasm.setup(); const { Manifold } = wasm; ``` -------------------------------- ### Basic Manifold Geometric Operation Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/documents/bindings.md Perform a geometric operation (subtract) using Manifold objects. This example demonstrates creating a cube and a sphere, then subtracting the sphere from the cube. ```javascript const {cube, sphere} = Manifold; const box = cube([100, 100, 100], true); const ball = sphere(60, 100); const result = box.subtract(ball); ``` -------------------------------- ### Configure NixOS Include Directories Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Sets standard include directories for NixOS environments. ```cmake set( CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES} ) endif() ``` -------------------------------- ### Build Project Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/examples/editor/README.md Builds the project for production. This command performs a full build and TS type-checking, ensuring the project is ready for deployment. ```bash npm run build ``` -------------------------------- ### Add project subdirectories Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Adds source, bindings, and optional test/sample directories to the build. ```cmake add_subdirectory(src) add_subdirectory(bindings) if(MANIFOLD_TEST) add_subdirectory(samples) add_subdirectory(test) add_subdirectory(extras) endif() ``` -------------------------------- ### Configure Development and Profiling Options Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Enables optional development features like Tracy profiling, fuzzing, and ASSIMP support, marking them as advanced in the CMake cache. ```cmake option(TRACY_ENABLE "Use tracy profiling" OFF) option(TRACY_MEMORY_USAGE "Track memory allocation with tracy (expensive)" OFF) option(MANIFOLD_FUZZ "Enable fuzzing tests" OFF) option(ASSIMP_ENABLE "Enable ASSIMP for utilities in extras" OFF) mark_as_advanced(TRACY_ENABLE) mark_as_advanced(TRACY_MEMORY_USAGE) mark_as_advanced(MANIFOLD_FUZZ) mark_as_advanced(ASSIMP_ENABLE) ``` -------------------------------- ### Build and Test Manifold Source: https://github.com/elalish/manifold/blob/master/README.md Standard commands to clone, configure, build, and test the library on Linux-based systems. ```bash git clone --recurse-submodules https://github.com/elalish/manifold.git cd manifold mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. && make make test ``` -------------------------------- ### Verify Python Docs Source: https://github.com/elalish/manifold/blob/master/bindings/python/README.md Run these commands from the Manifold repo root to verify that Python documentation is correct after changes. ```bash pip install . python -c 'import manifold3d; help(manifold3d)' ``` -------------------------------- ### Access Python binding documentation Source: https://github.com/elalish/manifold/blob/master/README.md Use the Python interpreter to display help documentation for the manifold3d module. ```python >>> import manifold3d >>> help(manifold3d) ``` -------------------------------- ### Build and test WASM library Source: https://github.com/elalish/manifold/blob/master/README.md Compile the WASM library using Emscripten and run the test suite. ```bash cd manifold mkdir buildWASM cd buildWASM emcmake cmake -DCMAKE_BUILD_TYPE=MinSizeRel .. && emmake make cd test node ./manifold_test.js ``` -------------------------------- ### Generate Bundle Analysis Report (Linux/macOS) Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/examples/editor/README.md Generates a bundle analysis report on Linux or macOS. This command sets an environment variable to include the analyzer in the build process. ```bash ANALYZE=1 npm run build ``` -------------------------------- ### Add Executable for File Conversion Source: https://github.com/elalish/manifold/blob/master/extras/CMakeLists.txt Creates an executable for file conversion, dependent on the 'meshIO' library. It applies specified compile options. ```cmake add_executable(convertFile convert_file.cpp) target_link_libraries(convertFile meshIO) target_compile_options(convertFile PRIVATE ${MANIFOLD_FLAGS}) exportbin(convertFile) ``` -------------------------------- ### Configure version header Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Generates the version header file and marks it as a generated source file. ```cmake include(${PROJECT_SOURCE_DIR}/cmake/info.cmake) # note that the path ${CMAKE_CURRENT_BINARY_DIR}/include is included when we # build the manifold target (as ${PROJECT_SOURCE_DIR}/include), so users can # include manifold/version.h without installing our library. configure_file( cmake/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/manifold/version.h @ONLY ) set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/include/manifold/version.h PROPERTIES GENERATED TRUE ) ``` -------------------------------- ### Generate Stubs with Nanobind Source: https://github.com/elalish/manifold/blob/master/bindings/python/README.md Use nanobind to generate stub files for Python, which include function signatures and docstrings. This can help in verifying documentation accuracy. ```bash pip install -m nanobind python -m nanobind.stubgen -m manifold3d -o manifold3d.pyi -i=. -p=bindings/python/stub_pattern.txt ``` -------------------------------- ### Configure CMake for Windows Source: https://github.com/elalish/manifold/blob/master/README.md Build command for Windows using MSVC with shared libraries disabled. ```bash cmake . -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DMANIFOLD_DEBUG=ON -DMANIFOLD_PAR=${{matrix.parallel_backend}} -A x64 -B build ``` -------------------------------- ### Configure Manifold Samples Library Source: https://github.com/elalish/manifold/blob/master/samples/CMakeLists.txt Defines the samples library, links dependencies, and sets include directories and compiler flags. ```cmake # Copyright 2020 The Manifold Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. if(NOT MANIFOLD_TEST) return() endif() add_library( samples src/menger_sponge.cpp src/rounded_frame.cpp src/scallop.cpp src/tet_puzzle.cpp src/gyroid_module.cpp src/condensed_matter.cpp ) target_sources(samples PUBLIC src/bracelet.cpp src/knot.cpp) target_include_directories(samples PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(samples PUBLIC manifold) target_compile_options(samples PRIVATE ${MANIFOLD_FLAGS}) exportlib(samples) ``` -------------------------------- ### Reproduce Sanitizer CI Tests Source: https://github.com/elalish/manifold/blob/master/README.md Commands to run the sanitizer test suite locally using the project's CI scripts. ```bash bash ./scripts/ci/sanitizer_build.sh source ./scripts/sanitizer_cases.sh ASAN_OPTIONS=detect_container_overflow=0:strict_init_order=1 \ UBSAN_OPTIONS=print_stacktrace=1 \ ./build/test/manifold_test --gtest_filter="${SANITIZER_GTEST_FILTER_CORE}" ``` -------------------------------- ### Add Executable for Parallel Benchmarking Source: https://github.com/elalish/manifold/blob/master/extras/CMakeLists.txt Configures an executable for parallel benchmarking, conditionally enabled when Assimp and parallel processing are active. It links against the 'meshIO' library and TBB, with specific compile options for parallelism. ```cmake add_executable(man_bench ember_tests/man_bench.cpp) target_link_libraries(man_bench PRIVATE meshIO TBB::tbb) target_compile_options( man_bench PRIVATE ${MANIFOLD_FLAGS} -DCONTROL_PARALLELISM ) ``` -------------------------------- ### Configure Emscripten Link Options Source: https://github.com/elalish/manifold/blob/master/test/CMakeLists.txt Applies specific link options for Emscripten builds, including file preloading for models and polygons. ```cmake if(EMSCRIPTEN) target_link_options( manifold_test PRIVATE -sASSERTIONS=1 --bind # https://cmake.org/cmake/help/latest/command/target_link_options.html#option-de-duplication "SHELL:--preload-file ${CMAKE_CURRENT_SOURCE_DIR}/models@/models" "SHELL:--preload-file ${CMAKE_CURRENT_SOURCE_DIR}/polygons@/polygons" ) endif() ``` -------------------------------- ### Set Built-in Dependency Options Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Configures whether to use built-in versions of TBB and nanobind instead of system-provided ones. ```cmake option(MANIFOLD_USE_BUILTIN_TBB "Use builtin tbb" OFF) option(MANIFOLD_USE_BUILTIN_NANOBIND "Use builtin nanobind" OFF) ``` -------------------------------- ### ManifoldCAD Command Line Usage Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/documents/using-manifoldcad.md This is the basic usage string for the ManifoldCAD command-line interface. It specifies the input JavaScript file and the output file name. ```bash Usage: manifold-cad [options] ``` -------------------------------- ### Generate Docstrings Source: https://github.com/elalish/manifold/blob/master/bindings/python/CMakeLists.txt Defines dependencies and a custom command to generate docstrings for the Python bindings. ```cmake set( DOCSTRING_DEPS ${PROJECT_SOURCE_DIR}/src/manifold.cpp ${PROJECT_SOURCE_DIR}/src/constructors.cpp ${PROJECT_SOURCE_DIR}/src/sort.cpp ${PROJECT_SOURCE_DIR}/src/cross_section.cpp ${PROJECT_SOURCE_DIR}/src/polygon.cpp ${PROJECT_SOURCE_DIR}/include/manifold/common.h ${CMAKE_CURRENT_SOURCE_DIR}/gen_docs.py ${CMAKE_CURRENT_SOURCE_DIR}/docstring_override.txt ) add_custom_command( OUTPUT autogen_docstrings.inl DEPENDS ${DOCSTRING_DEPS} COMMAND ${Python_EXECUTABLE} ARGS ${CMAKE_CURRENT_SOURCE_DIR}/gen_docs.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) target_include_directories(manifold3d PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) ``` -------------------------------- ### Define Build Defaults Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Sets default build type, library linkage, and compiler flags. ```cmake option(CMAKE_BUILD_TYPE "Build type" Release) option(BUILD_SHARED_LIBS "Build shared library" ON) set(MANIFOLD_FLAGS "" CACHE STRING "Manifold compiler flags") ``` -------------------------------- ### Define Manifold Source and Header Files Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Lists the source files and private headers used to build the manifold library. ```cmake set( MANIFOLD_SRCS boolean2.cpp boolean2_diagnostics.cpp boolean2_offset.cpp boolean2_predicates.cpp boolean2_sweep.cpp boolean3.cpp boolean_result.cpp constructors.cpp cross_section.cpp csg_tree.cpp edge_op.cpp execution_impl.cpp face_op.cpp impl.cpp manifold.cpp minkowski.cpp polygon.cpp properties.cpp quickhull.cpp sdf.cpp smoothing.cpp sort.cpp subdivision.cpp tree2d.cpp ) set( MANIFOLD_PRIVATE_HDRS boolean2.h boolean2_diagnostics.h boolean3.h collider.h csg_tree.h execution_impl.h hashtable.h impl.h iters.h mesh_fixes.h parallel.h polygon_internal.h quickhull.h shared.h svd.h tree2d.h tri_dist.h utils.h vec.h ) ``` -------------------------------- ### Generate Bundle Analysis Report (Windows) Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/examples/editor/README.md Generates a bundle analysis report on Windows PowerShell. This command sets an environment variable to include the analyzer in the build process. ```powershell $env:ANALYZE=1; npm run build ``` -------------------------------- ### Add Executable for Performance Phase Testing Source: https://github.com/elalish/manifold/blob/master/extras/CMakeLists.txt Adds an executable for performance phase testing, conditionally enabled for debug or timing builds. It links against 'manifold' and 'samples' libraries and includes a specific sample include directory. ```cmake add_executable(perfPhases perf_phases.cpp) target_link_libraries(perfPhases manifold samples) target_include_directories( perfPhases PRIVATE ${PROJECT_SOURCE_DIR}/samples/include ) target_compile_options(perfPhases PRIVATE ${MANIFOLD_FLAGS}) exportbin(perfPhases) ``` -------------------------------- ### Configure Emscripten Build Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Sets specific memory, threading, and exception handling flags for Emscripten targets. ```cmake if(EMSCRIPTEN) message("Building for Emscripten") add_link_options(-sALLOW_MEMORY_GROWTH=1) add_link_options(-sMAXIMUM_MEMORY=4294967296) if(MANIFOLD_PAR) set(CMAKE_THREAD_LIBS_INIT "-pthread") add_compile_options(-pthread) # mimalloc is needed for good performance add_link_options(-sMALLOC=mimalloc) add_link_options(-sPTHREAD_POOL_SIZE=4) # The default stack size apparently causes problem when parallelization is # enabled. add_link_options(-sSTACK_SIZE=30MB) add_link_options(-sINITIAL_MEMORY=32MB) endif() if(MANIFOLD_DEBUG) list(APPEND MANIFOLD_FLAGS -fexceptions) add_link_options(-fexceptions) add_link_options(-sDISABLE_EXCEPTION_CATCHING=0) endif() set(MANIFOLD_PYBIND OFF) set(BUILD_SHARED_LIBS OFF) endif() ``` -------------------------------- ### Import ModelViewerElement Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/examples/model-viewer/model-viewer.html Import the ModelViewerElement class from the @google/model-viewer package. ```typescript import { ModelViewerElement } from '@google/model-viewer'; ``` -------------------------------- ### Add Library for Mesh I/O Source: https://github.com/elalish/manifold/blob/master/extras/CMakeLists.txt Defines a library for mesh input/output operations, conditionally enabled if Assimp is enabled. It links against 'manifold' and Assimp libraries. ```cmake add_library(meshIO meshIO.cpp) target_link_libraries(meshIO PUBLIC manifold assimp::assimp) target_compile_options(meshIO PRIVATE ${MANIFOLD_FLAGS}) ``` -------------------------------- ### Set Source File Properties Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/CMakeLists.txt Specifies that 'bindings.cpp' depends on 'bindings.js', ensuring the JavaScript file is considered during the build process. ```cmake set_source_files_properties( bindings.cpp PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js ) ``` -------------------------------- ### Build and run CrossSection regression tests Source: https://github.com/elalish/manifold/blob/master/docs/Boolean2.md Use these commands to compile the project with tests enabled and execute the CrossSection-specific test suite. ```sh cmake -S . -B build -DMANIFOLD_TEST=ON cmake --build build -j4 --target manifold_test ctest --test-dir build -R '^CrossSection\.' --output-on-failure ``` -------------------------------- ### Include project modules Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Includes external CMake modules for dependencies and configuration helpers. ```cmake include(${PROJECT_SOURCE_DIR}/cmake/manifoldDeps.cmake) include(${PROJECT_SOURCE_DIR}/cmake/configHelper.cmake) ``` -------------------------------- ### Optimize Repeated Transformations with Caching Source: https://github.com/elalish/manifold/wiki/Performance-Considerations Shows how to optimize repeated transformations by caching the base shape and applying transformations to the cached result. This is faster than re-evaluating the base shape each time. ```javascript const { cylinder, sphere, union } = Manifold function foo(deg) { const r = 5 return sphere(1, 128).translate([r*Math.sin(deg / 180 * Math.PI), -r*Math.cos(deg/180*Math.PI), 0]) .add(sphere(1, 128).translate([-r*Math.sin(deg / 180 * Math.PI), r*Math.cos(deg/180*Math.PI), 0])) .add(cylinder(2*r, 0.2, 0.2, 128, true).rotate([90, 0, deg])) } const foo_cached = foo(0) function foo_faster(deg) { return foo_cached.rotate([0, 0, deg]) } let results = [] for (let i = 0; i < 180; i += 30) results.push(foo_faster(i)) // foo_faster will be faster than foo const result = union(results) ``` -------------------------------- ### Export CMake package configuration Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Generates configuration and version files for CMake package exports. ```cmake configure_file( cmake/manifoldConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake @ONLY ) include(CMakePackageConfigHelpers) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfigVersion.cmake VERSION ${MANIFOLD_VERSION} COMPATIBILITY SameMajorVersion ) ``` -------------------------------- ### Post-Build Command for Copying Artifacts Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/CMakeLists.txt Adds a post-build command to the 'js_deps' target that copies the compiled WASM build artifacts from the binary directory to the source directory for publishing. ```cmake add_custom_command( TARGET js_deps POST_BUILD # copy WASM build back here for publishing to npm COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/manifold.* ${CMAKE_CURRENT_SOURCE_DIR} ) ``` -------------------------------- ### Add Executable for Large Scene Testing Source: https://github.com/elalish/manifold/blob/master/extras/CMakeLists.txt Configures an executable for testing with large scenes. It links against the 'manifold' library and applies specified compile options. ```cmake add_executable(largeSceneTest large_scene_test.cpp) target_link_libraries(largeSceneTest manifold) target_compile_options(largeSceneTest PRIVATE ${MANIFOLD_FLAGS}) exportbin(largeSceneTest) ``` -------------------------------- ### Define Python Module with nanobind Source: https://github.com/elalish/manifold/blob/master/bindings/python/CMakeLists.txt Registers the manifold3d module using nanobind with static linking and LTO enabled. ```cmake nanobind_add_module(manifold3d NB_STATIC STABLE_ABI LTO autogen_docstrings.inl manifold3d.cpp ) ``` -------------------------------- ### Configure Target Properties Source: https://github.com/elalish/manifold/blob/master/bindings/python/CMakeLists.txt Links the manifold library and sets compilation options for the Python module. ```cmake target_link_libraries(manifold3d PRIVATE manifold) target_compile_options( manifold3d PRIVATE ${MANIFOLD_FLAGS} -DMODULE_NAME=manifold3d ) set_target_properties(manifold3d PROPERTIES OUTPUT_NAME "manifold3d") ``` -------------------------------- ### Add Executable for Performance Testing Source: https://github.com/elalish/manifold/blob/master/extras/CMakeLists.txt Defines an executable for performance testing. It links against the 'manifold' library and applies specific compile options. ```cmake add_executable(perfTest perf_test.cpp) target_link_libraries(perfTest manifold) target_compile_options(perfTest PRIVATE ${MANIFOLD_FLAGS}) exportbin(perfTest) ``` -------------------------------- ### Add Executable for Minimizing Test Cases Source: https://github.com/elalish/manifold/blob/master/extras/CMakeLists.txt Creates an executable for minimizing test cases, conditionally enabled for debug builds. It links against 'manifold' and optionally TBB if parallel compilation is enabled. ```cmake add_executable(minimizeTestcase minimize_testcase.cpp) target_link_libraries( minimizeTestcase manifold $<$:TBB::tbb> ) target_compile_options(minimizeTestcase PRIVATE ${MANIFOLD_FLAGS}) exportbin(minimizeTestcase) ``` -------------------------------- ### Configure Manifold Test Executable Source: https://github.com/elalish/manifold/blob/master/test/CMakeLists.txt Defines the test executable and links required libraries including GTest and optional components like TBB or C-bindings. ```cmake if(NOT MANIFOLD_TEST) return() endif() enable_testing() # put fast/simple tests files first to run earlier set( SOURCE_FILES test_main.cpp polygon_test.cpp properties_test.cpp manifold_test.cpp context_test.cpp measurement_test.cpp boolean_test.cpp sdf_test.cpp smooth_test.cpp hull_test.cpp samples_test.cpp boolean_complex_test.cpp boolean2_test.cpp cross_section_test.cpp cross_section_offset_corpus_test.cpp $<$:manifoldc_test.cpp> ) add_executable(manifold_test ${SOURCE_FILES}) target_link_libraries( manifold_test PRIVATE GTest::gtest_main manifold samples $<$:manifoldc> $<$:TBB::tbb> ) ``` -------------------------------- ### Add Executable for F3D Skeleton Source: https://github.com/elalish/manifold/blob/master/extras/CMakeLists.txt Defines a no-operation executable ('f3dNoop') for build confirmation purposes, linking against the 'meshIO' library. It applies specified compile options. ```cmake add_executable(f3dNoop f3d_skeleton.cpp) target_link_libraries(f3dNoop meshIO) target_compile_options(f3dNoop PRIVATE ${MANIFOLD_FLAGS}) ``` -------------------------------- ### Configure Fuzzing Flags Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Sets debug and fuzzing modes and applies address sanitizer options when MANIFOLD_FUZZ is enabled. ```cmake if(MANIFOLD_FUZZ) # we should enable debug checks set(MANIFOLD_DEBUG ON) # enable fuzztest fuzzing mode set(FUZZTEST_FUZZING_MODE ON) # address sanitizer required add_compile_options(-fsanitize=address) add_link_options(-fsanitize=address) endif() ``` -------------------------------- ### Run API Extractor Manually Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/documents/contributing.md Manually run the API Extractor tool, which consolidates documentation files. This is typically run automatically before each build as an npm lifecycle hook. ```bash npm run prebuild ``` -------------------------------- ### Measure CSG Operation and Mesh Evaluation Time Source: https://github.com/elalish/manifold/wiki/Performance-Considerations Demonstrates how to measure the time taken for a CSG operation (union) and the subsequent mesh evaluation. CSG operations are instantaneous, but GetMesh triggers evaluation. ```javascript const { sphere, union } = Manifold const a = sphere(10, 128) const b = sphere(10, 128).translate([10, 0, 0]) const start = performance.now() const result = a.add(b) const endAdd = performance.now() result.getMesh() const end = performance.now() console.log(endAdd - start) // 0 console.log(end - endAdd) // 14 ``` -------------------------------- ### Link Libraries and Options Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/CMakeLists.txt Links the 'manifoldjs' target with the 'manifold' library and optionally TBB if MANIFOLD_PAR is enabled. It also applies specific compile and link options for WASM. ```cmake target_link_libraries( manifoldjs PRIVATE manifold $<$:TBB::tbb> ) target_compile_options(manifoldjs PRIVATE ${MANIFOLD_FLAGS}) target_link_options( manifoldjs PUBLIC --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js --bind -sALLOW_TABLE_GROWTH=1 -sEXPORTED_RUNTIME_METHODS=addFunction,removeFunction -sMODULARIZE=1 -sEXPORT_ES6=1 ) ``` -------------------------------- ### Register Tests and Fuzzing Targets Source: https://github.com/elalish/manifold/blob/master/test/CMakeLists.txt Registers the test executable with the test runner and optionally configures fuzzing executables if enabled. ```cmake target_compile_options(manifold_test PRIVATE ${MANIFOLD_FLAGS}) exportbin(manifold_test) if(WIN32) # If you want to fix the DLL availability at build time, be my guest. add_test(NAME manifold_test COMMAND manifold_test) else() # *nix users get the tests individually broken out! gtest_discover_tests(manifold_test) endif() if(MANIFOLD_FUZZ) fuzztest_setup_fuzzing_flags() add_executable(polygon_fuzz polygon_fuzz.cpp) target_link_libraries(polygon_fuzz PUBLIC manifold) link_fuzztest(polygon_fuzz) gtest_discover_tests(polygon_fuzz) add_executable(manifold_fuzz manifold_fuzz.cpp) target_link_libraries(manifold_fuzz PUBLIC manifold) link_fuzztest(manifold_fuzz) gtest_discover_tests(manifold_fuzz) endif() ``` -------------------------------- ### Set Compilation Definitions Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Iterates through options to set public compilation definitions for the manifold library. ```cmake set( OPTIONS MANIFOLD_DEBUG MANIFOLD_ASSERT MANIFOLD_TIMING MANIFOLD_NO_IOSTREAM TRACY_ENABLE TRACY_MEMORY_USAGE ) foreach(OPT IN LISTS OPTIONS) if(${${OPT}}) target_compile_definitions(manifold PUBLIC ${OPT}) endif() endforeach() if(MANIFOLD_PAR) target_compile_definitions(manifold PUBLIC MANIFOLD_PAR=1) else() target_compile_definitions(manifold PUBLIC MANIFOLD_PAR=-1) endif() if(MANIFOLD_NO_IOSTREAM) target_compile_definitions(manifold PUBLIC MANIFOLD_NO_FILESYSTEM) endif() ``` -------------------------------- ### Configure Compiler Flags Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Applies platform-specific compiler flags for MSVC and other compilers, including warning management and optimization settings. ```cmake if(MSVC) list(APPEND MANIFOLD_FLAGS /DNOMINMAX /bigobj /fp:precise) if(MANIFOLD_STRICT) list(APPEND MANIFOLD_FLAGS /WX) endif() else() list( APPEND WARNING_FLAGS -Wall -Wno-unknown-warning-option -Wno-unused -Wno-shorten-64-to-32 -Wno-sign-compare -Wno-alloc-size-larger-than ) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") list(APPEND WARNING_FLAGS -Wno-format) endif() elseif(PROJECT_IS_TOP_LEVEL) # only do -Werror if we are the top level project and # MANIFOLD_STRICT is on if(MANIFOLD_STRICT) list(APPEND WARNING_FLAGS -Werror) endif() endif() list(APPEND MANIFOLD_FLAGS ${WARNING_FLAGS}) if( MANIFOLD_OPTIMIZED OR "${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo" ) list(APPEND MANIFOLD_FLAGS -O3) endif() if("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") list(APPEND MANIFOLD_FLAGS -fno-omit-frame-pointer) endif() # disable fp math optimizations, e.g. FMA for supported architectures, as # this changes floating-point results include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-ffp-contract=off HAS_FP_CONTRACT) check_cxx_compiler_flag(-fexcess-precision=standard HAS_FP_PRECISION) if(HAS_FP_CONTRACT) list(APPEND MANIFOLD_FLAGS -ffp-contract=off) endif() if(HAS_FP_PRECISION) list(APPEND MANIFOLD_FLAGS -fexcess-precision=standard) endif() if(CODE_COVERAGE) list( APPEND MANIFOLD_FLAGS -coverage -fno-inline-small-functions -fkeep-inline-functions -fkeep-static-functions ) add_link_options(-coverage) endif() endif() ``` -------------------------------- ### Set Build Type for Tracy Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Forces a specific build type when Tracy profiling is enabled. ```cmake if(TRACY_ENABLE) option(CMAKE_BUILD_TYPE "Build type" RelWithDebInfo) endif() ``` -------------------------------- ### Define Executable Target Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/CMakeLists.txt Defines the main executable target for the WASM build, named 'manifoldjs', using 'bindings.cpp' as the source file. ```cmake add_executable(manifoldjs bindings.cpp) ``` -------------------------------- ### Configure Emscripten JS Binding Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Enables the JavaScript binding option specifically for Emscripten builds. ```cmake cmake_dependent_option( MANIFOLD_JSBIND "Build js binding" ON "EMSCRIPTEN" OFF ) ``` -------------------------------- ### Add Executable for STL Testing Source: https://github.com/elalish/manifold/blob/master/extras/CMakeLists.txt Defines an executable for Standard Template Library (STL) testing, conditionally enabled for parallel builds on non-MSVC platforms. It links against 'manifold' and TBB. ```cmake add_executable(stlTest stl_test.cpp) target_link_libraries(stlTest PRIVATE manifold TBB::tbb) target_compile_options(stlTest PRIVATE ${MANIFOLD_FLAGS}) ``` -------------------------------- ### Set Output Name Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/CMakeLists.txt Sets the output name of the 'manifoldjs' target to 'manifold'. ```cmake set_target_properties(manifoldjs PROPERTIES OUTPUT_NAME "manifold") ``` -------------------------------- ### Generate Python Stubs Source: https://github.com/elalish/manifold/blob/master/bindings/python/CMakeLists.txt Conditionally generates type stubs for the Python module and runs a post-build script to process them. ```cmake if(MANIFOLD_PYBIND_STUBGEN) nanobind_add_stub( manifold3d_stub MODULE manifold3d OUTPUT manifold3d.pyi PYTHON_PATH $ DEPENDS manifold3d PATTERN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/stub_pattern.txt ) add_custom_command( TARGET manifold3d_stub POST_BUILD COMMAND "${Python_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/bindings/python/stub_postbuild.py" "${CMAKE_CURRENT_BINARY_DIR}/manifold3d.pyi" VERBATIM ) endif() ``` -------------------------------- ### Export Compile Commands Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Conditional check for exporting compile commands when not targeting Emscripten. ```cmake if(CMAKE_EXPORT_COMPILE_COMMANDS AND NOT EMSCRIPTEN) ``` -------------------------------- ### manifold__smooth__mesh_gl__sharpened_edges Source: https://github.com/elalish/manifold/blob/master/bindings/python/docstring_override.txt Constructs a smooth version of the input mesh by creating tangents, with options to control edge smoothness. ```APIDOC ## manifold__smooth__mesh_gl__sharpened_edges ### Description Constructs a smooth version of the input mesh by creating tangents; this method will throw if you have supplied tangents with your mesh already. The actual triangle resolution is unchanged; use the Refine() method to interpolate to a higher-resolution curve. By default, every edge is calculated for maximum smoothness (very much approximately), attempting to minimize the maximum mean Curvature magnitude. No higher-order derivatives are considered, as the interpolation is independent per triangle, only sharing constraints on their boundaries. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **mesh** (Mesh) - input Mesh. * **sharpened_edges** (vector of halfedge indices) - If desired, you can supply a vector of sharpened halfedges, which should in general be a small subset of all halfedges. Order of entries doesn't matter, as each one specifies the desired smoothness (between zero and one, with one the default for all unspecified halfedges) and the halfedge index (3 * triangle index + [0,1,2] where 0 is the edge between triVert 0 and 1, etc). * **edge_smoothness** (vector of floats) - Smoothness values associated to each halfedge defined in sharpened_edges. At a smoothness value of zero, a sharp crease is made. The smoothness is interpolated along each edge, so the specified value should be thought of as an average. Where exactly two sharpened edges meet at a vertex, their tangents are rotated to be colinear so that the sharpened edge can be continuous. Vertices with only one sharpened edge are completely smooth, allowing sharpened edges to smoothly vanish at termination. A single vertex can be sharpened by sharping all edges that are incident on it, allowing cones to be formed. ``` -------------------------------- ### Configure Manifold Library Target Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Defines the manifold library target, links dependencies, and sets compilation features. ```cmake add_library(manifold ${MANIFOLD_SRCS} ${MANIFOLD_PRIVATE_HDRS}) target_link_libraries(manifold PUBLIC $<$:TracyClient>) target_link_libraries( manifold PRIVATE # optional dependencies $<$:TBB::tbb> ) target_compile_options(manifold PRIVATE ${MANIFOLD_FLAGS}) # make sure users use appropriate c++ standard when including our headers target_compile_features(manifold PUBLIC cxx_std_17) ```