Skip to content

feat(wasm): run a fire in the browser on real terrain - #211

Merged
filippi merged 8 commits into
forefireAPI:devfrom
HugoFara:feat/wasm-demo
Oct 23, 2026
Merged

filippi merged 8 commits into
forefireAPI:devfrom
HugoFara:feat/wasm-demo

Conversation

@HugoFara

@HugoFara HugoFara commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

A browser demo of the WASM build from #210. Explore mode: click the map to light a fire, set the wind, and watch it spread in 2D or on 3D terrain. Research mode adds the model, propagationSpeedAdjustmentFactor, windReductionFactor, the numerics, and fuel moisture and classes.

wasm-pages.yml publishes it on every push to dev, as discussed in #212. The github-pages environment needs dev added as an allowed branch (Settings → Environments → github-pages).

Also fixes a bug from #210: the WASM addLayer returned nothing, so the demo failed to register its layers. The smoke test now fails when a layer is missing.

Tested in Chrome against dev. Each run uses a fresh worker, because the engine's state is process-wide (#175).

Drafted with Claude Opus 5.5.

@filippi

filippi commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

@HugoFara would be cool to deploy in pages indeed ! so cool, as demo, the thing is to get consistent tiled data, but cool. With a static page action ? or just deploy from a branch.. a github action might be more configurable with WASM build.

A static page over the WebAssembly module (forefireAPI#171). landscape.mjs builds the
fuel and elevation layers from satellite and Terrarium tiles for any square
of ground, worker.mjs runs the whole simulation off the main thread and
reports why it ended, and terrain3d.mjs draws the result on a raw WebGL
heightfield that tilts up from the 2D map, with click-to-ignite by ray cast.
@HugoFara

Copy link
Copy Markdown
Collaborator Author

I find GitHub Action more convenient. Keeping a separate branch leads to code drift and more time in maintenance... I am updating this PR, following the merge of #210

…sing layer

addLayer returned void, so JavaScript saw undefined and the demo's worker
treated the propagation layer as unregistered: every run failed with "a
layer failed to register". The engine side was fixed in forefireAPI#209; this is the
binding half, which forefireAPI#210 shipped without.

The smoke test printed each layer's result without checking it, which is
how this got through CI. It now exits non-zero if any layer is missing.
Explore is the default: click the map to light a fire, set the wind on a
dial or from a scenario, and watch it play back over a full-height map.
Research adds the propagation model, the two tuning factors, the numerics,
fuel moisture and bed depths, and the fuel class cut-offs, each labelled
with the ForeFire name it sets.

Each run now gets its own worker. The engine's state is process-wide
(forefireAPI#175), so a reused module kept the first run's propagation model and a
model switch did nothing.
The tile mosaic was drawn at fractional pixel offsets, so every tile edge
was antialiased: a dark seam in the imagery, and in the terrain tiles
half-blended pixels that decode to spikes hundreds of metres high. The
offsets are now rounded to whole pixels.

The wheel in 3D only moved the camera over the ground already loaded. It
now zooms the ground as in 2D, and the rebuilt mesh keeps the orbit pose.

setView dropped tilt.value, so the second terrain rebuild passed undefined
as the camera blend and drew nothing until the view was toggled.
Any pan or zoom cleared the run, because the fronts were drawn in the
current view's metres and would have landed on the wrong ground. Each run
now remembers the square it was computed on, its fronts are drawn wherever
that square sits in the view, and the ignition is measured against that
square rather than a view still waiting on its tiles.
…f the terrain

Each front was filled on its own, so the inner front ForeFire keeps round
ground the fire has encircled was filled orange like the burn around it.
The fronts are now one shape filled even-odd, which leaves that ground
clear.

The wind arrow was painted on the 2D canvas, which is also the texture of
the 3D mesh, so it was draped over the terrain. It is now an overlay on
the map, hidden in 3D where map north turns with the camera.
@HugoFara

Copy link
Copy Markdown
Collaborator Author

For the appearance of the app:

**Base view (orthophoto) **

image

3D view

image

Some fire propagation

image

I separated the UI between the base parameters users may want to tweak (model + wind direction), as I think that is what most firefighters or tinkerers will need. I kept a separate tab for the experts (the researchers), that need full control over the simulation.

image image

@HugoFara
HugoFara marked this pull request as ready for review October 23, 2026 15:45
@HugoFara

Copy link
Copy Markdown
Collaborator Author

One thing I did not do: should we add flames height? We have it with Balbi2020. Plume would be useful be needs Meso-NH.

@filippi filippi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I leave this one, cool.
There is the ability to load standard fuel tables procompiled as a parameter too i think. But that is great

@filippi
filippi merged commit 6b57d34 into forefireAPI:dev Oct 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants