Voxel-animation network API
Syncs an AnimationDocument through a voxelanimation:<assetId> room. Browser code imports @jolly-pixel/asset.voxel-animation/client; asset-server code imports @jolly-pixel/asset.voxel-animation/server.
ts
import { AssetRoom } from "@jolly-pixel/asset";
import {
voxelAnimationDocumentKind,
type AnimationRoom
} from "@jolly-pixel/asset.voxel-animation/client";
const room: AnimationRoom = client.room(new AssetRoom("voxelanimation", assetId).toString());
const synced = voxelAnimationDocumentKind().syncDocument(room);
room.join();
await synced.ready;
// On teardown: synced.dispose(); room.leave();Synchronization
voxelAnimationDocumentKind()is the@jolly-pixel/editor.hostlease adapter, built with network'scommandDocumentKind.syncDocument(room)returns aSyncedAnimationDocument: a networkSyncedCommandDocumentover a newAnimationDocument.- Call
syncDocument(room)beforeroom.join().dispose()destroys the sync; the caller still leaves the room. - The sync is a
DocumentSyncClientkeyed byanimationWriteKeys. Undo and redo carry thebasisof their step, and the server's answers reachdocument.receipts, so the history refuses steps a peer overwrote. - To listen to
snapshot,ready,commandandnotice, build the client yourself:new DocumentSyncClient(room, { document, keys: animationWriteKeys }).
Wire data
ts
interface AnimationSetSnapshot {
rig: string;
clips: AnimationClipJSON[];
}
type AnimationCommandAction =
| "rig-renamed"
| "clip-added" | "clip-removed" | "clip-changed" | "clip-moved"
| "key-set" | "key-removed"
| "track-removed" | "track-renamed";AnimationNetworkCommandis anAnimationCommandplus the network command header. The stored file adds aversionto the snapshot.ANIMATION_CHANNELSlists the key channels andANIMATION_INTERPOLATIONSthe interpolations.- The animation set page describes each command.
Server protocol
- The kind arbitrates with a network
KeyedCommandArbiter: a command is refused whenstate.accepts(command)is false or it loses one of itsanimationConflictKeys(command). Architecture lists the keys. animationWriteKeys(command)returns the values a command sets, for the client reconciler, ornullfor clip and track structure commands.animationCommandProtocolvalidates commands andanimationSetSnapshotSchemavalidates snapshots.