Models and animation
Use named imports from the .mjs files. The GLB tools accept self-contained binary glTF. The included Three.js loader resolves embedded model resources. Import assumes a secure origin for digest operations in the browser. A localhost server meets that requirement.
Resolve a model into gameplay points#
modelAnchors(root, role, {id?, point?} = {}) in src/model-anchors.mjs returns a Map from an authored ID to a Three.js Vector3. It updates world transforms and walks the supplied scene tree, matching node.userData.role. The defaults use each matching node's name and origin. An unmatched role returns an empty map.
Use id(node) to choose a nonempty string or safe integer. Use point(node) to select that node or one of its descendants. Duplicate IDs, missing or unrelated points, and non-finite positions throw. Returned vectors are snapshots. Resolve them again if the model placement changes.
The source GLBs give all docking assemblies a pivot at the station center. The child aperture gives the position a ship can actually reach. This example reads the four-port revision's real bytes, validates its release digest and resolves those apertures after placement.
import { readFile } from 'node:fs/promises';
import { parseArchiveModel, stationModels } from './examples/frontier-dispatch/models.mjs';
import { modelAnchors } from './src/model-anchors.mjs';
const asset = stationModels['4'];
const station = await parseArchiveModel(new Blob([await readFile(asset.url)]), asset);
station.rotation.x = -Math.PI / 2;
station.scale.setScalar(0.68);
const ports = modelAnchors(station, 'docking-port', {
id: node => node.userData.port,
point: node => node.children.find(
child => child.userData.name === 'Docking aperture ' + node.userData.port
)
});
console.log(ports.size, ports.get(1).x.toFixed(2));
4 7.26
In a browser, read the Blob from a file input or a successful fetch. parseArchiveModel and stationModels belong to the example. modelAnchors belongs to the engine. The example's two HOLO asset IDs, source credits, license and digests are recorded in examples/frontier-dispatch/assets/PROVENANCE.md and models.mjs.
Inspect and play a local model#
| Module and call | Contract |
|---|---|
model-preview.mjs · await inspectStudioModel(blob) |
Returns a frozen inspection with kind (static, animated or skinned), byte and geometry counts, and selected-scene clips: [{index, label}]. The validator rejects external resources, malformed data and files over 16 MiB. |
model-preview.mjs · modelPreviewSettings(inspection, options?) |
Validates a source clip index or null and normalizes fit. Duplicate clip names are valid. Store the source index. |
model-runtime.mjs · await openStudioModel(blob) |
Opens a local character preview session with clips (including duration), kind, createActor and dispose. The runtime checks the loaded scene and requires finite upright character bounds. |
session.createActor({height, fit}?) |
Creates an independently sampled actor. Attach actor.root to the scene. Height defaults to one scene unit. setFit accepts yaw, scale and groundOffset. |
actor.seek(clipIndex, seconds) |
Samples a clip at the clamped time and returns {index, time}. Use null for rest pose. actor.dispose() releases the clone. session.dispose() closes its remaining actors and source resources. |
Private casting and retargeting#
Private library operations return promises. model-library.mjs exports savePrivateModel(blob, {allowed, signal?}), listPrivateModels(), loadPrivateModel(id, options) and deletePrivateModel(id). Save returns metadata keyed by SHA-256. Load returns verified bytes as a Blob. Explicit preview permission is required for save and load. IndexedDB holds up to four models of up to 16 MiB each.
| Operation | Data and lifetime |
|---|---|
bindPrivateModelRole(role, modelId, {allowed, signal?, settings?}), getPrivateModelRole(role), unbindPrivateModelRole(role) |
A role uses {projectId, sceneId, slot} with slot 0 or 1. Role settings hold fit, a scene clip and optional gameplay clip indices. These records live in the private library. |
gameClips(raw?), validateGameClips(raw, clips) in model-game-clips.mjs |
Map idle, walk, rise, fall and clear to source indices. A missing state normalizes to null and uses rest pose. gameplaySample uses the resolved locomotion phase, ticks and velocity. |
openStudioRetargetPreview(sourceBlob, targetBlob, options) in model-retarget.mjs |
Requires two skinned models, a source clip, allowed: true and explicit mapping: [{source, target}] bone names. Mapped children require matching mapped ancestor chains. |
preview.seek(seconds, {allowed: true}), preview.dispose() |
Applies rotations to the target skeleton at the sampled time. Abort or dispose on consent withdrawal. Translation, scale and root motion are outside this retarget operation. |
savePrivateRetargetMapping(record, options), loadPrivateRetargetMapping(sourceId, targetId, options), deletePrivateRetargetMapping(sourceId, targetId, options) |
Store or look up a mapping for the ordered pair of model digests. The record includes a clip and up to 128 unique bone pairs. Options carry explicit allowed and an optional abort signal. |
Model audition, retargeting and private gameplay rehearsal share the preview library. Their records carry exportAllowed: false. The public Frontier Dispatch example instead distributes three specifically licensed GLB files. Their CC0 provenance travels with the engine source. Asset ownership and storage.