# @ferret/levels: API (continued)

### DistanceBlend

*interface* · `packages/levels/src/landscape.ts:67`

```ts
interface DistanceBlend
```

Unreal's Distance_Blend in metres: alpha = saturate((camera depth + offset) / range); 0 = the near picture, 1 = the far picture

- `offset: number`
- `range: number`

### DistanceFieldData

*interface* · `packages/levels/src/distance-field.ts:32`

```ts
interface DistanceFieldData
```

- `header: DistanceFieldHeader`
- `bytes: Uint8Array`

### DistanceFieldHeader

*interface* · `packages/levels/src/distance-field.ts:13`

```ts
interface DistanceFieldHeader
```

- `format: 'ferret-distance-field/1'`
- `voxel: number` — the spacing of the samples, metres
- `range: number` — the distance a byte reaches, metres, either way
- `brick: number` — cells along a side of a brick
- `origin: [number, number, number]` — the world place of sample 0 of brick (0, 0, 0), metres
- `grid: [number, number, number]` — bricks of the table along x, y, z
- `atlas: [number, number, number]` — bricks of the atlas along x, y, z
- `gradientScale: number`
- `data: string` — the data file, beside this one

### DockBackend

*interface* · `packages/levels/src/fmdl-docks.ts:42`

```ts
interface DockBackend
```

a join the geometry of which belongs to a capability (atoms): it places what it joins

- `handles(a: string, b: string): boolean`
- `dock(a: string, b: string): { placed: Record<string, Vec3>; info?: Record<string, unknown> }`
- `undock(a: string, b: string): void`

### DockBridgeLike

*interface* · `packages/levels/src/fmdl-docks.ts:274`

```ts
interface DockBridgeLike
```

- `define(name: string, sig: { args: string[]; min?: number; rest?: string; returns?: string }, fn: (ctx: any, ...args: any[]) => unknown): unknown`

### DockContext

*interface* · `packages/levels/src/dock.ts:28`

```ts
interface DockContext
```

What a docked level's `install` is given: the game's context as an example's code knows it (`game`, `levels`, `root`, `args`, `tier`) with the views of a dock.

- `game: DockParent['game']` — the parent's game seen through the scope: its world, scene and input record what the code adds
- `world: World`
- `levels: LevelService`
- `root: HTMLElement` — the level's own element in the parent's UI (its `docking.ui` fragment is inserted here); removed with the level
- `args: URLSearchParams`
- `tier: DockParent['tier']`
- `restart(): void` — start the level over: the same level is entered again under a travel (a standalone game reloads its page)
- `mount: PackageMount`
- `url(path: string): Promise<string>` — a blob URL for a file of the level's package
- `scope: Scope` — the level's scope: everything registered through it, and through `game` and `world`, is taken back at the end
- `parent: DockParent` — the parent as it is, outside the scope (for a completion layer that must reach it)
- `roles: Roles`
- `level: LevelDef`
- `pkg: { id: string; version: string; manifest: FerretPackage['manifest'] }`
- `docking: DockingBlock`
- `build: LevelContext` — the level's build context: `addSpawn` is the way to declare where the player stands
- `ferret: unknown` — the engine's API as the code loader holds it (`undefined` for code that imports `@ferret/*` itself)

### DockedLevel

*interface* · `packages/levels/src/dock.ts:57`

```ts
interface DockedLevel
```

What a docked level's `install` may return: the end of the level, and `ready` when the level goes on loading after `install` (the travel waits for it, with the world running).

- `dispose?(): void | Promise<void>`
- `ready?: Promise<unknown>`

### DockedPair

*interface* · `packages/levels/src/fmdl-docks.ts:58`

```ts
interface DockedPair
```

- `a: string`
- `b: string`
- `joint: DockJoint`
- `info?: Record<string, unknown>`

### DockHostOptions

*interface* · `packages/levels/src/dock.ts:59`

```ts
interface DockHostOptions
```

- `loader: CodeLoader`
- `mount: PackageMount`
- `parent: DockParent`
- `levels: LevelService`
- `onEnter?(ctx: DockContext): void | (() => void)` — called with the context just before `install` and after the roles are docked (the parent parks its hero, hides its own HUD ...); returns what it does at the end

### DockInfo

*interface* · `packages/levels/src/fmdl-docks.ts:48`

```ts
interface DockInfo
```

- `ref: string`
- `actor: string`
- `dock: string`
- `description: string`
- `position: Vec3` — world position and rotation of the dock's frame
- `rotation: Quat`
- `heldBy: string | null` — the ref of the dock holding this one, or null when it is free

### DockJoint

*interface* · `packages/levels/src/fmdl-docks.ts:27`

```ts
interface DockJoint
```

- `kind: 'fixed' | 'hinge' | 'ball' | 'bond'`
- `axis?: Vec3`
- `limits?: [number, number]`
- `breakForce?: number`

### DockOptions

*interface* · `packages/levels/src/fmdl-docks.ts:28`

```ts
interface DockOptions
```

- `joint?: DockJoint`
- `place?: boolean`

### DockParent

*interface* · `packages/levels/src/dock.ts:14`

```ts
interface DockParent
```

Docked travel: a level of kind `levels` with a `docking` block and code, entered from a parent game. The parent's door starts an ordinary `travel`; the
level's `build` step (`DockHost.enter`) runs the code's `install(DockContext)` under the transition, and the engine's unload of the level ends it: `dispose`, then the scope
(everything the code registered is taken back), the level's UI, the roles. The same engine runs both: the code is handed scoped views of the parent's game (`scopedGame`), so
what it adds is recorded and what the parent holds (the input, the player's character) answers for the roles the level does not bring itself.

- `game: { world: World; scene: BABYLON.Scene; input?: any; display?: { trackCamera?(cam: BABYLON.Camera): void } }` — the parent's game: `{ world, scene, input, display, ... }`
- `root: HTMLElement` — the element the parent's UI lives in; a level's own UI fragment goes in a child of it
- `args: URLSearchParams`
- `tier: 'desktop' | 'mobile' | 'low'`
- `engineModule?(name: string): string | undefined` — a URL of an engine package a worker of a level may import (`@ferret/<name>`); a parent that ships its engine inside its bundle has none, and a worker then must carry what it uses
- `camera?(): BABYLON.Camera | undefined` — the parent's own view, made current again when a level goes; without it the camera that was current when the level came, if it still exists

### DockPhysics

*interface* · `packages/levels/src/fmdl-docks.ts:31`

```ts
interface DockPhysics
```

what the kernel of a physics host gives: bodies of nodes and constraints (`dockPhysicsOf(host)`)

- `bodyOf(node: Node): unknown | undefined`
- `addConstraint(def: { type: 'fixed' | 'hinge' | 'ball'; a: any; b: any; anchor?: Vec3; axis?: Vec3; limits?: [number, number]; maxForce?: number; userData?: unknown }): { broken: boolean; userData?: unknown }`
- `removeConstraint(c: any): void`
- `moveBody(body: any, position: Vec3, orientation: Quat): void` — put a body where its node was placed (the docked actor was moved to the dock)
- `onBreak(cb: (c: any) => void): () => void` — called when a constraint breaks; returns the unsubscribe

### DocksOptions

*interface* · `packages/levels/src/fmdl-docks.ts:61`

```ts
interface DocksOptions
```

- `physics?: DockPhysics`
- `backends?: DockBackend[]`
- `emit?: (name: string, payload: unknown) => void`

### Environment

*interface* · `packages/levels/src/environment.ts:149`

```ts
interface Environment
```

- `post?: BABYLON.DefaultRenderingPipeline`
- `sun?: BABYLON.DirectionalLight`
- `shadows?: SunShadows` — the sun's shadows, when the definition asks for them: `add(meshes)` lets meshes cast and receive
- `ambient?: BABYLON.HemisphericLight`
- `veil?: FogVeil` — the volumetric fog's veil (`fog.volumetric`); shaders of their own read `fogVeilOf(scene)`
- `heightFog?: HeightFogMaterials` — the height fog integrated along each ray (`fog.alongRay`); `values` are the shader's numbers at the camera (heightFogShaderValues)
- `sky?: BABYLON.Mesh`
- `particles: BABYLON.ParticleSystem[]`
- `water: WaterSurfaceView[]`
- `lights?: LightBudget`
- `warnings: string[]` — effects that could not be made (an unknown kind)
- `dispose(): void`

### EnvironmentDef

*interface* · `packages/levels/src/environment.ts:24`

```ts
interface EnvironmentDef
```

The look of a level beyond its meshes: sun, ambient light, fog, sky and fixed effects. It is the manifest's `environment`;
`tools/ue-export` writes it from an Unreal level (sun, sky light, height fog, particle emitters). Every part is optional.

- `sun?: { direction: Vec3; color?: Vec3; intensity?: number; /** 0..1: how much of the atmosphere's reddening of the sun ray (its transmittance at the sun's elevation, scaled so the strongest channel stays 1) tints the light on the ground, as Unreal's atmosphere sun light does; needs `skyAtmosphere`; default 0 */ atmosphereTint?: number; /** cascaded shadow maps of the sun (see sun-shadows.ts); the level loader lets the placed groups and the scene's meshes cast and receive them */ shadows?: SunShadowsDef }` — the directional light; `direction` is where the light travels. `intensity` is in the source engine's units (Unreal lux-like): 4 is about 1 here
- `ambient?: { color?: Vec3; intensity?: number; direction?: Vec3; ground?: Vec3 }` — ambient light from the sky: a hemispheric light, a bit darker below. `direction` is the way its bright side faces (default up: floors are lit most); `ground` is the colour of the dark side (default `color` x 0.45). An interior lit from its ceiling faces it down: [0, -1, 0].
- `fog?: { density?: number; color?: Vec3; heightFalloff?: number; height?: number; maxOpacity?: number; start?: number; cutoff?: number; second?: { density: number; heightFalloff: number; heightOffset?: number }; /** with `heightFalloff`: integrate the fog along each ray from the eye, as Unreal does (height-fog-material.ts), instead of the camera's density for every distance; far peaks keep their shade */ alongRay?: boolean; /** with `alongRay`: Unreal's factor exactly: the transmittance is 2^-(the integral of the density), not e^-, and never below 1 - `maxOpacity` */ unreal?: boolean; /** Unreal's volumetric fog: a veil of the height fog's density times `extinctionScale` over the first `distance` metres (see fog-veil.ts) */ volumetric?: FogVeilDef }` — exponential fog; `density` in the source engine's units (per metre, about 10 times smaller here). With `heightFalloff` it is Unreal's ExponentialHeightFog: the density halves every 1 / (falloff x 0.1) metres above `height` (the fog actor's height, metres) and grows below it; the view's density follows the camera's height every frame. `second` is the component's second fog layer. Not done: `maxOpacity`, `start` and `cutoff` (Babylon's exponential fog has no such terms; they are carried in the manifest for a tool that wants them).
- `skyAtmosphere?: AtmosphereDef` — Unreal's SkyAtmosphere: the sky dome is the scattering of the sun's light in the planet's air (see atmosphere.ts) instead of the colour gradient. `{}` is the component's defaults. The sun gives the direction and colour; `top` / `horizon` / `ground` of `sky` still override the colours the water, the reflection and the fog take from it. The level's BP_Sky_Sphere actor adds nothing: the engine's sky sphere only recolours itself when a level asks it to, and the dome replaces it (`postprocess` drops the actor).
- `sky?: { top?: Vec3; horizon?: Vec3; ground?: Vec3 }` — the sky dome: a gradient from `horizon` to `top` with the sun's glow; colours default from the fog colour
- `reflection?: { intensity?: number; top?: Vec3; horizon?: Vec3; ground?: Vec3; sky?: boolean; size?: number }` — what metal and gloss reflect: a small cube map filled with a gradient (`top` / `horizon` / `ground` of its own, else the sky's), as the scene's environment texture. Without it a metal surface has nothing to reflect and draws near black (an interior has no sky for it). `intensity` scales both the reflection and the light the map adds to every surface (default 1; interiors want 0.3-0.6). With `sky` the map is the sky dome itself, drawn once into a cube of `size` pixels (default 128) when the dome's shader is ready: the gloss of wet ground and the metal of a hall reflect the clouds, the horizon's glow and the sun as the sky shows them. It only reflects: the light surfaces take from the sky stays the ambient's.
- `post?: { bloom?: number; threshold?: number }` — post-processing of the picture: `bloom` is the source engine's bloom intensity (Unreal's post process volume: 0.675 default, a glowing interior 3-4); bright parts (lamps, windows) glow around. A tier for weak GPUs leaves it out. `threshold` is the brightness that starts to glow (default 0.95).
- `probes?: ProbeVolumeDef` — baked global illumination (`tools/ue-export/bake-gi`): when present it lights every surface instead of the flat `ambient` light
- `roomReflection?: RoomReflectionDef` — an interior's reflections: the room drawn once into a cube map after loading (see room-reflection.ts); glass, glaze, metal and polished floors reflect it
- `effects?: { name?: string; kind?: 'fire'; template?: string; position: Vec3; scale?: number; /** an effect of the vfx catalogue (`fire.torch`, `fire.candle`, `fire.hearth` ...): drawn by the world's vfx service when it has one (else the simple fire); still near the camera only */ vfx?: string; params?: Record<string, number> }[]` — fixed effects placed in the level
- `motes?: AmbientParticlesDef[]` — motes in boxes of air (dust, pollen), see ambient-particles.ts
- `effectsRadius?: number` — metres: when set, a fire burns only while the camera is within this distance of it (hundreds of torches and candles cost nothing far away); it goes out beyond 1.25 x
- `water?: WaterDef | WaterDef[]` — open water: an ocean or a lake (see water.ts); swimming in it is the physics medium of the same surface
- `landscapes?: LandscapeDef[]` — layered landscapes (near ground, far backdrop) and the virtual texture blend of the props on them (see landscape.ts); the package loader applies them
- `materialScale?: MaterialScaleDef[]` — albedo repairs of baked materials that came out too dark (see material-scale.ts)
- `foliageWind?: FoliageWindDef` — wind in the foliage, bending grass, swaying trees and cloth, as Unreal's materials do it (see foliage-wind.ts)
- `lights?: LightBudgetDef` — hundreds of lamps and flames under a budget: the nearest few are real lights, the rest glow (see light-budget.ts)

### EnvironmentVfx

*interface* · `packages/levels/src/environment.ts:283`

```ts
interface EnvironmentVfx
```

An effect of the vfx catalogue placed by the environment: it is made out (no particles) and started and stopped as the camera comes near and goes.

- `start(): void`
- `stop(): void`
- `dispose(): void`

### FmdlLoadOptions

*interface* · `packages/levels/src/fmdl.ts:20`

```ts
interface FmdlLoadOptions
```

- `tier?: ModelTier` — the device tier: which levels are loaded (default desktop)
- `texture?: (ref: string, srgb: boolean) => Promise<BABYLON.Texture>` — a texture of the library by its `ferret://` reference (default: the file of the dependency package, read through the resolved model's reader; a model's own maps are read from its packages)
- `variant?: string` — the name of a variant of the materials (`render.variants.<name>`), a livery or a wear state

### Focus

*interface* · `packages/levels/src/streaming.ts:26`

```ts
interface Focus
```

A place the player (or a camera) is, with the way it faces: cells ahead are fetched first.

- `position: BABYLON.Vector3`
- `forward?: BABYLON.Vector3`

### FogVeilDef

*interface* · `packages/levels/src/fog-veil.ts:6`

```ts
interface FogVeilDef
```

- `extinctionScale: number` — Unreal's VolumetricFogExtinctionScale: the veil's density is the height fog's density at the camera times this
- `distance: number` — Unreal's VolumetricFogDistance, metres: the veil's depth
- `albedo?: [number, number, number]` — Unreal's VolumetricFogAlbedo (linear, 0..1): the veil's colour is the fog's colour times this (default white)

### FoliageFlowMap

*interface* · `packages/levels/src/foliage-wind.ts:235`

```ts
interface FoliageFlowMap
```

a local flow map the foliage reads on top of the wind (`FlowMap` of

- `readonly size: number`
- `readonly cell: number`
- `readonly originX: number`
- `readonly originZ: number`
- `readonly data: Float32Array`
- `readonly active: boolean`
- `readonly version: number`
- `readonly lowHeight?: number`
- `readonly highHeight?: number`

### FoliageWindDef

*interface* · `packages/levels/src/foliage-wind.ts:31`

```ts
interface FoliageWindDef
```

- `wind: { intensity: number; direction: [number, number] }` — Unreal's Wind_intensity and Wind_direction (X, Y)
- `rules: FoliageWindRule[]`
- `fromMaterials?: boolean` — the library materials that carry a `grassWind` (their master's SimpleGrassWind inputs) flutter by it, with no rule of their own to write; `rules` may then be empty

### FoliageWindHandle

*interface* · `packages/levels/src/foliage-wind.ts:237`

```ts
interface FoliageWindHandle
```

- `readonly materials: number` — how many materials took a rule
- `bendAt(p: { x: number; y: number; z: number } | null, radius?: number): void` — the player's position in the engine's metres (grass bends away from it); null: nobody
- `setWind(w: { intensity?: number; direction?: [number, number] }): void` — change the wind at run time
- `readonly current: { intensity: number; direction: [number, number] }` — the wind now (the same object every call: do not keep it across a change)
- `dispose(): void`

### FoliageWindRule

*interface* · `packages/levels/src/foliage-wind.ts:19`

```ts
interface FoliageWindRule
```

Wind in the foliage, as Unreal's materials do it: the vertex shader moves the vertices (world position offset). Four programs, each a material of Unreal's own set-up
(their graphs are written out in plans/port-forest.md), selected by the flags of a rule:
 - `flutter`: the engine's SimpleGrassWind function: a vertex swings about a point 10 cm below it, its angle two travelling triangle waves of the world position and time,
   scaled by a weight (a constant, or 1 - v of the first UV set) and by the vertex colour's red channel when the mesh has one (the painted mask: tips move, roots stay);
   a steady push along the wind direction is added (`directional`);
 - `bend`: MF_Collusion (grass bends away from the player): offset = (1 - clamp(distance to the player / distance)) * (1 - v)^2 * horizontal direction away * strength;
 - `sway`: MF_TreesWind's whole-tree rotation about the object's pivot, about the horizontal axis perpendicular to the wind, by an angle of
   ((sin(0.25 (pivotY + t)) + intensity) / 8) * windIntensity / 60 turns, weighted by the height of the vertex in the mesh's bounding box (0 at the foot, 1 at the top);
 - `swing`: the clothesline (M_ClothesLine): a hanging cloth swings about the object's local X axis through the pivot and droops by sin(pi u) * droop (u: the vertex's place
   along the bounding box's X), the swing angle a sine of time shifted by the pivot, the vertex colour's alpha and u, plus a SimpleGrassWind flutter weighted by the alpha.
The wind itself is two numbers of the level (`intensity`, `direction`: Unreal's Wind_intensity and Wind_direction of the MPC_Wind_And_COLOR_Parameter collection, the direction
in Unreal's X, Y). All lengths here are Unreal's centimetres and turns, the shader converts the engine's metres (x, y, z) to Unreal's (-x, z, y) * 100 and back.
The player's position (for `bend`) is given at run time with `bendAt`.

- `match: string` — a regular expression over the glTF material name
- `flutter?: { influence: number; speed?: number; weight?: number; weightFromUV?: boolean; directional?: number; useVertexColor?: boolean; alphaWeight?: { multiplier: number; offset: number }; /** the influence is not scaled by the level's wind and the added offset is `push` centimetres on all three axes: a leaf master's own SimpleGrassWind (see `GrassWindDef` of @ferret/assets) */ absolute?: boolean; push?: number; /** the whole flutter is scaled by one channel (0 r .. 3 a) of a picture the material carries (`levelMaterial.grassWindWeight`), read at the vertex's first texture coordinates */ weightMap?: { channel: number } }`
- `bend?: { distance: number; strength: number }`
- `sway?: { intensity: number }`
- `swing?: { droop: number; speed: number; vertexColorDistortion: number; uvTimeDistortion: number; angleAlongWind: number; againstWind: number; windMultiplier: number; flutterWeight: number; flutterSpeed: number }`

### FormBridgeLike

*interface* · `packages/levels/src/fmdl-motion.ts:480`

```ts
interface FormBridgeLike
```

- `define(name: string, sig: { args: string[]; min?: number; rest?: string; returns?: string }, fn: (ctx: any, ...args: any[]) => unknown): unknown`
- `lasting(name: string, sig: { args: string[]; min?: number; rest?: string; returns?: string }, fn: (ctx: any, ...args: any[]) => { done(): boolean; result?: unknown }): unknown`

### FreezeOptions

*interface* · `packages/levels/src/static-freeze.ts:10`

```ts
interface FreezeOptions
```

- `root: string` — the level root's name: only meshes named `<root>/...` are frozen
- `sequences?: { tracks?: { target?: unknown }[] }[]` — sequences of the level (their string track targets are moving)
- `find?: (name: string) => BABYLON.Node | null` — finds a scene node by a track target / name (the game's own lookup; default: by exact name or `/name` suffix)
- `moving?: Iterable<BABYLON.Node>` — more nodes that move
- `keepLive?: (mesh: BABYLON.AbstractMesh) => boolean` — meshes under the root that a name test keeps live (a game's own rule)

### GlbIndex

*interface* · `packages/levels/src/material-look.ts:106`

```ts
interface GlbIndex
```

what the scene glb says about its names: which glTF mesh each node name draws, and how many meshes carry a name

- `nodeMesh: Map<string, string | null>` — node name → glTF mesh name (null: nodes of that name draw meshes of different names)
- `meshCount: Map<string, number>` — glTF mesh name → how many glTF meshes carry it

### GroundSource

*interface* · `packages/levels/src/landscape.ts:581`

```ts
interface GroundSource
```

The baked ground (colour in rgb, ground height in a; and `surface`: normal and roughness) of a landscape with a virtual texture, over its rectangle, as materials that blend with the ground read it.

- `texture: BABYLON.BaseTexture`
- `rect: [number, number, number, number]`
- `toLandscape: () => BABYLON.Matrix`
- `surface?: BABYLON.BaseTexture` — the second baked picture: the ground normal's x and z in the landscape's frame (its y is rebuilt: sqrt(1 - x^2 - z^2)) in r and g, the ground roughness in b; absent when the ground has none

### HairFibreOptions

*interface* · `packages/levels/src/hair-fibre.ts:57`

```ts
interface HairFibreOptions
```

- `exposure?: number` — Overall brightness before the tone curve (default 0.6).
- `lights?: { dir: [number, number, number]; color: [number, number, number] }[]` — Lights as directions *towards* the light and colours (intensity folded in). Default: the scene's directional lights (up to three), else a studio key, rim and fill.
- `ambient?: [number, number, number]` — Ambient colour (default from the scene's hemispheric lights, else 1).

### HeightFogDef

*interface* · `packages/levels/src/height-fog.ts:10`

```ts
interface HeightFogDef
```

- `density: number`
- `heightFalloff: number`
- `height: number` — height of the fog actor, metres
- `second?: HeightFogLayer`
- `exact?: boolean` — the rays take Unreal's factor exactly (height-fog-material.ts): 2^-integral
- `maxOpacity?: number` — with `exact`: the most the fog may cover, 0..1 (default 1)

### HeightFogLayer

*interface* · `packages/levels/src/height-fog.ts:8`

```ts
interface HeightFogLayer
```

- `density: number`
- `heightFalloff: number`
- `heightOffset?: number`

### Key

*interface* · `packages/levels/src/sequence.ts:16`

```ts
interface Key<V>
```

- `t: number`
- `v: V`
- `interp?: Interp`

### LandscapeDef

*interface* · `packages/levels/src/landscape.ts:119`

```ts
interface LandscapeDef
```

- `name: string`
- `mesh?: string` — regex source for the landscape's mesh names (default `^<name>$`)
- `rect: [number, number, number, number]` — [minX, minZ, maxX, maxZ], metres, in the mesh's own coordinates; the weightmaps and the virtual texture cover it
- `layers: LandscapeLayerDef[]`
- `weights: string[]` — weightmap images over `rect`: file i holds the weights of layers 4i..4i+3 in R, G, B, A
- `far?: boolean` — the far backdrop: no collision, never picked, always drawn; layers and weights are optional for it
- `virtualTexture?: VirtualTextureDef`
- `packed?: boolean` — Keep every picture of the landscape in two texture arrays (colour with roughness in alpha; normal with occlusion in alpha) instead of one sampler each: a material then needs the weightmaps, two array samplers and the macro picture, however many layers, far pictures and world aligned pictures there are. Pictures of one array share a size.

### LandscapeFar

*interface* · `packages/levels/src/landscape.ts:65`

```ts
interface LandscapeFar
```

- `tile: number`
- `albedo?: string`
- `nao?: string`

### LandscapeLayerDef

*interface* · `packages/levels/src/landscape.ts:25`

```ts
interface LandscapeLayerDef
```

- `name: string`
- `albedo: string` — colour image (sRGB); with `heightBlend` its alpha channel is the layer's height map. '' for a layer that has only a `colour`
- `colour?: Vec3` — a constant colour (linear) instead of a picture: Unreal's far plane master blends vector parameters, not pictures
- `normal?: string` — optional tangent-space normal image
- `nao?: string` — a packed image of the near picture's normal map (rgb, as stored) and ambient occlusion (alpha), read at the layer's tiling; needs `LandscapeDef.packed`
- `flatten?: number` — Unreal's FlattenNormal on the layer's normal: the normal moves toward (0, 0, 1) by this fraction (negative: the relief is exaggerated); the layer function's Normal_Intensity
- `roughness?: string` — optional roughness image (data, its red channel), read at the layer's tiling: Unreal's layer function multiplies it by `roughnessScale`
- `roughnessScale?: number` — the layer's roughness multiplier (the function's scalar parameter); with no `roughness` image the layer's roughness is this number (default 1 when either is given)
- `tile: number` — metres of one repeat of the layer's textures (Unreal: 100 / the material's UV scale)
- `tint?: Vec3` — multiplies the albedo (linear)
- `heightBlend?: number` — 0 = plain weight blend; above 0 = Unreal's height blend, the layer's height (albedo alpha) times this decides who wins where weights overlap
- `slope?: LandscapeSlope` — Unreal's slope-driven automatic layer (WorldAlignedBlend on the ground normal): see `LandscapeSlope`
- `far?: LandscapeFar` — the picture for far distances: another tile size (and image); `tile` 0 is the one texel at uv 0 (a layer whose far scale is 0). Mixed with the near picture by `blend`
- `blend?: DistanceBlend` — the camera-depth mix of the near and the far picture (Unreal's Distance_Blend); without it the near picture is always used
- `roughnessAlpha?: boolean` — the albedo image's alpha channel is the layer's roughness (data), packed so that the layer needs no sampler of its own for it
- `saturation?: number` — Unreal's Desaturation node: the colour moves toward its luminance by this fraction (negative: more saturated)
- `power?: number` — Unreal's Power node on the colour (the picture's colour, linear)
- `hue?: number` — Unreal's HueShift function: the colour plus the colour turned about the grey axis by this many revolutions (0 turns nothing, so the colour comes out doubled, as the graph's Add does)
- `world?: LandscapeWorldAligned` — a world aligned layer: its own picture is the one on steep faces, projected along the axes; see `LandscapeWorldAligned`

### LandscapePicture

*interface* · `packages/levels/src/landscape.ts:70`

```ts
interface LandscapePicture
```

one picture of a world aligned layer

- `albedo: string` — colour image, or the same file as another layer's albedo (it then shares that layer's sampler)
- `tile: number`
- `far?: LandscapeFar`
- `blend?: DistanceBlend`
- `roughnessAlpha?: boolean`
- `roughnessScale?: number`
- `saturation?: number`
- `power?: number`
- `hue?: number`
- `nao?: string`
- `flatten?: number`

### LandscapeSlope

*interface* · `packages/levels/src/landscape.ts:106`

```ts
interface LandscapeSlope
```

The layer shows its own picture where the ground is flat and the pictures of two other layers (indices into `layers`, whatever their paint weights say)
where it is steep: colour = mix(mix(steep[0], steep[1], mix), own, flat), each ramp over the up component of the ground normal.
Unreal: the M_Landcape 'auto' layer blends rock and gravel by one WorldAlignedBlend and that with the grass by another.

- `steep: [number, number]`
- `flat: SlopeRamp`
- `mix: SlopeRamp`

### LandscapeTextures

*interface* · `packages/levels/src/landscape.ts:464`

```ts
interface LandscapeTextures
```

- `arrays?: { albedo: BABYLON.BaseTexture; nao?: BABYLON.BaseTexture }`
- `weights: BABYLON.BaseTexture[]`
- `albedo: (BABYLON.BaseTexture | undefined)[]`
- `normal: (BABYLON.BaseTexture | undefined)[]`
- `roughness?: (BABYLON.BaseTexture | undefined)[]`
- `extra?: BABYLON.BaseTexture[]`

### LandscapeView

*interface* · `packages/levels/src/landscape.ts:678`

```ts
interface LandscapeView
```

- `def: LandscapeDef`
- `meshes: BABYLON.AbstractMesh[]`
- `virtualTexture?: BABYLON.BaseTexture` — the baked virtual texture (colour in rgb, ground height in a), when the landscape has one
- `virtualSurface?: BABYLON.BaseTexture` — its second picture: the ground normal (x, z in the landscape's frame) and the roughness (see `GroundSource.surface`)
- `requiredMaxZ?: number` — camera depth (maxZ) a far landscape needs to be seen whole: the rectangle's diagonal plus the camera's height over it, rounded up
- `warnings: string[]`
- `dispose(): void`

### LandscapeWorldAligned

*interface* · `packages/levels/src/landscape.ts:90`

```ts
interface LandscapeWorldAligned
```

Unreal's MF_Rock_Cliff: three world aligned pictures stacked by the slope of the ground. The layer's own picture is on steep faces; `flat` takes over where the up component of the
ground normal rises over `flatRamp` ([from, to]: 0 below `from`, 1 above `to`), `top` (grass) over `topRamp`. `macro` multiplies the colour by powers of a large scale variation picture
(Unreal's Micro_Variation inputs): the colour times prod(pow(texture(uv / tiles[k]).rgb, powers[k])); the picture is data, not colour.

- `flat: LandscapePicture`
- `flatRamp: [number, number]`
- `top?: LandscapePicture`
- `topRamp?: [number, number]`
- `macro?: { albedo: string; tiles: [number, number, number]; powers: [number, number, number] }`

### LevelContext

*interface* · `packages/levels/src/levels.ts:11`

```ts
interface LevelContext
```

What a level's builder gets. Everything it makes (nodes, lights, materials, entities) is removed again when the level goes.

- `world: World`
- `scene: BABYLON.Scene`
- `level: LevelDef`
- `addSpawn(s: { id: string; position: BABYLON.Vector3 | [number, number, number]; yaw?: number; human?: string }): void` — declare where the player may start
- `progress(p: number): void` — report progress 0..1 to the loading screen

### LevelDef

*interface* · `packages/levels/src/levels.ts:22`

```ts
interface LevelDef
```

One entry of the level registry (the equivalent of a row of UE's DT_LevelInfo).

- `id: string`
- `name?: string`
- `url?: string` — a level package folder: scene.glb, manifest.json, navmesh.bin (see ./package)
- `build?(ctx: LevelContext): void | Promise<void>` — or code that builds the level: procedural levels, greyboxes, tests
- `spawn?: string` — the spawn used when the level is entered without naming one (default: the first declared)
- `data?: Record<string, unknown>` — anything the game wants to keep with the level: music, weather, display name
- `tags?: string[]` — free tags (a theme, a chapter): handed to the game's choices, never read by the engine
- `environment?: { skip?: EnvironmentPart[] }` — parts of the level's `environment` the game draws itself (its own sky, its own water): the loader leaves them out; the rest is as the manifest says
- `prepare?(progress: (p: number) => void, signal?: AbortSignal): Promise<void>` — Get what the level needs ready before the old level is touched (a remote level opens its package here). If it throws the travel fails and the player stays in the current level. `progress` takes 0..1 of this step.
- `plan?(): Promise<LevelPlan>` — What fetching the level will download, known after `prepare`: bytes and files not held yet, and whether everything is already on the device.
- `fetch?(ctx: { signal: AbortSignal; progress(loaded: number, total: number, files: number): void; /** files read at once (default: the level's own choice; a background prefetch asks for 1) */ concurrency?: number }): Promise<void>` — Step 4 of a travel: bring the core set of the level to the device. `progress` takes bytes. A failure or a cancel leaves the old level in place.

### LevelFiles

*interface* · `packages/levels/src/level-materials.ts:146`

```ts
interface LevelFiles
```

What the level materials read the package through (the package loader's own fetch, never the library).

- `json(path: string): Promise<any>`
- `blobUrl(path: string): Promise<string>` — a URL the engine can load the file from (a blob URL of the fetched bytes)

### LevelManifest

*interface* · `packages/levels/src/manifest.ts:84`

```ts
interface LevelManifest
```

- `version: number`
- `name?: string`
- `scene?: string` — file names inside the package folder (defaults: scene.glb, navmesh.bin)
- `navmesh?: string`
- `navBuild?: { agentRadius?: number; agentHeight?: number; maxClimb?: number; maxSlope?: number; cellSize?: number; bounds?: NavBoxDef | NavBoxDef[]; exclude?: (NavBoxDef & { yaw?: number })[] }` — how to build the NavMesh from the level's solid meshes: used when navmesh.bin is missing (or being rebuilt by the editor)
- `collision?: string` — a mesh of simple collision shapes (invisible, solid). When present, the visible meshes of the scene do not collide
- `collisionChunks?: CollisionChunksDef` — the solid shapes outside the play area, cut into chunks that are fetched as the player nears them (see CollisionChunksDef); written by tools/ue-export/collision.mjs. Needs `collision`
- `movement?: Partial<Record<(typeof MOVEMENT_KEYS)[number], number>>` — the values of the level's player character (metres, seconds; see CharacterParams in
- `animGraphs?: Record<string, unknown>` — animation graphs by name (see GraphDef in
- `entities?: ManifestEntity[]`
- `spawns?: ManifestSpawn[]`
- `zones?: unknown[]`
- `physics?: Record<string, unknown>` — realistic physics for this level (see PhysicsConfig in
- `vfx?: { defs?: unknown[]; place?: unknown[] }` — effects of the level (see VfxBlock in
- `libraries?: Record<string, string>` — the library packages the level needs, id -> version range: written by the editor from what the open libraries `provide`; `travel` requires them before the level is built
- `colliders?: { node: string; collide: boolean }[]` — collision overrides by glTF node name: make a node (and its meshes) solid or walk-through whatever the export says
- `defaultSpawn?: string` — the spawn used when the level is entered without naming one
- `environment?: EnvironmentDef` — sun, ambient light, fog, sky and fixed effects (see EnvironmentDef)
- `materialLooks?: MaterialLooks` — the look of the scene's glTF materials, by TYPE (a model: its uid, all instances) and by INSTANCE (one object: its uid, over the type's look), then by the glTF material name inside the model (see material-look.ts): colour, metallic, roughness, emissive, normal scale, alpha mode, maps; set live by the editor (`edit.material.set`)
- `tags?: string[]` — free tags and data for the game (a theme, a chapter, a mood): handed to the game's choices (`LevelDef.tags` / `data`), never read by the engine
- `data?: Record<string, unknown>`
- `placements?: string[]` — placement lists (`*.placements.json`, see placements.ts) loaded with the core: library models placed with GPU instancing, material overrides per actor
- `levelMaterials?: LevelMaterialsRef` — the level's own materials (level-materials.ts): `materials` a file of definitions (`ferret-materials/1`) or them inline, `textures` the catalogue of the level's KTX2 files (a file or inline), `codec` the one policy that picks UASTC or ETC1S (`best`, `light`, `chosen`; default `best`). A mesh slot of a placed model takes the material of its name; no library is asked
- `streaming?: StreamingBlock` — streaming inside the level: `scene` is then the core (what is visible and solid at the spawn) and the rest arrives by cell
- `visibility?: VisibilityBlock` — precomputed visibility for a level of rooms: what is not in sight from the player's grid cell is not drawn (see VisibilityBlock)
- `snapshot?: boolean` — the level keeps its draw list while it runs (its moving things only move): on a WebGPU engine its frame is recorded once and replayed
- `occlusion?: boolean | { minRadius?: number; minIndices?: number; algorithm?: 'conservative' | 'accurate' }` — occlusion queries on the level's big meshes; sizes in metres and indices
- `relevance?: RelevanceBlock` — the level's own values for the relevance service: per camera mode the largest turn rate `omega` (rad/s) and the horizon (s), and the tuning; they win over what the engine reads from the camera

### LevelMaterialOverride

*interface* · `packages/levels/src/placements.ts:39`

```ts
interface LevelMaterialOverride
```

A material of the level (level-materials.ts) standing in for a material of the model, by the name it has in the level's definitions.

- `material: string`

### LevelMaterialsFile

*interface* · `packages/levels/src/level-materials.ts:42`

```ts
interface LevelMaterialsFile
```

- `format: typeof LEVEL_MATERIALS_FORMAT`
- `materials: Record<string, MaterialDef>`

### LevelMaterialsOptions

*interface* · `packages/levels/src/level-materials.ts:169`

```ts
interface LevelMaterialsOptions
```

- `policy?: LevelCodecPolicy` — the file policy of two-codec textures (default `best`)
- `warn?: (message: string) => void`
- `makeTexture?: (path: string, o: { srgb: boolean; scene: BABYLON.Scene }) => BABYLON.BaseTexture | Promise<BABYLON.BaseTexture>` — make a texture from a file of the level (default: a Babylon texture from the blob URL, resolved when loaded; tests pass their own)
- `anisotropy?: number` — the anisotropy of the textures (default 8, Unreal's default texture filter)
- `programTextureBudget?: number` — How many pictures a program (a master carried whole) may read one by one (default 8: a fragment shader has 16 texture units and Babylon's own lighting, shadows, reflection and the level's decal buffer and distance field take some). A program with more has its pictures put into texture arrays by size and format (texture-array.ts): one unit per array. Not used with `makeTexture` (a test's own pictures are not KTX2 files).
- `readyTimeoutMs?: number` — the longest `ready()` waits for the transcoding of textures already read (default 20000 ms; a texture still not decoded is a warning)
- `video?: (mediaTexture: string, scene: BABYLON.Scene) => BABYLON.BaseTexture | undefined | Promise<BABYLON.BaseTexture | undefined>` — the picture of a `video` material (an unlit master whose colour is a media texture): the level's assembly hands the video source; none given, the surface stays its base colour

### LevelMaterialsRef

*interface* · `packages/levels/src/placements.ts:41`

```ts
interface LevelMaterialsRef
```

Where the level's own materials come from: file names (read through the loader) or definitions inline, the texture catalogue likewise, and the codec policy (default `best`).

- `materials?: string | Record<string, MaterialDef>`
- `textures?: string | Record<string, unknown> | unknown[]`
- `codec?: LevelCodecPolicy`
- `distanceField?: string` — the header of the level's distance field (distance-field.ts), for the materials that read it
- `screenDecals?: string` — the file of the level's projected decals (screen-decals.ts): `{ decals: ScreenDecalSpec[] }`, each naming one of the level's materials

### LevelOptions

*interface* · `packages/levels/src/levels.ts:86`

```ts
interface LevelOptions
```

Minimum time the loading screen stays up, so it does not flash (ms; 0 in tests).

- `minLoadingMs?: number`
- `slowMs?: number` — no new bytes for this long while the target downloads: `travel:slow` {slow: true} (default 5000)
- `holdMs?: number` — the longest the level waits, after it is built, for what its entities asked to be waited for (`hold`) before it is announced ready anyway (default 20000; what was missing goes to the report's warnings)
- `keepOldUntilReady?: boolean` — true on devices with room: a failed travel rebuilds the old level and returns the player to the spot; false (console): to the hub
- `transitionEnterMs?: number` — how long a transition has to get on screen before the engine's bar replaces it (default 2000)

### LevelPlan

*interface* · `packages/levels/src/levels.ts:51`

```ts
interface LevelPlan
```

- `bytes: number`
- `files: number`
- `cached: boolean`

### LevelReport

*interface* · `packages/levels/src/levels.ts:80`

```ts
interface LevelReport
```

- `warnings: string[]` — things the manifest asked for that the level could not provide: missing nodes, unknown behaviours ...

### LevelTextureCatalogue

*interface* · `packages/levels/src/level-materials.ts:40`

```ts
interface LevelTextureCatalogue
```

- `textures: Map<string, LevelTextureEntry>`

### LevelTextureEntry

*interface* · `packages/levels/src/level-materials.ts:39`

```ts
interface LevelTextureEntry
```

- `stem: string`
- `srgb?: boolean`
- `codec?: LevelCodec`
- `files: Partial<Record<LevelCodec, string>>`

### LibraryCard

*interface* · `packages/levels/src/library.ts:81`

```ts
interface LibraryCard
```

a candidate as the AI that asks reads it

- `id: string`
- `uid?: string`
- `type: string`
- `name: string`
- `tags: string[]`
- `rubric?: string`
- `description?: string`
- `preview?: string`
- `size?: number`
- `versions?: string[]`

### LibraryCharacter

*interface* · `packages/levels/src/library.ts:113`

```ts
interface LibraryCharacter
```

- `readonly id: string`
- `readonly item: CharacterItem`
- `readonly model: ModelHandle`
- `readonly clips: ClipRef[]` — the clip sets of the character, resolved from the catalog
- `dispose(): void`

### LibraryContext

*interface* · `packages/levels/src/code.ts:20`

```ts
interface LibraryContext
```

What `install` gets.

- `world: World`
- `ferret: any` — the engine's API (every package's exports in one namespace)
- `pkg: { id: string; version: string; manifest: FerretPackage['manifest'] }` — this package
- `mount: PackageMount`
- `url(path: string): Promise<string>` — a blob URL for a file of this package, or `ferret://dep/path` of a declared dependency
- `require(id: string): unknown` — the exports of a declared dependency's code (already loaded before this one)

### LibraryEntry

*interface* · `packages/levels/src/library.ts:71`

```ts
interface LibraryEntry extends CatalogAsset
```

- `id: string`
- `version?: string` — the library version this entry was resolved to (the reference's, or 1.0.0); set by `entry()`, absent from `list()`
- `versions?: string[]` — every version of the asset (the server's numbers, oldest first); set by `list()`

### LibraryFind

*interface* · `packages/levels/src/library.ts:79`

```ts
interface LibraryFind
```

a request to the library service: keywords (English), narrowed by exact type, rubric (and everything beneath it) and tags

- `q?: string`
- `type?: string`
- `rubric?: string`
- `tags?: string[]`
- `limit?: number`
- `offset?: number`

### LibraryModel

*interface* · `packages/levels/src/library.ts:100`

```ts
interface LibraryModel
```

A static library model on its way (a tree, a rock): `model` is the handle, `item` its file (bounds, collision).

- `readonly id: string`
- `readonly item: ModelItem`
- `readonly model: ModelHandle`
- `dispose(): void`

### LibraryModule

*interface* · `packages/levels/src/code.ts:34`

```ts
interface LibraryModule
```

What a package's code module exports. `install` may return `{ dispose }` or a promise of it.

- `install?(ctx: LibraryContext): unknown`
- `[name: string]: unknown`

### LibraryQuery

*interface* · `packages/levels/src/library.ts:70`

```ts
interface LibraryQuery
```

- `type?: LibraryItem['type']`
- `tags?: string[]`
- `text?: string`
- `rubric?: string`

