MeshLib Documentation
Loading...
Searching...
No Matches
MeshLib C++ Setup Guide

Setting Up MeshLib for C++ Development

This guide provides detailed instructions for setting up MeshLib for C++ development across Windows, Linux, and macOS. It covers all prerequisites as well as specific setup steps for each platform.

Windows

Prerequisites

  1. Git
    • Install Git to manage repositories and submodules, which is also required to install vcpkg.
  2. Visual Studio 2019 or 2022
  3. CUDA Toolkit
    • For Visual Studio 2019: Install CUDA v11.4
    • For Visual Studio 2022: Install CUDA v12.0
      Choose the appropriate version based on your Visual Studio installation.
  4. vcpkg
    • To install vcpkg, follow these steps:
      1. Open a command prompt (CMD) or PowerShell window.
      2. Navigate to a directory where you want to install vcpkg:
        cd C:\path\to\your\desired\directory
      3. Clone the vcpkg repository:
        git clone https://github.com/microsoft/vcpkg.git
      4. Navigate to the vcpkg directory:
        cd vcpkg
        git checkout 2024.10.21
      5. Run the bootstrap script to build the vcpkg executable:
        bootstrap-vcpkg.bat
      6. Integrate ** vcpkg **with Visual Studio (requires Administrator access):
        vcpkg integrate install

Learn more about vcpkg

Installing the local build

Note
The following steps will require approximately 40 GB of disk space.
  1. Clone the MeshLib Repository:
    git clone --recurse-submodules https://github.com/MeshInspector/MeshLib.git
  2. (Optional) Speed Up with AWS CLI
    • Optionally, install AWS CLI v2 to speed up the process before using the MeshLib Installation Script. Restart your terminal after installation.
  3. Install MeshLib Third-Party Dependencies
    • Execute the following commands to run the MeshLib third-party installation script:
      cd vcpkg
      ..\MeshLib\thirdparty\install.bat
    • This script automates the installation of necessary third-party dependencies.
  4. Build and Run:
    • Open MeshLib/source/MeshLib.sln in Visual Studio.
    • Build the solution and run the application.

Installing the release build

  1. Download and Extract the Built Version
    • Visit the MeshLib GitHub Releases.
    • Download the latest Windows built version archive (E.g. MeshLibDist_v3.0.0.40.zip).
    • Extract it to a directory, e.g., C:\meshlib-built\.
      Directory Structure After Extraction
      install/
      ├── include/ # Header files
      ├── lib/ # Static and shared libraries
      ├── bin/ # Executables
      example_plugin/ # example solution for creating plugins
  2. Configure and integrate with Visual Studio
    • C/C++ → General → Additional Include Directories:
      Add: C:\meshlib-built\install\include
    • Linker → General → Additional Library Directories:
      Add: C:\meshlib-built\install\app\$(Configuration)
    • Linker → Input → Additional Dependencies:
      Add: C:\meshlib-built\install\lib\$(Configuration)\*.lib
    • Debug Configuration: C/C++ → Preprocessor → Preprocessor Definitions:
      Add: _ITERATOR_DEBUG_LEVEL=0
    • Copy DLLs:
      Copy all .dll files from: C:\meshlib-built\install\app\$(Configuration) to your project’s output directory: $(TargetDir)
      xcopy C:\meshlib-built\install\app\$(Configuration)\*.dll $(TargetDir)

Linux (Ubuntu/Fedora)

Prerequisites

  1. Git
  2. CMake
    • Ensure CMake is installed for managing the build process.
  3. CUDA Toolkit
    • Install CUDA v12.0 from the official website. Follow the Linux installation instructions provided on the CUDA page.

Installing the local build

  1. Clone the MeshLib Repository:
    git clone --recurse-submodules https://github.com/MeshInspector/MeshLib.git
    cd MeshLib
  2. Install/Build Dependencies and Compile:
    ./scripts/build_thirdparty.sh # Do not select emscripten in the corresponding question
    ./scripts/build_source.sh # Do not select emscripten in the corresponding question
  3. Create and Install Package:
    This step will create distribution package and install it to the system
    For Ubuntu:
    ./scripts/distribution.sh
    sudo apt install ./distr/meshlib-dev.deb
    For Fedora**:
    ./scripts/distribution_rpm.sh
    sudo rpm -i ./distr/meshlib-dev.rpm
  4. Open MeshViewer
    To verify that everything is fine you can run MeshViewer application:
    • if you previously have installed meshlib to your system:
      MeshViewer
    • or run locally built binary
      MR_LOCAL_RESOURCES=1 ./build/Release/bin/MeshViewer
  5. Integrate Using CMake
    Examples of integration with CMake can be found in the examples directory on GitHub.

Installing the release build

  1. Download and Extract the Built Version
  2. Install Linux Build
    • For Ubuntu:
      sudo apt install ./meshlib-build-version-example.deb
    • For Fedora:
      sudo rpm -i ./meshlib-build-version-example.rpm
  3. Open MeshViewer
    To verify that everything is fine you can run MeshViewer application:
    MeshViewer
  4. Integrate Using CMake
    Examples of integration with CMake can be found in the examples directory on GitHub.

macOS

Prerequisites

  1. Install Homebrew
    • Run the following command in your terminal to install Homebrew:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    • Install Homebrew
  2. Update Homebrew
    • Make sure Homebrew is up to date:
      brew update
  3. Install Git Using Homebrew
    • Once Homebrew is installed and added to your PATH, you can proceed to install Git:
      brew install git
    • Learn more about Git

Installing the local build

  1. Clone the MeshLib Repository:
    git clone --recurse-submodules https://github.com/MeshInspector/MeshLib.git
    cd MeshLib
  2. Install/Build Dependencies and Compile:
    ./scripts/build_thirdparty.sh
    ./scripts/build_source.sh
  3. Open MeshViewer
    MR_LOCAL_RESOURCES=1 ./build/Release/bin/MeshViewer
    The new window with a viewer must appear.
  4. Integrate Using CMake
    Examples of integration with CMake can be found in the examples directory on GitHub.

Installing the release build

  1. Download the Built Version
    Visit the MeshLib GitHub Releases and download the latest macOS built version.
  2. Install Using macOS Installer
    • Double-click the .pkg file included in the downloaded package, and follow the instructions to complete the installation.
    • Install Dependencies via Homebrew
      Open Terminal and run the following command:
      xargs brew install < /opt/meshlib/requirements/macos.txt
  3. Integrate Using CMake
    Examples of integration with CMake can be found in the examples directory on GitHub.

Building WebAssembly with MeshLib Using Emscripten

This guide will help you build WebAssembly (WASM) using MeshLib and Emscripten. Please follow the instructions step by step.

Install Emscripten

Emscripten is required to compile C++ code into WebAssembly. You can install Emscripten by following the steps below. For more details, refer to the Emscripten official page.

  • Clone the Emscripten SDK Repository
    Run the following command on all platforms:
    git clone https://github.com/emscripten-core/emsdk.git
  • Navigate to the Emscripten SDK Directory
    cd emsdk
  • Update the SDK (Optional)
    This step ensures you have the latest updates:
    git pull origin
  • Install a Specific Version of Emscripten
    ./emsdk install 3.1.48
  • Activate the Installed Version
    ./emsdk activate 3.1.48
  • Set Up Environment Variables
    • macOS and Linux:
      source ./emsdk_env.sh
Note
For Windows Users:
Make sure you are using Git Bash, WSL, or another Unix-like environment if you want to follow the exact same steps as on Linux/macOS.

Building MeshLib

Now that Emscripten is set up, you can proceed to build MeshLib for WebAssembly.

  • Navigate to the MeshLib directory:
    cd ~/MeshLib
  • Run the script to build third-party dependencies. When prompted, select Emscripten as the build target:
    • Choose y for multithreaded, s for single-threaded, or n for a standard Linux build.
      ./scripts/build_thirdparty.sh
  • Build the MeshLib source code. Make sure to select the same Emscripten option you used in the build_thirdparty.sh script:
    ./scripts/build_source.sh
Note
For Windows Users:
You may encounter compatibility issues if building directly on Windows. Consider using WSL (Windows Subsystem for Linux) to follow Linux-like instructions.

Running the WebAssembly Build

After building MeshLib for WebAssembly, follow these steps to run it:

  • Setting Up a Local HTTP Server
  • Navigate to the build directory:
    cd ~/MeshLib/build
  • Start a local server:
    • Windows
      python -m http.server
    • macOS/Linux:
      python3 -m http.server
  • Configuring COEP and COOP for Multithreading
    If using multithreading, set these headers:

    • Cross-Origin Embedder Policy (COEP): require-corp
    • Cross-Origin Opener Policy (COOP): same-origin

    For Python servers, you can use this custom script (server.py):

    #!/usr/bin/env python
    from http import server
    class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler):
    def end_headers(self):
    self.send_my_headers()
    server.SimpleHTTPRequestHandler.end_headers(self)
    def send_my_headers(self):
    self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
    self.send_header("Cross-Origin-Opener-Policy", "same-origin")
    if __name__ == '__main__':
    server.test(HandlerClass=MyHTTPRequestHandler)
  • Access and Test
    • Open your browser and go to: http://127.0.0.1:8000
    • Ensure headers are set correctly for multithreading. Check the browser console for errors if needed.