Files
workinf_Blender_Wasm/web/protocol/mesh-authoring-commands.ts
mes123456 7549b9a15c
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
feat(web): switch to implementation-first capability wave
2026-08-29 01:22:03 +08:00

36 lines
2.0 KiB
TypeScript

import type { MeshEditOperation, MeshElementMode } from "./web-engine";
import type { SimplifyProfile } from "./simplify";
import type { WebEngineEditCommand } from "./web-engine";
type MeshCommand<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 for mesh authoring commands sent to WebEngine Main. */
export const meshAuthoringCommands = Object.freeze({
edit(meshId: string, operation: MeshEditOperation, selectionMode: MeshElementMode, elementIndices: readonly number[], options: { offset?: readonly number[]; amount?: number; segments?: number } = {}): MeshCommand<"meshEdit"> {
return {
type: "meshEdit", meshId, operation, selectionMode, elementIndices: [...elementIndices],
...(options.offset ? { offset: vector3(options.offset) } : {}),
...(options.amount === undefined ? {} : { amount: options.amount }),
...(options.segments === undefined ? {} : { segments: options.segments }),
};
},
decimate(meshId: string, profile: SimplifyProfile): MeshCommand<"decimateMesh"> {
return { type: "decimateMesh", meshId, profile };
},
previewDecimate(meshId: string, profile: SimplifyProfile): MeshCommand<"previewDecimateMesh"> {
return { type: "previewDecimateMesh", meshId, profile };
},
translateVertices(meshId: string, vertexIndices: readonly number[], offset: readonly number[]): MeshCommand<"translateMeshVertices"> {
return { type: "translateMeshVertices", meshId, vertexIndices: [...vertexIndices], offset: vector3(offset) };
},
createUVMap(meshId: string, name: string): MeshCommand<"createUVMap"> {
return { type: "createUVMap", meshId, name };
},
activeUVMap(meshId: string, name: string): MeshCommand<"setActiveUVMap"> {
return { type: "setActiveUVMap", meshId, name };
},
} satisfies Record<string, (...args: never[]) => WebEngineEditCommand>);