Code Monkey home page Code Monkey logo

opencascade.js's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.