Skip to content

Port of the OpenCascade library to JavaScript / WebAssembly using Emscripten

License

Notifications You must be signed in to change notification settings

levivoelz/opencascade.js

Repository files navigation

OpenCascade.js

This is OpenCascade.js - a port of the OpenCascade CAD library to JavaScript and WebAssembly via Emscripten.

Current OCCT version: V7_4_0p1

opencascade.js - Build Library

Projects & Examples:

Which parts of the OpenCascade library are supported?

The answer: 74.59%

Detailed list of supported classes

Use it

  1. Add the library as a dependency to your project

    # with yarn
    yarn add opencascade.js
    # with npm
    npm install opencascade.js
  2. Assuming that you use webpack in your project, you need to add the following configuration to your webpack.config.js

    module: {
      rules: [
        {
          test: /opencascade\.wasm\.wasm$/,
          type: "javascript/auto",
          loader: "file-loader"
        }
      ]
    },
    node: {
      fs: "empty"
    }

    You will also need to add file-loader as a dev-dependency to your project, i.e.

    # with yarn
    yarn add file-loader --dev
    # with npm
    npm install file-loader --save-dev

    This will

    • make sure that the path to the opencascade WASM file is made available by webpack. This is required to enable support for WebAssembly.InstantiateStreaming & Co.
    • stop webpack from complaining about fs being undefined in the Emscripten-generated loading script.

    For more info, see here.

  3. Use the library in your project:

    import { initOpenCascade } from "opencascade.js";
    initOpenCascade().then(openCascade => {
      // use it!
    });

    This code will load the WebAssembly version of the library.

Build it

You can build OpenCascade.js yourself. The easiest way to do that is to use the provided Docker image, which sets up a small Ubuntu container within your host system, which is correctly configured for building the library. Follow these steps:

  1. Get Docker and install it

  2. Build the container. Open a command prompt or terminal in the directory of opencascade.js and enter:

    docker build -t opencascade.js .
    

    This will build the container with the instructions given in the Dockerfile and give it the tag (name) opencascade.js.

  3. Run the build. If you're on Linux, enter:

    docker run -it \
      -v "$(pwd)/build/":"/opencascade/build/" \
      -v "$(pwd)/node_modules/":"/opencascade/node_modules/" \
      -v "$(pwd)/dist/":"/opencascade/dist/" \
      -v "$(pwd)/emscripten-cache/":"/emscripten/upstream/ \
      -v "$(pwd)/embind/":"/opencascade/embind/" \
      opencascade.js
    

    Or on windows

    docker run -it ^
      -v "%cd%\build":"/opencascade/build/" ^
      -v "%cd%\node_modules":"/opencascade/node_modules/" ^
      -v "%cd%\dist":"/opencascade/dist/" ^
      -v "%cd%\emscripten-cache":"/emscripten/upstream/emscripten/cache/" ^
      -v "%cd%\embind":"/opencascade/embind/" ^
      opencascade.js
    

    This command will run the container and will also set up some directories, which will be shared with your host system. This speeds up your development process, as temporary build files will be written and saved on your host machine's disk. The resulting build files are output to the dist folder.

  4. You have to run the docker build and docker run commands after each change, for every build.

Exposing additional OpenCascade APIs

Emscripten's Embind system is used to expose OpenCascade APIs to JavaScript. The Embind definitions are located in the embind folder. Please look at the code conventions document for best practices on how to expose additional APIs.

About

Port of the OpenCascade library to JavaScript / WebAssembly using Emscripten

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 93.7%
  • Dockerfile 6.2%
  • Shell 0.1%