geospatial-disaster-simulation
Simulate real-world natural disasters on geospatial map tiles using tile-snapped canvas raster sources, Mercator elevation decoding, and Three.js 3D WebGL building collapse physics. Do not use for non-georeferenced 2D animations, static GIS styling, or purely synthetic particle physics.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- geospatial-disaster-simulation
- description
- Simulate real-world natural disasters on geospatial map tiles using tile-snapped canvas raster sources, Mercator elevation decoding, and Three.js 3D WebGL building collapse physics. Do not use for non-georeferenced 2D animations, static GIS styling, or purely synthetic particle physics.
02 资源文件 3
- 参考文档CARD.md4.8 KB
- 参考文档config.default.yaml1.1 KB
- 脚本scripts/disaster_sim_engine.py23.1 KB
03 SKILL.md 正文
Geospatial Disaster Simulation: Real-Map Inundation & 3D Building Collapse Engine
geospatial-disaster-simulation is the authoritative simulation engineering skill for executing real-world natural disaster scenarios (tsunamis, riverine floods, and seismic structural collapses) on interactive web maps using Mapbox GL JS / MapLibre GL and Three.js.
Distilled from the engineering breakthroughs of Alex Oliinyk on HazardSim, this skill eliminates the "Sticker Problem" (naive screen-space canvas overlays that float, smear, and desynchronize when the camera tilts) by enforcing a strict Dual-World Coordinate Architecture:
- Ground Tier: Tile-aligned canvas raster sources draped directly onto 3D terrain mesh.
- Height Tier: Shared WebGL 3D context with
promoteIdfeature-state extrusion scaling and Three.js instanced physics.
See CARD.md for the companion summary card, 5-stage progression matrix, and invariants checklist. Consult open-source-gis-architect for raster GIS tooling, python-dataclass-architect for slotted domain models, and epistemic-isnad-audit for primary source provenance.
The 5-Stage Simulation Pipeline
[1. Grid Ingestion & Elevation] ──► [2. Ground Fluid Canvas Draping] ──► [3. Footprint Extraction & Feature Scaling]
│
▼
[5. Camera Choreography & Defense] ◄── [4. 3D WebGL Custom Layer & Instanced Debris] ◄─────┘
1. Geospatial Grid Ingestion & Tile Alignment
Map simulations must execute in map coordinates, not screen coordinates. Align computational grids directly to Web Mercator tile pyramids to consume external raster and elevation tiles without resampling:
- Web Mercator Coordinate Projection:
- Convert geographic bounds $(\text{lng}, \text{lat})$ to tile coordinates $(x, y)$ at zoom $z$: $$x = \frac{\text{lon} + 180}{360} \cdot 2^z$$ $$y = \frac{1 - \ln(\tan(\text{rad}) + \sec(\text{rad})) / \pi}{2} \cdot 2^z$$
- Automated Budgeted Zoom Selection:
- Step zoom $z$ downward from 15 to 8 until bounding box dimensions satisfy operational budgets ($\le 780\text{ px}$ width and $\le 620,000\text{ cells}$).
- Snap bounding box outward to integer tile coordinates $(x_0, y_0) \to (x_1, y_1)$ to guarantee exact 1-to-1 mapping with downloaded tiles.
- Calculate metric cell resolution: $\text{cellM} = 156543.03392 \cdot \cos(\text{lat}) / 2^z$.
- Dual Elevation Tile Decoding:
- AWS Terrarium PNGs (S3 Open Data): $$\text{elev}_m = R \cdot 256 + G + \frac{B}{256} - 32768$$
- Mapbox Terrain-RGB: $$\text{elev}_m = -10000 + (R \cdot 65536 + G \cdot 256 + B) \cdot 0.1$$
- Ingest into a contiguous 1D
Float32Array. Run a $3 \times 3$ median filter across neighbors differing by $> 8\text{ m}$ to eliminate single-pixel sensor spikes. - Identify sea cells: cells with $\text{elev} \le 0$ connected to the grid boundary via continuous water paths.
Completion Criterion: 1D Float32Array elevation grid loaded, snapped to tile boundaries, spikes filtered, and cell resolution established.
2. Ground-Tier Fluid & Inundation Simulation
Ground fluids (tsunami surges, flood inundations, mudflows) must live on the ground surface, allowing automatic terrain draping, foreshortening, and rotation:
- Hydraulic Inundation Propagation:
- Execute breadth-first search (BFS) flood progression from source coastlines or rivers across cell elevation gradients.
- Store reach timestamp $T_{\text{reach}}$ and water depth array per grid cell.
- Canvas Raster Source Attachment:
- Register an offscreen
<canvas>with dimensions $W \times H$ as a Mapboxcanvassource:map.addSource("flood", { type: "canvas", canvas: "floodcanvas", coordinates: coords, animate: true }); map.addLayer({ id: "flood", type: "raster", source: "flood", paint: { "raster-opacity": 0.94, "raster-resampling": "linear", "raster-fade-duration": 0 } }); - Mandatory flags:
animate: true(forces per-frame texture re-upload),"raster-resampling": "linear"(smooth cell interpolation),"raster-fade-duration": 0(eliminates ghosting).
- Register an offscreen
- Dual-Mask Video Texture Compositing:
- Avoid baking color into video textures; maintain neutral greyscale water footage.
- Tint dynamically in a scratch buffer with time-ramped sediment interpolation (
mudfactor: $0 \to 1$). - Apply
destination-inwithlandMask(white on land, transparent on open sea) to confine flood color to dry ground. - Composite onto the main flood canvas via
source-atop, ensuring water texture is clipped strictly to the simulated flood boundary with zero per-pixel iteration.
- Local Seaward Camera Calculation:
- Locate the nearest coastline cell to the city center.
- Average directional offsets to sea cells within a $2.5\text{ km}$ radius to determine true local seaward bearing $\theta_{\text{seaward}}$, preventing curved bay distortion.
Completion Criterion: Dynamic canvas raster draped over terrain, compositing video textures within flood masks, and seaward camera vector computed.
3. Footprint Extraction & Dynamic Feature-State Scaling
Earthquake destruction requires differentiating between distance-based background buildings and foreground hero structures:
- Vector Footprint Extraction & GeoJSON Promotion:
- Ingest building footprints from vector tiles via
map.querySourceFeatures(). - Deduplicate geometries across tile boundaries.
- Copy features into a dedicated GeoJSON source configured with
promoteId: "i"(whereiis an integer index). Callingmap.setFeatureState()on vector tile features silently fails because vector buildings lack feature IDs.
- Ingest building footprints from vector tiles via
- Patterned Facade Extrusion Styling:
- Configure dual
fill-extrusionlayers (bld-wallsandbld-roof). - Drive extrusion heights via feature-state multiplier $k$:
"fill-extrusion-height": ["*", ["get", "height"], ["feature-state", "k"]] - Insert building layers below the first
symbollayer (map.getStyle().layers) so labels remain visible above roofs.
- Configure dual
- Seismic Attenuation & Piecewise Fragility:
- Compute hypocentral distance: $R = \sqrt{r_{\text{km}}^2 + \text{depth}^2}$ (default depth: $10\text{ km}$).
- Calculate Modified Mercalli Intensity: $$\text{MMI} = 1.5 M - 3.0 \log_{10}(R) - 0.0018 R + 1.6$$
- Interpolate collapse probability $P_{\text{collapse}}$ across piecewise fragility curve:
[[6.5, 0], [7, 0.004], [8, 0.025], [9, 0.08], [10, 0.20], [11, 0.38], [12, 0.55]]. - Scale probability by structural quality factor $q$ (strict=0.2, avg=1.0, poor=3.0) and height factor $h_f$ (mid-rise 15–35m most vulnerable).
- 5-Mode Building Collapse Kinematics:
- Modulate $k(u)$ from $1.0$ down to rubble height $k_f$ across 5 distinct modes:
- Floor-by-Floor: Staircase drop and pause per floor level.
- Soft-Storey: Ground-floor drop, long pause, then rapid collapse.
- Crushed Top: Upper third fails early, pauses, then collapses lower sections.
- Sideways: Steady accelerating lean and sink.
- Pancake: Accelerating parabolic free fall ($k = k_0 - \Delta k \cdot u^2$).
- Clamp frame delta time $\Delta t \le 40\text{ ms}$ to eliminate visual jumping during tab stutter.
- Modulate $k(u)$ from $1.0$ down to rubble height $k_f$ across 5 distinct modes:
Completion Criterion: GeoJSON source promoted with IDs, MMI damage assigned per building, and feature-state $k$ animating collapse without layer rebuilds.
4. Three.js WebGL Custom Layer & Instanced Physics
Close-up buildings near the camera must break into physical objects with shared depth occlusion:
- Shared Context Custom 3D Layer:
- Register a custom layer with
renderingMode: "3d"to share Mapbox's WebGL depth buffer:const mc = mapboxgl.MercatorCoordinate.fromLngLat([origin.lng, origin.lat], 0); const s = mc.meterInMercatorCoordinateUnits(); const toMercator = new THREE.Matrix4() .makeTranslation(mc.x, mc.y, mc.z) .scale(new THREE.Vector3(s, -s, s)); - In
render(gl, matrix): multiply projection matrixcamera.projectionMatrix.fromArray(matrix).multiply(toMercator). Callrenderer.resetState()to restore GL bindings.
- Register a custom layer with
- Oriented Bounding Box (OBB) Derivation:
- Find the longest polygon footprint edge to define building yaw angle $\theta_{\text{yaw}}$.
- Project vertices onto the yaw axis and its normal to extract local dimensions $(L_1, L_2)$ and center offset.
- Multi-Block Rigid Body Tipping Physics:
- Partition building into 2–4 stacked boxes in a
THREE.Grouphinged on the bottom edge. - Integrate angular acceleration: $\theta'' = \frac{1.5 g}{h} \sin \theta$.
- Enforce safety clamps: angular velocity $\le 2.5\text{ rad/s}$, angular step $\le 0.09\text{ rad/frame}$.
- Detach upper blocks ballistically when lean exceeds critical threshold; clamp detachment velocity to $\le 18\text{ m/s}$.
- Partition building into 2–4 stacked boxes in a
- Pre-Allocated InstancedMesh Pools:
- Pool 30,000 slabs, 1,500 walls, 20,000 rebar segments, and 9,000 rubble rocks.
- Pre-allocate
instanceColorattribute for full capacity at initialization (new Float32Array(capacity * 3).fill(1)). Lazily sizing to count=0 produces all-black instances. - Set
frustumCulled = falseon all custom layer meshes to bypass Three.js camera culling. - Invoke
map.triggerRepaint()every frame objects move.
- Event-Driven Dust Particle Plumes:
- Do NOT emit constant ambient dust haze. Emit dust puffs strictly on discrete impact events (floor drops, block landings, soft-storey ground-floor jets).
- Draw dust in screen space on an overlay canvas: project ground anchor with
map.project(), scale vertical height by $z \cdot \text{scale} \cdot \sin(\text{pitch})$, sort by screen depth, and fade with age.
Completion Criterion: Three.js custom layer rendering tipping multi-block towers, instanced debris landing as permanent rubble, and event-driven dust plumes.
5. Cinematic Camera Orchestration & Anti-Pattern Defense
- Two-Stage Camera Dive:
- Ease from regional overview to zoom 14.6 at $45^\circ$ pitch.
- Pause until
map.areTilesLoaded()confirms vector tiles have arrived. - Ease into zoom 16.2 at $62^\circ$ pitch over epicentre. Skipping the hold renders an empty city.
- CSS DOM Container Shake:
- Never jitter the map camera with
easeTo; camera movement forces continuous tile re-fetching. - Shake the map DOM container with dynamic CSS transform: $$\text{amp} = \min(28, W \cdot 0.02, \max(6, (M - 4) \cdot 4.2))$$
- Apply envelope ($0.35$ buildup, $0.65$ decay) with rising frequency chirp $\omega(t) = 7 \to 46\text{ rad/s}$.
- Never jitter the map camera with
- Zero-Fork Configuration Budget:
- Store baseline operational parameters in
config.default.yaml(max cells, elevation provider, pool sizes, shake durations).
- Store baseline operational parameters in
Completion Criterion: Camera dive and CSS container shake execute smoothly, and all 11 field-tested gotchas pass verification.
The Visual Brief
Before running high-density disaster simulations or scaling instanced object pools:
- Interactive HTML Diagnostic Brief: Generate a self-contained visual brief at
%TEMP%\geospatial-disaster-sim-<timestamp>.html. - Brief Components:
- Web Mercator snapped grid extents overlaid on bounding coordinates.
- Decoded elevation profile heightmap and sea mask boundaries.
- Seismic attenuation curves (MMI vs distance) and piecewise fragility distribution.
- Three.js instanced pool capacity allocation table.
Mandatory Checkpoint Gates
Prevent browser WebGL crashes and runaway particle allocations:
- Scenario Initialization Gate: Before downloading vector tiles or allocating Three.js pools, evaluate tile and memory budgets against
config.default.yaml. - Execution Gate: When dispatching automated simulation pipelines, emit an
implementation_plan.mdartifact withRequestFeedback: truedetailing target epicentre, expected collapse counts, and pool capacities before triggering WebGL draw loops.
Diagnostic Coaching & Evaluation Scorecard
| Evaluation Dimension | Pass Criterion (100%) | Failure Mode / Trap |
|---|---|---|
| Coordinate Space | Grid snapped to Web Mercator tile boundaries; cell resolution computed in map metres. | Drawing simulation on a floating screen-space canvas overlay. |
| Elevation Decoding | Terrarium or Terrain-RGB decoded to 1D Float32Array; median filter removes sensor spikes. | Unfiltered synthetic elevations or non-georeferenced terrain. |
| Canvas Source Flags | animate: true, "raster-resampling": "linear", "raster-fade-duration": 0. |
Missing animate: true freezes texture on frame 1; default fade smears fluid. |
| Feature Scaling | Dedicated GeoJSON source with promoteId: "i" driving feature-state k multiplier. |
Calling setFeatureState directly on vector tiles (silent no-op). |
| WebGL 3D Context | renderingMode: "3d", shared depth buffer, frustumCulled = false, pre-allocated instanceColor. |
Debris vanishing when panning, or black instances from count=0 buffer. |
| Camera Shake | CSS container transform with buildup/decay envelope and frequency chirp. | Shaking map camera directly, triggering tile re-fetch stutter. |
Anti-Patterns
- Screen-Space Water Overlays — Drawing ground fluids onto a separate canvas above the map instead of attaching an offscreen canvas as a native map raster source.
- Silent Feature-State Vector Calls — Calling
map.setFeatureState()directly against Mapbox Streets vector tile sources without copying to a GeoJSON source withpromoteId. - Zero-Count Instance Color Allocation — Allowing Three.js to lazily allocate
instanceColorwhenmesh.count === 0, causing all instanced debris pieces to render black. - Unchecked Camera Frustum Culling — Leaving
frustumCulled = trueon Three.js custom layer meshes when using a bare camera injected with Mapbox's projection matrix. - Direct Camera Jitter Shaking — Shaking the map view via rapid camera
easeTocalls, causing severe tile thrashing and stutter instead of shaking the DOM container. - Missing Trigger Repaint Invariant — Updating Three.js objects in memory without calling
map.triggerRepaint(), leaving the screen unrefreshed when the map is stationary. - Sky Layer Depth Occlusion — Enabling
map.setSky()alongside arenderingMode: "3d"custom layer, causing the sky to write to the depth buffer and occlude 3D objects. - Alpha Channel Palette Quantization — Quantizing sprite PNGs with palette compression, reducing 256 alpha levels to 24 and creating artificial tile-boundary staircasing.
- Continuous Ambient Dust Haze — Spawning continuous ambient dust clouds instead of event-driven bursts tied strictly to structural impact moments.
- Bypassing Vector Tile Load Holds — Diving the camera directly to zoom 16 without waiting for
map.areTilesLoaded(), causing buildings to fail to spawn.
04 同仓库更多 Skills
ui-behavior-primitive-architect
Architect, audit, and verify zero-dependency headless UI behavior primitives, WebMCP agent bridges, WAI-ARIA/SSR/RTL tri-modal checks, and framework expert routing. Do not use for static CSS theme styling or backend database migrations.
trustgraph-ontology-governor
Govern knowledge graphs, SHACL-AF triple policies, OntologyRAG subclass validation, PROV-O dual named graphs, and Laya entropy decision scoring. Do not use for relational SQL queries or generic web scraping.
shim-harness-governor
Govern universal CLI agent loops, 4-tier tool permissions, ancestor-symlink workspace sandboxes, deterministic-first command routing, collision-safe MCP namespacing, and layered skill loading. Do not use for static UI styling or external SQL analytics.
graphiti-zep-memory-governor
Govern bi-temporal knowledge graphs with Graphiti future-edge clamping, MinHash/LSH entity dedup, RRF/MMR reranking, and Zep typed ontologies. Do not use for static SQL joins or generic web crawling.
agora-mcp-workbench-architect
Architect, audit, and orchestrate Agora Workbench MCP servers, loopback sidecars, unified state graphs, gateway/dispatcher connectors, and policy-enforced data lakes. Do not use for static frontend CSS styling or non-MCP desktop GUI automation.
skill-eval-assurance-runner
Evaluate and assure agent skills using small-N Wilson confidence intervals, unbiased pass^k reliability, deterministic trajectory graders, preflight boundary honesty, and sealed digest verification. Do not use for subjective prose review or unconstrained production deployment.