Add set box brush name command and update scene document migration

This commit is contained in:
2026-03-31 04:22:46 +02:00
parent 0040bcde35
commit 07999f8038
4 changed files with 76 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import {
createDefaultFaceUvState,
isBoxFaceId,
isFaceUvRotationQuarterTurns,
normalizeBrushName,
type BoxBrushFaces,
type BrushFace,
type FaceUvState
@@ -13,6 +14,7 @@ import {
BOX_BRUSH_SCENE_DOCUMENT_VERSION,
FACE_MATERIALS_SCENE_DOCUMENT_VERSION,
FOUNDATION_SCENE_DOCUMENT_VERSION,
RUNNER_V1_SCENE_DOCUMENT_VERSION,
SCENE_DOCUMENT_VERSION,
type SceneDocument,
type WorldSettings
@@ -80,6 +82,10 @@ function expectOptionalString(value: unknown, label: string): string | undefined
return expectString(value, label);
}
function readOptionalBrushName(value: unknown, label: string): string | undefined {
return normalizeBrushName(expectOptionalString(value, label));
}
function expectEmptyCollection(value: unknown, label: string): Record<string, never> {
if (!isRecord(value)) {
throw new Error(`${label} must be a record.`);
@@ -264,6 +270,7 @@ function readBrushes(
brushes[brushId] = createBoxBrush({
id: expectString(brushValue.id, `brushes.${brushId}.id`),
name: readOptionalBrushName(brushValue.name, `brushes.${brushId}.name`),
center,
size,
faces: readBoxBrushFaces(brushValue.faces, `brushes.${brushId}.faces`, materials, allowMissingUvState),
@@ -428,6 +435,23 @@ export function migrateSceneDocument(source: unknown): SceneDocument {
};
}
if (source.version === RUNNER_V1_SCENE_DOCUMENT_VERSION) {
const materials = readMaterialRegistry(source.materials, "materials");
return {
version: SCENE_DOCUMENT_VERSION,
name: expectString(source.name, "name"),
world: readWorldSettings(source.world),
materials,
textures: expectEmptyCollection(source.textures, "textures"),
assets: expectEmptyCollection(source.assets, "assets"),
brushes: readBrushes(source.brushes, materials, false),
modelInstances: expectEmptyCollection(source.modelInstances, "modelInstances"),
entities: readEntities(source.entities),
interactionLinks: expectEmptyCollection(source.interactionLinks, "interactionLinks")
};
}
if (source.version !== SCENE_DOCUMENT_VERSION) {
throw new Error(`Unsupported scene document version: ${String(source.version)}.`);
}