- update native web_engine sources and rebuilt wasm artifacts - add task cards, status notes and tooling scripts - add web e2e specs, tutorial UI sources and tutorial assets - sync golden task manifests and audit records Co-Authored-By: Claude Code <noreply@anthropic.com>
59 lines
3.5 KiB
TypeScript
59 lines
3.5 KiB
TypeScript
import type { MeshPrimitive, WebEngineEditCommand } from "./web-engine";
|
|
|
|
type CoreCommand<T extends WebEngineEditCommand["type"]> = Extract<WebEngineEditCommand, { type: T }>;
|
|
type Vector3 = [number, number, number];
|
|
|
|
const vector3 = (value: readonly number[]): Vector3 => [value[0] ?? 0, value[1] ?? 0, value[2] ?? 0];
|
|
|
|
/** Typed constructors used by the workbench for the source-backed scene API. */
|
|
export const coreSceneCommands = Object.freeze({
|
|
createPrimitive(primitive: MeshPrimitive, location: readonly number[] = [0, 0, 0], name?: string): CoreCommand<"createPrimitive"> {
|
|
return { type: "createPrimitive", primitive, location: vector3(location), ...(name ? { name } : {}) };
|
|
},
|
|
createCube(location: readonly number[] = [0, 0, 0], name?: string): CoreCommand<"createPrimitive"> {
|
|
return { type: "createPrimitive", primitive: "CUBE", location: vector3(location), ...(name ? { name } : {}) };
|
|
},
|
|
duplicate(objectId: string, offset: readonly number[] = [0.25, 0.25, 0], linked = false): CoreCommand<"duplicateObject"> {
|
|
return { type: "duplicateObject", objectId, offset: vector3(offset), ...(linked ? { linked: true } : {}) };
|
|
},
|
|
delete(objectId: string): CoreCommand<"deleteObject"> {
|
|
return { type: "deleteObject", objectId };
|
|
},
|
|
visibility(objectId: string, visible: boolean): CoreCommand<"setObjectVisibility"> {
|
|
return { type: "setObjectVisibility", objectId, visible };
|
|
},
|
|
transform(objectId: string, translation: readonly number[], rotationEuler: readonly number[], scale: readonly number[]): CoreCommand<"setObjectTransform"> {
|
|
return { type: "setObjectTransform", objectId, translation: vector3(translation), rotationEuler: vector3(rotationEuler), scale: vector3(scale) };
|
|
},
|
|
parent(objectId: string, parentId: string | null, keepTransform = true): CoreCommand<"setParent"> {
|
|
return { type: "setParent", objectId, parentId, keepTransform };
|
|
},
|
|
createCollection(name: string, parentCollectionId?: string | null): CoreCommand<"createCollection"> {
|
|
return { type: "createCollection", name, ...(parentCollectionId === undefined ? {} : { parentCollectionId }) };
|
|
},
|
|
moveCollection(collectionId: string, parentCollectionId: string | null = null, anchorCollectionId: string | null = null, after = false): CoreCommand<"moveCollection"> {
|
|
return { type: "moveCollection", collectionId, parentCollectionId, ...(anchorCollectionId ? { anchorCollectionId } : {}), ...(after ? { after: true } : {}) };
|
|
},
|
|
deleteCollection(collectionId: string, hierarchy = false): CoreCommand<"deleteCollection"> {
|
|
return { type: "deleteCollection", collectionId, ...(hierarchy ? { hierarchy: true } : {}) };
|
|
},
|
|
setScene(sceneId: string): CoreCommand<"setScene"> {
|
|
return { type: "setScene", sceneId };
|
|
},
|
|
setActiveCollection(collectionId: string): CoreCommand<"setActiveCollection"> {
|
|
return { type: "setActiveCollection", collectionId };
|
|
},
|
|
moveToCollection(objectId: string, collectionId: string): CoreCommand<"moveObjectToCollection"> {
|
|
return { type: "moveObjectToCollection", objectId, collectionId };
|
|
},
|
|
rename(id: string, name: string): CoreCommand<"renameId"> {
|
|
return { type: "renameId", id, name };
|
|
},
|
|
applyTransform(objectId: string): CoreCommand<"applyObjectTransform"> {
|
|
return { type: "applyObjectTransform", objectId };
|
|
},
|
|
setOrigin(objectId: string, mode: CoreCommand<"setObjectOrigin">["mode"] = "GEOMETRY"): CoreCommand<"setObjectOrigin"> {
|
|
return { type: "setObjectOrigin", objectId, mode };
|
|
},
|
|
} satisfies Record<string, (...args: never[]) => WebEngineEditCommand>);
|