Update brush material handling in set-box-brush-all-face-materials-command.ts
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { ToolMode } from "../core/tool-mode";
|
||||
import { createOpaqueId } from "../core/ids";
|
||||
import type { EditorSelection } from "../core/selection";
|
||||
import type { WhiteboxFaceId } from "../document/brushes";
|
||||
import { updateBrush, type WhiteboxFaceId } from "../document/brushes";
|
||||
import { getBrushFaceIds } from "../geometry/whitebox-topology";
|
||||
|
||||
import {
|
||||
@@ -46,7 +46,7 @@ export function createSetBoxBrushAllFaceMaterialsCommand(
|
||||
previousMaterialIds = Object.fromEntries(
|
||||
getBrushFaceIds(currentBrush).map((faceId) => [
|
||||
faceId,
|
||||
currentBrush.faces[faceId].materialId
|
||||
currentBrush.faces[faceId]?.materialId ?? null
|
||||
])
|
||||
);
|
||||
}
|
||||
@@ -60,8 +60,9 @@ export function createSetBoxBrushAllFaceMaterialsCommand(
|
||||
}
|
||||
|
||||
context.setDocument(
|
||||
replaceBrush(currentDocument, {
|
||||
...currentBrush,
|
||||
replaceBrush(
|
||||
currentDocument,
|
||||
updateBrush(currentBrush, {
|
||||
faces: Object.fromEntries(
|
||||
getBrushFaceIds(currentBrush).map((faceId) => [
|
||||
faceId,
|
||||
@@ -72,6 +73,7 @@ export function createSetBoxBrushAllFaceMaterialsCommand(
|
||||
])
|
||||
) as typeof currentBrush.faces
|
||||
})
|
||||
)
|
||||
);
|
||||
context.setToolMode("select");
|
||||
},
|
||||
@@ -82,20 +84,23 @@ export function createSetBoxBrushAllFaceMaterialsCommand(
|
||||
|
||||
const currentDocument = context.getDocument();
|
||||
const currentBrush = getBoxBrushOrThrow(currentDocument, options.brushId);
|
||||
const restoredMaterialIds = previousMaterialIds;
|
||||
|
||||
context.setDocument(
|
||||
replaceBrush(currentDocument, {
|
||||
...currentBrush,
|
||||
replaceBrush(
|
||||
currentDocument,
|
||||
updateBrush(currentBrush, {
|
||||
faces: Object.fromEntries(
|
||||
getBrushFaceIds(currentBrush).map((faceId) => [
|
||||
faceId,
|
||||
{
|
||||
...currentBrush.faces[faceId],
|
||||
materialId: previousMaterialIds[faceId] ?? null
|
||||
materialId: restoredMaterialIds[faceId] ?? null
|
||||
}
|
||||
])
|
||||
) as typeof currentBrush.faces
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
if (previousSelection !== null) {
|
||||
|
||||
Reference in New Issue
Block a user