If the pre-compiled libraries do not work in your situation, you can compile the libraries from their source, the repo uses OpenNURBS as a submodule, so you need to run a couple more git commands after you have cloned. cd
into the new repository directory and run
git submodule update --init
Compiling rhino3dm.js can be done on macOS, Linux and Windows (via Windows Subsystem for Linux). The following tools are required...
- Python 2 (>2.17.12) or 3 (> 3.6.9)
- Emscripten - See Emscripten's Getting started guide or WebAssembly's Developer's Guide .
- CMake (>3.12.2) - Note: The version of CMake distributed with Ubuntu 18.04 LTS isn't new enough so you'll have to build it from source. This may also be true for other package managers.
⭐️ TIP: A great way to get a build environment that's ready to go for building rhino3dm.js is to use a Dev Container in VS Code! 🐳
A number of scripts are used to setup and build rhino3dm:
- script/bootstrap.py - checks for (and downloads) the required tools
- script/setup.py - generates the platform-specific project files using CMake
- script/build.py - builds the library project(s)
These scripts support Python 2 and 3 on Windows (linux subsystem), macOS, or Linux (Ubuntu).
You have to make sure that the Emscripten environment is set up. Here are the steps to install Emscripten and the make tool to make it work. After that you can set up the environment by running emsdk_env.bat
.
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
git pull
emsdk install latest
emsdk activate latest
emsdk install mingw-4.6.2-32bit
emsdk activate mingw-4.6.2-32bit
The script/bootstrap.py
script can be used to check your system for (and, in some cases, download) the necessary tools for a specific build target. For example, you can run:
$ python3 bootstrap.py --platform js
to check for all the tools needed to build the javascript version of rhino3dm.
The setup.py script uses CMake to generate the make files necessary to build the project. These projects are generated into build/javascript folder. To setup a JavaScript build, you can run:
$ python3 setup.py --platform js --verbose
The build.py script run make
to build the rhino3dm.js and rhino3dm.wasm files to the build/javascript/artifacts_js folder. To build, run:
$ python3 build.py --platform js --verbose --overwrite
The build might take a few minutes, but if everything is configured correctly you should now have rhino3dm.js and rhino3dm.wasm in the build/javascript/artifacts_js folder. The script also copies these files to the docs/javascript/samples/resources folder where they can be used for testing.
-
cd
to thedocs/javascript/samples
folder. -
Type
python3 -m http.server
. This will run a simple web server which serves files in the artifacts directory -
Go to your browser and navigate to
http://localhost:8080/rhino3dm.html
-
For chrome, right click and select
inspect
. Click on theconsole
tab and try typing in the following javascript:
> sphere = new _rhino3dm.Sphere([1,2,3], 12);
> brep = sphere.toBrep();
> jsonobject = brep.encode();
Getting the toolchain set up for building rhino3dm.js can be painful. Visual Studio Code can help by using a preconfigured Docker container as a development environment.
macos setup
-
Install vscode: https://code.visualstudio.com/
-
Install Docker desktop: https://docs.docker.com/get-docker/ and start the docker app
-
Install vscode extension for containers: https://code.visualstudio.com/docs/containers/overview
-
Open the rhino3dm directory in vscode and open a terminal.
-
In the terminal, run the following command:
docker run --rm -dit -v $(pwd):/src emscripten/emsdk:3.1.30
--rm
deletes the container when it's stopped-dit
runs the container as a daemon (in the background) but still allows interaction-v $(pwd):/src
maps the current directory (rhino3dm) to /src in the container. On Windows you should include the full path to the rhino3dm directory. For example:docker run --rm -dit -v c:\dev\rhino3dm:/src emscripten/emsdk:3.1.30
emsdk:3.1.30
is the version of emscripten we are using. -
In vs code, open Docker explorer
-
You should see a container in the list. Right-click on it and select "Attach shell" which will open a new terminal from the container. Alternatively, you can run
docker exec -it <mycontainer> bash
, where<mycontainer>
is the container id printed out after step 5. -
Make sure the terminal is in the rhino3dm directory. Run the following command to setup the rhino3dm.js build:
python3 script/setup.py --platform js
-
Run the following command to build rhino3dm.js (use
--verbose
to get verbose output while compiling):python3 script/build.py --platform js --overwrite --verbose
- Current Development Tools - This file (which is used by bootstrap) lists the current build tools and versions we have tested with.