Voxel-model network API
Syncs a ModelDocument through a voxelmodel:<assetId> room. Browser code imports @jolly-pixel/asset.voxel-model/client; asset-server code imports @jolly-pixel/asset.voxel-model/server.
ts
import { AssetRoom } from "@jolly-pixel/asset";
import {
voxelModelDocumentKind,
type VoxelModelRoom
} from "@jolly-pixel/asset.voxel-model/client";
const room: VoxelModelRoom = client.room(new AssetRoom("voxelmodel", assetId).toString());
const synced = voxelModelDocumentKind().syncDocument(room);
room.join();
await synced.ready;
// On teardown: synced.dispose(); room.leave();Synchronization
voxelModelDocumentKind()is the@jolly-pixel/editor.hostlease adapter, built with network'scommandDocumentKind.syncDocument(room)returns aSyncedModelDocument: a networkSyncedCommandDocumentover a newModelDocument.- Call
syncDocument(room)beforeroom.join().dispose()destroys the sync; the caller still leaves the room. - The sync is a
DocumentSyncClientkeyed byvoxelModelWriteKeys. Undo and redo carry thebasisof their step, and the server's answers reachdocument.receipts, so the history refuses steps a peer overwrote. - A pending command the tree now refuses, such as a move into a removed folder, stays out of the tree until the next snapshot.
- To listen to
snapshot,ready,commandandnotice, build the client yourself:new DocumentSyncClient(room, { document, keys: voxelModelWriteKeys }).
Wire data
ts
interface VoxelModelSnapshot {
nodes: ModelNodeJSON[]; // siblings in array order
materials: MaterialEntryJSON[];
animationSets: AnimationSetLinkJSON[];
}
type VoxelModelCommandAction =
| "node-added" | "node-removed" | "node-renamed" | "node-moved"
| "node-transformed" | "node-uv-changed" | "node-shape-changed"
| "node-material-changed"
| "material-added" | "material-folder-added" | "material-moved"
| "material-removed" | "material-renamed" | "material-changed"
| "animation-set-linked" | "animation-set-unlinked" | "animation-set-owned"
| "animation-binding-changed" | "animation-binding-cleared";VoxelModelNetworkCommandis aVoxelModelCommandplus the network command header.- The stored file adds a
versionand thetexturereference, which the live snapshot leaves out. - The model, materials and animation pages describe 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 itsvoxelModelConflictKeys(command). Architecture lists the keys. voxelModelWriteKeys(command)returns the values a command sets, for the client reconciler.voxelModelCommandProtocolvalidates commands andvoxelModelSnapshotSchemavalidates snapshots.