Asset library
What the Unreal ports have already exported (baked materials and textures, characters with their clips) is kept once, as a library any game takes from by id instead of copying files out of another project. The library is a set of .ferret packages of kind assets and a catalog.json that lists their items. The library is kept on a server, https://ferret.partners.solutions/ferret/library/ (the Storage Box behind a service: tools/server/library), and is read through the asset store like any catalog; nothing of it is in the repository. A game opens it by ?lib=<catalog.json url>, FERRET_ASSETS, or on OS Beroun the folder /lib/ferret-assets/ (the engine's default). Everyone adds to it with their own SW account through the service (tools/lib-cache, tools/asset-lib/publish.mjs; the moderator's items go straight in, the others' wait in an incoming area); the search is GET /ferret/library/api/search?q=&type=&rubric=&tags=. Tools and tests fetch what they need into a cache outside the repository (D:/temp/ferret-library-cache, FERRET_LIBRARY_CACHE).
This page is the format.
Items#
Every item has an id (lower case letters, digits, ., _, -) that stays the same across re-exports, and an item file items/<id>.json in its package. A package lists its items in provides.assets; the package check (FerretPackage.validate) reads every item file, so a bad item, a file it names that is not in the package, an item that is not listed and a listed id with no item all show up as problems with a path.
| Type | What it is | Main fields |
|---|---|---|
texture | a texture set: base colour, normal (OpenGL, +Y), occlusion-roughness-metallic, emissive | maps, tiling (metres per repeat), seamless, size, aliases |
material | a PBR description that maps one to one to Babylon's PBRMaterial | colour and factors, maps (ferret://<package>/<path>), uv, worldAligned, alpha, variants |
character | a skinned model per quality tier, a part of one, or an assembled one | kind (human, animal, creature, part), tiers, skeleton, clips, graph, movement, height, facing, parts |
clips | a skeleton with animations and no mesh | skeleton, compatible, file, clips (name, duration) |
sound | a recording as a WAV and/or an MP3 | files (wav, mp3: file, bytes, bitrate), rate, channels, duration, loop (true or {start, end} seconds), bus, volume, spatial, marks, wave |
module | a ready-made package of code: a sea, a sky, a shader, a generator, a whole scene; the item of a package of kind library | exports (names, install among them), engine (the @ferret/* packages it reads), usage, docs, sources |
A material refers to its textures with ferret://<package>/<path> and may refer only to packages it depends on (dependencies in ferret.json), so several materials share one texture package. A character names its clip sets by id; a clip set belongs to a skeleton id, and skeletons that share bone names are marked compatible, because clips bind to bones by name.
The colour model of a material (Unreal masters)#
Four optional fields on a material (and on its variants) carry what Unreal masters do with colour and a plain PBR description cannot. They are read off the master graphs, parameter for parameter (Unreal units: 1 = 1 cm; colours linear, as the material instance gives them), and drawn by a plugin on the PBR material (material-models.ts of @ferret/levels), so lights, fog, shadows and probes still apply. A material without them is unchanged.
masks: extra pictures by name (ferret://, read as data, repeating).colourLayers{ base, layers }:colour = mix(colour, layer.color, pow(mask[channel], layer.power))layer after layer, starting frombase(a colour, or'albedo'for the albedo map). Masks are read at the mesh's first UV set.channelisr g b aorrgb(each colour channel by its own). M_Roof_Tile_01: baseBase_Color, a layerEdges_Colorthrough the edge mask with powerEdges_Contrast, thenDirt_Colorthrough the dirt mask. A leaf master: baseEdge_Color, one layerBase_Colorthrough channelb.macro(up to two):colour *= pow(picture(world position), power), the picture projected from the three axes overscaleUnreal units (MacroVar_Scale,Macro_Var_Power).groundBlend{ fallOff, blendHigh, sideContrast, enabled?, landscape? }(VT_FallOff,VT_Blend_High,Stretches_Side_Contrast,UseVT?ofMF_Virtual_Texturing): the foot of the object takes the colour of the landscape under it. With h the height of the pixel over the ground, H the object's own height (its local bounds) and nz the up component of the vertex normal:weight = (1 - saturate((h + H - H * blendHigh) / fallOff)) * saturate(nz * sideContrast),colour = mix(own, ground, weight). The ground colour and height are the landscape's blended colour baked once at load (virtualTextureof the landscape def;groundSourceOf); until it is baked the material draws without the blend. Not carried: the ground's roughness and normal, which Unreal's virtual texture blends too.
Ready-made packages of code (module)#
Code a game takes by id, as it takes a model: the sea, the sky, the ice shader, the iceberg generator and the whole moonlit field of examples/titanic-field are modules. A module's package is of kind library (mod-<id>): one bundled ES module under code/ (code.entry) that exports install(ctx) and what a game calls, its item file, a README and a preview. The package check refuses a module without code, a module in a package of kind assets and any other item in a package of kind library.
The code carries only its own sources: an import of the engine (@ferret/terrain) is read from the shared engine, globalThis.Ferret (the engine of lib/ferret/ferret.js), as the libraries of tools/code-lib do; the item's engine lists those packages. AssetLibrary.module(id) opens the package through the catalog (with its dependencies), runs its code once through the CodeLoader under the code policy (code.origin: the library is the game's own, by default when the catalog is on the page's origin; otherwise the package must carry a valid signature, from code.trusted keys when given), checks the module against the sha256 in the manifest and returns its exports. A game that bundles the engine itself gives the packages the modules read as code.engine; they become globalThis.Ferret when the page has none.
const library = world.addService(new AssetLibrary({ store, mount, code: { engine: { ...terrain, ...waves } } }));
await library.open();
const f = await library.module<typeof import('./field-scene')>('north-atlantic-night');
const field = f.createNightField(scene, camera); // then field.update(dt) each frame
The catalog lists a module with its exports, so a list shows what it offers without running it; the command lib.module {id} runs one and returns the names.
The catalog#
The library's catalog is an ordinary catalog (packages, tiers, hashes, signature) with an assets section that finds an item without opening a package:
"assets": {
"bear": { "package": "chr-bear", "type": "character", "name": "Bear", "tags": ["animal"], "preview": "previews/bear.webp", "bytes": { "desktop": 1840000, "low": 420000 } }
}
validateCatalog checks the section: each entry points at a package of the catalog and has a known type and a name.
Versions, uids and descriptions#
Every asset of the library has versions numbered by the library server: 1.0.0 at its first submission, then 1.1.0, 1.2.0 ... for each accepted new variant of the same uid. Old versions are never deleted and a new version may hold fewer items than the one before. The catalog lists them (versions: per package, oldest first, each with its url, manifest, items; the packages entry is the newest and carries libraryVersion, while version stays the one inside the package). A catalog without versions is read as one version, 1.0.0, per package (packageVersions).
A scene refers to a concrete version: id@version (splitAssetRef; AssetLibrary.entry/item/model/material/..., library.get, library.place, lib.spawn, ferret lib get id@1.1.0). A reference without a version means 1.0.0, never the latest, so a new version never changes a scene that is already made (an item that 1.0.0 of its package does not hold, because the package gained it later, means the first version that holds it). One AssetLibrary opens one version of a package at a time; a reference to another version of an open package is an error that says so.
An entry of assets may carry uid (issued by the server at the first submission; the assets of the first library have none, their id is their uid) and description (English only, for the AI that picks among candidates).
Rubrics and tags#
The library is a tree. The catalog keeps the tree once, in rubrics ({ path, name, description } for every node, a path such as vehicles/aircraft/bombers), and every entry of assets names the one rubric it is in (rubric). Tags stay free and run across the tree (1940, dunkirk, ice). The top level: vehicles, nature, characters, animation, surfaces, effects, sound, code, education.
validateCatalog refuses a rubric that is not a path of the tree, an item without a rubric once the catalog has a tree, a path whose parent is missing and a node without a name or a description. A rubric takes in everything beneath it: lib.list { rubric: 'vehicles' } lists the aircraft too. The tree with the number of items in each node is lib.rubrics {under?} (AssetLibrary.rubrics, rubricTree); the viewer's library page has a rubric filter.
The tree and the rules that place items in it are in tools/asset-lib/rubrics.mjs (RUBRICS, rubricOf); build.mjs decides them and publish.mjs sends them to the library, and an item the rules do not place stops the build: add a rule, there is no default. An item may also say its own rubric in its item file (rubric), which the rules respect. node tools/asset-lib/rubrics.mjs <build folder> places every item of the catalog of a build (not a signed one); --check alone checks the server's catalog. Nothing inside a package changes, so the packages and their hashes stay as they are.
Tools#
tools/asset-lib/ builds the library from the exports of a port. The tools take export folders as arguments and name no game; ids.json holds the stable ids (and a few hand-set decisions: which materials are tiling or baked, which clip exports to skip, the names of skeletons).
| Tool | Does |
|---|---|
inventory.mjs | lists what the exports hold: counts, duplicate images, shared skeletons, characters missing a tier |
materials.mjs | a level's baked glb -> texture packages and material packages (repeating maps only; ORM packed; world-aligned size kept) |
characters.mjs | sized characters, parts and clip sets -> packages (the clips file stripped of its mesh) |
authored.mjs | clip sets made in Ferret (ids.json authoredClips: the clip JSON of tools/fight-clips) -> clip set packages: each clip sampled every frame on the rest pose of the body it was made for, notifies and loops in the item |
sounds.mjs | a folder of WAV and MP3 recordings -> a sound package with both formats of every sound (pack); one file to the other format (convert); a line about a file (info). The WAV's loop and cue marks become the item's loop and marks; an MP3 is never encoded twice |
previews.mjs | a preview of every item in one studio scene, and the load check |
build.mjs | packs the folders, writes the catalog and the layout, and checks every file it wrote |
ferret-models.mjs | models made in Ferret itself (ids.json ferretModels: glb tiers and data files from the repository) -> model packages |
modules.mjs | ready-made packages of code (ids.json modules: name, tags, sources (.ts files), usage, docs, preview) -> packages of kind library; the bundle reads @ferret/* from the shared engine, and the tool imports each module in Node against the engine packages it reads and checks it exports every name of its item |
make.mjs | all of the above for --from <export dir> (stages ferretmodels and modules with --only) |
The output layout is catalog.json, c/<hh>/<sha256>.ferret (the packages, content addressed) and previews/<id>.webp. A character package holds all three tiers; a client that opens it over HTTP reads only the tier it needs. A texture package has a .mobile / .low sibling only where its maps are larger than that tier's cap.
In a game#
AssetLibrary (in @ferret/levels) is a service that opens the catalog through the asset store, so the cache, the hashes and range reads of the streaming layer apply. It opens the package of an item, and the packages that item depends on, on first use. Without an argument it opens globalThis.FERRET_ASSETS, else /lib/ferret-assets/ (the engine's default; give the server's https://ferret.partners.solutions/ferret/library/catalog.json where that folder does not exist).
const library = world.addService(new AssetLibrary({ store, mount, assets: runtimeAssets, tier: 'mobile' }));
await library.open(); // or open('https://host/lib/catalog.json')
library.list({ type: 'material', text: 'bark' }); // from the catalog: no package is opened
const wall = await library.material('bricks', { variant: 'red' }); // PBRMaterial, textures shared between materials
const bear = await library.character('bear', { position: [2, 0, 3] }); // a placeholder at once, the model swaps in
const { groups } = await library.bindClips(bear); // the clip sets of the character on its bones, by bone name
A sound is taken by name into the audio service: await library.sound('door-slam', { audio }) reads the file the device should have (the WAV on desktop, the MP3 on mobile and low, whichever there is when only one is; format says it), hands its bytes to audio.addFile and defines the sound with the item's bus, volume, loop (and loop points) and distance falloff; then audio.play('door-slam', { at }). The catalog lists a sound with its duration and the sizes of its files by tier.
A tier picks the file a character is loaded from (a lighter tier when the item has no heavier one's equal, never a heavier one than asked for when a lighter exists) and, for texture packages, the .mobile / .low sibling. A relative base in the catalog (./) is the folder of the catalog file, so the folder can be moved or served from anywhere. Commands for an agent: lib.open, lib.list, lib.item, lib.material, lib.spawn, lib.module.
Browsing#
The viewer shows the library with ?library (or ?library=<catalog.json url>): a grid of previews with a type filter and a search; opening an item puts it in the scene (a character with its clips, a material on a sphere with its variants, a texture set on a plane) with its id, sizes and the line of code that loads it. Arrows move in the grid, Enter opens, Escape closes. The commands are library.list, library.show {id, variant?, tier?}, library.play {clip} and library.clear. The docs site gets a gallery page of every item from node tools/docs/build.mjs --library <dir of catalog.json>.
The sample examples/library is a scene made only of library items (materials on a floor and walls, animals with their clips, a person on a locomotion graph); it asks for ids and takes what the catalog has, so it runs on any library (?lib=<catalog.json url>).