Skip to content

Port of the OpenCascade library to JavaScript / WebAssembly using emScripten

License

Notifications You must be signed in to change notification settings

zalo/opencascade.js

 
 

Repository files navigation

OpenCascade.js

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

opencascade.js - Build Library

Projects & Examples:

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/emscripten/cache/" \
      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/" ^
      opencascade.js
    

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

Exposing additional OpenCascade API's

Certain parts of the OpenCascade API are already exposed. If you need additional API's, go ahead and edit the opencascade.idl file. This file defines the exposed parts of the interface via the WebIDL Interface Description Language.

About

Port of the OpenCascade library to JavaScript / WebAssembly using emScripten

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Python 83.6%
  • C 8.2%
  • Dockerfile 4.6%
  • JavaScript 3.6%