# @ferret/assets: API (continued)

### MaterialDef

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

```ts
interface MaterialDef
```

A superset of glTF's PBR material that maps to Babylon's `PBRMaterial` one to one.

- `model?: 'pbr' | 'unlit'`
- `baseColor?: [number, number, number, number]`
- `metallic?: number`
- `roughness?: number`
- `maps?: Partial<Record<MapSlot, string>>` — `ferret://<package>/<path>` references to the maps; the package must be a dependency of the one holding the material
- `normalScale?: number`
- `uv?: { scale?: [number, number]; offset?: [number, number]; rotation?: number }`
- `worldAligned?: { size: number }` — projected by world position (triplanar), one repeat per `size` metres
- `alpha?: { mode: AlphaMode; cutoff?: number; source?: 'rgb' | 'a' }` — `source`: where a mask or blend material's opacity comes from in its `opacity` map: `rgb` (its luminance, default) or `a` (its alpha channel, what Unreal's leaf masters read)
- `opacityGradient?: OpacityGradientDef` — a soft edge: the opacity is multiplied by `1 - u` (`invert`) or `u` of the UV set `coordinate` (only set 0 is carried)
- `depthFade?: DepthFadeDef` — Unreal's DepthFade: the opacity is multiplied by `opacity * saturate((scene depth behind the surface - the surface's depth) / distance)` (centimetres)
- `opacity?: number` — a constant factor of the opacity of a translucent surface (default 1)
- `video?: { mediaTexture: string }` — a video on the surface (an unlit master whose colour is a MediaTexture): the level's assembly gives `mediaTexture` a video source (`LevelMaterialsOptions.video`)
- `graph?: GraphDef` — the master as an expression tree no field above can say (Unreal's own default grid material): see `GraphDef`
- `doubleSided?: boolean`
- `specular?: number`
- `ior?: number`
- `emissive?: [number, number, number]`
- `emissiveStrength?: number`
- `masks?: Record<string, string>` — extra pictures the colour model below reads, by name (`ferret://` references; mask and grunge images are data, never sRGB)
- `colourLayers?: ColourLayersDef` — colour layers by mask channel: the albedo is a base colour (or the albedo map) painted over by colours through masks (Unreal's chain of LinearInterpolate nodes)
- `macro?: MacroVariationDef[]` — world-space macro variation: the albedo times `pow(picture, power)`, the picture projected from the three axes by world position (Unreal's WorldCoordinate3Way)
- `groundBlend?: GroundBlendDef` — the foot of the object takes the colour of the ground under it (Unreal's runtime virtual texture blend, `MF_Virtual_Texturing`)
- `detailNormal?: DetailNormalDef` — a second normal map read at its own scale and added to the normal's x and y only (Unreal's DetailTexturing): see `DetailNormalDef`
- `patternLayer?: PatternLayerDef` — a second set of maps (a pattern) blended with the base maps by a mask (the pattern masters): see `PatternLayerDef`
- `vertexMasks?: VertexMasksDef` — vertex colours as masks (Unreal's VertexColor node): the albedo is never tinted by them; see `VertexMasksDef`
- `twoSidedFoliage?: TwoSidedFoliageDef` — Unreal's TwoSidedFoliage shading model: light that falls on the back of the surface shows through it, tinted by `color` (the master's SubsurfaceColor; linear)
- `pixelDepth?: PixelDepthDef` — Unreal's PixelDepthOffset of a master: see `PixelDepthDef`
- `grassWind?: GrassWindDef` — wind of the leaf masters: the engine's SimpleGrassWind with its inputs as the material instance gives them (see `GrassWindDef`); played by `applyFoliageWind` when its block says `fromMaterials`
- `program?: MaterialProgram` — the master carried whole as a program (nodes, textures, the instance's parameters): see `MaterialProgram` (material-program.ts)
- `decal?: boolean` — a decal laid on a surface (Unreal's mesh decal): drawn translucent just in front of what is under it, writing no depth, casting no shadow

### MaterialInput

*interface* · `packages/assets/src/model-import.ts:92`

```ts
interface MaterialInput
```

- `color?: [number, number, number, number]`
- `roughness?: number`
- `metallic?: number`
- `doubleSided?: boolean`
- `alpha?: 'opaque' | 'mask' | 'blend'`

### MaterialItem

*interface* · `packages/assets/src/library.ts:238`

```ts
interface MaterialItem extends ItemBase, MaterialDef
```

- `type: 'material'`
- `variants?: Record<string, MaterialDef>` — values that differ per variant, over the base values

### MaterialProgram

*interface* · `packages/assets/src/material-program.ts:50`

```ts
interface MaterialProgram
```

- `nodes: ProgramNode[]`
- `outputs: Partial<Record<ProgramOutput, number>>`
- `textures?: string[]` — the pictures `tex` nodes read, by index (`k`)
- `params?: number[][]` — the values of `param` nodes by index (`k`), 1 to 4 numbers each: what differs between two instances of one master
- `worldNormal?: boolean` — the master gives its normal in world space (Unreal's "Tangent Space Normal" off)

### MeshInput

*interface* · `packages/assets/src/model-import.ts:91`

```ts
interface MeshInput
```

- `name: string`
- `positions: Float32Array`
- `normals?: Float32Array`
- `indices: Uint32Array | Uint16Array`
- `colors?: Float32Array`
- `uvs?: Float32Array`
- `material: string`

### ModelCodeModule

*interface* · `packages/assets/src/model.ts:102`

```ts
interface ModelCodeModule
```

a module of the model's own code: `file` is what runs (an ES module under `code/`), `source` the TypeScript or JavaScript the packer builds it from

- `file: string`
- `source?: string`
- `description: string`

### ModelCollision

*interface* · `packages/assets/src/library.ts:352`

```ts
interface ModelCollision
```

How a model collides when a game does not want its triangles: a box or a cylinder from the model's own base, in metres.

- `shape: 'box' | 'cylinder'`
- `size: [number, number, number]`
- `center: [number, number, number]`

### ModelCollisionShape

*interface* · `packages/assets/src/model.ts:76`

```ts
interface ModelCollisionShape
```

- `part?: string`
- `node?: string`
- `shape: 'box' | 'sphere' | 'cylinder' | 'capsule' | 'hull' | 'mesh'`
- `size?: number[]`
- `center?: Vec3`
- `material?: string`

### ModelDescription

*interface* · `packages/assets/src/model.ts:129`

```ts
interface ModelDescription
```

- `summary?: string`
- `kind?: string`
- `category?: string`
- `tags?: string[]`
- `purpose?: string`
- `size?: { height?: number; length?: number; width?: number; span?: number; mass?: number; drawScale?: number }`
- `period?: string`
- `place?: string`
- `parts?: Record<string, string | null>`
- `includes?: Record<string, string | null>`
- `motions?: Record<string, { summary: string; params?: Record<string, string> } | null>`
- `functions?: Record<string, { summary: string; kind: ModelFunctionKind; params?: Record<string, string>; returns?: ModelValueType } | null>`
- `docks?: Record<string, string | null>`
- `materials?: string | Record<string, string | null>`
- `physics?: string`
- `levels?: { triangles?: number; bytes?: number; tier?: ModelTier }[]`
- `lineage?: string[]`
- `source?: { author?: string; licence?: string; url?: string; project?: string }`
- `text?: string`
- `[extension: `x-${string}`]: unknown`

### ModelDock

*interface* · `packages/assets/src/model.ts:92`

```ts
interface ModelDock
```

- `node?: string`
- `frame?: { position?: Vec3; rotation?: Quat }`
- `description: string`

### ModelFunction

*interface* · `packages/assets/src/model.ts:113`

```ts
interface ModelFunction
```

A function of the model, called for one instance of it: `(name instance args...)`. `code` names the module (an entry of `code`) that exports it; `kind` is as
for an `extern` of the game language (default `world`); `params` are in the order of the call, after the instance.

- `code: string`
- `kind?: ModelFunctionKind`
- `params?: ModelFunctionParam[]`
- `returns?: ModelValueType`
- `description: string`

### ModelFunctionParam

*interface* · `packages/assets/src/model.ts:108`

```ts
interface ModelFunctionParam
```

- `name: string`
- `type: ModelValueType`
- `default?: unknown`
- `unit?: string`
- `description?: string`

### ModelInclude

*interface* · `packages/assets/src/model.ts:94`

```ts
interface ModelInclude
```

- `id: string`
- `version: string`
- `at: ModelPlacement | ModelPlacement[] | { file: string }`
- `fuse?: 'body' | 'rigid'`
- `overrides?: Record<string, unknown>`
- `optional?: boolean`
- `levels?: number[]`

### ModelInstance

*interface* · `packages/assets/src/cache.ts:5`

```ts
interface ModelInstance
```

What a loaded model gives a game.

- `root: BABYLON.TransformNode` — the model's top node(s): move this to place the model
- `meshes: BABYLON.AbstractMesh[]`
- `skeletons: BABYLON.Skeleton[]`
- `animations: Record<string, BABYLON.AnimationGroup>` — animation groups by name (stopped: a graph or a viewer plays them)
- `dispose(): void` — remove this instance from the scene; the cached source stays until released

### ModelItem

*interface* · `packages/assets/src/library.ts:355`

```ts
interface ModelItem extends ItemBase
```

A static mesh with its materials and textures in one glTF per tier (trees, rocks, props): placed by a game as many times as it likes (thin instances).

- `type: 'model'`
- `impostor?: ImpostorEntry` — the baked impostor for the far levels of `@ferret/perspective`
- `tiers: Partial<Record<LibraryTier, TierFile>>`
- `bounds: { min: [number, number, number]; max: [number, number, number] }` — bounding box in metres of the model at its origin
- `materials?: { name: string; alpha?: AlphaMode; doubleSided?: boolean }[]` — the materials in the file and how they draw (`mask` for leaves)
- `collision?: ModelCollision`
- `up?: '+Y'` — the axis that is up in the file (always `+Y`; written so a reader need not guess)
- `data?: Record<string, string>` — files that belong to the model and ride in its package, by what they are: the airship's `physics` contract and the `spec` it was built from (a package path each)

### ModelJson

*interface* · `packages/assets/src/model.ts:115`

```ts
interface ModelJson
```

- `fmdl: 1`
- `id: string`
- `abstract?: boolean`
- `extends?: { id: string; version: string }`
- `up?: '+Y'`
- `forward?: '+X' | '-X' | '+Z' | '-Z'`
- `scale?: { drawn?: number }`
- `levels?: ModelLevel[]`
- `levelEdits?: Record<string, Partial<ModelLevel> | null>`
- `nodeEdits?: NodeEdit[]`
- `impostors?: Record<string, Record<string, unknown> | null>`
- `parts?: Record<string, ModelPart | null>`
- `materials?: Record<string, ModelMaterial | null>`
- `physics?: ModelPhysics`
- `movingParts?: Record<string, ModelMovingPart | null>`
- `docks?: Record<string, ModelDock | null>`
- `includes?: Record<string, ModelInclude | null>`
- `clips?: Record<string, string | null>`
- `motions?: Record<string, ModelMotion | null>`
- `code?: Record<string, ModelCodeModule | null>`
- `functions?: Record<string, ModelFunction | null>`
- `requires?: { forms?: string[]; capabilities?: string[] }`
- `final?: string[]`
- `required?: string[]`
- `[extension: `x-${string}`]: unknown`

### ModelLevel

*interface* · `packages/assets/src/model.ts:36`

```ts
interface ModelLevel
```

One quality level of a model, index 0 the richest. The cost fields are written by the packer.

- `file: string`
- `bytes?: number`
- `triangles?: number`
- `texCap?: number`
- `bones?: number`
- `drawCalls?: number`
- `load?: 'cpu' | 'gpu' | 'both'`
- `maxTier?: ModelTier`
- `thresholds?: { px: number; tolerance: number; /** what the measurement was made of (`levelKey`): a changed level or include makes it stale */ of?: string }` — the size in pixels below which the next level is within `tolerance` of this one (measured, never typed)

### ModelMaterial

*interface* · `packages/assets/src/model.ts:50`

```ts
interface ModelMaterial
```

- `gltf?: string`
- `render?: Record<string, unknown>`
- `physical?: string | Record<string, number>`
- `response?: ModelResponse`

### ModelMotion

*interface* · `packages/assets/src/model.ts:95`

```ts
interface ModelMotion
```

- `file: string`
- `description: string`
- `duration?: number`
- `params?: Record<string, { type: 'number' | 'boolean' | 'string' | 'vector'; default?: unknown; unit?: string; description: string }>`
- `requires?: { forms?: string[] }`

### ModelMovingPart

*interface* · `packages/assets/src/model.ts:91`

```ts
interface ModelMovingPart
```

- `node?: string`
- `kind: 'hinge' | 'slider' | 'rotor'`
- `axis?: Vec3`
- `pivot?: Vec3`
- `limits?: [number, number]`
- `rest?: number`
- `unit?: 'rad' | 'm'`
- `link?: { to: string; ratio: number; offset?: number }`
- `description?: string`

### ModelPart

*interface* · `packages/assets/src/model.ts:47`

```ts
interface ModelPart
```

- `node?: string`
- `role?: string`
- `description?: string`
- `material?: string`
- `optional?: boolean`

### ModelPhysics

*interface* · `packages/assets/src/model.ts:77`

```ts
interface ModelPhysics
```

- `mass?: number | 'computed'`
- `centerOfMass?: Vec3`
- `inertia?: Vec3`
- `charge?: number | 'computed'` — the charge of the whole in coulombs, or "computed": the sum of the included models' charges
- `bindingEnergy?: number` — the energy that holds the whole together, in joules: its mass is the sum less this over c^2 (a nucleus's mass defect)
- `computed?: { hash: string; mass: number; charge?: number; centerOfMass?: Vec3; inertia?: Vec3; counted?: string[] }`
- `collision?: Record<string, ModelCollisionShape | null>`
- `bodies?: Record<string, { parts: string[]; kind?: 'static' | 'dynamic' | 'kinematic' } | null>`
- `joints?: Record<string, { between: [string, string]; kind: 'fixed' | 'hinge' | 'ball' | 'slider'; anchor?: Vec3; axis?: Vec3; limits?: [number, number]; breakForce?: number; breakTorque?: number } | null>`
- `modules?: Record<string, Record<string, unknown> | null>`
- `propulsors?: Record<string, ModelPropulsor | null>` — the propulsors that throw a medium: the jets of the model; absent: the model makes no wash

### ModelPlacement

*interface* · `packages/assets/src/model.ts:93`

```ts
interface ModelPlacement
```

- `name?: string`
- `dock?: string`
- `to?: string`
- `node?: string`
- `position?: Vec3`
- `rotation?: Quat`
- `scale?: number | Vec3`
- `overrides?: Record<string, unknown>`

### ModelPropulsor

*interface* · `packages/assets/src/model.ts:59`

```ts
interface ModelPropulsor
```

A propulsor of a model: a fan, a rotor, a propeller, a nozzle or an exhaust that throws a medium. The engine makes its jet and, where it
meets the ground, the water or a body, the wall jet from this and the thrust. Positions and axes are in the frame the model is drawn in; the jet runs along `axis`
(the direction the medium is thrown, so the thrust on the body is the other way).

- `kind: typeof PROPULSOR_KINDS[number]`
- `node?: string` — the node the propulsor rides on (a gimbal turns the jet with it); the model's root when missing
- `position: Vec3`
- `axis: Vec3`
- `diameter?: number` — the disc (rotor, propeller) or the exit (fan, nozzle, exhaust) diameter, m; the exit area of a duct that is not round instead
- `exitArea?: number`
- `medium?: 'air' | 'water'`
- `actuator?: string` — the physics actuator, or the moving part whose running state gives the thrust: the force the actuator exerts on the body, N
- `hoverShare?: number` — its share of the weight in hover (the fallback when the model's physics is not running); default 1 over the number of propulsors
- `temperature?: number` — the temperature excess at the exit, K (a hot exhaust)
- `wash?: false | number` — `false`: this propulsor makes no wash; a number scales its jet

### ModelSource

*interface* · `packages/assets/src/model-resolve.ts:23`

```ts
interface ModelSource
```

A model package read far enough to resolve it: its manifest, `model.json`, `description.json`, and the files (levels, node sources) by path.

- `manifest: PackageManifest`
- `model: ModelJson`
- `description?: ModelDescription`
- `source: PackageSource`

### ModelSummary

*interface* · `packages/assets/src/model.ts:839`

```ts
interface ModelSummary
```

What `ferret fmdl info` shows: the model in a few lines, from the files, without resolving the parent.

- `id: string`
- `name: string`
- `version: string`
- `abstract: boolean`
- `extends?: string`
- `levels: { file: string; triangles?: number; bytes?: number }[]`
- `impostors: string[]`
- `parts: string[]`
- `movingParts: string[]`
- `docks: string[]`
- `includes: string[]`
- `motions: string[]`
- `clips: string[]`
- `functions: string[]`
- `mass?: number | 'computed'`
- `materials: string[]`
- `dependencies: Record<string, string>`
- `summary?: string`
- `kind?: string`
- `signed: boolean`
- `encrypted: boolean`

### ModuleItem

*interface* · `packages/assets/src/library.ts:415`

```ts
interface ModuleItem extends ItemBase
```

A ready-made package of code: a package of kind `library` whose one ES module (`code.entry`) exports `install(ctx)` and the functions and classes a game
calls (a sea, a sky, a shader, a generator). The code reads the engine's other packages from the shared engine (`globalThis.Ferret`), so it carries only
its own code; `AssetLibrary.module(id)` runs it under the code policy and returns its exports.

- `type: 'module'`
- `exports: string[]` — what the module exports (names), so a list can show them without running it
- `engine?: string[]` — the engine's packages the code reads from the shared engine (`@ferret/terrain`): the game must have them
- `usage?: string` — one line that shows how it is used
- `docs?: string` — a README (Markdown) in the package
- `sources?: string[]` — the source files it was built from, for the record

### Moments

*interface* · `packages/assets/src/model-physics.ts:64`

```ts
interface Moments
```

Integrals over a solid of unit density, in the units of the geometry: volume, first moments and second moments about the origin.

- `v: number`
- `x: number`
- `y: number`
- `z: number`
- `xx: number`
- `yy: number`
- `zz: number`

### OpacityGradientDef

*interface* · `packages/assets/src/library.ts:142`

```ts
interface OpacityGradientDef
```

- `axis: 'u' | 'v'`
- `invert: boolean`
- `coordinate: number`

### PackageEncryption

*interface* · `packages/assets/src/security.ts:25`

```ts
interface PackageEncryption
```

- `alg: 'AES-256-GCM'`
- `kdf: 'PBKDF2-SHA256' | 'none'`
- `salt?: string` — base64 (kdf PBKDF2)
- `iterations?: number`
- `check: string` — a sealed constant: opening it tells a wrong password from a damaged file (kdf none: the key's id)

### PackageFiles

*interface* · `packages/assets/src/model-resolve.ts:31`

```ts
interface PackageFiles
```

a package that is read only for its files

- `manifest: PackageManifest`
- `source: PackageSource`

### PackageInfo

*interface* · `packages/assets/src/package.ts:511`

```ts
interface PackageInfo
```

- `id: string`
- `name: string`
- `version: string`
- `kind: PackageKind`
- `format: number`
- `files: number`
- `bytes: number`
- `levels: string[]`
- `assets: string[]`
- `behaviours: string[]`
- `dependencies: Record<string, string>`
- `hasCode: boolean`
- `signed: boolean`
- `encrypted: boolean`
- `locked: boolean`
- `entry?: PackageManifest['entry']`
- `codeEntry?: string` — the module the code loader runs, if any (`code.entry`, else a game's `entry.code`)

### PackageIssue

*interface* · `packages/assets/src/package.ts:142`

```ts
interface PackageIssue
```

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

### PackageManifest

*interface* · `packages/assets/src/package.ts:80`

```ts
interface PackageManifest
```

- `format: number`
- `id: string` — lower case letters, digits, `.`, `_`, `-`
- `name: string`
- `version: string` — semver `major.minor.patch`
- `kind: PackageKind`
- `engine?: { ferret?: string; babylon?: string; /** the parts of Babylon the game loads at start, and the ones a feature may ask for later (stage P6; without them the full build is loaded) */ parts?: string[]; lazyParts?: string[]; /** a standalone game: the exact release whose engine files are inside the package, under `engine/` */ bundled?: string }` — the versions it was built and tested with
- `dependencies?: Record<string, string>` — other packages by id and version range (`1.2.0`, `^1.2.0`, `~1.2.0`, `>=1.2.0`, `*`)
- `catalogs?: string[]` — catalogs (`catalog.json`) where the player looks for the `dependencies` that are not open yet, in order: absolute URLs, or relative ones read from where this package itself was loaded. A dependency's own `catalogs` are searched for its dependencies, after these.
- `modules?: string[]` — a game only: the engine modules its code and levels use, written by the compiler (a project has none)
- `babylon?: string[]` — a game only: the Babylon parts it uses, written by the compiler
- `keep?: string[]` — a game or a project: files the compiler must keep although no literal path reaches them (globs, `*` within a folder, `**` across)
- `game?: GameBlock` — a game or a project: what `createGame` gets
- `for?: { game: string; version: string }` — a package of levels made for a game: which game and versions it fits
- `entry?: { code?: string; /** the level to start in; a game whose code builds its own world names none (then `code` is required) */ level?: string; spawn?: string; ui?: string; /** a game's own Web Worker scripts, built by the compiler from the `*-worker.ts` files beside the entry code (`code/sim-worker.js` ...): the player starts them from the package (`gameWorker`) */ workers?: string[]; /** a game's own kernels for the engine's kernel workers (PLAN-SCHEDULER): code/kernels.js and code/kernels-babylon.js, built from kernels.ts and kernels-babylon.ts beside the entry code */ kernels?: string[]; }` — a game or a project: the code module (a game: built, under `code/`; a project: the source), the level to start in, the spawn, the UI fragment
- `docking?: DockingBlock` — a package of kind `levels` only: the level has code and is docked into a parent game (`.level`)
- `code?: { entry: string }` — a game or a library: the code module the code loader runs (one bundled ES module under `code/` exporting `install`)
- `provides?: PackageProvides` — what it offers to others
- `files?: Record<string, string>` — sha256 (hex) of every file but this one
- `encryption?: PackageEncryption` — present when the files are encrypted (see ./security); `ferret.json` itself never is
- `signature?: PackageSignature` — a signature over the whole manifest (so over `files`) made by the publisher; checked by whoever decides to trust the code

### PackageProvides

*interface* · `packages/assets/src/package.ts:134`

```ts
interface PackageProvides
```

What a package offers, so that a level or a program can be resolved to the packages it needs without running their code. The
lists after `behaviours` are names a library's code registers: physics capabilities, actuator kinds, flow sources, forms of the
motion language, commands and level manifest keys.

- `levels?: string[]`
- `assets?: string[]`
- `behaviours?: { name: string; params?: Record<string, unknown> }[]`
- `capabilities?: string[]`
- `kinds?: string[]`
- `flowSources?: string[]`
- `forms?: string[]`
- `commands?: string[]`
- `levelKeys?: string[]`

### PackageSignature

*interface* · `packages/assets/src/security.ts:15`

```ts
interface PackageSignature
```

- `alg: 'ES256'`
- `key: string` — the public key, SPKI in base64
- `keyId: string` — first 16 bytes of the sha256 of the public key, in hex
- `value: string` — base64 of the raw (r || s) signature

### PackageSource

*interface* · `packages/assets/src/package.ts:417`

```ts
interface PackageSource
```

Reads the files of a package, whether it is a zip or a folder.

- `readonly kind: 'zip' | 'folder' | 'memory'`
- `list(): string[]` — every file path (the manifest included)
- `has(path: string): boolean`
- `size(path: string): number` — bytes of the file in the package (uncompressed); 0 when unknown
- `read(path: string): Promise<Uint8Array>`
- `readonly libraryVersion?: string` — the number a library catalog gave the file this was opened from (`openCatalogPackage`)

### PackedPackage

*interface* · `packages/assets/src/catalog.ts:347`

```ts
interface PackedPackage
```

- `bytes?: Uint8Array` — the package file in memory; a package too big for that (`packPackageTo`) leaves this out and gives `file`
- `file?: { size: number; sha256: string; manifestSha256: string }` — a package written to disk by `packPackageTo`: its size, the sha256 of the whole file and of its `ferret.json`; the publisher puts the file at `publishedPath(sha256)` itself
- `manifest: PackageManifest`
- `tiers?: Record<string, Uint8Array>` — packed again for a device tier
- `ext?: string` — the extension of the published file

### PackOptions

*interface* · `packages/assets/src/package.ts:782`

```ts
interface PackOptions
```

Build a `.ferret` from a source (a folder, another package, a draft): the manifest gets the sha256 of every file, the levels
and assets it provides when they are not named, and the zip is written the same way every time (sorted, no dates). Files that
are compressed already are stored, so a reader slices them out without inflating.

- `manifest?: Partial<PackageManifest>`
- `engine?: PackageManifest['engine']`
- `encrypt?: KeyInput` — seal every file but the manifest (a password, or a 32-byte key in base64)
- `iterations?: number` — PBKDF2 rounds for a password (default 310000; tests use less)
- `sign?: { privateKey: string }` — sign the finished manifest with this private key (base64 PKCS8, from `generateSigningKey`)
- `decrypt?: boolean` — pack an encrypted package's files as plain ones (without it, repacking an encrypted package needs `encrypt`)

### PatternLayerDef

*interface* · `packages/assets/src/library.ts:136`

```ts
interface PatternLayerDef
```

A pattern over a fill (the pattern masters): `normal = lerp(Flatten(patternN, 1 - normalScale), baseNormal, mask)` and `occlusion = lerp(patternAO, baseOcclusion, mask)`, so a mask of 1 is the base.
`mask` is a name of `masks`, read at the first UV set times `uvScale`, `channel` its channel (`rgb`, the default: x, y, z of the normal and the occlusion are mixed by r, g, b of the mask);
the pattern's maps are read at the same `uvScale`. `normal` and `occlusion` are texture references.

- `mask: string`
- `channel?: MaskChannel`
- `uvScale?: [number, number]`
- `normal?: string`
- `normalScale?: number`
- `occlusion?: string`
- `occlusionChannel?: 'r' | 'g' | 'b' | 'a'`

### PersistentCacheOptions

*interface* · `packages/assets/src/persist.ts:121`

```ts
interface PersistentCacheOptions
```

- `cap?: number` — Hard cap in bytes (defaults: 400 MB desktop, 200 MB phone, 100 MB console: the caller picks).
- `quota?: () => Promise<number | undefined>` — The browser's quota (`navigator.storage.estimate().quota`) when it has one; the cache stays under 80% of it.
- `now?: () => number`
- `partialMaxAgeMs?: number` — Partial downloads older than this are removed (24 h).

### PhysicsPlan

*interface* · `packages/assets/src/model-physics.ts:332`

```ts
interface PhysicsPlan
```

- `id: string`
- `bodies: PlanBody[]`
- `joints: PlanJoint[]`
- `mass: number`
- `charge: number`

### PixelDepthDef

*interface* · `packages/assets/src/library.ts:167`

```ts
interface PixelDepthDef
```

PixelDepthOffset of a master that feeds it `DitherTemporalAA(AlphaThreshold) * Ditcher_Effect` (the cliff master): every pixel is pushed away from the camera by
`dither` centimetres times a screen-space dither value of about 0.5 to 1.3, so where the object meets the ground the seam is broken up by noise. `dither` is the master's
`Ditcher_Effect`; `threshold` the function's Alpha Threshold input (default 0.5). A master that computes the product but does not connect it (the plank and log masters)
has no such field.

- `dither: number`
- `threshold?: number`

### PlanBody

*interface* · `packages/assets/src/model-physics.ts:330`

```ts
interface PlanBody
```

A rigid body of the whole: its mass properties (true SI, in the whole's drawn frame), its shapes, and the instance it comes from (none for the whole's own).

- `name: string`
- `kind: 'static' | 'dynamic' | 'kinematic'`
- `mass: number`
- `charge: number`
- `centerOfMass: Vec3`
- `inertia: Vec3`
- `shapes: PlanShape[]`
- `instance?: string`
- `parts: string[]`

### PlanEdit

*interface* · `packages/assets/src/model-plan.ts:10`

```ts
interface PlanEdit
```

- `op: 'replace' | 'add' | 'hide' | 'material'`
- `node: string`
- `parent?: string` — `add`: the node of the level the new node goes under
- `from?: string` — `replace`, `add`: the qualified path of the glTF the node comes from, for this level
- `material?: string` — `material`: the name in the model's `materials`

### PlanInstance

*interface* · `packages/assets/src/model-plan.ts:21`

```ts
interface PlanInstance
```

- `name: string` — the instance's name, its address (`<instance>/<part>`)
- `include: string` — the name of the include this instance is of
- `id: string` — the id of the included model
- `placement: Omit<ModelPlacement, 'name' | 'overrides'>`
- `fuse: 'body' | 'rigid'`
- `level: number` — the level of the included model the instance is drawn on
- `plan: AssemblyPlan`

### PlanJoint

*interface* · `packages/assets/src/model-physics.ts:331`

```ts
interface PlanJoint
```

- `name: string`
- `between: [string, string]`
- `kind: 'fixed' | 'hinge' | 'ball' | 'slider'`
- `anchor?: Vec3`
- `axis?: Vec3`
- `limits?: number[]`
- `breakForce?: number`
- `breakTorque?: number`

### PlanShape

*interface* · `packages/assets/src/model-physics.ts:328`

```ts
interface PlanShape
```

A collision shape in a body's frame, with its physical material.

- `name: string`
- `shape: ModelCollisionShape['shape']`
- `size?: number[]`
- `center?: Vec3`
- `material?: string`
- `physical?: unknown`
- `frame: number[]`

### PreparedModel

*interface* · `packages/assets/src/model-pack.ts:22`

```ts
interface PreparedModel
```

- `files: Map<string, Uint8Array>` — the folder as it must be packed
- `written: string[]` — the files the preparation wrote (`model.json`, `description.json`, `description.md`), with what changed in `model.json`
- `changed: string[]`
- `issues: PackageIssue[]`

### PrepareOptions

*interface* · `packages/assets/src/model-pack.ts:33`

```ts
interface PrepareOptions
```

- `bundle?: ModelBundler`

### ProgramNode

*interface* · `packages/assets/src/material-program.ts:45`

```ts
interface ProgramNode
```

One node: the operation, the indices of earlier nodes it reads, and its constant part.

- `op: string`
- `a?: number[]`
- `k?: number[] | number | string | { from: ProgramSpace; to: ProgramSpace; position?: boolean }`

### RequireOptions

*interface* · `packages/assets/src/store.ts:36`

```ts
interface RequireOptions
```

- `priority?: StreamPriority`
- `signal?: AbortSignal`
- `sha256?: string` — sha256 (hex) from a signed catalog or package manifest. Without it the file is not verified (development only).
- `size?: number` — Size in bytes when the catalog knows it: the progress total is exact from the start.
- `mirrors?: string[]`
- `pkg?: string` — The package (or level) the file belongs to: the unit of eviction, pinning and `clear`.
- `version?: string`
- `group?: string` — Files asked with the same group add up into one progress (a travel).

### ResolvedInclude

*interface* · `packages/assets/src/model-resolve.ts:235`

```ts
interface ResolvedInclude
```

- `id: string`
- `version?: string` — the version of the package that was found
- `fuse: 'body' | 'rigid'`
- `optional?: boolean`
- `missing?: true` — an optional include whose package was not found
- `instances: ResolvedInstance[]`

### ResolvedInstance

*interface* · `packages/assets/src/model-resolve.ts:234`

```ts
interface ResolvedInstance
```

One place of an included model in the whole: its name (`<include>` for a single placement, `<include>.<index>` in a list, or the placement's own), where it sits, and the model resolved with the overlays.

- `name: string`
- `placement: Omit<ModelPlacement, 'name' | 'overrides'>`
- `resolved: ResolvedModel`

### ResolvedModel

*interface* · `packages/assets/src/model-resolve.ts:212`

```ts
interface ResolvedModel
```

- `fmdl: 1`
- `id: string`
- `abstract: boolean`
- `lineage: string[]` — the ids of the chain, the root ancestor first (SPEC 8.6)
- `chain: { id: string; version: string }[]` — the packages the chain was read from, with their versions
- `resolvedHash: string` — SPEC 8.5: what an impostor's `modelHash` is
- `model: ModelJson` — the merged model; its paths are qualified (`fmdl://<package>/<path>`)
- `description: ModelDescription` — the merged `description.json`, with `lineage`
- `texts?: { id: string; summary?: string; text?: string }[]` — what each member of the chain says of itself, the root first (`description.md` shows them in this order)
- `includes?: Record<string, ResolvedInclude>` — the included models, resolved (SPEC 8.4); absent when the model includes nothing
- `levelKeys: string[]` — the key of each level (SPEC 4.5): what a measurement of the level's thresholds is made of

### ResolveResult

*interface* · `packages/assets/src/model-resolve.ts:245`

```ts
interface ResolveResult
```

- `resolved?: ResolvedModel`
- `issues: PackageIssue[]`
- `read?: (qualified: string) => Promise<Uint8Array>` — reads a file of any package the model was made from (the whole chain and every included model) by its qualified path (`fmdl://<package>/<path>`)

### RubricNode

*interface* · `packages/assets/src/library.ts:1024`

```ts
interface RubricNode extends LibraryRubric
```

- `count: number`
- `own: number`
- `children: RubricNode[]`

### SigningKey

*interface* · `packages/assets/src/security.ts:57`

```ts
interface SigningKey
```

- `publicKey: string`
- `privateKey: string`
- `keyId: string`

### Socket

*interface* · `packages/assets/src/library.ts:245`

```ts
interface Socket
```

A place on a body where something is held: a bone and an offset from it (metres, radians as a quaternion), kept in the item so every game puts a weapon in a hand the same way.

- `bone: string`
- `position?: [number, number, number]`
- `rotation?: [number, number, number, number]`
- `grip?: { point: [number, number, number]; axis: [number, number, number]; radius: number; spacing?: number; edge?: [number, number, number] }` — how the thing in this socket is held, in the frame of `bone`: the middle of the grip, its axis (toward the blade), its radius, the distance to the second hand (toward the pommel), and for a blade the way its edge faces (across the axis; a two-edged blade cuts along it either way)

### SoundFile

*interface* · `packages/assets/src/library.ts:379`

```ts
interface SoundFile
```

One file of a sound item: a WAV (exact, big) or an MP3 (small), the same sound.

- `file: string`
- `bytes: number`
- `bitrate?: number`

### SoundItem

*interface* · `packages/assets/src/library.ts:387`

```ts
interface SoundItem extends ItemBase
```

A sound: the same recording as a WAV and/or an MP3 (a device on the `low` or `mobile` tier takes the MP3 when there is one, the others the
WAV), with what a game needs to place it - how long it is, whether and where it loops, the bus it belongs on and how it falls with distance.

- `type: 'sound'`
- `files: Partial<Record<'wav' | 'mp3', SoundFile>>`
- `rate: number` — frames per second of the recording
- `channels: number`
- `duration: number` — seconds
- `peak?: number` — the largest sample, 0..1 (a game can raise the quiet ones)
- `loop?: boolean | { start: number; end: number }` — the sound repeats; `start` and `end` in seconds when only a part of it does (a WAV `smpl` loop)
- `bus?: SoundBus`
- `volume?: number` — 0..1
- `spatial?: { min?: number; max?: number; model?: 'linear' | 'inverse' | 'exponential'; rolloff?: number }` — how it falls with distance when played at a place (metres)
- `marks?: { name: string; time: number }[]` — moments named in the sound, seconds (cue marks of the WAV: `hit`, `step`)
- `wave?: number[]` — the shape of the wave for a picture of it: lowest and highest sample of equal parts, interleaved (min0, max0, min1, max1...)

### StoreOptions

*interface* · `packages/assets/src/store.ts:17`

```ts
interface StoreOptions
```

- `fetch?: typeof fetch`
- `origins?: string[]` — Origins files may come from (`https://cdn.example.com`). Empty or missing: any origin that passes the https rule.
- `base?: string` — Relative refs are resolved against this.
- `concurrency?: number`
- `stallMs?: number` — No bytes for this long: the attempt is abandoned and retried (resumed when it can).
- `retries?: number`
- `backoffMs?: number`
- `maxFileBytes?: number` — A file bigger than this is refused (the catalog's size is the usual limit; this is the engine's cap).
- `cache?: PersistentCache` — The persistent cache; without one every file lives in memory for the session.
- `random?: () => number`
- `sleep?: (ms: number, signal?: AbortSignal) => Promise<void>`

### StreamProgress

*interface* · `packages/assets/src/store.ts:15`

```ts
interface StreamProgress
```

- `loaded: number`
- `total: number`
- `files: number`
- `filesDone: number`
- `rate: number`
- `eta: number`

### TextureCodecFile

*interface* · `packages/assets/src/library.ts:43`

```ts
interface TextureCodecFile
```

one codec's file of a KTX2 map, with what the encoder measured against the source (dB; `shift` in 8-bit levels)

- `file: string`
- `bytes: number`
- `psnr?: number`
- `block?: number`
- `shift?: number`

### TextureItem

*interface* · `packages/assets/src/library.ts:44`

```ts
interface TextureItem extends ItemBase
```

- `type: 'texture'`
- `maps: Partial<Record<TextureChannel, string>>` — the maps present: path inside the package per channel (`basecolor`, `normal`, `orm`, `emissive`, `height`), per tier a folder or file set
- `tiling?: number` — metres of the world one repeat of the texture covers; absent when unknown
- `seamless?: boolean`
- `size?: number` — pixels of the largest side at full size
- `tiers?: Partial<Record<LibraryTier, { bytes: number; side: number }>>`
- `aliases?: string[]` — other names of the same image (the same pixels exported under another name)
- `codecs?: Partial<Record<TextureCodec, TextureCodecFile>>` — a KTX2 map kept in both codecs: the file of each (a codec that was not made is absent); `maps` names the `codec` one. The library takes the codec its `texCodec` policy asks for, else `codec`.
- `codec?: TextureCodec` — the codec the encoder's check chose, whose file `maps` names
- `srgb?: boolean` — the map is colour data (sRGB), false for every other map
- `layers?: string[]` — the ground layers (`LAYER_SET` of

### TierFile

*interface* · `packages/assets/src/library.ts:19`

```ts
interface TierFile
```

- `file: string`
- `bytes: number`
- `triangles?: number`
- `texCap?: number`
- `bones?: number`

### Totals

*interface* · `packages/assets/src/model-physics.ts:180`

```ts
interface Totals
```

The mass properties of a resolved model as the whole sees them: stated, or the computed values (which must be written and fresh).

- `mass: number`
- `charge: number`
- `centerOfMass: Vec3`
- `inertia: Vec3`

### TwoSidedFoliageDef

*interface* · `packages/assets/src/library.ts:159`

```ts
interface TwoSidedFoliageDef
```

TwoSidedFoliage's SubsurfaceColor (linear): the colour of the light that passes through the surface; `intensity` scales it (default 1)

- `color: [number, number, number]`
- `intensity?: number`
- `albedo?: boolean`

### VatBakeEntry

*interface* · `packages/assets/src/library.ts:291`

```ts
interface VatBakeEntry
```

The vertex-animation bake of a character for a GPU crowd (`@ferret/crowd`): the file is the packed bone-matrix texture (`vat/<id>.vat`), made at build time by
`tools/perspective/bake-vat.mjs` so that any game with the figure gets it for free (and keeps the browser bake as a fallback).

- `file: string` — path inside the package of the packed bake
- `bytes: number`
- `recipe: string` — the recipe and its version that made it (`vat-crowd:v1`): a game's loader uses the file only when it knows the recipe
- `clips: string` — the lengths of the clips baked, as the recipe writes them: a changed clip set is another bake
- `signature?: string` — the signature of the rig it was baked for (`bones:hash` of the bones' inverse binds and the mesh's frame): a bake is used for a figure only when its rig has the same one
- `bones: number` — bones of the skeleton, frames baked
- `frames: number`
- `tier: LibraryTier` — the tier file the bake was made from, and its sha256
- `modelHash: string`
- `specHash?: string` — a digest of what the bake was asked for (profile, clips, bones kept): a changed spec is baked again

### VerifyResult

*interface* · `packages/assets/src/package.ts:534`

```ts
interface VerifyResult
```

- `signed: boolean`
- `valid: boolean` — the signature matches the manifest (and, when files could be read, every file matches the manifest)
- `keyId?: string`
- `trusted: boolean` — valid, and the key is in (true for any valid signature when no list was given)
- `problems: string[]`

### VertexMasksDef

*interface* · `packages/assets/src/library.ts:170`

```ts
interface VertexMasksDef
```

`opacity`: the alpha of the surface is multiplied by the vertex colour's alpha (OpacityMask = texture alpha x vertex alpha); `ao`: ambient occlusion = the vertex colour's red channel.

- `opacity?: boolean`
- `ao?: boolean`

### VolumeItem

*interface* · `packages/assets/src/library.ts:457`

```ts
interface VolumeItem extends ItemBase
```

A sequence of density volumes (a baked smoke or fire), the near rung of the effect ladder: `frames` volumes of `resolution` voxels, one byte per voxel per
channel, laid out frame after frame, then z, then y, then x, then channel, in one file `file`. `channels` says what the bytes are (density, temperature) in order.

- `type: 'volume'`
- `resolution: [number, number, number]`
- `frames: number`
- `fps: number`
- `channels: Array<'density' | 'temperature'>`
- `voxel: number` — metres one voxel edge spans at the size it was made for
- `densityMax?: number` — what a full byte means: the density, and the temperature (kelvin) of the heat channel; `ambient` is the air's (a zero heat byte)
- `temperatureMax?: number`
- `ambient?: number`
- `file: string`
- `loop?: boolean`

### ZipEntryInfo

*interface* · `packages/assets/src/zip.ts:73`

```ts
interface ZipEntryInfo
```

- `path: string`
- `size: number`
- `compressedSize: number`
- `method: 0 | 8`
- `crc: number`
- `offset: number`

### ZipFile

*interface* · `packages/assets/src/zip.ts:224`

```ts
interface ZipFile
```

- `path: string`
- `data: Uint8Array`
- `compress?: boolean`

## Types

### AlphaMode

*type* · `packages/assets/src/library.ts:66`

```ts
type AlphaMode = 'opaque' | 'mask' | 'blend'
```

### CatalogFailure

*type* · `packages/assets/src/catalog.ts:135`

```ts
type CatalogFailure = 'invalid' | 'signature' | 'untrusted' | 'unsigned' | 'engine' | 'network'
```

### CatalogPackageSource

*type* · `packages/assets/src/catalog.ts:343`

```ts
type CatalogPackageSource = PackageSource & { manifest: PackageManifest; cached(paths: string[]): Promise<boolean>; /** `id@version`: the unit the cache evicts and pins */ tag: string }
```

### CharacterKind

*type* · `packages/assets/src/library.ts:13`

```ts
type CharacterKind = 'human' | 'animal' | 'creature' | 'part' | 'vehicle'
```

`vehicle`: a machine with moving parts (an aircraft with its gear and canopy) kept as a rigged model, not a person or an animal

### DockingRole

*type* · `packages/assets/src/package.ts:45`

```ts
type DockingRole = typeof DOCKING_ROLES[number]
```

### GraphExpr

*type* · `packages/assets/src/library.ts:146`

```ts
type GraphExpr = | { c: number[] } | { tex: string; sampler: 'LinearColor' | 'Color' | 'Normal'; ch: 'r' | 'g' | 'b' | 'a' | 'rgb'; uv: [number, number]; mul?: number[] } | { op: GraphOp; args: GraphExpr[] }
```

One node of a `graph`: a constant (1 or 3 numbers), a picture read at the first UV set times `uv`, or an operation on others.

### GraphOp

*type* · `packages/assets/src/library.ts:150`

```ts
type GraphOp = 'mul' | 'add' | 'subtract' | 'divide' | 'lerp' | 'oneMinus' | 'clamp' | 'power' | 'cameraDepthFade' | `mask:${'r' | 'g' | 'b' | 'a'}`
```

### KeyInput

*type* · `packages/assets/src/security.ts:36`

```ts
type KeyInput = { password: string } | { key: string }
```

What opens an encrypted package: a password, or the 32-byte key in base64.

### Ktx2Target

*type* · `packages/assets/src/ktx2.ts:35`

```ts
type Ktx2Target = 'ASTC4x4' | 'BC7' | 'ETC2' | 'ETC1' | 'BC3' | 'BC1' | 'PVRTC' | 'RGBA8'
```

the block format a KTX2 map ends up in on a device

### LibraryItem

*type* · `packages/assets/src/library.ts:473`

```ts
type LibraryItem = TextureItem | MaterialItem | CharacterItem | ClipsItem | ModelItem | FmdlItem | SoundItem | ModuleItem | FlipbookItem | VolumeItem
```

