Skip to content

Building an example in WASM

To build an example you downloaded from VTK Examples in WebAssembly, you are going to need to download the tarball of the example and extract it.

tar xf example.tar.gz
cd example

Then, remove the CMakeLists.txt file from the extracted tarball. Now follow the instructions from the contribution guidelines to create the new CMakeLists.txt and index.html.

Building VTK

To build an example using WebAssembly, you can use the kitware/vtk-wasm docker image but some modules are disabled in that version that may be needed for many examples.

To build VTK by yourself, you will need to download VTK source code and then follow the instructions in this documentation article, except that at the first step of the build, you will have to change the configuration command to:

emcmake cmake \
        -S /work/src \
        -B /work/build-vtk-wasm \
        -GNinja \

Building the example

To build your example, simply run:

emcmake cmake -DVTK_DIR=/work/build-vtk-wasm -S path_to_source -B path_to_build
cmake --build path_to_build

Then the only thing you have to do is to run the example:

cd path_to_build
python3 -m http.server 8000

Open your browser to http://localhost:8000 and enjoy !