A Javascript package is created from the following modules.
- JsMaterialXCore: Contains all of the core classes and util functions.
- JsMaterialXFormat: Contains the
readFromXmlString
function to read a MaterialX string.
Make sure to clone the emsdk repository, install and enable the latest emsdk environment.
# Get the emsdk repo
git clone https://github.com/emscripten-core/emsdk.git
# Enter that directory
cd emsdk
# Download and install the latest SDK tools.
./emsdk install latest
# Make the "latest" SDK "active" for the current user. (writes ~/.emscripten file)
./emsdk activate latest
For more information follow the steps described in the emscripten documentation. The Emscripten toolchain is documented here.
In the root of directory of this repository run the following:
It is recommended to build the project with docker here are the required steps:
-
For Windows make sure to use Linux containers and that File Sharing is set up to allow local directories on Windows to be shared with Linux containers.
For example, if the path to MaterialX is
"c:\git\MaterialXrepo"
then the"c"
drive should be set. (See https://docs.docker.com/docker-for-windows/#file-sharing for more details) -
Get the
emscripten
docker imagedocker run -dit --name emscripten -v {path_to_MaterialX}:/src trzeci/emscripten:1.39.7-upstream bash
-
Build the JavaScript bindings.
docker exec -it emscripten sh -c "cd build && cmake .. -DMATERIALX_BUILD_JS=ON -DMATERIALX_BUILD_RENDER=OFF -DMATERIALX_BUILD_TESTS=OFF -DMATERIALX_EMSDK_PATH=/emsdk_portable/ && cmake --build . --target install"
The JavasScript library can be built using cmake and make.
- Create a build folder from in the root of the repository.
mkdir -p ./<build_folder>
cd ./<build_folder>
- Run cmake and make
When building the JavaScript output the user can specify the emsdk path with the
MATERIALX_EMSDK_PATH
option. This option can be omitted if theemsdk/emsdk_env.sh
script was run before hand.
# This will generate the release library
cmake .. -DMATERIALX_BUILD_JS=ON -DMATERIALX_BUILD_RENDER=OFF -DMATERIALX_BUILD_TESTS=OFF -DMATERIALX_EMSDK_PATH=/mnt/c/GitHub/PUBLIC/emsdk
cmake --build .
For Windows use Ninja as the cmake generator.
cmake .. -DMATERIALX_BUILD_JS=ON -DMATERIALX_BUILD_RENDER=OFF -DMATERIALX_BUILD_TESTS=OFF -DMATERIALX_EMSDK_PATH=C:\GitHub\PUBLIC\emsdk -G "Ninja"
cmake --build .
After building the project the JsMaterialX.wasm
and JsMaterialX.js
files can be found in ./<build_folder>/source/JsMaterialX/
.
To install the results into the install directory run
cmake --build --target install
from the build directory.
The JavaScript tests are located in <root_dir>/source/JsMaterialX/test
folder and are defined with the .spec.js
suffix.
Most of these tests are the same as the Python main.py tests.
These tests require node.js
. This is a part of the emscripten environment. So make sure to call emsdk_env
before running the steps described below.
- From the test directory, install the npm packages.
npm install
- Run the tests from the test directory.
npm run test
Note that a sample build, install and test configuration can be found in the .travis.yml
file.