### Install Manifold Python Bindings and Dependencies Source: https://github.com/elalish/manifold/blob/master/README.md Installs necessary system packages, Python libraries, and runs example scripts for the Manifold Python binding. Ensure you have the build directory set up correctly. ```bash sudo apt install pkg-config libpython3-dev python3 python3-distutils python3-pip pip install trimesh pytest python3 run_all.py -e ``` -------------------------------- ### Install emscripten on Linux Source: https://github.com/elalish/manifold/blob/master/README.md Instructions for installing the emscripten SDK on a Linux system, including downloading, installing, and activating the latest SDK. ```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 ``` -------------------------------- ### 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 ``` -------------------------------- ### 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 emscripten on Mac Source: https://github.com/elalish/manifold/blob/master/README.md Instructions for installing Node.js and emscripten on a macOS system using Homebrew. ```bash brew install nodejs brew install emscripten ``` -------------------------------- ### Install Manifold Configuration Files Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Installs the manifoldConfigVersion.cmake and manifoldConfig.cmake files to the CMake export directory. These files are essential for CMake to find and configure the installed manifold package. ```cmake install( FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake DESTINATION ${EXPORT_INSTALL_DIR}/manifold ) ``` -------------------------------- ### 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

``` -------------------------------- ### 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'); ``` -------------------------------- ### Setup Fuzzing for Polygon Source: https://github.com/elalish/manifold/blob/master/test/CMakeLists.txt Configures fuzzing for the polygon functionality, creating a fuzzing executable and linking necessary libraries. ```cmake 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() ``` -------------------------------- ### Configure Install RPath Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Sets the RPath for installed libraries to ensure they can be found at runtime, especially when not using the system's default library paths. ```cmake # RPath settings 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") ``` -------------------------------- ### Generate PkgConfig File Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Configures and installs the manifold.pc file, which is used by pkg-config to provide information about the installed manifold library. Conditional variables are set based on build options like MANIFOLD_PAR and MANIFOLD_CROSS_SECTION. ```cmake if(MANIFOLD_PAR) set(TEMPLATE_OPTIONAL_TBB "tbb") endif() if(MANIFOLD_CROSS_SECTION AND MANIFOLD_CROSS_SECTION_BACKEND STREQUAL "clipper2") set(TEMPLATE_OPTIONAL_CLIPPER "Clipper2") 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 ) ``` -------------------------------- ### Integrating with Assimp for Mesh I/O Source: https://github.com/elalish/manifold/blob/master/README.md An example demonstrating integration with the Assimp library for mesh input/output operations. This C++ code is part of the Manifold project's extras. ```cpp Example for integrating with [Assimp](https://github.com/assimp/assimp) is in `extras/meshIO.cpp`, which is used by files such as `extras/convert_file.cpp`. ``` -------------------------------- ### Define and Install Public Headers Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Defines a list of public header files for the manifold library, including conditional headers based on build options. These headers are then installed to the appropriate 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 Manifold Targets Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Installs the manifoldTargets export set with a 'manifold::' namespace to the specified CMake export directory. This allows other CMake projects to find and use the installed targets. ```cmake set(EXPORT_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake) install( EXPORT manifoldTargets NAMESPACE manifold:: DESTINATION ${EXPORT_INSTALL_DIR}/manifold ) ``` -------------------------------- ### Generate Version Header File Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Configures and generates the version header file for the project, allowing users to include version information directly without installing the library. ```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 ) ``` -------------------------------- ### 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 ``` -------------------------------- ### Set Manifold Include Directories (Public/Private) Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Configures public and private include directories for the manifold target, including install and build interfaces. ```cmake target_include_directories( manifold PUBLIC $ $ $ PRIVATE ${MANIFOLD_INCLUDE_DIRS} ) ``` -------------------------------- ### 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; ``` -------------------------------- ### Export Manifold Library Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Exports the manifold library for use by other targets and installs it with its targets. ```cmake exportlib(manifold) install(TARGETS manifold EXPORT manifoldTargets) ``` -------------------------------- ### 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); ``` -------------------------------- ### 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 ``` -------------------------------- ### Build and Test Manifold (Ubuntu) Source: https://github.com/elalish/manifold/blob/master/README.md Standard procedure to clone the repository, create a build directory, configure with CMake, compile, and run tests on Ubuntu-like 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 ``` -------------------------------- ### Configure C++ Standard Include Directories Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Sets the C++ standard include directories for NixOS builds when CMAKE_EXPORT_COMPILE_COMMANDS is enabled and Emscripten is not used. ```cmake if(CMAKE_EXPORT_COMPILE_COMMANDS AND NOT EMSCRIPTEN) # for nixos set( CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES} ) endif() ``` -------------------------------- ### Initialize ManifoldCAD WASM Application Source: https://github.com/elalish/manifold/blob/master/bindings/wasm/examples/editor/index.html Sets up the ManifoldCAD WebApplication schema for search engines. Initializes the ModelViewerElement and sets its model cache size to 0. ```javascript { "@context": "https://schema.org", "@type": "WebApplication", "name": "ManifoldCAD", "applicationCategory": "DesignApplication", "offers": { "@type": "Offer", "price": "0" } } self.ModelViewerElement = self.ModelViewerElement || {}; self.ModelViewerElement.modelCacheSize = 0; ``` -------------------------------- ### 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)' ``` -------------------------------- ### 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 ``` -------------------------------- ### Build WASM JS Library Source: https://github.com/elalish/manifold/blob/master/README.md Steps to build the JavaScript WASM library using emscripten, including setting up emscripten and then using emcmake and emmake for the build process. ```bash cd manifold mkdir buildWASM cd buildWASM emcmake cmake -DCMAKE_BUILD_TYPE=MinSizeRel .. && emmake make cd test node ./manifold_test.js ``` -------------------------------- ### 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) ``` -------------------------------- ### Include Project Information Module Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Includes a CMake module to gather and manage project information, potentially used for versioning or build details. ```cmake include(${PROJECT_SOURCE_DIR}/cmake/info.cmake) ``` -------------------------------- ### 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 ``` -------------------------------- ### 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 Test Execution for Windows Source: https://github.com/elalish/manifold/blob/master/test/CMakeLists.txt Sets up the 'manifold_test' to run as a CMake test on Windows. ```cmake 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() ``` -------------------------------- ### 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] ``` -------------------------------- ### Link Tracy Client Library Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Links the TracyClient library to the manifold target if TRACY_ENABLE is set. ```cmake target_link_libraries(manifold PUBLIC $<$:TracyClient>) ``` -------------------------------- ### Enable Tracy Profiler for Tests Source: https://github.com/elalish/manifold/blob/master/README.md Compiles the project with Tracy profiler support enabled. This allows for detailed performance analysis of the tests when run with a Tracy server. ```cmake -DTRACY_ENABLE=on ``` -------------------------------- ### Emscripten Build Options Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Configures linker options for Emscripten builds, including memory growth, maximum memory, and threading options when parallelization is enabled. ```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() ``` -------------------------------- ### Optimization Flags for Release Builds Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Applies optimization flags like -O3 for Release or RelWithDebInfo build types to improve performance. ```cmake if( MANIFOLD_OPTIMIZED OR "${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo" ) list(APPEND MANIFOLD_FLAGS -O3) endif() ``` -------------------------------- ### 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) ``` -------------------------------- ### Enable Tracy Memory Profiling Source: https://github.com/elalish/manifold/blob/master/README.md Compiles the project with both Tracy profiler and memory usage tracking enabled. This provides in-depth performance and memory usage insights for tests. ```cmake -DTRACY_MEMORY_USAGE=ON -DTRACY_ENABLE=ON ``` -------------------------------- ### 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'; ``` -------------------------------- ### Define Compile-Time Options Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Iterates through a list of options and defines them as preprocessor macros for the manifold target if they are enabled. ```cmake set( OPTIONS MANIFOLD_DEBUG MANIFOLD_ASSERT MANIFOLD_TIMING MANIFOLD_CROSS_SECTION MANIFOLD_NO_IOSTREAM TRACY_ENABLE TRACY_MEMORY_USAGE ) foreach(OPT IN LISTS OPTIONS) if(${${OPT}}) target_compile_definitions(manifold PUBLIC ${OPT}) endif() endforeach() ``` -------------------------------- ### 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 ) ``` -------------------------------- ### Access Manifold Python Binding Documentation Source: https://github.com/elalish/manifold/blob/master/README.md Imports the manifold3d module and displays its documentation in the Python interpreter. This is useful for understanding the available functions and their usage. ```python import manifold3d help(manifold3d) ``` -------------------------------- ### Add Test Executable and Link Libraries Source: https://github.com/elalish/manifold/blob/master/test/CMakeLists.txt Adds the 'manifold_test' executable and links it against Google Test, the Manifold library, and other conditional libraries. ```cmake add_executable(manifold_test ${SOURCE_FILES}) target_link_libraries( manifold_test PRIVATE GTest::gtest_main manifold samples $<$:manifoldc> $<$:TBB::tbb> ) ``` -------------------------------- ### 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) ``` -------------------------------- ### Windows Specific Warning Flags Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Adds specific warning flags for Windows builds when using GCC, such as -Wno-format. ```cmake if(CMAKE_SYSTEM_NAME STREQUAL "Windows") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") list(APPEND WARNING_FLAGS -Wno-format) endif() endif() ``` -------------------------------- ### 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 Subdirectories for Build Targets Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Adds subdirectories to the build, defining the source directories for the main library, bindings, samples, tests, and extras. ```cmake add_subdirectory(src) add_subdirectory(bindings) if(MANIFOLD_TEST) add_subdirectory(samples) add_subdirectory(test) add_subdirectory(extras) endif() ``` -------------------------------- ### Configure Compiler Flags for Fuzzing Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Sets up compiler and linker flags for address sanitization and fuzzing when the MANIFOLD_FUZZ option 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() ``` -------------------------------- ### 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) ``` -------------------------------- ### Emscripten Specific Link Options Source: https://github.com/elalish/manifold/blob/master/test/CMakeLists.txt Configures link options for Emscripten builds, including assertions and preloading files. ```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() ``` -------------------------------- ### Define Test Executable Source Files Source: https://github.com/elalish/manifold/blob/master/test/CMakeLists.txt Sets the list of source files for the 'manifold_test' executable. Includes conditional files based on CMake variables. ```cmake 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 $<$:cross_section_test.cpp> $<$:manifoldc_test.cpp> ) ``` -------------------------------- ### Set Build Type for Tracy Profiler Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Configures the build type to RelWithDebInfo when the TRACY_ENABLE option is set, optimizing for release builds with debugging information. ```cmake if(TRACY_ENABLE) option(CMAKE_BUILD_TYPE "Build type" RelWithDebInfo) endif() ``` -------------------------------- ### Set Manifold Include Directories Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Defines the include directories for the Manifold project. ```cmake set(MANIFOLD_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include) ``` -------------------------------- ### 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) ``` -------------------------------- ### Create Manifold Library Target Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Adds the 'manifold' library target with specified source and header files. ```cmake add_library(manifold ${MANIFOLD_SRCS} ${MANIFOLD_PRIVATE_HDRS}) ``` -------------------------------- ### GCC/Clang Warning Flags Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Configures a comprehensive set of warning flags for GCC and Clang compilers to enhance code quality and catch potential issues. ```cmake list( APPEND WARNING_FLAGS -Wall -Wno-unknown-warning-option -Wno-unused -Wno-shorten-64-to-32 -Wno-sign-compare -Wno-alloc-size-larger-than ) ``` -------------------------------- ### 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}) ``` -------------------------------- ### 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 ) ``` -------------------------------- ### Generate CMake Package Configuration File Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Configures and generates the CMake package configuration file (manifoldConfig.cmake) and version file, enabling easy integration with other CMake projects using find_package. ```cmake # CMake exports 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 ) ``` -------------------------------- ### Set Compile Options Source: https://github.com/elalish/manifold/blob/master/test/CMakeLists.txt Applies specific compile flags to the 'manifold_test' executable. ```cmake target_compile_options(manifold_test PRIVATE ${MANIFOLD_FLAGS}) ``` -------------------------------- ### Build Manifold with Fuzzing Support Source: https://github.com/elalish/manifold/blob/master/README.md Configures CMake to build the project with fuzzing support enabled. This involves enabling fuzzing, disabling Python bindings, and specifying the C++ compiler as clang. Additional options for disabling parallelization and setting ASAN options may be required on macOS. ```cmake -DMANIFOLD_FUZZ=ON -DMANIFOLD_PYBIND=OFF -DCMAKE_CXX_COMPILER=clang++ ``` -------------------------------- ### Enable Code Coverage Flags Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Adds compiler and linker flags for code coverage analysis when the CODE_COVERAGE option is enabled. ```cmake if(CODE_COVERAGE) list( APPEND MANIFOLD_FLAGS -coverage -fno-inline-small-functions -fkeep-inline-functions -fkeep-static-functions ) add_link_options(-coverage) endif() ``` -------------------------------- ### Define Manifold Source Files Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Sets the list of source files for the Manifold library, including core files and cross-section sources. ```cmake set( MANIFOLD_SRCS boolean3.cpp boolean_result.cpp constructors.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 ${MANIFOLD_CROSS_SECTION_SRCS} ) ``` -------------------------------- ### 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) ``` -------------------------------- ### Define No IOStream Macro Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Defines MANIFOLD_NO_FILESYSTEM if MANIFOLD_NO_IOSTREAM is enabled, as they track together. ```cmake if(MANIFOLD_NO_IOSTREAM) target_compile_definitions(manifold PUBLIC MANIFOLD_NO_FILESYSTEM) endif() ``` -------------------------------- ### 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}) ``` -------------------------------- ### Link Optional Dependencies Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Links optional dependencies like TBB and cross-section libraries to the manifold target. ```cmake target_link_libraries( manifold PRIVATE # optional dependencies $<$:TBB::tbb> ${MANIFOLD_CROSS_SECTION_LIBS} ) ``` -------------------------------- ### 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") ``` -------------------------------- ### Set C++ Standard Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Ensures the manifold library uses C++17 standard for compatibility. ```cmake target_compile_features(manifold PUBLIC cxx_std_17) ``` -------------------------------- ### Define Cross-Section Source Files Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Appends source files for cross-section functionality based on the selected backend (clipper2 or boolean2). ```cmake set(MANIFOLD_CROSS_SECTION_SRCS) if(MANIFOLD_CROSS_SECTION) if(MANIFOLD_CROSS_SECTION_BACKEND STREQUAL "clipper2") list(APPEND MANIFOLD_CROSS_SECTION_SRCS cross_section/cross_section.cpp) elseif(MANIFOLD_CROSS_SECTION_BACKEND STREQUAL "boolean2") list(APPEND MANIFOLD_CROSS_SECTION_SRCS cross_section/cross_section_boolean2.cpp) endif() endif() ``` -------------------------------- ### Build Manifold for Windows with Shared Libraries Disabled Source: https://github.com/elalish/manifold/blob/master/README.md Configures the CMake build for Windows, disabling shared libraries to simplify the build process. This command sets the build type to Release, disables shared libraries, enables debug information, and specifies the parallel backend and architecture. ```sh cmake . -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DMANIFOLD_DEBUG=ON -DMANIFOLD_PAR=${{matrix.parallel_backend}} -A x64 -B build ``` -------------------------------- ### 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. ``` -------------------------------- ### Include Dependency CMake Modules Source: https://github.com/elalish/manifold/blob/master/CMakeLists.txt Includes external CMake modules for handling project dependencies, ensuring all required libraries and configurations are available. ```cmake include(${PROJECT_SOURCE_DIR}/cmake/manifoldDeps.cmake) include(${PROJECT_SOURCE_DIR}/cmake/configHelper.cmake) ``` -------------------------------- ### Define Cross-Section Libraries Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Appends libraries for cross-section functionality, specifically for the clipper2 backend. ```cmake set(MANIFOLD_CROSS_SECTION_LIBS) if(MANIFOLD_CROSS_SECTION AND MANIFOLD_CROSS_SECTION_BACKEND STREQUAL "clipper2") list(APPEND MANIFOLD_CROSS_SECTION_LIBS Clipper2::Clipper2) endif() ``` -------------------------------- ### Export Executable Source: https://github.com/elalish/manifold/blob/master/test/CMakeLists.txt Exports the 'manifold_test' executable, typically for use by other build targets or tools. ```cmake exportbin(manifold_test) ``` -------------------------------- ### Define Manifold Private Headers Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Sets the list of private header files for the Manifold library. ```cmake set( MANIFOLD_PRIVATE_HDRS 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 ) ``` -------------------------------- ### Define Parallelism Macro Source: https://github.com/elalish/manifold/blob/master/src/CMakeLists.txt Defines MANIFOLD_PAR macro based on whether MANIFOLD_PAR is enabled, setting it to 1 or -1. ```cmake if(MANIFOLD_PAR) target_compile_definitions(manifold PUBLIC MANIFOLD_PAR=1) else() target_compile_definitions(manifold PUBLIC MANIFOLD_PAR=-1) endif() ```