FERRETGame engine over Babylon.js
Ferret

@ferret/weather

The weather and what it does: states and presets, clouds by genus, rain, snow and hail, lightning and thunder, blizzards; the storm sea with whitecaps and freak waves, the surf on sand, cobble, boulder and rock shores; rivers with rapids and waterfalls; wind on trees (sway, limbs, snapping, uprooting) and on grass; sand and dust storms, haboobs, the simoom; tornadoes, dust devils and waterspouts.

241 exports · source in packages/weather/src

Classes

FunnelView class

class FunnelView

A tornado, dust devil or waterspout as a funnel mesh (rings of vertices whose radius is the funnel's at each height, leaning with the track) with debris orbiting it in the swirl and a dust skirt at the foot. One per whirl in the service; made when the whirl appears and removed with it.

readonly rings: 24
readonly seg: 20
constructor(private scene: BABYLON.Scene, private weather: WeatherService)
update(dt: number)
get count()
dispose()

packages/weather/src/view.ts:959

GrassView class

class GrassView

Grass you can walk in and see the wind run over: thousands of tufts (thin instances of one mesh of tapering blades) in a ring about the camera, which stay where they are in the world and are handed on as the camera moves. The wave is grassWave sampled on a grid of 1.5 m cells about the camera and read by the vertex shader from a texture: each tuft leans downwind by the gust at its place and straightens up behind it, shivers in a stronger wind, and the front of the gust is lighter.

readonly mesh: BABYLON.Mesh
drawn: numberhow many tufts are drawn now
constructor(private scene: BABYLON.Scene, private weather: WeatherService, o: GrassViewOptions = {})
setSnow(cover: number)Snow on the ground, 0 none .. 1 buried: the tufts the snow covers drop out (a few stand out of it), and the rest are dusted white.
setLight(sunCol: V3, fogCol?: V3, fogDensity?: number)the light of the picture: the colour the grass takes from the sun and the sky, and the fog
update()
dispose()

packages/weather/src/view.ts:731

Grove class

class Grove

A set of trees stepped together; events collects the damage.

readonly trees: Tree[]
constructor(public seed = 0)
add(x: number, z: number, species: string | TreeSpecies, scale = 1): Tree
step(dt: number, s: WeatherState, t: number, extra?: (tree: Tree) => number): TreeEvent[]
count(kind: TreeDamage): number

packages/weather/src/vegetation.ts:272

LightningView class

class LightningView

The bolts: on each weather:lightning event a jagged path from the cloud to the ground (to the struck thing if there is one) is drawn as lines that flicker with the strokes and are gone with the flash; sky is the brightness (0..1) of the flash now, for the sky and the light of the scene to use.

sky: number
constructor(private scene: BABYLON.Scene, private weather: WeatherService)
update()
dispose()

packages/weather/src/view.ts:922

ParticleCloud class

class ParticleCloud

A pool of billboard quads in one mesh with simple ballistics, for spray, mist, splashes and dust.

readonly mesh: BABYLON.Mesh
active: number
gravity: number
drag: number
color: [number, number, number]
alpha: number
wind: [number, number]
constructor(scene: BABYLON.Scene, readonly max = 600, name = 'particles')
emit(p: V3, v: V3, size: number, life: number, grow = 0, alpha = 1, stretch = 0)Emits one particle: position, velocity (m/s), size (m), life (s), growth (m/s of size), its own opacity 0..1, and stretch (s: the streak a drop leaves in that time of its flight, 0 for a round puff).
update(dt: number, right: V3 = [1, 0, 0], up: V3 = [0, 1, 0])right and up are the camera's axes, so the quads face it.
dispose()

packages/weather/src/view.ts:177

PrecipView class

class PrecipView

Rain, snow, hail and sleet as streaks in a box around the camera. A particle's place is a function of its number and the time, wrapped in the box, so there is no state; the streak leans in the wind and is as long as the particle moves in a frame's exposure. Snow wanders; rain stays crisp; the count follows the weather.

readonly mesh: BABYLON.Mesh
count: number
constructor(private scene: BABYLON.Scene, private weather: WeatherService, private o: { max?: number; box?: number; height?: number } = {})
update()
dispose()

packages/weather/src/view.ts:854

River class

class River

A river of reaches and waterfalls, sampled at a point.

constructor(public reaches: Reach[], public falls: Waterfall[] = [], public seed = 0)
segment(reach: number, i: number, q?: number): { h: Hydraulics; slope: number; len: number }The hydraulics of segment i of a reach at a discharge.
sample(p: V3, t = 0, scale = 1): RiverPoint | nullThe water at a place: null if there is no river within reach metres.
fallStates(scale = 1): Array<{ fall: Waterfall; state: FallState }>The waterfalls with their numbers at a discharge scale.
sources(scale = 1, path = 'river'): ChannelSource[]The sources for the flow package: every reach as channels, at the discharge scale.
loudnessAt(p: V3, scale = 1): numberThe loudest water within hearing of a point: 0..1 by the roar and the distance (sound falls with distance, a waterfall is heard farther).

packages/weather/src/river.ts:190

RiverView class

class RiverView
readonly meshes: BABYLON.Mesh[]
readonly mist: ParticleCloud
get scale()the discharge scale now drawn
constructor(private scene: BABYLON.Scene, readonly river: River, private o: RiverViewOptions = {})
setLight(sunDir: V3, sky?: V3, sun?: V3)the light the water reflects
setBed(c: V3)the colour of the bed seen through the shallows
update(t: number, dt: number, wind: [number, number] = [0, 0])Call every frame: the water moves, the mist rises. t is the world time.
fallStates(): FallState[]the numbers of every fall now (the discharge scale applied)
dispose()

packages/weather/src/river-view.ts:80

SandstormView class

class SandstormView
readonly saltation: ParticleCloud
readonly streaks: ParticleCloud
readonly billows: ParticleCloud
storm: SandStorm | nullthe storm at the camera as of the last update
constructor(readonly scene: BABYLON.Scene, readonly o: SandstormViewOptions)
static fogDensity(visibility: number): numberThe air at the camera: the fog density that gives the visibility v (the contrast of a dark target is 2 % at that distance: exp2 fog, density = sqrt(3.912) / v).
update(camera: V3, right: V3, up: V3, dt: number, t: number): SandStormCall once a frame with the camera and the frame time. t is the simulated time.
dispose(): void

packages/weather/src/sandstorm-view.ts:29

SeaSurface class

class SeaSurface

The surface of the sea as the weather makes it: the wave components of the wind (the Pierson-Moskowitz sea), the freak waves the weather announced, and the shoaling of every component on the bathymetry. It is a pure function of the weather's state and the time, so every peer's ships float on the same water. Rebuilt when the wind, its direction or its gustiness change.

readonly level: number
constructor(private readonly weather: Pick<WeatherService, 'state' | 'rogue'>, o: { level?: number; depth?: (x: number, z: number) => number; waves?: Wave[] } = {})
height(x: number, z: number, t: number): numberthe water surface height at a world point, m
velocity(x: number, z: number, t: number): V3the orbital velocity of the water at the surface, m/s
foam(x: number, z: number, t: number): numberhow much the crest breaks here, 0..1
fn(): (x: number, z: number, t: number) => numberthe (x, z, t) => y that ships ride (vehicles().surface)

packages/weather/src/bridge.ts:169

SnowView class

class SnowView
constructor(private scene: BABYLON.Scene, meshes: BABYLON.AbstractMesh[], private o: SnowViewOptions = {})
get coverage()0..1 of the ground covered now (the depth over full)
setLight(sunDir: [number, number, number], sunCol: [number, number, number], sky: [number, number, number])the light the snow takes
update(depth: number, wind: number, t: number)Call every frame with the depth of snow (m), the wind (m/s) and the clock.
dispose()

packages/weather/src/snow-view.ts:52

SurfView class

class SurfView
readonly mesh: BABYLON.Mesh
readonly spray: ParticleCloud
readonly lip: BABYLON.Meshthe overhanging lips of the breaking waves: up to LIPS crests along each column, a loop of LIP_M points round the section of each lip (outer sheet, then inner back)
setLight(sunDir: V3, sky?: V3, sun?: V3)the light the water reflects: the direction to the sun, the sky and the sun's colours
setBed(c: V3)the colour of the bed seen through thin water (sand, stones)
onBreak?: (strength: number, kind: Surf['shore']['kind'], at: V3) => voidcalled when a wave breaks on the shore with its strength 0..1 (for the sound)
constructor(private scene: BABYLON.Scene, public surf: Surf, private o: SurfViewOptions)
at(a: number, x: number, y = 0): V3A point on the shore: m along the shore a and m seaward x; y is the height.
update(t: number)
wet: numberhow wet the rock and boulders above the water are 0..1: soaked by a plume, drying over half a minute (see WetSurfaces)
updateParticles(dt: number, state?: WeatherState)
get lastBreakTime()
dispose()

packages/weather/src/view.ts:323

Tree class

class Tree

A tree standing in the wind: a damped oscillator that is driven by the load of the wind, the lean (radians, the top away from the vertical) it gives, and the damage the gusts do. Branches and twigs go first (the thresholds are fractions of the trunk's), then limbs, then the trunk or the roots. Deterministic: a tree's strength is from its id, and whether a gust breaks a twig is a hash of the tree and the moment.

readonly sp: TreeSpecies
readonly scale: number
readonly strength: number
lean: numberthe lean along the wind and across it (radians), and their speeds
leanV: number
side: number
sideV: number
damage: TreeDamage
crown: numberthe share of the crown still on the tree 0..1 (limbs and twigs lost take it down)
leaves: numberthe share of leaves still on 0..1 (a gale strips them)
fallen: numberthe fall: angle from vertical (rad), 0 standing, PI/2 on the ground
constructor(readonly id: number, readonly x: number, readonly z: number, species: string | TreeSpecies, scale = 1, readonly seed = 0)
restore()Stand the tree up whole again: no damage, the crown and leaves back, at rest.
get height()
get frequency()
get standing()
crownWind(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness'>, t: number): numberThe wind at the crown now, m/s.
step(dt: number, s: WeatherState, t: number, extra = 0): TreeEvent[]Move on by dt seconds under the state at time t. Returns the damage events of the step (0 or 1). The oscillator is driven by the static lean the instant wind would give: lean = F h^2 / (3 E I) / h at the tip, which saturates (a tree is not bent more than a radian before it goes).
fallTime(): numberThe time a tree of this size takes to fall flat from a lean of 0.1 rad, s (the pendulum law, for the sounds and the warning).
get fallDirection()The direction the tree falls (degrees); valid after it fell.
topOffset(windDir: number): { x: number; z: number }The lean of the top as an offset (m) along the wind and across, for the drawing.

packages/weather/src/vegetation.ts:145

TreeDebris class

class TreeDebris
constructor(private readonly host: PhysicsLike, private readonly weather: WeatherService, private readonly o: { ground?: (x: number, z: number) => number; max?: number; density?: number; sea?: SeaSurface; trunk?: TrunkHook; flight?: number } = {})
get count()
get settled()the limbs that fell and came to rest: they leave the simulation (a stick on the ground costs nothing) and stay where they lie
get trunkCount()
get bodies(): ReadonlyArray<{ id: number; position: V3; radius: number; kind: string }>the limbs lying or falling now: for a view to draw
update()call every step: lay the trunks of felled trees, lift them when the tree is restored, drop limbs that are gone
dispose()

packages/weather/src/bridge.ts:290

TreesView class

class TreesView

Moves the trees of a WeatherService's grove. Near the camera: the trunk leans (a share of the lean on the trunk and a larger share on the crown, which makes a bend), the crown rocks across the wind, every limb sways at its own frequency (a long limb slowly and widely, a twig quickly), every leaf cluster shivers at the flutter frequency of the wind that blows through the crown right then, in its own phase; in a gust it all grows. A fallen tree goes over by its fall angle, a snapped one keeps its stump.

readonly rigs: TreeRig[]
moved: { leaves: number; limbs: number; trunks: number; }how many leaf nodes and limbs were moved in the last frame (the budget made visible)
constructor(private scene: BABYLON.Scene, private weather: WeatherService, o: TreesViewOptions = {})
bind(rig: TreeRig): TreeRig
restoreAll()Every tree whole and standing again (the fallen ones rise, the limbs they lost come back).
static tilt(angle: number, deg: number): BABYLON.QuaternionThe quaternion of a tilt by angle (rad) towards the heading deg (degrees, 0 = +x, 90 = +z).
update(dt: number)
dispose()

packages/weather/src/view.ts:51

WeatherPhysics class

class WeatherPhysics

The service that keeps the physics in step with the weather. Register it after the PhysicsHost and the WeatherService.

readonly name: "weather.physics"
readonly debris?: TreeDebris
constructor(private readonly host: PhysicsLike, private readonly weather: WeatherService, private readonly o: WeatherPhysicsOptions = {})
init()
fixedUpdate()
dispose()

packages/weather/src/bridge.ts:368

WeatherService class

class WeatherService implements Service
readonly name: "weather"
world: World
state: WeatherState
readonly area: [number, number, number, number]
readonly seed: number
readonly grove: Grove
shore: ShoreSpec
shoreAngle: number
sand: Sand
seaOpen: boolean
river: River | undefined
strikeTargets: StrikeTarget[]the trees, the thunder and the whirls the service watches
snow: numberthe depth of snow on the ground, m
whirls: Whirl[]the whirls now known (made by the state and by commands)
haboob: Haboob | null
rogue: RogueWave[]
constructor(o: WeatherOptions = {})
init(world: World)
set(preset: string | Partial<WeatherState>, over: Partial<WeatherState> = {}): void
blendTo(preset: string | Partial<WeatherState>, seconds = 60, over: Partial<WeatherState> = {}): void
fixedUpdate(): voidCalled before the components' fixed update, at the fixed rate.
targets(): StrikeTarget[]The things lightning can hit: the targets given plus every standing tree.
whirlBoost(x: number, z: number, y: number, t: number): numberThe extra wind (m/s) of the whirls at a place.
spawnWhirl(kind: VortexKind, x: number, z: number, strength = 0.7, seconds?: number): WhirlStarts a whirl now at a place with a strength 0..1 (0.5 is an EF2-ish tornado).
deck(): CloudLayer[]
cloudField()The clouds package takes cover and wind.
waves(): Wave[]The waves of the sea for the water shader.
foliageWind(x = 0, z = 0)
surf(shore?: ShoreKind, angle?: number): Surf
sample(p: V3): WeatherSample
report(): string
dispose(): void

packages/weather/src/service.ts:80

WetSurfaces class

class WetSurfaces
constructor(meshes: BABYLON.AbstractMesh[])
set(wet: number)0 dry .. 1 soaked

packages/weather/src/view.ts:632

Functions

airDensity function

function airDensity(tempC: number, altitude = 0): number

the density of dry air at a temperature (C) and altitude (m): ideal gas, standard lapse

packages/weather/src/common.ts:46

anvilOf function

function anvilOf(s: WeatherState, layer: CloudLayer, cell: CloudCell): { x: number; z: number; length: number; width: number; height: number } | null

The anvil of a cumulonimbus cell: a flat plume at the top, blown downwind by the winds up there, so its length is the wind speed times how long the tower has been pushing out.

packages/weather/src/clouds.ts:199

bathymetry function

function bathymetry(ground: GroundLike): (x: number, z: number) => number

The depth of the water at a place, m (0 on land): what the waves shoal and break on.

packages/weather/src/bridge.ts:105

beaufort function

function beaufort(wind: number): number

The Beaufort force (0..12) of a wind speed (m/s).

packages/weather/src/state.ts:56

bedOfSlope function

function bedOfSlope(slope: number): BedKind

The bed a reach has from the steepness of its slope (a pool is smooth, a torrent is boulders).

packages/weather/src/bridge.ts:117

blend function

function blend(a: WeatherState, b: WeatherState, k: number): WeatherState

The state between two states: numbers blend, directions blend along the short way round.

packages/weather/src/state.ts:94

blizzard function

function blizzard(s: Pick<WeatherState, 'wind' | 'looseSnow' | 'temperature' | 'precipitation' | 'freezingLevel'>): Blizzard

Blowing snow: snow lifts when the wind friction passes the threshold, flies in hops (saltation) and in suspension, and the air fills with it. The transport follows Bagnold's cubic law with the snow threshold (friction velocity 0.25 m/s fresh and dry, rising with age and warmth), the concentration is the transport over the speed and depth of the layer, and the visibility from the extinction of ice grains of 100 micron (3 C / 2 rho d for the mass concentration C). Falling snow adds to the extinction.

packages/weather/src/storm.ts:205

boltPath function

function boltPath(from: V3, to: V3, seed: number, o: { levels?: number; roughness?: number; branches?: number } = {}): { main: V3[]; branches: V3[][] }

The shape of a bolt: points from the cloud to the ground by midpoint displacement (the jagged line), with side branches. Deterministic from the seed. from is in the cloud, to on the ground; roughness 0..1.

packages/weather/src/storm.ts:145

boulderWaves function

function boulderWaves(reach: Reach, seed = 0, perHundred = 6): Array<{ x: number; z: number; size: number }>

A hash-seeded pair of stones in the rapids: positions where standing waves form behind boulders (for the drawing of white patches).

packages/weather/src/river.ts:260

branchFrequency function

function branchFrequency(len: number): number

The sway of a twig (Hz): a thin shoot of length len m rocks at ~ 1 / len^1.5 (a 0.5 m twig 3 Hz, a 3 m branch 0.5 Hz...). Branches sway lower and larger.

packages/weather/src/vegetation.ts:124

cellRain function

function cellRain(distance: number, radius: number, behind: boolean): number

The rain of a cell for a point under a moving storm: 0..1 of the rate at the centre, a gaussian core with a stronger front edge (a squall line leads with the heaviest rain).

packages/weather/src/precip.ts:144

channelSources function

function channelSources(r: Reach, q = r.q, path = 'river'): ChannelSource[]

The reach as a flow channel the flow package reads: one source per segment with the speed from Manning; turbulence is made by the readers.

packages/weather/src/river.ts:177

clamp function

function clamp: (v: number, lo?: number, hi?: number) => number

packages/weather/src/common.ts:9

cloudCells function

function cloudCells(s: WeatherState, layer: CloudLayer, area: [number, number, number, number], t: number, seed = 0): CloudCell[]

The cells of a heap layer (cumulus, cumulonimbus) in a square of the world at time t: a grid of places, each with a hashed life. A cell is born, its tower rises, a mature cell (a cumulonimbus) rains and spreads its anvil, and it dies and spreads thin; the cell travels with the wind of its height, and cells of the same layer are many (cover). area is [minX, minZ, maxX, maxZ]. Cells drift: the grid moves with the layer.

packages/weather/src/clouds.ts:165

cloudDeck function

function cloudDeck(s: WeatherState): CloudLayer[]

The layers of the sky for a state: from the ground up, each with its kind, height and cover. Fair weather has cumulus humilis and a high veil of cirrus; a warm moist air that rises makes towering cumulus and, when the rise is strong, cumulonimbus with an anvil; a steady rain comes from nimbostratus under altostratus; a cold damp overcast is stratus or stratocumulus; the signs of an approaching front are cirrus then cirrostratus then altostratus.

packages/weather/src/clouds.ts:68

cloudFieldFor function

function cloudFieldFor(s: WeatherState): { cover: number; wind: (height: number, t: number) => [number, number] }

The options for the clouds package's CloudField: its cover and a wind per height from this state. Add the layers it supports (cumulus, cirrus, stratus).

packages/weather/src/clouds.ts:221

conjugateDepth function

function conjugateDepth(h1: number, froude: number): number

The depth after a hydraulic jump (the conjugate depth), m: h2 = h1 (sqrt(1 + 8 Fr^2) - 1) / 2. Only for supercritical flow, Fr > 1.

packages/weather/src/river.ts:39

crestLean function

function crestLean(sv: Pick<Surf, 'breaker'>, steep: number, eta: number, foam: number): number

How far (m) a point of the surface moves shoreward as the water rises: the crest leans over the trough in front of it. For a plunging breaker the lean is more than the width of the front, so the surface folds over itself into a barrel.

packages/weather/src/shore.ts:164

crestPlume function

function crestPlume(ustar: number, duneHeight: number, s: Sand = DUNE_SAND): { length: number; density: number }

The plume of sand blown off a dune crest (m): the wind speeds up over the crest and lifts the grains; the plume's length along the wind.

packages/weather/src/desert.ts:150

crestSpray function

function crestSpray(c: SeaCondition, windSpeed: number): number

The spray a wave of height h throws up where a crest breaks in a wind: a plume that the gale blows flat. Height of the plume above the crest, m.

packages/weather/src/sea.ts:191

criticalWind function

function criticalWind(sp: TreeSpecies, mode: 'trunk' | 'root', o: { scale?: number; leaves?: boolean; soilWetness?: number; strength?: number } = {}): number

The wind speed at the crown (m/s) at which a tree fails by trunk snapping or root uprooting: found by bisection on treeLoad.

packages/weather/src/vegetation.ts:95

crownArea function

function crownArea(sp: TreeSpecies, scale = 1, leaves = true): number

The crown's frontal area (m^2) with or without leaves.

packages/weather/src/vegetation.ts:68

damageFor function

function damageFor(speed: number): string

What the wind does to things at a speed: the first thing that gives way.

packages/weather/src/tornado.ts:43

deg function

function deg: (r: number) => number

packages/weather/src/common.ts:12

dirVec function

function dirVec: (degrees: number) => [number, number]

the unit vector a direction in degrees points along (0 = +x, 90 = +z: the axes of the waves package and the flow fields)

packages/weather/src/common.ts:40

discharge function

function discharge(base: number, rainRate: number, soilWetness: number, area = 20, hours = 1): number

The discharge after rain: a base flow plus the runoff of rain on wet soil, with the catchment's size area (km^2) turning the rain into the flow.

packages/weather/src/river.ts:168

driftGrowth function

function driftGrowth(b: Blizzard, shelter: number): number

The drift of snow across the ground, m/h of height (negative: the snow is stripped). Where the wind drops (shelter 1 = dead calm behind a wall, 0 = open ground) the transport can no longer be carried and settles over the length of the wind shadow (about 20 m) as wind-packed snow (350 kg/m^3): rate = q shelter / (rho L); open ground loses a quarter of that to the wind, since the snow that leaves it is replaced from upwind.

packages/weather/src/storm.ts:235

driveFoliageWind function

function driveFoliageWind(handle: { setWind(w: { intensity?: number; direction?: [number, number] }): void }, weather: WeatherService, scene: BABYLON.Scene)

The foliage-wind rules' wind, drawn from the weather at the camera: call each frame with the handle of applyFoliageWind so that every tree and bush with that shader shivers in the local gust.

packages/weather/src/view.ts:1023

dropFallSpeed function

function dropFallSpeed(d: number): number

The fall speed of a raindrop (m/s) of D mm in still air (Atlas et al.): 9.65 - 10.3 exp(-0.6 D), and Stokes' law for the smallest.

packages/weather/src/precip.ts:38

dropSeed function

function dropSeed(i: number, seed = 0): V3

A hash-based draw for particle positions in a view that wraps (the same drops on every peer): x, y, z each 0..1 for particle i.

packages/weather/src/precip.ts:151

dropSpectrum function

function dropSpectrum(rate: number): { n0: number; lambda: number }

Marshall-Palmer: the number of drops per m^3 per mm of diameter, N(D) = N0 exp(-L D), with N0 = 8000 and L = 4.1 R^-0.21 per mm.

packages/weather/src/precip.ts:30

duneSpeed function

function duneSpeed(ustar: number, h: number, s: Sand = DUNE_SAND): number

The speed at which a dune of height h migrates (m/s): c = Q / (rho_bulk h); a 10 m dune in a strong wind moves 10 m a year to hundreds.

packages/weather/src/desert.ts:112

dustAtHeight function

function dustAtHeight(storm: Pick<SandStorm, 'concentration' | 'dustHeight'>, height: number): number

A grain-size dependent dust ceiling check used by the views: the fraction of the wind column that is dust at a height, falling off with the scale height of the dust.

packages/weather/src/desert.ts:216

dustDevilChance function

function dustDevilChance(s: Pick<WeatherState, 'temperature' | 'wind' | 'cloudCover' | 'dustiness' | 'precipitation'>): number

The chance per ten minutes of a dust devil in a box: hot calm sunny ground.

packages/weather/src/tornado.ts:173

dynamicPressure function

function dynamicPressure(u: number, rho = 1.225): number

The wind pressure (Pa) on a flat surface at speed u: q = 0.5 rho u^2.

packages/weather/src/wind.ts:54

efOf function

function efOf(speed: number): number

The EF class (-1 for less than 29 m/s) of a wind.

packages/weather/src/tornado.ts:36

faceShare function

function faceShare(sv: Pick<Surf, 'breaker'>): number

The share of a wave's period that its steep front takes: a spilling breaker has a long front, a plunging one throws its crest forward from a front that is nearly a wall.

packages/weather/src/shore.ts:149

fall function

function fall(s: Pick<WeatherState, 'precipitation' | 'temperature' | 'freezingLevel' | 'convection' | 'thunder'>): Fall

The rain, snow or hail that falls: size, speed, number in the air, visibility, the sound. Snow is described by its rate in water equivalent: dry snow flakes are a few mm across and fall at about 1 m/s, wet snow flakes are bigger and fall at about 2 m/s; graupel is 2-5 mm and falls at 2-3.5 m/s; hail is 0.5-6 cm.

packages/weather/src/precip.ts:76

fallVelocity function

function fallVelocity(f: Fall, windX: number, windZ: number, swirl = 0, t = 0, seed = 0): V3

The velocity of a falling particle at the ground for a state: the wind carries it sideways at the wind speed near the ground (a drop reaches the wind's speed in a fraction of a second; a light flake in a tenth), and it falls at its speed. gust 0..1 adds the swirl of turbulence.

packages/weather/src/precip.ts:117

flashDistance function

function flashDistance(delay: number, tempC = 15): number

The distance (m) a thunder delay means: the old count of seconds to the kilometre.

packages/weather/src/storm.ts:120

flashes function

function flashes(s: Pick<WeatherState, 'thunder'>, t0: number, t1: number, centre: [number, number] = [0, 0], radius = 6000, seed = 0): Flash[]

The flashes that begin within [t0, t1) of a storm centred on (cx, cz) with a radius (the cell). The schedule is a hashed grid of time slots of one second: each slot has a flash with probability rate/60, so the times and places are a function of the clock. Four of five flashes are inside the cloud, one of five (more over flat ground) reaches the ground; ground flashes are placed in the cell, more near its centre and its rain core.

packages/weather/src/storm.ts:49

flashLight function

function flashLight(f: Flash, t: number): number

How bright the sky is from a flash at time t (0..1): the strokes flicker with a quick decay, the rest of the flash glows.

packages/weather/src/storm.ts:77

flashRate function

function flashRate(thunder: number): number

Flashes per minute for the activity of a storm (0..1): from a flash every few minutes to one every two or three seconds.

packages/weather/src/storm.ts:39

floatOnSea function

function floatOnSea(host: PhysicsLike, sea: SeaSurface, body: { position: V3; velocity: V3 }, o: { radius: number; Cd?: number; density?: number }): () => void

Let a body float on the sea: buoyancy from the part of a sphere of radius under the wave at the body, drag against the water's orbital motion. Returns the function that stops it.

packages/weather/src/bridge.ts:255

foamAt function

function foamAt(c: SeaCondition, x: number, z: number, t: number, crest = 0.5, wind: [number, number] = [1, 0]): number

Whitecaps at a point: 0..1 of foam density. Patches follow the crests: a hashed field of patches advected with the waves, whose coverage is the sea's whitecaps fraction, with a fixed life (a breaking crest leaves foam for about 10 s that thins out). crest is the local wave height above the mean (0..1 of the highest), so foam sits on the high water.

packages/weather/src/sea.ts:179

foliageWind function

function foliageWind(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness'>, t = 0, x = 0, z = 0): { intensity: number; direction: [number, number] }

The wind that Unreal's foliage-wind rules read, for a state: intensity (Beaufort 4 is about 1) and the direction in Unreal's (x, y).

packages/weather/src/vegetation.ts:320

frictionVelocity function

function frictionVelocity(u10: number, z0 = 0.0004): number

The friction velocity u* (m/s) of a wind U10 at 10 m over a surface of roughness z0: the log law, U = (u* / kappa) ln(z / z0).

packages/weather/src/desert.ts:28

frontPosition function

function frontPosition(h: Haboob, t: number): { x: number; z: number }

Where the front is at time t: the distance (m) along its direction from the starting point.

packages/weather/src/desert.ts:175

funnelRadius function

function funnelRadius(w: Whirl, now: WhirlNow, h: number): number

The radius of the visible funnel at a height h above the ground (m): narrow at the ground (the debris cloud is wider), widening up to the cloud base.

packages/weather/src/tornado.ts:132

grassWave function

function grassWave(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness'>, x: number, z: number, t: number, o: { stiffness?: number; seed?: number } = {}): GrassBlade

The wave on the grass: where a gust passes, the grass bends over and straightens up behind it; the pattern is the gust pattern of the wind, moving with it. Tall soft grass (stiffness low) lies down at a wind where short coarse grass only shivers. The result is a function of the place and the time, the same on every peer.

packages/weather/src/vegetation.ts:305

gustFactor function

function gustFactor(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness'>, x: number, z: number, t: number, seed = 0): number

The gust factor: how much the wind at a point differs from the mean now, 1 = the mean. Patches of 30..200 m move with the wind; strength follows the gustiness.

packages/weather/src/wind.ts:10

haboobAt function

function haboobAt(h: Haboob, x: number, z: number, t: number): { concentration: number; top: number; gust: number; behind: number }

The dust of a haboob at a point at time t: concentration in g/m^3 (the wall leans forward: the dust is densest just behind the front and thins to the back), the height of the top of the dust there, and the wind jump at the front (the outflow gust, m/s). A point ahead of the front sees none.

packages/weather/src/desert.ts:185

haboobOf function

function haboobOf(s: Pick<WeatherState, 'wind' | 'windDir' | 'dustiness'>, x0: number, z0: number, t0 = 0): Haboob

A haboob from a thunderstorm's outflow: the front runs at the speed of the outflow (a good 1.3 of the mean wind), and its wall is 1 to 2 km high.

packages/weather/src/desert.ts:169

hailFallSpeed function

function hailFallSpeed(dcm: number): number

The fall speed of a hailstone of D cm: terminal velocity with drag coefficient 0.6 and the density of ice (917 kg/m^3).

packages/weather/src/precip.ts:44

hash function

function hash(a: number, b = 0, c = 0, d = 0): number

an integer hash to 0..1 (the same on every peer and every start)

packages/weather/src/common.ts:16

layerOffset function

function layerOffset(s: WeatherState, layer: CloudLayer, t: number): [number, number]

Where a layer's pattern is at time t: it has drifted along the wind at the layer's middle height (the mean wind, so any two peers agree at any time).

packages/weather/src/clouds.ts:141

leafFlutter function

function leafFlutter(sp: TreeSpecies, u: number): { frequency: number; amplitude: number; silver: number }

The leaf's flutter: frequency (Hz, from a Strouhal number of 0.2 on the leaf width, kept to what the eye sees) and amplitude 0..1 (still below 0.5 m/s, full at gale).

packages/weather/src/vegetation.ts:114

lerp function

function lerp: (a: number, b: number, k: number) => number

packages/weather/src/common.ts:10

lifted function

function lifted(speed: number): Debris[]

The things that the wind at a point lifts, lightest first.

packages/weather/src/tornado.ts:74

liftSpeed function

function liftSpeed(mass: number, area: number, cd = 1.0, hold = 1): number

The slowest wind (m/s) that lifts an object of mass m (kg) and frontal area a (m^2) with drag coefficient cd: drag on it equals the weight times hold, how much more than its weight keeps it where it is (1 for a loose thing, 3 for a branch on its tree, 8-12 for tiles, fences and roofing nailed down).

packages/weather/src/tornado.ts:59

longshoreDir function

function longshoreDir(shoreNormalDeg: number, angle: number): [number, number]

The direction a longshore current runs: along the shore, given the shore's normal direction (degrees, towards the sea), +90 or -90 as the waves come.

packages/weather/src/shore.ts:243

makeWhirl function

function makeWhirl(kind: VortexKind, s: Pick<WeatherState, 'wind' | 'windDir'>, t0: number, area: [number, number, number, number], r: number, seed = 0): Whirl

Makes one whirl: r is a draw 0..1 that sets its strength (the rare strong ones).

packages/weather/src/tornado.ts:209

manning function

function manning(q: number, width: number, slope: number, n: number = BED.gravel): Hydraulics

The uniform flow of a rectangular reach: the depth at which Manning's v = R^(2/3) S^(1/2) / n carries the discharge Q (m^3/s) through a channel width wide on a bed of slope slope (tan). Solved by bisection; a dry or flat bed gives no flow.

packages/weather/src/river.ts:28

meanDropDiameter function

function meanDropDiameter(rate: number): number

The mean drop diameter (mm) of rain at a rate: 1 / lambda. Drizzle is 0.2-0.5 mm, a downpour 2 mm and more.

packages/weather/src/precip.ts:35

noise1 function

function noise1(t: number, seed = 0): number

1D smooth noise in time, -1..1

packages/weather/src/common.ts:34

noise3 function

function noise3(x: number, y: number, t: number, seed = 0): number

smooth value noise in 2D and time, -1..1

packages/weather/src/common.ts:23

precipKind function

function precipKind(s: Pick<WeatherState, 'precipitation' | 'temperature' | 'freezingLevel' | 'convection' | 'thunder'>): PrecipKind

What falls at the ground. rate is mm of water per hour. Above freezing at the ground and in the whole column it is rain (drizzle under 1 mm/h, a shower when the air rises hard); a freezing level below the ground is snow; a thin warm layer between is sleet; a deep convective storm with a cold top throws hail when the rise is violent and graupel when it is merely strong and cool.

packages/weather/src/precip.ts:15

pressureDrop function

function pressureDrop(vmax: number, rc: number, r: number, rho = RHO_AIR): number

The pressure drop below the surrounding air (Pa) at radius r: the cyclostrophic balance, 2 rho vmax^2 / (1 + s^2). At the centre of an EF4 it is ~ 100 hPa.

packages/weather/src/tornado.ts:19

rad function

function rad: (d: number) => number

packages/weather/src/common.ts:13

regime function

function regime(h: Hydraulics, slope: number, bed: BedKind): Regime

What the water looks like: a pool is smooth and slow, a run is glassy, a riffle ripples, rapids are white, a cascade is a torrent over steps.

packages/weather/src/river.ts:46

ripCurrent function

function ripCurrent(sv: Surf, y: number, seed = 0): number

Rip currents: narrow seaward flows through the surf zone every few tens of metres, m/s outward at the position y along the shore (Gaussian jets, 0 when the surf is small).

packages/weather/src/shore.ts:248

rippleHeight function

function rippleHeight(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness'>, x: number, z: number, t: number, sand: Sand = DUNE_SAND, seed = 0): number

The height of the rippled surface (m) at a point and time: a field of crests at a right angle to the wind that creep along; the ripple pattern gets bigger and sharper with the u*, irregular in length (a line of ripples forks). Zero below the threshold wind (the old ripples stay, as they were, at the weakest).

packages/weather/src/desert.ts:118

rippleSpeed function

function rippleSpeed(ustar: number, s: Sand = DUNE_SAND): number

The speed at which ripples creep downwind (m/s): the flux over the bulk density and the ripple height; centimetres a minute in a strong wind.

packages/weather/src/desert.ts:105

rippleWavelength function

function rippleWavelength(ustar: number, s: Sand = DUNE_SAND): number

The wavelength of ripples (m): a few hundred grains plus a twelfth of the hop (ripples of fine sand are ~ 5-10 cm, of coarse ~ 15 cm).

packages/weather/src/desert.ts:102

riverFromProfile function

function riverFromProfile(profile: ProfilePointLike[], falls: FallLike[] = [], o: { discharge?: number; seed?: number; name?: string; floor?: number } = {}): River

A River from the profile of a landscape's river line and its waterfalls: the line is cut at every fall into reaches (each with the bed its slope gives, the width and the discharge it has), and every fall becomes a lip with the direction the water goes. The lip is where the surface turns steep (the landscape's fall may begin a little upstream of it), and the drop is measured down to floor, the level of the water it lands in (the sea; the landscape measures to the bed of what it falls into). Points of the line below floor are under that water and are left out. discharge overrides the flow (m3/s); by default it is the mean of width x 0.5 m x speed.

packages/weather/src/bridge.ts:127

riverMedia function

function riverMedia(river: River, o: { scale?: number } = {}): MediumLike[]

The river and its falls as media: every reach is a ribbon of water that flows downstream at the speed Manning gives at the discharge (scale x the base), where a body feels drag against the current and buoyancy under the surface; every fall is a box of aerated water with the speed of the sheet, going down. A body swept into a river is carried along.

packages/weather/src/bridge.ts:234

rogueHeight function

function rogueHeight(w: RogueWave, x: number, z: number, t: number): number

The extra height (m, positive up) a freak wave adds at a point and time: a travelling group of a carrier wave under a Gaussian envelope, narrower across the crest. Ahead of the crest the envelope carries a deep trough ("a hole in the sea"): the carrier's phase makes the trough come first. The envelope rises and falls with the life so that the wave grows out of the sea and goes back into it. The group moves at half the speed of the carrier (deep water).

packages/weather/src/sea.ts:148

rogueRate function

function rogueRate(c: SeaCondition): number

The expected rate of freak waves: a wave higher than twice the significant height has probability exp(-8) (3.4e-4) among Rayleigh distributed waves; a steep, wind-against-current or very rough sea is observed to make them more often, so the rate is raised with the steepness of the sea. Returns events per hour in a sea area of 100 km^2.

packages/weather/src/sea.ts:103

rogueSum function

function rogueSum(list: RogueWave[], x: number, z: number, t: number): number

The sum of the rogue waves at a point.

packages/weather/src/sea.ts:166

rogueWaves function

function rogueWaves(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness'>, t0: number, t1: number, area: [number, number, number, number], seed = 0, rateScale = 1): RogueWave[]

The freak waves within an hour of the clock at a place: each hour of the world is split in slots of one minute; a slot holds a rogue wave with the probability from the rate. The group is placed upwind of the viewer so that it arrives within the slot. area is the box [minX, minZ, maxX, maxZ] watched.

packages/weather/src/sea.ts:114

saltationHeight function

function saltationHeight(ustar: number): number

The height of the saltation layer (m): grains hop to about u*^2 / g times a few; 1 to 2 decimetres in a strong storm.

packages/weather/src/desert.ts:53

saltationLength function

function saltationLength(ustar: number): number

The length of a hop (m): about 10 times the height.

packages/weather/src/desert.ts:56

sandFlux function

function sandFlux(ustar: number, s: Sand): number

The sand transport rate (kg per metre of width per second) by Kawamura: Q = 2.78 rho / g (u* - u*t)(u* + u*t)^2. Zero below the threshold.

packages/weather/src/desert.ts:46

sandStorm function

function sandStorm(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness' | 'dustiness' | 'soilWetness'>, x = 0, z = 0, t = 0, sand: Sand = DUNE_SAND, seed = 0): SandStorm

The sand and dust in the wind of a place: from the state's wind, the gust at the place and time, and the ground. The dust raised grows with the square of the excess of the wind over the dust threshold and with the dustiness of the ground; the visibility follows from the extinction of the dust (Koschmieder: V = 3.912 / beta).

packages/weather/src/desert.ts:82

sandStreamers function

function sandStreamers(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness' | 'dustiness'>, x: number, z: number, t: number, sand: Sand = DUNE_SAND, seed = 0): number

The "snakes" of sand: where a gust lifts the ground over the threshold the sand runs in streams close to the ground, in long thin streaks along the wind that appear, wriggle and fade. Returns the density 0..1 of the moving sand at the ground at a point; zero below the threshold wind.

packages/weather/src/desert.ts:135

seaCondition function

function seaCondition(s: Pick<WeatherState, 'wind' | 'gustiness'>, o: { fetch?: number; duration?: number } = {}): SeaCondition

The sea a state makes. fetch (m) and duration (s) limit the growth of a young sea: a gale over a small bay does not raise a big sea; the default is a fully developed one (an open ocean, a long gale). The heights follow the fully developed spectrum (Hs = 0.0214 U^2 at 19.5 m height; here on U10 as in the waves package), the whitecaps the Monahan law W = 3.84e-6 U^3.41.

packages/weather/src/sea.ts:36

seaWaves function

function seaWaves(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness'>, o: SeaOptions = {}): Wave[]

The wave components of a state, for the water shader and the waves package's field: seaState of the wind with the sharper crests of a stormy sea.

packages/weather/src/sea.ts:67

sheetPosition function

function sheetPosition(f: Waterfall, st: FallState, u: number, t: number): { x: number; y: number; z: number; broken: number }

A particle of the falling sheet at time t: its position along the fall (0 at the lip, 1 at the pool) for the drawing of the streaks.

packages/weather/src/river.ts:125

shoalAmplitude function

function shoalAmplitude(a: number, L: number, d: number): number

What a wave of height-amplitude a and length L becomes in water of depth d: the same in deep water (d > L/2), taller as it shoals (Green's law, a ~ d^-1/4), never taller than 0.4 d (it breaks), and nothing at the waterline. The AmplitudeFn of the waves package, so the ship and the water the camera sees agree.

packages/weather/src/bridge.ts:158

shoreAt function

function shoreAt(ground: GroundLike, x: number, z: number, seaward: number, o: { max?: number; step?: number } = {}): ShoreHit | null

Walk from (x, z) towards the sea (the direction seaward, degrees) until the ground is under the sea, and say what the shore there is: sand or cobble or boulders or rock by the layer under the waterline and the slope of the ground about it. null when no sea within max metres.

packages/weather/src/bridge.ts:90

shoreDepth function

function shoreDepth(s: ShoreSpec, x: number, max = 60): number

The depth of the water (m) at x metres seaward of the still waterline: the beach face continues down at its slope to the shelf (not deeper than max).

packages/weather/src/shore.ts:110

shoreKindOf function

function shoreKindOf(layer: string, slope: number): ShoreKind

The kind of shore for a ground layer (the paint layers of the landscape's biomes) and the steepness of the slope there.

packages/weather/src/bridge.ts:70

shoreOf function

function shoreOf(kind: ShoreKind, slope?: number): ShoreSpec

A shore of a kind, optionally with another slope.

packages/weather/src/shore.ts:38

simoom function

function simoom(s: Pick<WeatherState, 'wind' | 'temperature' | 'humidity' | 'dustiness'>): { air: number; stress: number; description: string }

The simoom (samum): a hot dry gale off the desert, full of dust, that lasts minutes to an hour: the temperature goes to 45-55 C, humidity falls under 10%, and the heat on the skin and in the lungs can kill. Returns the air temperature at the ground and the heat stress index (0 comfortable .. 1 deadly) for a person.

packages/weather/src/desert.ts:206

skyDescription function

function skyDescription(deck: CloudLayer[]): string

Names the sky for a person: 'fair-weather cumulus', 'a thunderhead with an anvil'... the lowest layer that covers more than a tenth.

packages/weather/src/clouds.ts:226

slant function

function slant(f: Fall, windSpeed: number): number

The angle from the vertical (degrees) that a falling particle's path makes in the wind.

packages/weather/src/precip.ts:126

slipperiness function

function slipperiness(s: { soilWetness: number; temperature: number; precipitation: number }, snow = 0): number

The scale of friction that the weather puts on every ground: wet ground is slippery (rain on rock or clay takes a third of the grip), snow packs and slides (a quarter off), ice below freezing is nearly frictionless. Multiplies the surface the landscape gave (physics-friction scale).

packages/weather/src/bridge.ts:271

smoothstep function

function smoothstep: (a: number, b: number, v: number) => number

packages/weather/src/common.ts:11

snowDepth function

function snowDepth(rate: number, hours: number, tempC: number): number

How deep snow lies after hours of snowfall at a rate (mm water per hour): the snow-to-liquid ratio is 10:1 at 0 C and 20:1 and more in the cold. Metres.

packages/weather/src/precip.ts:138

snowStreamDir function

function snowStreamDir(s: Pick<WeatherState, 'windDir'>): [number, number]

The direction snow streams along near the ground, as a unit vector (the wind).

packages/weather/src/storm.ts:241

softSprite function

function softSprite(scene: BABYLON.Scene): BABYLON.Texture | null

A soft round sprite (white, alpha falling to the edge), made once per scene; null where there is no canvas (tests, servers).

packages/weather/src/view.ts:156

speedOfSound function

function speedOfSound: (tempC: number) => number

the speed of sound in air (m/s) at a temperature in Celsius

packages/weather/src/common.ts:43

sprayPlume function

function sprayPlume(sv: Surf, t: number, seed = 0): number

The plume of spray over the rock or boulders as a function of the time: 0..1 of its height, the wave comes, the water goes up and falls in a few seconds.

packages/weather/src/shore.ts:228

stateOf function

function stateOf(preset: string | Partial<WeatherState>, over: Partial<WeatherState> = {}): WeatherState

A state from a preset name and changes.

packages/weather/src/state.ts:85

strikeHarm function

function strikeHarm(d: number): number

The danger of the open: a person is hit by a flash within reach metres of the strike; here the chance a flash at distance d harms (the ground current falls off fast).

packages/weather/src/storm.ts:172

strikeTarget function

function strikeTarget(f: Flash, targets: StrikeTarget[], striking = 45): StrikeTarget | null

What a ground flash strikes: the bolt comes down and reaches towards objects within the striking distance (about 10 I^0.65 metres of the stroke current, 30-100 m, the "rolling sphere"); the taller and better conducting one within that distance wins. Returns the target, or null when the bolt reaches open ground.

packages/weather/src/storm.ts:129

sunBlocked function

function sunBlocked(s: WeatherState, deck: CloudLayer[], x: number, z: number, t: number): number

How much of the sunlight is cut at a ground point (0 none, 1 dark): the cover of the layers above it, thickened by cells overhead, thinned between.

packages/weather/src/clouds.ts:208

surf function

function surf(sea: Pick<SeaCondition, 'hs' | 'period'>, shore: ShoreSpec | ShoreKind, angle = 0): Surf

The surf of a sea on a shore. angle is the angle between the wave crests' travel and the shore normal at the deep water. The waves are described by a sea condition (the significant height and the peak period); the breaker is of the significant wave.

packages/weather/src/shore.ts:76

surfAt function

function surfAt(sv: Surf, x: number, t: number, seed = 0): SurfPoint

packages/weather/src/shore.ts:169

surfPhase function

function surfPhase(sv: Pick<Surf, 'shore' | 'period' | 'l0'>, x: number, t: number): number

The phase of the wave at x and time t, 0..1: 0 is the trough ahead of the front, faceShare is the crest. A crest that is at x now reaches the shore travel later, so x falls as t grows.

packages/weather/src/shore.ts:152

swayFrequency function

function swayFrequency(sp: TreeSpecies, scale = 1): number

The natural frequency of the tree's sway (Hz): a cantilever of the trunk with the crown's mass at the top. Big trees rock slowly (0.2-0.5 Hz), small ones faster.

packages/weather/src/vegetation.ts:104

tangential function

function tangential(vmax: number, rc: number, r: number): number

The tangential speed (m/s) at radius r of a vortex with peak speed vmax at the core radius rc.

packages/weather/src/tornado.ts:13

terrainGround function

function terrainGround(ground: GroundLike, state: () => WeatherState, o: { reference?: [number, number] } = {}): NonNullable<WeatherOptions['ground']>

The ground option of WeatherService from a landscape: a sandstorm rises where the biomes are dusty and not over a meadow, blowing snow where snow lies, the soil is as wet as the biome and the rain make it, and the air is colder up the mountain (the climate's own gradient, else the lapse rate of 6.5 K per km) than at reference.

packages/weather/src/bridge.ts:42

thresholdUstar function

function thresholdUstar(s: Sand): number

The threshold friction velocity (Bagnold): u*t = A sqrt((rho_s - rho) g d / rho), A = 0.1, raised by moisture (wet grains stick: u*t is multiplied by 1 + 4 w). Dust grains (< 0.06 mm) are held by cohesion and need stronger wind than sand to lift: they leave when sand grains are already hopping and bombard them.

packages/weather/src/desert.ts:37

thresholdWind function

function thresholdWind(s: Sand): number

The threshold wind at 10 m, m/s.

packages/weather/src/desert.ts:43

thunderOf function

function thunderOf(f: Flash, at: V3, tempC = 15): Thunder

The thunder of a flash for a listener at at (x, y, z), temperature in Celsius: the delay is the distance over the speed of sound (about 3 s to the km).

packages/weather/src/storm.ts:104

tornadoChance function

function tornadoChance(s: Pick<WeatherState, 'convection' | 'thunder' | 'humidity' | 'temperature' | 'wind'>): number

The chance per ten minutes that a supercell in the area makes a tornado: a violent, wet, hot storm.

packages/weather/src/tornado.ts:168

treeLoad function

function treeLoad(sp: TreeSpecies, u: number, o: { scale?: number; leaves?: boolean; soilWetness?: number; strength?: number } = {}): TreeLoad

The load of a wind speed on a tree: drag on the crown with its coefficient falling as the crown folds in (Cd = cd0 (u/10)^vogel above 10 m/s), the bending moment at the base and its stress against the modulus of rupture (the trunk at the base, 1.15 of the breast height diameter), and the overturning moment against the root plate (weaker in wet soil, and a tree with a big crown and a thin trunk is loaded worse). u is the wind at the middle of the crown. scale is the size of this tree relative to the species' typical one.

packages/weather/src/vegetation.ts:79

turbulenceIntensity function

function turbulenceIntensity(roughness: number, gustiness: number): number

The turbulence intensity (standard deviation / mean) of the wind: 0.1 over open water, 0.2 over fields, 0.4 in a forest; goes up with gustiness.

packages/weather/src/wind.ts:40

unrealWindDirection function

function unrealWindDirection(windDir: number): [number, number]

The direction of the wind as a unit vector and as the (x, y) of Unreal's wind collection (the engine's x, z mapped to Unreal's -x, y).

packages/weather/src/wind.ts:48

validateState function

function validateState(s: Partial<WeatherState>): string[]

The problems of a (partial) state: the names that are not numbers, the ranges that are broken.

packages/weather/src/state.ts:105

visibilityOf function

function visibilityOf(s: WeatherState, parts: { fall?: Fall; sand?: SandStorm; blizzard?: Blizzard; sea?: SeaCondition; atSea?: boolean }): { visibility: number; limit: WeatherSample['limit'] }

The visibility of a state: the extinctions add (Koschmieder 3.912 / V), the fog from the humidity and the calm air.

packages/weather/src/service.ts:67

visibleFunnel function

function visibleFunnel(now: WhirlNow, humidity: number): number

The condensation funnel's lowest point: the pressure falls in the core until the air is saturated; the lower the humidity, the lower the funnel stays above the ground (a dry tornado is a dust column with no visible funnel).

packages/weather/src/tornado.ts:227

waterfall function

function waterfall(f: Waterfall): FallState

The numbers of a waterfall at a discharge.

packages/weather/src/river.ts:104

waterline function

function waterline(sv: Surf, t: number, seed = 0): number

The position of the waterline at time t, m seaward (+) or up the beach (-) of the still waterline: each wave runs up to the run-up and the backwash brings it down; a rock wall has no swash. The swash period is the wave period; with the infragravity wobble of long beaches.

packages/weather/src/shore.ts:217

waterspoutChance function

function waterspoutChance(s: Pick<WeatherState, 'convection' | 'humidity' | 'wind' | 'temperature'>): number

The chance per ten minutes of a waterspout over a sea in a humid unstable air.

packages/weather/src/tornado.ts:178

waveHeightAt function

function waveHeightAt(sv: Surf, depth: number): number

The wave height (crest to trough, m) at a depth: from deep water the wave grows by shoaling (Green's law, H ~ d^-1/4) until it breaks at gamma d; inside the surf zone the broken wave is a bore of gamma d. The wave of the significant height is used; waves higher or lower break farther out or in.

packages/weather/src/shore.ts:119

wetting function

function wetting(wetness: number, f: Fall, temperature: number, dt: number): number

Ground wetness 0..1 after dt seconds: rain soaks it (a downpour in a few minutes), and it dries slowly, faster when warm.

packages/weather/src/precip.ts:131

whirlNow function

function whirlNow(w: Whirl, t: number): WhirlNow

The funnel's life: a bell. The funnel lowers in the first fifth, matures, then ropes out in the last quarter.

packages/weather/src/tornado.ts:109

whirls function

function whirls(s: WeatherState, t0: number, t1: number, area: [number, number, number, number], seed = 0, kinds: VortexKind[] = ['tornado', 'dustdevil', 'waterspout'], water = false): Whirl[]

The whirls of a time span in a box [minX, minZ, maxX, maxZ]: the span is split into ten-minute slots, each slot has the chance from the state to hold one, placed by hash. For a given seed the same list comes on every peer, whatever the span. kinds limits which are made.

packages/weather/src/tornado.ts:186

whirlSource function

function whirlSource(w: Whirl, t: number, name = 'whirl'): VortexSource | null

The same as a source for the flow package (a Rankine vortex): everything that reads the flow (smoke, flags, sails, the clouds) feels the tornado.

packages/weather/src/tornado.ts:159

whirlWind function

function whirlWind(w: Whirl, now: WhirlNow, px: number, py: number, pz: number): V3

The wind of a whirl at a point: [x, y, z] in m/s, swirl counter-clockwise seen from above, inflow near the ground, an updraft in the core.

packages/weather/src/tornado.ts:140

whiteness function

function whiteness(h: Hydraulics, bed: BedKind): number

The share of the surface that is white: waves break where the flow is fast over rough bed.

packages/weather/src/river.ts:62

whitewaterClass function

function whitewaterClass(h: Hydraulics, slope: number, bed: BedKind): number

The class of whitewater (the International Scale of River Difficulty) I to VI of a reach: from the Froude number, the slope and the bed roughness.

packages/weather/src/river.ts:56

windAloft function

function windAloft(s: WeatherState, height: number): [number, number]

The wind at a height (m above the ground): a speed from the log law near the ground and a power law above (the boundary layer is about 1 km; above it the wind keeps gaining slowly towards the jet), and the direction turning with height (veering: about 20 degrees by 1 km, 40 by 5 km). Returns [x, z] in m/s.

packages/weather/src/clouds.ts:130

windAngle function

function windAngle: (s: Pick<WeatherState, "windDir">) => number

A degree to radian pair used by the views.

packages/weather/src/wind.ts:57

windAtHeight function

function windAtHeight(w10: number, height: number, z0 = 0.03): number

Wind speed at a height (m) from the 10 m wind: the log law over open ground (roughness length z0, m).

packages/weather/src/state.ts:121

windForFriction function

function windForFriction(ustar: number, z0 = 0.0004): number

The wind at 10 m (m/s) that gives a friction velocity.

packages/weather/src/desert.ts:31

windSpeedAt function

function windSpeedAt(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness'>, x: number, z: number, height: number, t: number, o: { z0?: number; seed?: number } = {}): number

The wind speed (m/s) at a point, a height above the ground (m) and a time: the profile of the height with the gusts on top.

packages/weather/src/wind.ts:25

windVector function

function windVector(s: Pick<WeatherState, 'wind' | 'windDir' | 'gustiness'>, x: number, z: number, height: number, t: number, o: { z0?: number; seed?: number } = {}): V3

The wind vector (m/s) at a place: the direction veers (turns clockwise in the north's hemisphere) with the height by up to ~20 degrees over a few hundred metres.

packages/weather/src/wind.ts:30

Interfaces

Blizzard interface

interface Blizzard
wind: numberwind at 10 m, m/s
threshold: numberthe wind at which the snow starts to move: dry fresh snow about 5 m/s at 10 m; old crusted snow 12 m/s and more
drifting: booleanis the snow moving at all
transport: numberkg per metre of width per second carried over the ground
concentration: numberthe mass of snow in the air near the ground, g/m^3 (below 2 m)
depth: numberhow deep the blowing layer is, m: low "ground blizzard" in a light wind, 30 m and more in a strong one
visibility: numberhow far you see at head height, m; the sky may be clear above the layer
whiteout: booleana whiteout: no horizon, no shadows, no sense of depth (below 100 m with snow cover)
blizzard: booleanthe formal blizzard: wind over 16 m/s and visibility under 400 m for hours
windChill: numberthe cold on the skin: wind chill in Celsius (the Canadian formula)

packages/weather/src/storm.ts:176

CloudCell interface

interface CloudCell
x: numberthe cell's centre at the time asked, m
z: number
age: number0..1 along its life: born at 0, a tower in the middle, gone at 1
height: numberthe height the cloud reaches now, above its base, m
radius: numberthe radius of the cloud now, m
maturity: number0..1 how dark and wet it is (a mature cell rains)
id: number

packages/weather/src/clouds.ts:146

CloudLayer interface

interface CloudLayer
genus: CloudGenus
base: numberbase and top above the ground, m
top: number
cover: number0..1 of the sky this layer covers
opticalDepth: number
darkness: number
form: GenusSpec['form']
precipitates: GenusSpec['precipitates']0..1 how likely it drops what it can
flat: number
cell: number
anvil: numberthe anvil of a thunderhead: how far it spreads downwind at the top, m (0 for the rest)

packages/weather/src/clouds.ts:45

Debris interface

interface Debris
name: string
mass: number
area: number
cd: number
hold: number

packages/weather/src/tornado.ts:61

EfClass interface

interface EfClass
ef: number
name: string
min: number
max: number
damage: string

packages/weather/src/tornado.ts:24

Fall interface

interface Fall
kind: PrecipKind
rate: numbermm of water per hour
size: numberthe typical particle: diameter in mm, and its still-air fall speed in m/s
speed: number
perM3: numberthe particles in a cubic metre (the ones that matter for the eye: bigger than 0.5 mm for rain)
water: numberliquid water in the air, g/m^3
visibility: numberhow far you see through it, m (up to 20000)
streak: numbera length for a streak of one particle in a 1/60 s exposure, m (for the picture)
sound: 'none' | 'hiss' | 'patter' | 'roar' | 'rattle'a tone for the sound: 'hiss' for drizzle and snow, 'patter' for rain, 'roar' for a downpour, 'rattle' for hail
loudness: numberthe loudness 0..1
wet: booleanwet snow sticks to things and melts on the ground

packages/weather/src/precip.ts:49

FallLike interface

interface FallLike

A waterfall as a landscape reports it (waterfalls).

x: number
z: number
height: number
run: number
width: number
discharge: number
s: number

packages/weather/src/bridge.ts:114

FallState interface

interface FallState
head: numberthe depth of the water over the lip (a broad crested weir: q = 1.7 w h^1.5), m
lipSpeed: numberthe speed at the lip (critical, sqrt(g h)), m/s, and at the bottom (free fall), m/s
impactSpeed: number
airTime: numberthe time the water is in the air, s, and how far from the wall it lands, m
throwDistance: number
sheet: numberthe thickness of the sheet at the bottom, m (the water spreads thin as it speeds up: continuity)
pool: numberthe depth of the plunge pool the fall digs, m (Mason and Arumugam scale)
mistHeight: numberthe mist: height of the cloud above the pool, m, and its density 0..1
mist: number
loudness: numberthe loudness 0..1: it roars, from the power of the fall
power: numberthe power of the fall, W
look: 'trickle' | 'veil' | 'curtain' | 'torrent''veil' when the sheet is thin, 'curtain' when thick, 'torrent' when huge, 'trickle' when tiny

packages/weather/src/river.ts:79

Flash interface

interface Flash
t: numberthe time the flash starts, s
kind: 'ground' | 'cloud'cloud to ground, or inside the cloud (the sheet lightning that lights the whole cloud)
x: numberwhere the bolt reaches the ground (ground) or where the cloud lights (cloud), m; y is the ground
z: number
height: numberthe height of the charge centre / cloud base, m
strokes: Stroke[]the return strokes: a ground flash has 1 to 6, 40-80 ms apart, the first brightest and the rest dimmer
duration: numberthe whole flash lasts this long, s (0.2-0.5)
seed: numberthe seed of the shape of the branches
energy: number0..1 how bright, from the energy: sets the flash of the sky and the thunder
index: numberthe time in the schedule: a flash is number index of its place

packages/weather/src/storm.ts:17

GenusSpec interface

interface GenusSpec
genus: CloudGenus
base: [number, number]the height of the base above the ground, m: lowest and highest it usually has
thickness: [number, number]the thickness, m: thinnest and thickest
form: 'heap' | 'layer' | 'veil' | 'wave''heap' separate towers, 'layer' a sheet, 'veil' a thin sheet, 'wave' rows of cloudlets
opticalDepth: numberthe optical depth of its thickest part (about 1 you see the sun as a disc, above 10 it is gone)
darkness: number0..1 how dark its underside is
precipitates: 'none' | 'drizzle' | 'rain' | 'shower' | 'snow'what it can drop: nothing, drizzle, rain, showers, snow
flat: numbervertical squash of a puff for the picture: 1 round, small for a sheet
cell: numberthe size of one cell or cloudlet, m

packages/weather/src/clouds.ts:12

GrassBlade interface

interface GrassBlade
lean: numberhow far the blades lean 0..1 (1 = lying along the ground)
dir: [number, number]the direction they lean (unit, xz)
sheen: number0..1 the brightness of the wave front: blades turn to show their pale underside in the gust
shiver: numberthe quick shiver of the tips 0..1

packages/weather/src/vegetation.ts:290

GrassViewOptions interface

interface GrassViewOptions
count?: numberhow many tufts are kept around the camera (default 6000) and how far they reach (m, default 26)
radius?: number
ground?: (x: number, z: number) => numberthe height of the ground at a place (default 0)
density?: (x: number, z: number) => numberhow much grass grows at a place 0..1 (default 1 everywhere): none on sand, rock or in the water
height?: numberthe grass: the height of a blade (m, default 0.7), how stiff it is 0 soft .. 1 coarse (default 0.4) and its colours at the root and at the tip
stiffness?: number
base?: V3
tip?: V3
flowMap?: { readonly size: number; readonly cell: number; readonly originX: number; readonly originZ: number; readonly data: Float32Array; readonly active: boolean; readonly version: number }local air on top of the wind (propeller and fan wash, jets): a FlowMap of

packages/weather/src/view.ts:710

GroundLike interface

interface GroundLike

What a landscape's Ground is, as far as the weather is concerned.

sample(x: number, z: number): GroundSampleLike
registry?: { get(id: string): { weather: { dustiness: number; looseSnow: number; soilWetness: number } } }
climate?: { at(x: number, z: number, height: number): { temperature: number } }
relief?: { height(x: number, z: number): number; seaLevel?: number }the bare relief, if the landscape has one: a cheaper answer for the height (bathymetry uses it)

packages/weather/src/bridge.ts:30

GroundSampleLike interface

interface GroundSampleLike

What a landscape's Ground.sample answers (the fields the weather reads).

height: number
slope: number
wetness: number
layer: string
biome: string
weights: Record<string, number>
water: { level: number; kind: string } | null

packages/weather/src/bridge.ts:24

Haboob interface

interface Haboob
x0: numberwhere the front is at t0 (x, z), the direction it moves (degrees), its speed (m/s)
z0: number
dir: number
speed: number
t0: numberthe time the front was at (x0, z0)
height: numberthe height of the wall, m (1-2 km) and the length across the wind, m (tens of km), and the depth of the dust behind the front, m
width: number
depth: number
peak: numberthe peak dust concentration at the front, g/m^3

packages/weather/src/desert.ts:157

Hydraulics interface

interface Hydraulics
depth: numbermean depth, m
velocity: numbermean speed, m/s
froude: numberthe Froude number v / sqrt(g h)
shear: numberthe shear stress at the bed N/m^2 (what moves sand and stones)

packages/weather/src/river.ts:13

MediumLike interface

interface MediumLike

A medium as physics-media takes it (structural).

name: string
density: number
viscosity: number
flow?: V3
bounds?: { min: V3; max: V3 }
river?: { points: V3[]; widths: number[]; depth: number; speed: number }

packages/weather/src/bridge.ts:224

Pending interface

interface Pending
at: number
flash: Flash
thunder: Thunder

packages/weather/src/service.ts:64

PhysicsLike interface

interface PhysicsLike

What the bridge needs of the physics host (structural, so this package does not import it).

kernel: { caps: { rigidBodies?: boolean }; addBody(def: { shape: unknown; kind?: string; mass?: number; position?: V3; orientation?: [number, number, number, number]; velocity?: V3; angularVelocity?: V3; material?: string; userData?: unknown; linearDamping?: number; angularDamping?: number }): { id: number; position: V3; velocity: V3; mass: number; removed: boolean }; removeBody(b: never): void; addForceField(fn: (b: never, h: number) => V3 | null): () => void; }
capabilities: Map<string, unknown>
isEnabled(name: string): boolean
config(name: string): { set(scope: 'world' | 'level', key: string, value: unknown): void; get<T = number>(key: string): T }
world: { time: number; events: { on(name: string, fn: (e: never) => void): unknown } }

packages/weather/src/bridge.ts:210

ProfilePointLike interface

interface ProfilePointLike

A point of a river's profile as a landscape reports it (riverProfile).

x: number
z: number
level: number
width: number
speed: number
slope: number
s?: number

packages/weather/src/bridge.ts:112

Reach interface

interface Reach
points: V3[]the line of the reach: at least two points (x, y = water surface, z)
width: number
q: numberthe base discharge, m^3/s, at the usual state of the weather
bed?: BedKind
name?: stringthe name for the sound and the debugging

packages/weather/src/river.ts:137

RiverPoint interface

interface RiverPoint
at: V3the point on the river line nearest to the query, and the distance from the line, m
distance: number
across: numberacross the channel: 0 centre, 1 bank
dir: V3the downstream direction (unit), the water velocity (m/s, vector), the depth
velocity: V3
depth: number
hydraulics: Hydraulics
regime: Regime
foam: numberthe share of the surface that is white
loudness: numberthe roar of the water, 0..1
inside: boolean

packages/weather/src/river.ts:148

RiverViewOptions interface

interface RiverViewOptions
scale?: () => numberthe discharge now relative to the base (1 = the usual flow): rain swells the river; read every half second
ground?: (x: number, z: number) => numberthe height of the ground (m) at a place, for the pool bed (unused without a pool)
particles?: numberhow many mist and spray particles may live (default 3000)

packages/weather/src/river-view.ts:71

RogueWave interface

interface RogueWave
t0: numberthe clock time at which the wave is at its origin, s
x0: numberwhere the group is at t0 (centre), m
z0: number
dir: numberthe direction it travels, degrees
height: numberthe height crest to trough of its tallest wave, m (2 to 3 times the significant height)
wavelength: numberthe wavelength of the carrier, m
crestWidth: numberthe width along the crest, m: it is a short crest, a few hundred metres; the length of the group along travel, m
groupLength: number
life: numberthe life of the event: it appears out of the sea, lives this long, and dissolves, s
seed: number

packages/weather/src/sea.ts:79

Sand interface

interface Sand
grain: numberthe grain diameter, m: dune sand 0.15-0.4 mm, coarse 1 mm
z0: numberaerodynamic roughness length, m of the surface (flat sand 0.0003, rippled 0.001, with stones 0.005)
dust: numberhow much of the fine dust the surface holds, 0..1 (a dry lake bed is dusty, clean dune sand is not)
wetness: numberwet sand does not move (soil wetness raises the threshold)

packages/weather/src/desert.ts:13

SandStorm interface

interface SandStorm
u10: numberthe wind at 10 m now, with the gusts, m/s, and u*
ustar: number
threshold: numberthe threshold wind, m/s
flux: numberthe sand moving at the ground, kg/m/s, and the height of the saltating cloud, m
saltation: number
concentration: numberthe dust in the air at head height, g/m^3, and the height the dust reaches, m
dustHeight: number
visibility: numberhow far you see, m (Koschmieder with the dust's extinction; up to 20000 m)
light: numberthe share of the light that gets through at noon, 0..1 (a brown sky; the sun goes red and dim)
kind: 'none' | 'blowing' | 'storm' | 'severe'a name by visibility, the WMO terms: 'none', 'dust haze', 'blowing sand', 'sandstorm', 'severe sandstorm'

packages/weather/src/desert.ts:58

SandstormViewOptions interface

interface SandstormViewOptions
state: () => Pick<WeatherState, 'wind' | 'windDir' | 'gustiness' | 'dustiness' | 'soilWetness'>the weather state to read (wind, direction, dustiness, wetness); read each update
sand?: Sand
dust?: V3colour of the dust, 0..1 (tan by default)
groundAt?: (x: number, z: number) => numberground height at (x, z), so the sand streams along the surface
budget?: numbermost particles in each of the three clouds (default 900)
seed?: numbera seed for the pseudo-random placement (no Math.random: the view is reproducible)
onAir?: (density: number, color: V3) => voidcalled each update with the fog density per metre and the dust colour (0..1), for materials that do their own fog (the terrain shader); density is the scene's own when there is no dust

packages/weather/src/sandstorm-view.ts:11

SeaCondition interface

interface SeaCondition
force: numberthe Beaufort force 0..12
hs: numberthe significant wave height Hs (mean of the highest third), m, of a fully developed sea
period: numberthe wave period at the peak, s, and its wavelength, m
wavelength: number
hmax: numberthe height of the highest wave likely in 1000 waves, m (Rayleigh: Hs * sqrt(ln(N) / 2))
whitecaps: numberthe fraction of the sea surface covered by whitecaps (Monahan and O'Muircheartaigh)
streaks: number0..1 how streaky the foam is: wind-blown streaks begin at force 8
spray: number0..1 spindrift: spray torn off the crests, which lowers the visibility from force 9
visibility: numberthe visibility left by the spray alone, m
description: stringa person's description

packages/weather/src/sea.ts:9

ShoreHit interface

interface ShoreHit
at: V3the water's edge, and the shore there
kind: ShoreKind
slope: number
angle: numberthe direction the sea lies in, degrees (0 = +x, 90 = +z)
distance: numberhow far from the start the sea began, m

packages/weather/src/bridge.ts:77

ShoreSpec interface

interface ShoreSpec
kind: ShoreKind
slope: numbertan(beta) of the beach face below the waterline
reflection: numberthe share of the wave energy that returns as reflected wave
porosity: numberthe water that the shore takes in (sand and gravel soak up the swash; rock does not) 0..1
grain: numberroughness, m (the size of grains, stones, boulders): drags the swash and breaks the water
shelf: numberthe depth of the water right at the foot of the shore, m: a cliff drops into deep water, so the waves arrive whole and stand against it (clapotis); a beach starts at zero
description: stringa person's words

packages/weather/src/shore.ts:13

SnowViewOptions interface

interface SnowViewOptions
lift?: numberhow far the skin stands off the ground, m (default 0.12: also the depth that hides the coarse cells of a terrain mesh)
full?: numberthe depth (m) at which the ground is white all over (default 0.15)

packages/weather/src/snow-view.ts:45

StrikeTarget interface

interface StrikeTarget
id: string | number
position: V3
height: number
conductivity?: number

packages/weather/src/storm.ts:122

Stroke interface

interface Stroke
at: numberseconds after the flash begins
power: number0..1 of the brightest

packages/weather/src/storm.ts:10

Surf interface

interface Surf
shore: ShoreSpec
h0: numberthe deep water wave: height H0 (the significant height), period T, wavelength L0 = g T^2 / 2 pi
period: number
l0: number
angle: numberthe angle the waves make with the shore normal at the deep water, degrees (0 = straight in)
iribarren: numberthe Iribarren number and the kind of breaker it makes
breaker: Breaker
hb: numberthe breaker height Hb and the depth hb at which it breaks, m
depth: number
width: numberthe distance seaward from the waterline at which the waves break, m, and the width of the foamy zone (equal)
runup: numberthe run-up above the still waterline (2% exceedence, Stockdon), m, and the horizontal reach of it up the slope, m
reach: number
longshore: numberthe longshore current, m/s, along the shore in the direction of the waves' alongshore travel
spray: numberthe height of the spray thrown up, m, and how often a wave throws it (per minute)
sprayRate: number
sound: 'none' | 'wash' | 'crash' | 'rattle' | 'boom'the sound: 'wash' (sand), 'crash' (plunging), 'rattle' (stones in the backwash), 'boom' (rock, boulders); loudness 0..1
loudness: number
foam: number0..1 the foam on the surf zone

packages/weather/src/shore.ts:46

SurfPoint interface

interface SurfPoint
eta: numberthe elevation of the water surface above still water at the point, m
foam: numberthe foam density 0..1
height: numberthe wave height there, m
flow: numberthe horizontal speed of the water in the direction of the shore, m/s (positive towards the shore)
breaking: booleanwhether the point is inside the surf zone (breaking)
steep: number0..1: how far the wave has steepened into a bore (it grows over the last half depth before the break, so the surface has no step at the edge of the surf zone)

packages/weather/src/shore.ts:128

SurfViewOptions interface

interface SurfViewOptions
origin: [number, number]where the still waterline starts (x, z), the direction to the sea (degrees, 0 = +x) and the length along the shore (m)
seaward: number
length: number
reach?: numberhow far out the mesh reaches (m, default 3 surf widths) and how many cells along the shore (default 48)
cells?: number
level?: numberthe height of the still water (m)
ground?: (x: number, z: number) => numberthe height of the ground (m, world y) at a point: the terrain's own, so the surf lies on the real beach, rocks and shelf; without it the shore kind's plain slope is used

packages/weather/src/view.ts:303

Thunder interface

interface Thunder
delay: numberseconds after the flash that the first sound arrives
duration: numberthe rumble lasts this long, s (the bolt is long: the sound from its near end comes first, from its far end last)
loudness: number0..1 loudness at the listener
kind: 'crack' | 'clap' | 'rumble''crack' a sharp bang (the bolt is near), 'clap', 'rumble' a long low roll (far)
lowpass: numberthe sound's lowest weight: the highs are absorbed by the air with distance, so far thunder is a low rumble. Hz of the lowpass
audible: booleanthe listener is too far: below 25 km you hear it; none beyond

packages/weather/src/storm.ts:88

TreeEvent interface

interface TreeEvent
kind: Exclude<TreeDamage, 'intact'>
tree: number
t: number
at: V3where, and the direction it goes (degrees) for a fall
dir: number
height: numberthe tree's size, m (for the debris), and the wind that did it
wind: number

packages/weather/src/vegetation.ts:128

TreeLoad interface

interface TreeLoad
u: numberthe wind at the middle of the crown, m/s
force: numberthe drag on the crown, N, with the crown folded in the wind
cd: numberthe effective drag coefficient after folding
moment: numberthe bending moment at the base N m, the stress in the base MPa-scale Pa, and the share of the strength used (1 = snaps)
stress: number
trunkLoad: number
rootLoad: numberthe share of the overturning strength used (1 = uprooted)
area: numberthe crown's frontal area, m^2

packages/weather/src/vegetation.ts:47

TreeRig interface

interface TreeRig

The parts of a tree model the view moves. All optional but root (placed at the foot of the trunk).

tree: Tree
root: BABYLON.TransformNodethe node at the foot: the whole tree leans and falls about it
crown?: BABYLON.TransformNodethe crown (the leafy top), pivoting where it joins the trunk: it bends more than the trunk, so the tree is a curve and not a stick
limbs?: Array<{ node: BABYLON.TransformNode; length: number }>branches: nodes that rock on their own about their joint, each with a length (m) that sets its rhythm
leaves?: BABYLON.TransformNode[]leaf clusters: nodes that shiver; many small ones look best
upper?: BABYLON.TransformNodethe upper part of the trunk, which stays as a stump when the tree snaps (without it the whole tree falls)
onLimbLost?: (node: BABYLON.TransformNode) => voidcalled once when a limb tears off: the view hides the limb's node and calls this so the game can drop a branch

packages/weather/src/view.ts:21

TreeSpecies interface

interface TreeSpecies
name: string
height: numbertypical height m, diameter at breast height m, crown diameter m, crown depth as share of the height
dbh: number
crown: number
crownShare: number
cd: numberdrag coefficient of the crown in the light wind, and the reconfiguration exponent (Vogel: -0.2 stiff .. -0.8 flexible)
vogel: number
fill: numberthe share of the crown area that is solid with leaves on (a leafless crown keeps bare of it)
bare: number
mor: numbermodulus of rupture of green wood Pa, modulus of elasticity Pa, density kg/m^3
mod: number
density: number
anchor: numberthe root plate: overturning moment at failure per d^2.5 (N m / m^2.5) in dry soil, 600e3 for a typical tree; fitted so that a tree in dry soil goes over at 25-55 m/s in the crown
leaf: numberthe leaf: the width of the leaf, m, and whether its underside is pale (shows silver in the wind)
silver: boolean
deciduous: booleandeciduous trees lose their leaves in the cold
damping: numberthe damping ratio of the sway (conifers damp more)
lma?: numberthe mass of a leaf or needle per area, kg/m2; mid of the ranges of Wright et al. 2004 (GLOPNET): deciduous broadleaf 0.04-0.09, conifer needles 0.2-0.35

packages/weather/src/vegetation.ts:12

TreesViewOptions interface

interface TreesViewOptions
near?: numberwithin this distance of the camera (m) leaves and limbs move individually (default 45)
mid?: numberwithin this the trunk and crown bend every frame (default 160)
farRate?: numberbeyond mid a tree is moved this many times a second (default 4)

packages/weather/src/view.ts:37

TrunkHook interface

interface TrunkHook

What a game does with a lying trunk besides the physics host's own collider: a character's world (its own physics service) needs the same box. add returns a handle that remove takes.

add(info: { tree: number; position: V3; half: V3; yaw: number }): unknown
remove(handle: unknown): void

packages/weather/src/bridge.ts:285

Waterfall interface

interface Waterfall
lip: V3the top of the fall: where the water leaves the lip (x, y of the lip, z), and the direction it goes (unit, horizontal)
dir: V3
drop: numberthe drop, m, and the width of the lip, m
width: number
q: numberthe discharge over it, m^3/s

packages/weather/src/river.ts:68

WeatherOptions interface

interface WeatherOptions
state?: string | Partial<WeatherState>the state at the start: a preset name or numbers
area?: [number, number, number, number]the box [minX, minZ, maxX, maxZ] of the world the weather works in (lightning, whirls, freak waves are placed in it); default 20 km square about the origin
seed?: number
shore?: ShoreKind | ShoreSpecthe shore kind and the angle the waves come at, for surf
shoreAngle?: number
sand?: Sandthe sand of the ground, for sand storms
sea?: booleanwhether the world has open sea (waterspouts, freak waves)
river?: Riverthe river, if any
flow?: booleanwrite the wind and whirls to the flow service if it is there (default true)
ground?: (x: number, z: number) => Partial<Pick<WeatherState, 'dustiness' | 'looseSnow' | 'soilWetness' | 'temperature'>> | null | undefinedwhat the ground at a place gives the weather (the terrain's weatherAt): how dusty it is, how much loose snow lies, how wet the soil is. sample uses it for the place asked about, so a sandstorm rises over sand and not over meadow, and snow blows only where it lies. Leave out a field to use the state's own.
listener?: () => V3where the listener is for thunder (default the camera is not known: the centre of the area)

packages/weather/src/service.ts:22

WeatherPhysicsOptions interface

interface WeatherPhysicsOptions
sea?: SeaSurfacethe sea the ships ride (also given to vehicles().surface when that capability is on)
river?: Riverthe rivers as media; riverScale is the discharge now relative to the base, read twice a second
riverScale?: () => number
friction?: booleanfriction scale from the weather (needs the friction capability)
debris?: boolean | { max?: number; trunk?: TrunkHook }limbs and trunks as bodies; ground(x, z) is the height of the land
ground?: (x: number, z: number) => number

packages/weather/src/bridge.ts:355

WeatherSample interface

interface WeatherSample
time: number
state: WeatherState
wind: V3the wind vector at the place (m/s), including a whirl's wind
speed: number
force: number
fall: Fall
visibility: numberthe visibility, m, and what limits it
limit: 'clear' | 'rain' | 'snow' | 'sand' | 'blizzard' | 'fog' | 'spray'
sand: SandStorm
blizzard: Blizzard
sea: SeaCondition
sky: string
temperature: numberthe temperature at the place (the wind chill is in blizzard.windChill)

packages/weather/src/service.ts:45

WeatherState interface

interface WeatherState
wind: numbermean wind at 10 m, m/s
windDir: numberthe direction the wind blows towards, degrees (0 = +x, 90 = +z)
gustiness: number0..1: how much the wind varies (gusts up to 1 + 0.9 * gustiness times the mean)
cloudCover: number0 clear .. 1 overcast
convection: number0..1: how much the air rises (towers, thunderclouds)
humidity: number0..1 relative humidity of the air near the ground
temperature: numbersurface air temperature, Celsius
freezingLevel: numberheight of the 0 C level above the ground, m (below 0 the ground is freezing and snow lies)
precipitation: numberprecipitation at the ground, mm of water per hour (0 none; 0.5 drizzle, 2.5 light rain, 10 moderate, 50 downpour)
thunder: number0..1 how active the thunderstorm is: 0 none, 1 a flash every few seconds
dustiness: number0..1 how much sand or dust the ground gives to the wind (0 none, grass or snow; 1 loose desert)
looseSnow: number0..1 how much loose fresh snow lies on the ground to be lifted (drives blowing snow)
soilWetness: number0..1 how wet the soil is (trees fall easier in wet soil)

packages/weather/src/state.ts:5

Whirl interface

interface Whirl
kind: VortexKind
x0: numberwhere its path starts at t0 (x, z), the direction (degrees) and the ground speed (m/s)
z0: number
dir: number
speed: number
t0: number
life: numberthe life: seconds from the first funnel to the end
vmax: numberthe greatest peak speed (m/s) and core radius (m) in its life
rc: number
cloudBase: numberthe cloud base (m), the funnel hangs from it (zero for a dust devil that starts from the ground)
height: numberthe dust devil's height (m), the tornado's top is the cloud base
seed: number

packages/weather/src/tornado.ts:78

WhirlNow interface

interface WhirlNow
touch: numberthe share of the way down the funnel is: 0 not formed, 1 touches the ground
stage: 'none' | 'forming' | 'mature' | 'roping' | 'gone'the stage: 'forming' (funnel lowering), 'mature', 'roping' (narrowing), 'gone'
x: number
z: number
vmax: number
rc: number
ef: number
funnelBase: numberthe height of the bottom of the visible funnel above the ground, m (0 when it touches)
tilt: V3the tilt of the funnel: the offset of the top from the bottom, m, along the direction of travel

packages/weather/src/tornado.ts:94

Types

BedKind type

type BedKind = keyof typeof BED

packages/weather/src/river.ts:11

Breaker type

type Breaker = 'none' | 'spilling' | 'plunging' | 'collapsing' | 'surging'

packages/weather/src/shore.ts:11

CloudGenus type

type CloudGenus = | 'cirrus' | 'cirrostratus' | 'cirrocumulus' | 'altocumulus' | 'altostratus' | 'stratocumulus' | 'stratus' | 'cumulus' | 'nimbostratus' | 'cumulonimbus'

packages/weather/src/clouds.ts:9

PrecipKind type

type PrecipKind = 'none' | 'drizzle' | 'rain' | 'shower' | 'sleet' | 'snow' | 'graupel' | 'hail'

packages/weather/src/precip.ts:8

Regime type

type Regime = 'pool' | 'run' | 'riffle' | 'rapids' | 'cascade'

packages/weather/src/river.ts:43

ShoreKind type

type ShoreKind = 'sand' | 'cobble' | 'boulder' | 'rock'

packages/weather/src/shore.ts:10

TreeDamage type

type TreeDamage = 'intact' | 'leaves' | 'twigs' | 'branch' | 'limb' | 'snapped' | 'uprooted'

packages/weather/src/vegetation.ts:45

V3 type

type V3 = [number, number, number]

packages/weather/src/common.ts:3

VortexKind type

type VortexKind = 'tornado' | 'dustdevil' | 'waterspout'

packages/weather/src/tornado.ts:10

Constants

Beaufort const

const Beaufort: readonly [{ readonly force: 0; readonly name: "calm"; readonly min: 0; readonly sea: "glassy"; }, { readonly force: 1; readonly name: "light air"; readonly min: 0.3; readonly sea: "ripples"; }, { readonly force: 2; readonly name: "light breeze"; readonly min: 1.6; readonly sea: "small wavelets"; }, { readonly force: 3; readonly name: "gentle breeze"; readonly min: 3.4; readonly sea: "large wavelet …

packages/weather/src/state.ts:39

BED const

const BED: { readonly smooth: 0.025; readonly gravel: 0.035; readonly cobbles: 0.045; readonly boulders: 0.07; readonly torrent: 0.1; }

Manning's roughness n (s/m^(1/3)) of bed types.

packages/weather/src/river.ts:10

BREAKING_INDEX const

const BREAKING_INDEX: 0.78

packages/weather/src/shore.ts:44

CALM const

const CALM: WeatherState

packages/weather/src/state.ts:34

COARSE_SAND const

const COARSE_SAND: Sand

packages/weather/src/desert.ts:25

DEBRIS const

const DEBRIS: Debris[]

packages/weather/src/tornado.ts:62

DESERT_SOIL const

const DESERT_SOIL: Sand

packages/weather/src/desert.ts:24

DUNE_SAND const

const DUNE_SAND: Sand

packages/weather/src/desert.ts:23

DUST_EXTINCTION const

const DUST_EXTINCTION: 1

Mass extinction efficiency of the dust, m^2/g.

packages/weather/src/desert.ts:76

EF_SCALE const

const EF_SCALE: EfClass[]

The Enhanced Fujita scale: 3-second gust, m/s.

packages/weather/src/tornado.ts:26

G const

const G: 9.81

packages/weather/src/common.ts:4

GENERA const

const GENERA: Record<CloudGenus, GenusSpec>

packages/weather/src/clouds.ts:32

KAPPA const

const KAPPA: 0.4

packages/weather/src/desert.ts:9

MAX_STEEPNESS const

const MAX_STEEPNESS: number

The crest line of a wave, steepness H/L: a wave breaks at 1/7 (0.142) in deep water.

packages/weather/src/sea.ts:75

PRESETS const

const PRESETS: Record<string, Partial<WeatherState>>

The ready states. A game blends to one (WeatherService.preset) or starts from one and changes a number.

packages/weather/src/state.ts:63

RHO_AIR const

const RHO_AIR: 1.225

packages/weather/src/common.ts:5

RHO_BULK const

const RHO_BULK: 1600

packages/weather/src/desert.ts:11

RHO_SAND const

const RHO_SAND: 2650

packages/weather/src/desert.ts:10

RHO_WATER const

const RHO_WATER: 1000

packages/weather/src/common.ts:6

ROUGHNESS const

const ROUGHNESS: { readonly water: 0.0002; readonly sand: 0.0005; readonly snow: 0.001; readonly grass: 0.03; readonly crops: 0.1; readonly shrubs: 0.3; readonly forest: 1; readonly town: 2; }

The roughness length of the ground (m) by type, for the profile and the turbulence.

packages/weather/src/wind.ts:45

SHORES const

const SHORES: Record<ShoreKind, ShoreSpec>

The kinds of shore with their typical slope: a sand beach is gentle, cobbles steeper (steeper still for coarse), boulders and rock very steep.

packages/weather/src/shore.ts:30

SPECIES const

const SPECIES: Record<string, TreeSpecies>

packages/weather/src/vegetation.ts:34

TAU const

const TAU: number

packages/weather/src/common.ts:7

WOOD_DEFECT const

const WOOD_DEFECT: 0.28

What is left of the strength of clean green wood in a real tree: knots, splits, rot, the stress where the trunk meets the crown, and the dynamic load of the gusts.

packages/weather/src/vegetation.ts:63