Support multiple brush kinds in migrate-scene-document.ts
This commit is contained in:
@@ -2107,9 +2107,7 @@ function readBrushes(
|
|||||||
throw new Error(`brushes.${brushId} must be an object.`);
|
throw new Error(`brushes.${brushId} must be an object.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (brushValue.kind !== "box") {
|
const kind = brushValue.kind;
|
||||||
throw new Error(`brushes.${brushId}.kind must be box.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const center = readVec3(brushValue.center, `brushes.${brushId}.center`);
|
const center = readVec3(brushValue.center, `brushes.${brushId}.center`);
|
||||||
const size = readVec3(brushValue.size, `brushes.${brushId}.size`);
|
const size = readVec3(brushValue.size, `brushes.${brushId}.size`);
|
||||||
@@ -2118,7 +2116,7 @@ function readBrushes(
|
|||||||
throw new Error(`brushes.${brushId}.size values must be positive.`);
|
throw new Error(`brushes.${brushId}.size values must be positive.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
brushes[brushId] = createBoxBrush({
|
const sharedBrushFields = {
|
||||||
id: expectString(brushValue.id, `brushes.${brushId}.id`),
|
id: expectString(brushValue.id, `brushes.${brushId}.id`),
|
||||||
name: readOptionalBrushName(brushValue.name, `brushes.${brushId}.name`),
|
name: readOptionalBrushName(brushValue.name, `brushes.${brushId}.name`),
|
||||||
visible: readOptionalBoolean(
|
visible: readOptionalBoolean(
|
||||||
@@ -2138,17 +2136,6 @@ function readBrushes(
|
|||||||
DEFAULT_BOX_BRUSH_ROTATION_DEGREES
|
DEFAULT_BOX_BRUSH_ROTATION_DEGREES
|
||||||
),
|
),
|
||||||
size,
|
size,
|
||||||
geometry: readBoxBrushGeometry(
|
|
||||||
brushValue.geometry,
|
|
||||||
`brushes.${brushId}.geometry`,
|
|
||||||
size
|
|
||||||
),
|
|
||||||
faces: readBoxBrushFaces(
|
|
||||||
brushValue.faces,
|
|
||||||
`brushes.${brushId}.faces`,
|
|
||||||
materials,
|
|
||||||
allowMissingUvState
|
|
||||||
),
|
|
||||||
volume: readBoxBrushVolumeSettings(
|
volume: readBoxBrushVolumeSettings(
|
||||||
brushValue.volume,
|
brushValue.volume,
|
||||||
`brushes.${brushId}.volume`
|
`brushes.${brushId}.volume`
|
||||||
@@ -2161,7 +2148,74 @@ function readBrushes(
|
|||||||
brushValue.groupId,
|
brushValue.groupId,
|
||||||
`brushes.${brushId}.groupId`
|
`brushes.${brushId}.groupId`
|
||||||
)
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (kind === "box") {
|
||||||
|
brushes[brushId] = createBoxBrush({
|
||||||
|
...sharedBrushFields,
|
||||||
|
geometry: readBoxBrushGeometry(
|
||||||
|
brushValue.geometry,
|
||||||
|
`brushes.${brushId}.geometry`,
|
||||||
|
size
|
||||||
|
),
|
||||||
|
faces: readBoxBrushFaces(
|
||||||
|
brushValue.faces,
|
||||||
|
`brushes.${brushId}.faces`,
|
||||||
|
materials,
|
||||||
|
allowMissingUvState
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kind === "wedge") {
|
||||||
|
brushes[brushId] = createWedgeBrush({
|
||||||
|
...sharedBrushFields,
|
||||||
|
geometry: readBrushGeometry(
|
||||||
|
brushValue.geometry,
|
||||||
|
`brushes.${brushId}.geometry`,
|
||||||
|
createDefaultWedgeBrushGeometry(size),
|
||||||
|
WEDGE_VERTEX_IDS
|
||||||
|
),
|
||||||
|
faces: readBrushFaces(
|
||||||
|
brushValue.faces,
|
||||||
|
`brushes.${brushId}.faces`,
|
||||||
|
materials,
|
||||||
|
allowMissingUvState,
|
||||||
|
WEDGE_FACE_IDS
|
||||||
|
)
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kind === "radialPrism") {
|
||||||
|
const sideCount = normalizeRadialPrismSideCount(
|
||||||
|
expectNumber(brushValue.sideCount, `brushes.${brushId}.sideCount`)
|
||||||
|
);
|
||||||
|
|
||||||
|
brushes[brushId] = createRadialPrismBrush({
|
||||||
|
...sharedBrushFields,
|
||||||
|
sideCount,
|
||||||
|
geometry: readBrushGeometry(
|
||||||
|
brushValue.geometry,
|
||||||
|
`brushes.${brushId}.geometry`,
|
||||||
|
createDefaultRadialPrismBrushGeometry(size, sideCount),
|
||||||
|
getRadialPrismVertexIds(sideCount)
|
||||||
|
),
|
||||||
|
faces: readBrushFaces(
|
||||||
|
brushValue.faces,
|
||||||
|
`brushes.${brushId}.faces`,
|
||||||
|
materials,
|
||||||
|
allowMissingUvState,
|
||||||
|
getRadialPrismFaceIds(sideCount)
|
||||||
|
)
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`brushes.${brushId}.kind must be box, wedge, or radialPrism.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return brushes;
|
return brushes;
|
||||||
|
|||||||
Reference in New Issue
Block a user