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-examples contains general examples on how to use the library.
- CascadeStudio is a SCAD (Scripted-Computer-Aided-Design) editor, which runs in the browser.
The answer: 74.59%
Detailed list of supported classes
-
Add the library as a dependency to your project
# with yarn yarn add opencascade.js # with npm npm install opencascade.js
-
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.
- make sure that the path to the opencascade WASM file is made available by webpack. This is required to enable support for
-
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.
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:
-
Get Docker and install it
-
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
. -
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. -
You have to run the
docker build
anddocker run
commands after each change, for every build.
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.