This is OpenCascade.js - a port of the OpenCascade CAD library to JavaScript and WebAssembly via Emscripten.
- 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.
-
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/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
andnode_modules
folders) and emscripten cache files (in theemscripten-cache
folder) will be written and saved on your host machine's disk. The resulting build files are output to thedist
folder.
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.