210 lines
12 KiB
TypeScript
210 lines
12 KiB
TypeScript
import type { ErrorReport } from "./error";
|
|
import type { ProgressEvent } from "./progress";
|
|
import type { NonMeshCurveSplineType, NonMeshFontCharacterIR, NonMeshFontLinksIR, NonMeshFontPropertiesIR, NonMeshFontTextBoxIR, SceneSnapshotIR } from "./scene-ir";
|
|
import type { SceneDelta } from "./scene-delta";
|
|
import type { SimplifyProfile } from "./simplify";
|
|
import type { SimplifyResult } from "./simplify";
|
|
import type { LODGenerationRequest } from "./lod";
|
|
import type { LODManifest } from "./simplify";
|
|
import type { DepsgraphEvaluationIR } from "./depsgraph";
|
|
import type { SculptMeshAttributesIR, SculptStrokeIR } from "./sculpt";
|
|
import type { GeometryNodeGraphIR } from "./geometry-nodes";
|
|
import type { ShaderGraphIR } from "./shader-graph";
|
|
import type { NlaTrackIR } from "./nla";
|
|
import type { RenderCapabilityRequest } from "./render-capabilities";
|
|
import type { CapabilityGateResult } from "./capability-gates";
|
|
import type { NonMeshGeometryChunk } from "./nonmesh-binary";
|
|
|
|
export interface MeshGeometryBuffer {
|
|
schemaVersion: 1;
|
|
meshId: string;
|
|
byteLength: number;
|
|
positions: ArrayBuffer;
|
|
indices: ArrayBuffer;
|
|
normals?: ArrayBuffer;
|
|
triangleCornerIndices?: ArrayBuffer;
|
|
uvs?: ArrayBuffer;
|
|
colors?: ArrayBuffer;
|
|
triangleMaterialIndices?: ArrayBuffer;
|
|
triangleFaceIndices?: ArrayBuffer;
|
|
edgeVertexIndices?: ArrayBuffer;
|
|
tangents?: ArrayBuffer;
|
|
splitNormals?: ArrayBuffer;
|
|
sculptMask?: ArrayBuffer;
|
|
faceSets?: ArrayBuffer;
|
|
}
|
|
|
|
export type MeshGeometryBufferField =
|
|
| "positions"
|
|
| "indices"
|
|
| "normals"
|
|
| "triangleCornerIndices"
|
|
| "uvs"
|
|
| "colors"
|
|
| "triangleMaterialIndices"
|
|
| "triangleFaceIndices"
|
|
| "edgeVertexIndices"
|
|
| "tangents"
|
|
| "splitNormals"
|
|
| "sculptMask"
|
|
| "faceSets";
|
|
|
|
export interface MeshGeometryRangePatch {
|
|
meshId: string;
|
|
field: MeshGeometryBufferField;
|
|
byteOffset: number;
|
|
data: ArrayBuffer;
|
|
}
|
|
|
|
export interface MeshGeometryDelta {
|
|
schemaVersion: 1;
|
|
patches: MeshGeometryRangePatch[];
|
|
replaced: MeshGeometryBuffer[];
|
|
removed: string[];
|
|
}
|
|
|
|
export type MeshElementMode = "VERT" | "EDGE" | "FACE";
|
|
export type MeshEditOperation = "MERGE" | "DISSOLVE" | "EXTRUDE" | "INSET" | "BEVEL" | "LOOP_CUT";
|
|
export type FCurveInterpolation = "CONSTANT" | "LINEAR" | "BEZIER";
|
|
|
|
export type WebEngineEditCommand =
|
|
| { type: "setFrame"; frame: number }
|
|
| { type: "setObjectVisibility"; objectId: string; visible: boolean }
|
|
| { type: "setModifierEnabled"; meshId: string; modifierUuid: string; enabled: boolean }
|
|
| { type: "setModifierVisibility"; meshId: string; modifierUuid: string; showViewport: boolean; showRender: boolean; showEditMode: boolean; showOnCage: boolean }
|
|
| { type: "decimateMesh"; meshId: string; profile: SimplifyProfile }
|
|
| { type: "previewDecimateMesh"; meshId: string; profile: SimplifyProfile }
|
|
| { type: "createPrimitive"; primitive: "CUBE" | "PLANE"; name?: string; location: [number, number, number] }
|
|
| { type: "duplicateObject"; objectId: string; offset?: [number, number, number]; linked?: boolean }
|
|
| { type: "deleteObject"; objectId: string }
|
|
| { type: "setObjectTransform"; objectId: string; translation: [number, number, number]; rotationEuler: [number, number, number]; scale: [number, number, number] }
|
|
| { type: "translateMeshVertices"; meshId: string; vertexIndices: number[]; offset: [number, number, number] }
|
|
| { type: "meshEdit"; meshId: string; operation: MeshEditOperation; selectionMode: MeshElementMode; elementIndices: number[]; offset?: [number, number, number]; amount?: number; segments?: number }
|
|
| { type: "createUVMap"; meshId: string; name: string }
|
|
| { type: "setActiveUVMap"; meshId: string; name: string }
|
|
| { type: "unwrapUV"; meshId: string; faceIndices: number[]; method: "PLANAR" | "CUBE" }
|
|
| { type: "addMaterialSlot"; objectId: string; name?: string }
|
|
| { type: "removeMaterialSlot"; objectId: string; slotIndex: number }
|
|
| { type: "assignMaterialFaces"; meshId: string; faceIndices: number[]; slotIndex: number }
|
|
| { type: "setMaterialPrincipled"; materialId: string; baseColor: [number, number, number, number]; roughness: number; metallic: number; emissionColor?: [number, number, number, number]; alpha?: number; ior?: number; specularIORLevel?: number; transmissionWeight?: number; coatWeight?: number; coatRoughness?: number; emissionStrength?: number }
|
|
| { type: "importImage"; name: string; mimeType: "image/png" | "image/jpeg"; width: number; height: number; base64: string }
|
|
| { type: "setMaterialImageNode"; materialId: string; imageId: string; usage: "BASE_COLOR" | "NORMAL"; uvMap?: string }
|
|
| { type: "insertObjectKeyframe"; objectId: string; frame: number; property: "LOCATION" | "ROTATION_EULER" | "SCALE"; interpolation?: FCurveInterpolation }
|
|
| { type: "deleteObjectKeyframe"; objectId: string; frame: number; property?: "LOCATION" | "ROTATION_EULER" | "SCALE" }
|
|
| { type: "setFCurveInterpolation"; animationId: string; path: string; interpolation: FCurveInterpolation }
|
|
| { type: "setActiveAction"; objectId: string; actionId: string | null }
|
|
| { type: "setConstraint"; objectId: string; constraintName: string; enabled: boolean; influence: number }
|
|
| { type: "setParent"; objectId: string; parentId: string | null; keepTransform?: boolean }
|
|
| { type: "createCollection"; name: string; parentCollectionId?: string | null }
|
|
| { type: "moveObjectToCollection"; objectId: string; collectionId: string }
|
|
| { type: "renameId"; id: string; name: string }
|
|
| { type: "joinObjects"; activeObjectId: string; objectIds: string[] }
|
|
| { type: "separateMeshFaces"; objectId: string; faceIndices: number[]; name?: string }
|
|
| { type: "applyObjectTransform"; objectId: string }
|
|
| { type: "setObjectOrigin"; objectId: string; mode: "GEOMETRY" | "WORLD" }
|
|
| { type: "createCurve"; curveType: "CURVE"; name?: string; controlPoints: number[]; cyclic?: boolean; resolution?: number }
|
|
| { type: "deleteNonMeshData"; dataId: string }
|
|
| { type: "setCurveControlPoints"; dataId: string; controlPoints: number[]; splineOffsets?: number[]; resolution?: number }
|
|
| { type: "setCurveHandle"; dataId: string; pointIndex: number; side: "LEFT" | "RIGHT"; position: [number, number, number] }
|
|
| { type: "setCurveTopology"; dataId: string; baseRevision?: number; splineTypes?: NonMeshCurveSplineType[]; cyclicU?: boolean[]; cyclicV?: boolean[]; handleTypes?: number[]; handlePoints?: number[] }
|
|
| { type: "setCurveSplines"; dataId: string; splineTypes: NonMeshCurveSplineType[]; splineOffsets: number[]; ordersU: number[]; controlPoints: number[]; pointWeights: number[]; cyclicU: boolean[]; handleTypes: number[]; handlePoints: number[] }
|
|
| { type: "setSurfaceTopology"; dataId: string; splineDimensions: Array<{ u: number; v: number; orderU: number; orderV: number }>; controlPoints: number[]; pointWeights: number[]; cyclicU: boolean[]; cyclicV: boolean[] }
|
|
| { type: "setFontBody"; dataId: string; body: string }
|
|
| { type: "setFontProperties"; dataId: string; properties: Partial<NonMeshFontPropertiesIR> }
|
|
| { type: "setFontAdvanced"; dataId: string; characters: NonMeshFontCharacterIR[]; textBoxes: NonMeshFontTextBoxIR[]; activeTextBox: number }
|
|
| { type: "setFontLinks"; dataId: string; links: NonMeshFontLinksIR }
|
|
| { type: "createGreasePencilLayer"; dataId: string; name: string }
|
|
| { type: "removeGreasePencilLayer"; dataId: string; layerId: string }
|
|
| { type: "moveGreasePencilLayer"; dataId: string; layerId: string; direction: "UP" | "DOWN" | "TOP" | "BOTTOM" }
|
|
| { type: "insertGreasePencilFrame"; dataId: string; layerId: string; frame: number; duration?: number }
|
|
| { type: "removeGreasePencilFrame"; dataId: string; layerId: string; frame: number }
|
|
| { type: "setGreasePencilStrokes"; dataId: string; layerId: string; frame: number; strokes: Array<{ cyclic?: boolean; materialIndex?: number; points: Array<{ position: [number, number, number]; radius?: number; opacity?: number; vertexColor?: [number, number, number, number] }> }> }
|
|
| { type: "setVertexColors"; meshId: string; attributeName: string; domain: "POINT" | "CORNER"; indices: number[]; colors: number[] }
|
|
| { type: "setVertexWeights"; objectId: string; vertexGroup: string; indices: number[]; values: number[]; normalize?: boolean; mirror?: boolean }
|
|
| { type: "setLightProperties"; dataId: string; properties: { color?: [number, number, number]; energy?: number; exposure?: number; temperature?: number; useTemperature?: boolean; castsShadow?: boolean; radius?: number; spotAngle?: number; spotBlend?: number; areaSize?: number; areaSizeY?: number; areaSpread?: number; sunAngle?: number } }
|
|
| { type: "setCameraProperties"; dataId: string; properties: { projection?: "PERSPECTIVE" | "ORTHOGRAPHIC"; lensMm?: number; sensorWidthMm?: number; sensorHeightMm?: number; sensorFit?: 0 | 1 | 2; shift?: [number, number]; near?: number; far?: number; orthoScale?: number; depthOfField?: { enabled?: boolean; focusDistance?: number; apertureFStop?: number; apertureBlades?: number; apertureRotation?: number; apertureRatio?: number } } }
|
|
| { type: "setWorldProperties"; dataId: string; properties: { color?: [number, number, number]; exposure?: number; mist?: { enabled?: boolean; type?: "QUADRATIC" | "LINEAR" | "INVERSE_QUADRATIC"; start?: number; depth?: number; intensity?: number; height?: number } } }
|
|
| { type: "setMetaballElements"; dataId: string; elements: Array<{ type: number; position: [number, number, number]; radius: number; scale: [number, number, number] }> }
|
|
| { type: "sculptStroke"; stroke: SculptStrokeIR }
|
|
| { type: "setSculptMeshAttributes"; attributes: SculptMeshAttributesIR }
|
|
| { type: "setGeometryNodeGraph"; meshId: string; graph: GeometryNodeGraphIR }
|
|
| { type: "setShaderGraph"; materialId: string; graph: ShaderGraphIR }
|
|
| { type: "setNLAStack"; objectId: string; tracks: NlaTrackIR[] }
|
|
| { type: "undo" }
|
|
| { type: "redo" };
|
|
|
|
export type WebEngineRequest =
|
|
| { requestId: string; command: { type: "init" } }
|
|
| { requestId: string; command: { type: "openBlend"; buffer: ArrayBuffer }; }
|
|
| { requestId: string; command: { type: "snapshot" } }
|
|
| { requestId: string; command: { type: "applyCommand"; payload: WebEngineEditCommand } }
|
|
| { requestId: string; command: { type: "generateLOD"; payload: LODGenerationRequest } }
|
|
| { requestId: string; command: { type: "delta" } }
|
|
| { requestId: string; command: { type: "requestAsset"; assetId: string } }
|
|
| { requestId: string; command: { type: "queryRenderCapability"; request: RenderCapabilityRequest } }
|
|
| { requestId: string; command: { type: "queryNonMeshCapability"; dataId: string } }
|
|
| { requestId: string; command: { type: "evaluateDepsgraph" } }
|
|
| { requestId: string; command: { type: "saveBlend" } }
|
|
| { requestId: string; command: { type: "shutdown" } };
|
|
|
|
export interface WebEngineStatus {
|
|
ready: boolean;
|
|
liveHandles: number;
|
|
allocatedBytes: number;
|
|
}
|
|
|
|
export interface AssetRequestResult {
|
|
assetId: string;
|
|
status: "external" | "packed" | "packed-unavailable" | "missing" | "blocked";
|
|
sourcePath?: string;
|
|
safeSourcePath?: string;
|
|
pathStatus?: "safe" | "blocked";
|
|
errorCode?: "ASSET_PATH_OUTSIDE_PROJECT";
|
|
mimeType?: string;
|
|
width?: number;
|
|
height?: number;
|
|
data?: ArrayBuffer;
|
|
}
|
|
|
|
export interface WebEngineLODLevelResult {
|
|
level: number;
|
|
meshId: string;
|
|
triangleBudget: number;
|
|
outputTriangleCount: number;
|
|
outputVertexCount: number;
|
|
simplify?: SimplifyResult;
|
|
geometryBuffers: MeshGeometryBuffer[];
|
|
}
|
|
|
|
export interface WebEngineLODResult {
|
|
manifest: LODManifest;
|
|
levels: WebEngineLODLevelResult[];
|
|
errors?: WebEngineLODError[];
|
|
}
|
|
|
|
export interface WebEngineLODError {
|
|
requestedLevel: number;
|
|
triangleBudget: number;
|
|
message: string;
|
|
}
|
|
|
|
export interface WebEngineResult {
|
|
status: WebEngineStatus;
|
|
snapshot?: SceneSnapshotIR;
|
|
geometryBuffers?: MeshGeometryBuffer[];
|
|
nonMeshGeometryBuffers?: NonMeshGeometryChunk[];
|
|
geometryDelta?: MeshGeometryDelta;
|
|
delta?: SceneDelta;
|
|
simplify?: SimplifyResult;
|
|
lod?: WebEngineLODResult;
|
|
asset?: AssetRequestResult;
|
|
capabilityGate?: CapabilityGateResult;
|
|
depsgraph?: DepsgraphEvaluationIR;
|
|
blend?: ArrayBuffer;
|
|
}
|
|
|
|
export type WebEngineResponse =
|
|
| { kind: "progress"; requestId: string; progress: ProgressEvent }
|
|
| { kind: "result"; requestId: string; ok: true; result: WebEngineResult }
|
|
| { kind: "result"; requestId: string; ok: false; error: ErrorReport };
|