# @ferret/levels: API (continued)

### AttachOptions

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

```ts
interface AttachOptions
```

- `socket?: string` — a socket of the body's item (`grip_r`, `axe_r`...)
- `bone?: string` — a bone by name, with `position` and `rotation` of your own (they win over the socket's)
- `position?: [number, number, number]`
- `rotation?: [number, number, number, number]`
- `compatibleClips?: boolean` — also bind the clip sets of other skeletons that fit the part by bone names, and the other sets of its own skeleton (as for `CharacterOptions`): a rider's riding clips

### BindOptions

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

```ts
interface BindOptions
```

- `map?: Record<string, string>` — graph clip name -> clip name in the clip sets (default: every clip under its own name)
- `oneShot?: string[]` — graph clip names that do not loop

### BudgetLight

*interface* · `packages/levels/src/light-budget.ts:13`

```ts
interface BudgetLight
```

A level with hundreds of lamps, candles, torches and fires (Unreal draws them all as movable lights) cannot give each a real light: every
real light is paid for in every pixel of every lit surface. The light budget keeps a small pool of real lights and moves it to the lights
nearest the camera, from time to time; every other lamp is a glowing dot (an emissive instance of one shared mesh: one draw call for all).
The pool never changes size while it runs, so no shader is rebuilt when a light changes hands. A light that changes hands fades out and in
instead of popping. This is a performance limit, not a design: Unreal lights all of them.

- `id?: string` — a name for events and tests (the source actor's)
- `group?: string` — a group of lamps of one kind ('torch', 'candle'), for statistics and the sound budget
- `position: Vec3` — the level's metres
- `color: Vec3` — linear colour 0..1
- `intensity: number` — Babylon intensity at 1 m (already converted from the source engine's units, see `tools/ue-export/lights.mjs`)
- `range: number` — the metres where the light reaches zero (the source engine's attenuation radius)
- `kind?: 'point' | 'spot'`
- `direction?: Vec3` — a spot's axis (the way the light travels) and full cone angle in radians
- `angle?: number`
- `innerAngle?: number` — a spot's full bright core in radians (Unreal's 2 x inner cone angle): the light fades from it to `angle` as Unreal's cone does (glTF falloff only); default 0
- `flicker?: { min: number; max: number; rate?: number }` — a flame's flicker: the intensity moves between `min` and `max` times its value, `rate` times a second
- `priority?: number` — nearer than a light of priority 1 by this factor when ranking (a chandelier over a candle); default 1
- `size?: number` — the size of the glow dot in metres (default from the range)
- `sound?: string` — a looping sound this lamp makes (a torch's crackle); it is budgeted by `sounds`, the caller plays it

### CatalogOptions

*interface* · `packages/levels/src/catalog.ts:12`

```ts
interface CatalogOptions extends CatalogPolicy
```

- `tier?: string` — device tier: packages with a `tiers[tier]` file use it
- `prefix?: string` — put in front of every level id of this catalog (two catalogs may share ids)
- `decorate?: (def: LevelDef, entry: CatalogLevel) => LevelDef | void` — What the game adds to a level the catalog lists: its `build` step, its default spawn, its own name. Called with the def the catalog made (`prepare`, `plan` and `fetch` are set) and the catalog's entry; the returned def (or the same one changed in place) is registered. Runs again for every level when a refresh brings a new version.

### CatalogRegistration

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

```ts
interface CatalogRegistration
```

- `readonly url: string`
- `readonly catalog: Catalog`
- `readonly stale: boolean` — the catalog came from the copy kept by an earlier session (no network)
- `readonly unsigned: boolean` — development only: the catalog was not signed
- `readonly levels: string[]` — ids registered in the LevelService
- `refresh(): Promise<{ changed: boolean; stale: boolean }>` — Ask the server again. `changed` when a new version replaced the registered levels; a failure leaves everything as it was.

### CellSource

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

```ts
interface CellSource
```

What the service needs from the asset layer (an `AssetCache` fits): fetch and parse a file, then instantiate it.

- `load(url: string): Promise<void>`
- `instantiate(url: string, name?: string): Promise<{ root: BABYLON.TransformNode; dispose(): void }>`
- `release(url: string): void`

### CharacterOptions

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

```ts
interface CharacterOptions extends Omit<ModelOptions, 'pkg'>
```

- `compatibleClips?: boolean` — also bind the clip sets of other skeletons that list this body's skeleton as `compatible`, and the other sets of its own skeleton (as `<set id>/<clip>`)
- `tier?: LibraryTier`
- `yaw?: number`

### ClipRef

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

```ts
interface ClipRef
```

A clip set a character can use: where its file is, and the clips in it. Bind them with `bindClips` of `@ferret/animation`.

- `id: string`
- `ref: string`
- `skeleton: string`
- `clips: ClipsItem['clips']`
- `prefix?: string` — set for a clip set that only fits by bone names (`compatible`): its clips are bound as `<prefix><clip>`, so they never replace the body's own

### CodeLoaderOptions

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

```ts
interface CodeLoaderOptions
```

- `origin?: (pkg: FerretPackage) => boolean` — does this package come from where the game does (shipped with it, its own site)? Then its code is the game's (CodePolicy.origin)
- `trusted?: () => Iterable<string> | undefined` — key ids whose signatures are trusted; without them any valid signature is enough
- `ferret?: unknown` — the engine's API handed to the code (default `globalThis.Ferret`, the shared engine)
- `esm?: boolean` — the engine is ES modules: the code imports `@ferret/*` itself, so no engine API object is needed and `ctx.ferret` may be undefined
- `extendContext?: (ctx: LibraryContext, pkg: FerretPackage) => void` — add to the context handed to a package's `install` (the player adds `game`, `levels`, `root`, `args`, `tier`)
- `open?: (id: string, range: string) => Promise<FerretPackage | null>` — a package that is not open yet (a dependency, a `require` by id): open it, e.g. through the catalog; null when there is none
- `importModule?: (bytes: Uint8Array, path: string, pkg: FerretPackage) => Promise<LibraryModule>` — import the module from its checked bytes (default: a blob URL and `import()`; tests use a data URL)

### CollisionChunkDef

*interface* · `packages/levels/src/collision-chunks.ts:10`

```ts
interface CollisionChunkDef
```

- `file: string`
- `bounds: [number, number, number, number, number, number]`

### CollisionChunksDef

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

```ts
interface CollisionChunksDef
```

- `loadRadius: number`
- `unloadRadius: number`
- `chunks: CollisionChunkDef[]`

### DependencyOptions

*interface* · `packages/levels/src/dependencies.ts:12`

```ts
interface DependencyOptions
```

- `store: AssetStore` — the store the catalogs and packages are fetched through (give it a PersistentCache to keep them across sessions)
- `catalogs?: string[]` — catalogs searched first, in order, as absolute URLs (the page's own, from `<ferret-player catalogs>`)
- `tier?: string` — the device tier: a catalog package with a file for this tier uses it
- `policy?: (catalogUrl: string) => CatalogPolicy` — how a catalog is checked (signature, trusted keys), by its URL; default: signed by any valid key

### DependencyTarget

*interface* · `packages/levels/src/dependencies.ts:27`

```ts
interface DependencyTarget
```

Something that can hold open packages: a PackageMount (`add` registers its levels too) or a plain PackageSet.

- `get(id: string): FerretPackage | undefined`
- `add(pkg: FerretPackage): unknown`

### 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`

### DockedPair

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

```ts
interface DockedPair
```

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

### 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`

### 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:129`

```ts
interface Environment
```

- `post?: BABYLON.DefaultRenderingPipeline`
- `sun?: BABYLON.DirectionalLight`
- `ambient?: BABYLON.HemisphericLight`
- `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:21`

```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 }` — 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 } }` — 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 }` — 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).
- `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 }[]` — 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)

### 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 (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`

### FoliageFlowMap

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

```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:27`

```ts
interface FoliageWindDef
```

- `wind: { intensity: number; direction: [number, number] }` — Unreal's Wind_intensity and Wind_direction (X, Y)
- `rules: FoliageWindRule[]`

### FoliageWindHandle

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

```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 } }`
- `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:428`

```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:105`

```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:296`

```ts
interface GroundSource
```

The baked ground (colour in rgb, ground height in a) 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`

### 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`

### 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:58`

```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`

### LandscapeLayerDef

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

```ts
interface LandscapeLayerDef
```

- `name: string`
- `albedo: string` — colour image (sRGB); with `heightBlend` its alpha channel is the layer's height map
- `normal?: string` — optional tangent-space normal image
- `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`

### LandscapeSlope

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

```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:230`

```ts
interface LandscapeTextures
```

- `weights: BABYLON.BaseTexture[]`
- `albedo: BABYLON.BaseTexture[]`
- `normal: (BABYLON.BaseTexture | undefined)[]`

### LandscapeView

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

```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
- `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`

### 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.

### LevelManifest

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

```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
- `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

### 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 ...

### LibraryCard

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

```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:99`

```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:19`

```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:57`

```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:65`

```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:86`

```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:33`

```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:56`

```ts
interface LibraryQuery
```

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

### LibrarySound

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

```ts
interface LibrarySound
```

- `readonly id: string`
- `readonly name: string`
- `readonly item: SoundItem`
- `readonly format: 'wav' | 'mp3'`

### LightBudgetDef

*interface* · `packages/levels/src/light-budget.ts:42`

```ts
interface LightBudgetDef
```

- `budget: number` — how many real lights at most. A quality tier sets it in its own manifest (a weak GPU 2-3, a strong one 8-12)
- `items: BudgetLight[]`
- `perMesh?: number` — how many real lights one material draws (the cost per pixel), default the budget, at most MAX_MATERIAL_LIGHTS - 2. Each mesh takes the pool's lights that reach it first (see sortMeshLights), so a pool larger than this costs no more per pixel: a big pool with a small `perMesh` lights a hall of hundreds of lamps where each surface sees its own nearest few
- `interval?: number` — seconds between two re-rankings (default 0.25)
- `fade?: number` — seconds a light takes to fade out of / into a real light (default 0.35)
- `hysteresis?: number` — a new light must be nearer than the one it replaces by this share to take its place (default 0.15): no flapping between two equal lamps
- `maxDistance?: number` — lights farther from the camera than this are nothing at all (default 200 m)
- `rank?: 'distance' | 'view'` — how the real lights are chosen. 'distance' (default): the nearest to the camera. 'view': the ones whose reach (sphere of `range`) is in the camera's view, largest on screen first (range / distance): a lamp behind the camera that lights nothing in view gives way to the lamps that light what the player sees (Castle: the lamps at a door 20 m ahead lost to the candles over the player's head)
- `falloff?: 'gltf' | 'linear' | 'unreal'` — how a light fades with distance. 'gltf' (default): 1/d^2 cut off at `range` (physical, Unreal's inverse-squared lights). 'linear': 1 - d/range, the intensity is the value at the source (Babylon's standard falloff): Unreal's legacy lights fade as (1 - (d/R)^2)^8 and stay near their source, which a line through the same half-value point follows closely (tools/ue-export/lights.mjs `falloff`), but its edge is a visible ring on a near wall. 'unreal': Unreal's own curve (1 - (d/range)^2)^8 with `range` the attenuation radius, soft to zero at its edge. It replaces Babylon's standard falloff in the PBR shader for the whole page (see useUnrealFalloff; nothing else in Ferret uses the standard falloff)
- `excludeMeshes?: string` — a regular expression on mesh names: the pool's real lights do not light these meshes (a surface that already carries its lamps' light baked in, see tools/ue-export/bake-direct.mjs: the real light would count twice, and the baked one shows at any distance)
- `glow?: { enabled?: boolean; /** colour multiplier (above 1 feeds bloom), default 2 */ boost?: number; /** metres, default from each light's range */ size?: number }` — the dot for lamps that are not real lights
- `clustered?: boolean` — every lamp is a real light, drawn through Babylon's clustered lighting (`ClusteredLightContainer`: lights are binned into screen tiles and depth slices, a material reads only its tile's lights) instead of a pool of the nearest few: no 8-light limit per material, no ranking, no glow dots, no per-mesh sorting. `budget` is ignored (every item is a light). Needs WebGL2 / WebGPU and spot or point lights; where the engine cannot (`BABYLON.ClusteredLightContainer` missing or unsupported) the pool works as before. `excludeMeshes` does not apply to clustered lights
- `sounds?: { budget: number; maxDistance?: number }` — the nearest lamps that have a `sound`: events tell which to start and stop

### LightBudgetOptions

*interface* · `packages/levels/src/light-budget.ts:157`

```ts
interface LightBudgetOptions
```

- `name?: string`
- `viewer?: () => Vec3 | undefined` — where the viewer is, in the level's metres; default the active camera
- `materials?: boolean` — raise the materials' light limit to fit the pool plus the sun and ambient lights (default true)

### LightBudgetStats

*interface* · `packages/levels/src/light-budget.ts:155`

```ts
interface LightBudgetStats
```

- `items: number`
- `budget: number`
- `real: number`
- `glowing: number`
- `reranks: number`
- `soundsOn: number`

### LoadedCode

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

```ts
interface LoadedCode
```

- `id: string`
- `version: string`
- `exports: LibraryModule | null` — the module's exports; null for a package without code (only its dependencies were loaded)
- `commands: string[]` — commands and behaviours that appeared while `install` ran
- `behaviours: string[]`

### LookDef

*interface* · `packages/levels/src/material-models.ts:131`

```ts
interface LookDef
```

- `colourLayers?: ColourLayersDef`
- `macro?: MacroVariationDef[]`
- `groundBlend?: GroundBlendDef`

### LookStructure

*interface* · `packages/levels/src/material-models.ts:70`

```ts
interface LookStructure
```

What the shader is built from: part of the define's name, so two materials of one structure share a program and two of different structure never do.

- `base: 'albedo' | 'colour' | 'none'`
- `layers: { mask: string; channel: MaskChannel }[]`
- `macro: { mask: string }[]`
- `ground: boolean`

### LookTarget

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

```ts
interface LookTarget
```

an address the scene answers to

- `scope: LookScope`
- `uid: string`
- `via: string[]` — where the uid comes from: extras, model, library, mesh (type); extras, entity, actor, path (instance)
- `meshes: number` — meshes (placed actors count once each) it covers
- `materials: string[]` — the glTF material names found on them
- `ambiguous?: string` — why a write on it is refused (absent: it is one thing)

### ManifestEntity

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

```ts
interface ManifestEntity
```

- `id: string`
- `behaviour?: string` — a behaviour or component registered in the world (`world.components`)
- `components?: { name: string; params?: Record<string, unknown> }[]` — several components, each with its own parameters, when one behaviour is not enough
- `node?: string` — the name of a glTF node to wrap; without it a new empty node is made
- `transform?: { position?: [number, number, number]; rotation?: [number, number, number]; scale?: [number, number, number] }` — local transform applied to the node (or the new node)
- `params?: Record<string, unknown>`
- `tags?: string[]`
- `needs?: string` — the id of a streaming bundle this entity depends on: it is created once the bundle is in, and a placeholder stands at its position until then. It may also be the id of a streaming cell: the entity wraps a node of that cell, is made whenever the cell is resident and destroyed when the cell is released (no placeholder)

### ManifestIssue

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

```ts
interface ManifestIssue
```

- `path: string`
- `message: string`

### ManifestSpawn

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

```ts
interface ManifestSpawn
```

- `id: string`
- `position: [number, number, number]`
- `yaw?: number`
- `human?: string`

### MaterialInfo

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

```ts
interface MaterialInfo
```

- `name: string`
- `meshes: number`
- `look: boolean`
- `baseColor: [number, number, number, number]`
- `metallic: number | null`
- `roughness: number | null`
- `emissive: [number, number, number]`
- `emissiveStrength: number`
- `normalScale: number | null`
- `alphaMode: 'opaque' | 'mask' | 'blend'`
- `doubleSided: boolean`
- `maps: Partial<Record<MaterialMapSlot, boolean>>`

### MaterialLookDef

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

```ts
interface MaterialLookDef
```

- `baseColor?: [number, number, number] | [number, number, number, number]`
- `metallic?: number`
- `roughness?: number`
- `emissive?: [number, number, number]`
- `emissiveStrength?: number`
- `normalScale?: number`
- `alpha?: { mode: 'opaque' | 'mask' | 'blend'; cutoff?: number }`
- `doubleSided?: boolean`
- `maps?: Partial<Record<MaterialMapSlot, string>>`

### MaterialLooks

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

```ts
interface MaterialLooks
```

- `types?: LookTable`
- `instances?: LookTable`

