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 type { ToolMode } from "../core/tool-mode";
|
||||||
import { createOpaqueId } from "../core/ids";
|
import { createOpaqueId } from "../core/ids";
|
||||||
import type { EditorSelection } from "../core/selection";
|
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 { getBrushFaceIds } from "../geometry/whitebox-topology";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -46,7 +46,7 @@ export function createSetBoxBrushAllFaceMaterialsCommand(
|
|||||||
previousMaterialIds = Object.fromEntries(
|
previousMaterialIds = Object.fromEntries(
|
||||||
getBrushFaceIds(currentBrush).map((faceId) => [
|
getBrushFaceIds(currentBrush).map((faceId) => [
|
||||||
faceId,
|
faceId,
|
||||||
currentBrush.faces[faceId].materialId
|
currentBrush.faces[faceId]?.materialId ?? null
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -60,8 +60,9 @@ export function createSetBoxBrushAllFaceMaterialsCommand(
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.setDocument(
|
context.setDocument(
|
||||||
replaceBrush(currentDocument, {
|
replaceBrush(
|
||||||
...currentBrush,
|
currentDocument,
|
||||||
|
updateBrush(currentBrush, {
|
||||||
faces: Object.fromEntries(
|
faces: Object.fromEntries(
|
||||||
getBrushFaceIds(currentBrush).map((faceId) => [
|
getBrushFaceIds(currentBrush).map((faceId) => [
|
||||||
faceId,
|
faceId,
|
||||||
@@ -72,6 +73,7 @@ export function createSetBoxBrushAllFaceMaterialsCommand(
|
|||||||
])
|
])
|
||||||
) as typeof currentBrush.faces
|
) as typeof currentBrush.faces
|
||||||
})
|
})
|
||||||
|
)
|
||||||
);
|
);
|
||||||
context.setToolMode("select");
|
context.setToolMode("select");
|
||||||
},
|
},
|
||||||
@@ -82,20 +84,23 @@ export function createSetBoxBrushAllFaceMaterialsCommand(
|
|||||||
|
|
||||||
const currentDocument = context.getDocument();
|
const currentDocument = context.getDocument();
|
||||||
const currentBrush = getBoxBrushOrThrow(currentDocument, options.brushId);
|
const currentBrush = getBoxBrushOrThrow(currentDocument, options.brushId);
|
||||||
|
const restoredMaterialIds = previousMaterialIds;
|
||||||
|
|
||||||
context.setDocument(
|
context.setDocument(
|
||||||
replaceBrush(currentDocument, {
|
replaceBrush(
|
||||||
...currentBrush,
|
currentDocument,
|
||||||
|
updateBrush(currentBrush, {
|
||||||
faces: Object.fromEntries(
|
faces: Object.fromEntries(
|
||||||
getBrushFaceIds(currentBrush).map((faceId) => [
|
getBrushFaceIds(currentBrush).map((faceId) => [
|
||||||
faceId,
|
faceId,
|
||||||
{
|
{
|
||||||
...currentBrush.faces[faceId],
|
...currentBrush.faces[faceId],
|
||||||
materialId: previousMaterialIds[faceId] ?? null
|
materialId: restoredMaterialIds[faceId] ?? null
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
) as typeof currentBrush.faces
|
) as typeof currentBrush.faces
|
||||||
})
|
})
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (previousSelection !== null) {
|
if (previousSelection !== null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user