2026-03-31 02:02:34 +02:00
|
|
|
import { createOpaqueId } from "../core/ids";
|
2026-03-31 02:33:18 +02:00
|
|
|
import type { Vec2, Vec3 } from "../core/vector";
|
2026-03-31 02:02:34 +02:00
|
|
|
|
|
|
|
|
export const BOX_FACE_IDS = ["posX", "negX", "posY", "negY", "posZ", "negZ"] as const;
|
2026-04-04 20:06:42 +02:00
|
|
|
export const BOX_EDGE_IDS = [
|
|
|
|
|
"edgeX_negY_negZ",
|
|
|
|
|
"edgeX_posY_negZ",
|
|
|
|
|
"edgeX_negY_posZ",
|
|
|
|
|
"edgeX_posY_posZ",
|
|
|
|
|
"edgeY_negX_negZ",
|
|
|
|
|
"edgeY_posX_negZ",
|
|
|
|
|
"edgeY_negX_posZ",
|
|
|
|
|
"edgeY_posX_posZ",
|
|
|
|
|
"edgeZ_negX_negY",
|
|
|
|
|
"edgeZ_posX_negY",
|
|
|
|
|
"edgeZ_negX_posY",
|
|
|
|
|
"edgeZ_posX_posY"
|
|
|
|
|
] as const;
|
|
|
|
|
export const BOX_VERTEX_IDS = [
|
|
|
|
|
"negX_negY_negZ",
|
|
|
|
|
"posX_negY_negZ",
|
|
|
|
|
"negX_posY_negZ",
|
|
|
|
|
"posX_posY_negZ",
|
|
|
|
|
"negX_negY_posZ",
|
|
|
|
|
"posX_negY_posZ",
|
|
|
|
|
"negX_posY_posZ",
|
|
|
|
|
"posX_posY_posZ"
|
|
|
|
|
] as const;
|
2026-03-31 02:33:18 +02:00
|
|
|
export const FACE_UV_ROTATION_QUARTER_TURNS = [0, 1, 2, 3] as const;
|
2026-03-31 02:02:34 +02:00
|
|
|
|
|
|
|
|
export type BoxFaceId = (typeof BOX_FACE_IDS)[number];
|
2026-04-04 20:06:42 +02:00
|
|
|
export type BoxEdgeId = (typeof BOX_EDGE_IDS)[number];
|
|
|
|
|
export type BoxVertexId = (typeof BOX_VERTEX_IDS)[number];
|
2026-03-31 02:33:18 +02:00
|
|
|
export type FaceUvRotationQuarterTurns = (typeof FACE_UV_ROTATION_QUARTER_TURNS)[number];
|
|
|
|
|
|
2026-04-04 20:06:42 +02:00
|
|
|
export const BOX_FACE_LABELS: Record<BoxFaceId, string> = {
|
|
|
|
|
posX: "Right",
|
|
|
|
|
negX: "Left",
|
|
|
|
|
posY: "Top",
|
|
|
|
|
negY: "Bottom",
|
|
|
|
|
posZ: "Front",
|
|
|
|
|
negZ: "Back"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const BOX_EDGE_LABELS: Record<BoxEdgeId, string> = {
|
|
|
|
|
edgeX_negY_negZ: "X Edge (-Y, -Z)",
|
|
|
|
|
edgeX_posY_negZ: "X Edge (+Y, -Z)",
|
|
|
|
|
edgeX_negY_posZ: "X Edge (-Y, +Z)",
|
|
|
|
|
edgeX_posY_posZ: "X Edge (+Y, +Z)",
|
|
|
|
|
edgeY_negX_negZ: "Y Edge (-X, -Z)",
|
|
|
|
|
edgeY_posX_negZ: "Y Edge (+X, -Z)",
|
|
|
|
|
edgeY_negX_posZ: "Y Edge (-X, +Z)",
|
|
|
|
|
edgeY_posX_posZ: "Y Edge (+X, +Z)",
|
|
|
|
|
edgeZ_negX_negY: "Z Edge (-X, -Y)",
|
|
|
|
|
edgeZ_posX_negY: "Z Edge (+X, -Y)",
|
|
|
|
|
edgeZ_negX_posY: "Z Edge (-X, +Y)",
|
|
|
|
|
edgeZ_posX_posY: "Z Edge (+X, +Y)"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const BOX_VERTEX_LABELS: Record<BoxVertexId, string> = {
|
|
|
|
|
negX_negY_negZ: "Vertex (-X, -Y, -Z)",
|
|
|
|
|
posX_negY_negZ: "Vertex (+X, -Y, -Z)",
|
|
|
|
|
negX_posY_negZ: "Vertex (-X, +Y, -Z)",
|
|
|
|
|
posX_posY_negZ: "Vertex (+X, +Y, -Z)",
|
|
|
|
|
negX_negY_posZ: "Vertex (-X, -Y, +Z)",
|
|
|
|
|
posX_negY_posZ: "Vertex (+X, -Y, +Z)",
|
|
|
|
|
negX_posY_posZ: "Vertex (-X, +Y, +Z)",
|
|
|
|
|
posX_posY_posZ: "Vertex (+X, +Y, +Z)"
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-31 02:33:18 +02:00
|
|
|
export interface FaceUvState {
|
|
|
|
|
offset: Vec2;
|
|
|
|
|
scale: Vec2;
|
|
|
|
|
rotationQuarterTurns: FaceUvRotationQuarterTurns;
|
|
|
|
|
flipU: boolean;
|
|
|
|
|
flipV: boolean;
|
|
|
|
|
}
|
2026-03-31 02:02:34 +02:00
|
|
|
|
|
|
|
|
export interface BrushFace {
|
|
|
|
|
materialId: string | null;
|
2026-03-31 02:33:18 +02:00
|
|
|
uv: FaceUvState;
|
2026-03-31 02:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type BoxBrushFaces = Record<BoxFaceId, BrushFace>;
|
|
|
|
|
|
2026-04-05 02:21:22 +02:00
|
|
|
export type BoxBrushGeometryVertices = Record<BoxVertexId, Vec3>;
|
|
|
|
|
|
|
|
|
|
export interface BoxBrushGeometry {
|
|
|
|
|
vertices: BoxBrushGeometryVertices;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:02:34 +02:00
|
|
|
export interface BoxBrush {
|
|
|
|
|
id: string;
|
|
|
|
|
kind: "box";
|
2026-03-31 04:22:24 +02:00
|
|
|
name?: string;
|
2026-03-31 02:02:34 +02:00
|
|
|
center: Vec3;
|
2026-04-04 19:25:15 +02:00
|
|
|
rotationDegrees: Vec3;
|
2026-03-31 02:02:34 +02:00
|
|
|
size: Vec3;
|
2026-04-05 02:21:22 +02:00
|
|
|
geometry: BoxBrushGeometry;
|
2026-03-31 02:02:34 +02:00
|
|
|
faces: BoxBrushFaces;
|
|
|
|
|
layerId?: string;
|
|
|
|
|
groupId?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type Brush = BoxBrush;
|
|
|
|
|
|
|
|
|
|
export const DEFAULT_BOX_BRUSH_CENTER: Vec3 = {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 1,
|
|
|
|
|
z: 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const DEFAULT_BOX_BRUSH_SIZE: Vec3 = {
|
|
|
|
|
x: 2,
|
|
|
|
|
y: 2,
|
|
|
|
|
z: 2
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-04 19:25:15 +02:00
|
|
|
export const DEFAULT_BOX_BRUSH_ROTATION_DEGREES: Vec3 = {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
z: 0
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-31 04:22:24 +02:00
|
|
|
export function normalizeBrushName(name: string | null | undefined): string | undefined {
|
|
|
|
|
if (name === undefined || name === null) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const trimmedName = name.trim();
|
|
|
|
|
return trimmedName.length === 0 ? undefined : trimmedName;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:02:34 +02:00
|
|
|
function cloneVec3(vector: Vec3): Vec3 {
|
|
|
|
|
return {
|
|
|
|
|
x: vector.x,
|
|
|
|
|
y: vector.y,
|
|
|
|
|
z: vector.z
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cloneBrushFace(face: BrushFace): BrushFace {
|
|
|
|
|
return {
|
2026-03-31 02:33:18 +02:00
|
|
|
materialId: face.materialId,
|
|
|
|
|
uv: cloneFaceUvState(face.uv)
|
2026-03-31 02:02:34 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 02:21:22 +02:00
|
|
|
function cloneBoxBrushGeometryVertex(vertex: Vec3): Vec3 {
|
|
|
|
|
return {
|
|
|
|
|
x: vertex.x,
|
|
|
|
|
y: vertex.y,
|
|
|
|
|
z: vertex.z
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function cloneBoxBrushGeometry(geometry: BoxBrushGeometry): BoxBrushGeometry {
|
|
|
|
|
return {
|
|
|
|
|
vertices: {
|
|
|
|
|
negX_negY_negZ: cloneBoxBrushGeometryVertex(geometry.vertices.negX_negY_negZ),
|
|
|
|
|
posX_negY_negZ: cloneBoxBrushGeometryVertex(geometry.vertices.posX_negY_negZ),
|
|
|
|
|
negX_posY_negZ: cloneBoxBrushGeometryVertex(geometry.vertices.negX_posY_negZ),
|
|
|
|
|
posX_posY_negZ: cloneBoxBrushGeometryVertex(geometry.vertices.posX_posY_negZ),
|
|
|
|
|
negX_negY_posZ: cloneBoxBrushGeometryVertex(geometry.vertices.negX_negY_posZ),
|
|
|
|
|
posX_negY_posZ: cloneBoxBrushGeometryVertex(geometry.vertices.posX_negY_posZ),
|
|
|
|
|
negX_posY_posZ: cloneBoxBrushGeometryVertex(geometry.vertices.negX_posY_posZ),
|
|
|
|
|
posX_posY_posZ: cloneBoxBrushGeometryVertex(geometry.vertices.posX_posY_posZ)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getBoxBrushGeometryLocalBounds(geometry: BoxBrushGeometry): { min: Vec3; max: Vec3 } {
|
|
|
|
|
const vertices = Object.values(geometry.vertices);
|
|
|
|
|
const firstVertex = vertices[0];
|
|
|
|
|
const min = { ...firstVertex };
|
|
|
|
|
const max = { ...firstVertex };
|
|
|
|
|
|
|
|
|
|
for (const vertex of vertices.slice(1)) {
|
|
|
|
|
min.x = Math.min(min.x, vertex.x);
|
|
|
|
|
min.y = Math.min(min.y, vertex.y);
|
|
|
|
|
min.z = Math.min(min.z, vertex.z);
|
|
|
|
|
max.x = Math.max(max.x, vertex.x);
|
|
|
|
|
max.y = Math.max(max.y, vertex.y);
|
|
|
|
|
max.z = Math.max(max.z, vertex.z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
min,
|
|
|
|
|
max
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function deriveBoxBrushSizeFromGeometry(geometry: BoxBrushGeometry): Vec3 {
|
|
|
|
|
const bounds = getBoxBrushGeometryLocalBounds(geometry);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
x: bounds.max.x - bounds.min.x,
|
|
|
|
|
y: bounds.max.y - bounds.min.y,
|
|
|
|
|
z: bounds.max.z - bounds.min.z
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 02:37:15 +02:00
|
|
|
export function scaleBoxBrushGeometryToSize(geometry: BoxBrushGeometry, size: Vec3): BoxBrushGeometry {
|
|
|
|
|
const bounds = getBoxBrushGeometryLocalBounds(geometry);
|
|
|
|
|
const currentSize = deriveBoxBrushSizeFromGeometry(geometry);
|
|
|
|
|
|
|
|
|
|
if (!hasPositiveBoxSize(currentSize) || !hasPositiveBoxSize(size)) {
|
|
|
|
|
throw new Error("Box brush geometry size must remain positive on every axis.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const center = {
|
|
|
|
|
x: (bounds.min.x + bounds.max.x) * 0.5,
|
|
|
|
|
y: (bounds.min.y + bounds.max.y) * 0.5,
|
|
|
|
|
z: (bounds.min.z + bounds.max.z) * 0.5
|
|
|
|
|
};
|
|
|
|
|
const scale = {
|
|
|
|
|
x: size.x / currentSize.x,
|
|
|
|
|
y: size.y / currentSize.y,
|
|
|
|
|
z: size.z / currentSize.z
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
vertices: {
|
|
|
|
|
negX_negY_negZ: {
|
|
|
|
|
x: center.x + (geometry.vertices.negX_negY_negZ.x - center.x) * scale.x,
|
|
|
|
|
y: center.y + (geometry.vertices.negX_negY_negZ.y - center.y) * scale.y,
|
|
|
|
|
z: center.z + (geometry.vertices.negX_negY_negZ.z - center.z) * scale.z
|
|
|
|
|
},
|
|
|
|
|
posX_negY_negZ: {
|
|
|
|
|
x: center.x + (geometry.vertices.posX_negY_negZ.x - center.x) * scale.x,
|
|
|
|
|
y: center.y + (geometry.vertices.posX_negY_negZ.y - center.y) * scale.y,
|
|
|
|
|
z: center.z + (geometry.vertices.posX_negY_negZ.z - center.z) * scale.z
|
|
|
|
|
},
|
|
|
|
|
negX_posY_negZ: {
|
|
|
|
|
x: center.x + (geometry.vertices.negX_posY_negZ.x - center.x) * scale.x,
|
|
|
|
|
y: center.y + (geometry.vertices.negX_posY_negZ.y - center.y) * scale.y,
|
|
|
|
|
z: center.z + (geometry.vertices.negX_posY_negZ.z - center.z) * scale.z
|
|
|
|
|
},
|
|
|
|
|
posX_posY_negZ: {
|
|
|
|
|
x: center.x + (geometry.vertices.posX_posY_negZ.x - center.x) * scale.x,
|
|
|
|
|
y: center.y + (geometry.vertices.posX_posY_negZ.y - center.y) * scale.y,
|
|
|
|
|
z: center.z + (geometry.vertices.posX_posY_negZ.z - center.z) * scale.z
|
|
|
|
|
},
|
|
|
|
|
negX_negY_posZ: {
|
|
|
|
|
x: center.x + (geometry.vertices.negX_negY_posZ.x - center.x) * scale.x,
|
|
|
|
|
y: center.y + (geometry.vertices.negX_negY_posZ.y - center.y) * scale.y,
|
|
|
|
|
z: center.z + (geometry.vertices.negX_negY_posZ.z - center.z) * scale.z
|
|
|
|
|
},
|
|
|
|
|
posX_negY_posZ: {
|
|
|
|
|
x: center.x + (geometry.vertices.posX_negY_posZ.x - center.x) * scale.x,
|
|
|
|
|
y: center.y + (geometry.vertices.posX_negY_posZ.y - center.y) * scale.y,
|
|
|
|
|
z: center.z + (geometry.vertices.posX_negY_posZ.z - center.z) * scale.z
|
|
|
|
|
},
|
|
|
|
|
negX_posY_posZ: {
|
|
|
|
|
x: center.x + (geometry.vertices.negX_posY_posZ.x - center.x) * scale.x,
|
|
|
|
|
y: center.y + (geometry.vertices.negX_posY_posZ.y - center.y) * scale.y,
|
|
|
|
|
z: center.z + (geometry.vertices.negX_posY_posZ.z - center.z) * scale.z
|
|
|
|
|
},
|
|
|
|
|
posX_posY_posZ: {
|
|
|
|
|
x: center.x + (geometry.vertices.posX_posY_posZ.x - center.x) * scale.x,
|
|
|
|
|
y: center.y + (geometry.vertices.posX_posY_posZ.y - center.y) * scale.y,
|
|
|
|
|
z: center.z + (geometry.vertices.posX_posY_posZ.z - center.z) * scale.z
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 02:21:22 +02:00
|
|
|
export function createDefaultBoxBrushGeometry(size: Vec3 = DEFAULT_BOX_BRUSH_SIZE): BoxBrushGeometry {
|
|
|
|
|
const halfSize = {
|
|
|
|
|
x: size.x * 0.5,
|
|
|
|
|
y: size.y * 0.5,
|
|
|
|
|
z: size.z * 0.5
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
vertices: {
|
|
|
|
|
negX_negY_negZ: { x: -halfSize.x, y: -halfSize.y, z: -halfSize.z },
|
|
|
|
|
posX_negY_negZ: { x: halfSize.x, y: -halfSize.y, z: -halfSize.z },
|
|
|
|
|
negX_posY_negZ: { x: -halfSize.x, y: halfSize.y, z: -halfSize.z },
|
|
|
|
|
posX_posY_negZ: { x: halfSize.x, y: halfSize.y, z: -halfSize.z },
|
|
|
|
|
negX_negY_posZ: { x: -halfSize.x, y: -halfSize.y, z: halfSize.z },
|
|
|
|
|
posX_negY_posZ: { x: halfSize.x, y: -halfSize.y, z: halfSize.z },
|
|
|
|
|
negX_posY_posZ: { x: -halfSize.x, y: halfSize.y, z: halfSize.z },
|
|
|
|
|
posX_posY_posZ: { x: halfSize.x, y: halfSize.y, z: halfSize.z }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:02:34 +02:00
|
|
|
export function isBoxFaceId(value: unknown): value is BoxFaceId {
|
|
|
|
|
return typeof value === "string" && BOX_FACE_IDS.some((faceId) => faceId === value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-04 20:06:42 +02:00
|
|
|
export function isBoxEdgeId(value: unknown): value is BoxEdgeId {
|
|
|
|
|
return typeof value === "string" && BOX_EDGE_IDS.some((edgeId) => edgeId === value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isBoxVertexId(value: unknown): value is BoxVertexId {
|
|
|
|
|
return typeof value === "string" && BOX_VERTEX_IDS.some((vertexId) => vertexId === value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:33:18 +02:00
|
|
|
export function isFaceUvRotationQuarterTurns(value: unknown): value is FaceUvRotationQuarterTurns {
|
|
|
|
|
return typeof value === "number" && FACE_UV_ROTATION_QUARTER_TURNS.includes(value as FaceUvRotationQuarterTurns);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:02:34 +02:00
|
|
|
export function hasPositiveBoxSize(size: Vec3): boolean {
|
|
|
|
|
return size.x > 0 && size.y > 0 && size.z > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:33:18 +02:00
|
|
|
export function createDefaultFaceUvState(): FaceUvState {
|
|
|
|
|
return {
|
|
|
|
|
offset: {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0
|
|
|
|
|
},
|
|
|
|
|
scale: {
|
|
|
|
|
x: 1,
|
|
|
|
|
y: 1
|
|
|
|
|
},
|
|
|
|
|
rotationQuarterTurns: 0,
|
|
|
|
|
flipU: false,
|
|
|
|
|
flipV: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function cloneFaceUvState(uv: FaceUvState): FaceUvState {
|
|
|
|
|
return {
|
|
|
|
|
offset: {
|
|
|
|
|
...uv.offset
|
|
|
|
|
},
|
|
|
|
|
scale: {
|
|
|
|
|
...uv.scale
|
|
|
|
|
},
|
|
|
|
|
rotationQuarterTurns: uv.rotationQuarterTurns,
|
|
|
|
|
flipU: uv.flipU,
|
|
|
|
|
flipV: uv.flipV
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:02:34 +02:00
|
|
|
export function cloneBoxBrushFaces(faces: BoxBrushFaces): BoxBrushFaces {
|
|
|
|
|
return {
|
|
|
|
|
posX: cloneBrushFace(faces.posX),
|
|
|
|
|
negX: cloneBrushFace(faces.negX),
|
|
|
|
|
posY: cloneBrushFace(faces.posY),
|
|
|
|
|
negY: cloneBrushFace(faces.negY),
|
|
|
|
|
posZ: cloneBrushFace(faces.posZ),
|
|
|
|
|
negZ: cloneBrushFace(faces.negZ)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createDefaultBoxBrushFaces(): BoxBrushFaces {
|
|
|
|
|
return {
|
|
|
|
|
posX: {
|
2026-03-31 02:33:18 +02:00
|
|
|
materialId: null,
|
|
|
|
|
uv: createDefaultFaceUvState()
|
2026-03-31 02:02:34 +02:00
|
|
|
},
|
|
|
|
|
negX: {
|
2026-03-31 02:33:18 +02:00
|
|
|
materialId: null,
|
|
|
|
|
uv: createDefaultFaceUvState()
|
2026-03-31 02:02:34 +02:00
|
|
|
},
|
|
|
|
|
posY: {
|
2026-03-31 02:33:18 +02:00
|
|
|
materialId: null,
|
|
|
|
|
uv: createDefaultFaceUvState()
|
2026-03-31 02:02:34 +02:00
|
|
|
},
|
|
|
|
|
negY: {
|
2026-03-31 02:33:18 +02:00
|
|
|
materialId: null,
|
|
|
|
|
uv: createDefaultFaceUvState()
|
2026-03-31 02:02:34 +02:00
|
|
|
},
|
|
|
|
|
posZ: {
|
2026-03-31 02:33:18 +02:00
|
|
|
materialId: null,
|
|
|
|
|
uv: createDefaultFaceUvState()
|
2026-03-31 02:02:34 +02:00
|
|
|
},
|
|
|
|
|
negZ: {
|
2026-03-31 02:33:18 +02:00
|
|
|
materialId: null,
|
|
|
|
|
uv: createDefaultFaceUvState()
|
2026-03-31 02:02:34 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createBoxBrush(
|
2026-04-05 02:21:22 +02:00
|
|
|
overrides: Partial<Pick<BoxBrush, "id" | "name" | "center" | "rotationDegrees" | "size" | "geometry" | "faces" | "layerId" | "groupId">> = {}
|
2026-03-31 02:02:34 +02:00
|
|
|
): BoxBrush {
|
|
|
|
|
const center = cloneVec3(overrides.center ?? DEFAULT_BOX_BRUSH_CENTER);
|
2026-04-04 19:25:15 +02:00
|
|
|
const rotationDegrees = cloneVec3(overrides.rotationDegrees ?? DEFAULT_BOX_BRUSH_ROTATION_DEGREES);
|
2026-04-05 02:21:22 +02:00
|
|
|
const fallbackSize = cloneVec3(overrides.size ?? DEFAULT_BOX_BRUSH_SIZE);
|
|
|
|
|
const geometry = overrides.geometry === undefined ? createDefaultBoxBrushGeometry(fallbackSize) : cloneBoxBrushGeometry(overrides.geometry);
|
|
|
|
|
const size = deriveBoxBrushSizeFromGeometry(geometry);
|
2026-03-31 02:02:34 +02:00
|
|
|
|
|
|
|
|
if (!hasPositiveBoxSize(size)) {
|
|
|
|
|
throw new Error("Box brush size must remain positive on every axis.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: overrides.id ?? createOpaqueId("brush"),
|
|
|
|
|
kind: "box",
|
2026-03-31 04:22:24 +02:00
|
|
|
name: normalizeBrushName(overrides.name),
|
2026-03-31 02:02:34 +02:00
|
|
|
center,
|
2026-04-04 19:25:15 +02:00
|
|
|
rotationDegrees,
|
2026-03-31 02:02:34 +02:00
|
|
|
size,
|
2026-04-05 02:21:22 +02:00
|
|
|
geometry,
|
2026-03-31 02:02:34 +02:00
|
|
|
faces: overrides.faces === undefined ? createDefaultBoxBrushFaces() : cloneBoxBrushFaces(overrides.faces),
|
|
|
|
|
layerId: overrides.layerId,
|
|
|
|
|
groupId: overrides.groupId
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function cloneBoxBrush(brush: BoxBrush): BoxBrush {
|
|
|
|
|
return createBoxBrush(brush);
|
|
|
|
|
}
|