Add box brush mesh and update related files
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import type { WhiteboxSelectionMode } from "./whitebox-selection-mode";
|
||||
import type { BoxEdgeId, BoxFaceId, BoxVertexId } from "../document/brushes";
|
||||
import type {
|
||||
WhiteboxEdgeId,
|
||||
WhiteboxFaceId,
|
||||
WhiteboxVertexId
|
||||
} from "../document/brushes";
|
||||
|
||||
export type EditorSelection =
|
||||
| { kind: "none" }
|
||||
| { kind: "brushes"; ids: string[] }
|
||||
| { kind: "brushFace"; brushId: string; faceId: BoxFaceId }
|
||||
| { kind: "brushEdge"; brushId: string; edgeId: BoxEdgeId }
|
||||
| { kind: "brushVertex"; brushId: string; vertexId: BoxVertexId }
|
||||
| { kind: "brushFace"; brushId: string; faceId: WhiteboxFaceId }
|
||||
| { kind: "brushEdge"; brushId: string; edgeId: WhiteboxEdgeId }
|
||||
| { kind: "brushVertex"; brushId: string; vertexId: WhiteboxVertexId }
|
||||
| { kind: "paths"; ids: string[] }
|
||||
| { kind: "pathPoint"; pathId: string; pointId: string }
|
||||
| { kind: "entities"; ids: string[] }
|
||||
@@ -93,7 +97,9 @@ export function getSingleSelectedBrushId(selection: EditorSelection): string | n
|
||||
return selection.ids[0];
|
||||
}
|
||||
|
||||
export function getSelectedBrushFaceId(selection: EditorSelection): BoxFaceId | null {
|
||||
export function getSelectedBrushFaceId(
|
||||
selection: EditorSelection
|
||||
): WhiteboxFaceId | null {
|
||||
if (selection.kind !== "brushFace") {
|
||||
return null;
|
||||
}
|
||||
@@ -101,7 +107,9 @@ export function getSelectedBrushFaceId(selection: EditorSelection): BoxFaceId |
|
||||
return selection.faceId;
|
||||
}
|
||||
|
||||
export function getSelectedBrushEdgeId(selection: EditorSelection): BoxEdgeId | null {
|
||||
export function getSelectedBrushEdgeId(
|
||||
selection: EditorSelection
|
||||
): WhiteboxEdgeId | null {
|
||||
if (selection.kind !== "brushEdge") {
|
||||
return null;
|
||||
}
|
||||
@@ -109,7 +117,9 @@ export function getSelectedBrushEdgeId(selection: EditorSelection): BoxEdgeId |
|
||||
return selection.edgeId;
|
||||
}
|
||||
|
||||
export function getSelectedBrushVertexId(selection: EditorSelection): BoxVertexId | null {
|
||||
export function getSelectedBrushVertexId(
|
||||
selection: EditorSelection
|
||||
): WhiteboxVertexId | null {
|
||||
if (selection.kind !== "brushVertex") {
|
||||
return null;
|
||||
}
|
||||
@@ -168,15 +178,27 @@ export function isBrushSelected(selection: EditorSelection, brushId: string): bo
|
||||
);
|
||||
}
|
||||
|
||||
export function isBrushFaceSelected(selection: EditorSelection, brushId: string, faceId: BoxFaceId): boolean {
|
||||
export function isBrushFaceSelected(
|
||||
selection: EditorSelection,
|
||||
brushId: string,
|
||||
faceId: WhiteboxFaceId
|
||||
): boolean {
|
||||
return selection.kind === "brushFace" && selection.brushId === brushId && selection.faceId === faceId;
|
||||
}
|
||||
|
||||
export function isBrushEdgeSelected(selection: EditorSelection, brushId: string, edgeId: BoxEdgeId): boolean {
|
||||
export function isBrushEdgeSelected(
|
||||
selection: EditorSelection,
|
||||
brushId: string,
|
||||
edgeId: WhiteboxEdgeId
|
||||
): boolean {
|
||||
return selection.kind === "brushEdge" && selection.brushId === brushId && selection.edgeId === edgeId;
|
||||
}
|
||||
|
||||
export function isBrushVertexSelected(selection: EditorSelection, brushId: string, vertexId: BoxVertexId): boolean {
|
||||
export function isBrushVertexSelected(
|
||||
selection: EditorSelection,
|
||||
brushId: string,
|
||||
vertexId: WhiteboxVertexId
|
||||
): boolean {
|
||||
return selection.kind === "brushVertex" && selection.brushId === brushId && selection.vertexId === vertexId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,56 @@
|
||||
import type { EditorSelection } from "./selection";
|
||||
import {
|
||||
BOX_EDGE_LABELS,
|
||||
BOX_FACE_LABELS,
|
||||
BOX_VERTEX_LABELS
|
||||
type Brush
|
||||
} from "../document/brushes";
|
||||
import type { SceneDocument } from "../document/scene-document";
|
||||
import {
|
||||
getBrushDefaultName,
|
||||
getBrushEdgeLabel,
|
||||
getBrushFaceLabel,
|
||||
getBrushKindLabel,
|
||||
getBrushVertexLabel
|
||||
} from "../geometry/whitebox-topology";
|
||||
|
||||
function getBrushDisplayLabel(document: SceneDocument, brushId: string): string {
|
||||
const brushes = Object.values(document.brushes);
|
||||
const brushIndex = brushes.findIndex((brush) => brush.id === brushId);
|
||||
|
||||
if (brushIndex === -1) {
|
||||
return "Whitebox Box";
|
||||
return "Whitebox Solid";
|
||||
}
|
||||
|
||||
return brushes[brushIndex].name ?? `Whitebox Box ${brushIndex + 1}`;
|
||||
return brushes[brushIndex].name ?? getBrushDefaultName(brushes[brushIndex], brushIndex);
|
||||
}
|
||||
|
||||
function getBrushOrNull(
|
||||
document: SceneDocument,
|
||||
brushId: string
|
||||
): Brush | null {
|
||||
return document.brushes[brushId] ?? null;
|
||||
}
|
||||
|
||||
export function getWhiteboxSelectionFeedbackLabel(document: SceneDocument, selection: EditorSelection): string | null {
|
||||
switch (selection.kind) {
|
||||
case "brushes":
|
||||
return selection.ids.length === 1 ? `Solid · ${getBrushDisplayLabel(document, selection.ids[0])}` : null;
|
||||
case "brushFace":
|
||||
return `Face · ${BOX_FACE_LABELS[selection.faceId]} · ${getBrushDisplayLabel(document, selection.brushId)}`;
|
||||
case "brushEdge":
|
||||
return `Edge · ${BOX_EDGE_LABELS[selection.edgeId]} · ${getBrushDisplayLabel(document, selection.brushId)}`;
|
||||
case "brushVertex":
|
||||
return `Vertex · ${BOX_VERTEX_LABELS[selection.vertexId]} · ${getBrushDisplayLabel(document, selection.brushId)}`;
|
||||
case "brushFace": {
|
||||
const brush = getBrushOrNull(document, selection.brushId);
|
||||
return brush === null
|
||||
? `Face · ${selection.faceId} · ${getBrushDisplayLabel(document, selection.brushId)}`
|
||||
: `Face · ${getBrushFaceLabel(brush, selection.faceId)} · ${getBrushDisplayLabel(document, selection.brushId)}`;
|
||||
}
|
||||
case "brushEdge": {
|
||||
const brush = getBrushOrNull(document, selection.brushId);
|
||||
return brush === null
|
||||
? `Edge · ${selection.edgeId} · ${getBrushDisplayLabel(document, selection.brushId)}`
|
||||
: `Edge · ${getBrushEdgeLabel(brush, selection.edgeId)} · ${getBrushDisplayLabel(document, selection.brushId)}`;
|
||||
}
|
||||
case "brushVertex": {
|
||||
const brush = getBrushOrNull(document, selection.brushId);
|
||||
return brush === null
|
||||
? `Vertex · ${selection.vertexId} · ${getBrushDisplayLabel(document, selection.brushId)}`
|
||||
: `Vertex · ${getBrushVertexLabel(brush, selection.vertexId)} · ${getBrushDisplayLabel(document, selection.brushId)}`;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user