web/README.md
This directory contains the web-based samples, tutorials, and the JavaScript wrapper for Filament.
examples/
Contains the source for the WebGL tutorials, HTML samples, materials, and assets.
These examples use filament.js and filament.wasm to demonstrate various features of the engine.
filament-js/
Contains the JavaScript bindings for Filament, generated via Emscripten.
To build the WebGL targets and compile all required materials and assets, you will need the Emscripten SDK installed and activated.
Activate Emscripten SDK:
Make sure you have EMSDK in your environment.
cd path/to/emsdk
./emsdk activate latest
source ./emsdk_env.sh
Run the Build Script: From the root directory of the repository, execute the build script targeting WebGL:
./build.sh -p webgl release
This will:
filament.wasm and filament.js..mat to .filamat) and process textures required by the examples.out/cmake-webgl-release/examples/.Because of CORS restrictions and the need to serve WebAssembly files with the correct MIME type, you must serve the files via a local web server.
Install Python Requirements:
The serve script dynamically renders Markdown tutorials on-the-fly using mistletoe. It is highly recommended to use a Python virtual environment to install dependencies.
python3 -m venv .venv
source .venv/bin/activate
pip install -r web/examples/requirements.txt
Start the Server:
From the root of the repository, run the serve.py script:
./web/examples/serve.py
View the Examples:
Open your browser and navigate to http://localhost:8000. You will see an index page listing all the generated tutorials and samples.
serve.pyThe custom serve.py script in the web/examples/ directory performs the following:
out/ directory.index.html listing all the available samples and tutorials..md tutorial files into HTML using an embedded template.docs_src)If you want your web sample or tutorial to appear on the official Filament documentation website via
mdbook, follow these steps:
Map the Built HTML:
Add your generated .html or .md file to the mapping in docs_src/build/duplicates.json. This
tells the documentation build script to copy your sample into the mdbook structure.
"out/cmake-webgl-release/web/examples/examples/your_sample/your_sample.html": {
"dest": "samples/web/your_sample.md"
}
Add to the Navigation Menu:
Link your sample in the table of contents by adding it to docs_src/src_mdbook/src/SUMMARY.md
under the "Web Tutorials" or "Web Samples" section.
Generate a Thumbnail Image:
Add your sample's name to the samples array in docs_src/build/snapshot_samples.py. Then,
manually run this script (python3 snapshot_samples.py). It will launch a headless browser,
wait for your scene to render, and snap a 100x100 preview image.
Dynamic Asset Loading (Optional):
When mdbook serves your sample, the assets (.filamat, textures) are segregated into a
web/assets/ directory.
<script src="..."> or `` tags embedded in the HTML, the paths will be
automatically rewritten by docs_src/build/copy_web_docs.py.fetch()), you
must prepend (window.FILAMENT_ASSET_DIR || '') to the file URL.window.FILAMENT_ASSET_DIR to be properly populated, make sure to add logic to
docs_src/build/copy_web_docs.py to inject the proper path prefix for your sample.