Update box brush calculations to use face and vertex IDs

This commit is contained in:
2026-04-05 02:23:08 +02:00
parent ce5e18641b
commit b23cb0dd32
2 changed files with 17 additions and 31 deletions

View File

@@ -8,7 +8,7 @@ import {
type BoxFaceId,
type BoxVertexId
} from "../document/brushes";
import { getBoxBrushHalfSize } from "./box-brush";
import { getBoxBrushFaceVertexIds, getBoxBrushLocalVertexPosition } from "./box-brush-mesh";
type Sign = -1 | 1;
@@ -172,16 +172,18 @@ export function getBoxBrushVertexSigns(vertexId: BoxVertexId): BoxVertexSigns {
}
export function getBoxBrushFaceWorldCenter(brush: BoxBrush, faceId: BoxFaceId): Vec3 {
const halfSize = getBoxBrushHalfSize(brush);
const meta = getBoxBrushFaceTransformMeta(faceId);
const localCenter = {
x: 0,
y: 0,
z: 0
};
const axisOffset = meta.sign * (meta.axis === "x" ? halfSize.x : meta.axis === "y" ? halfSize.y : halfSize.z);
localCenter[meta.axis] = axisOffset;
const faceVertexIds = getBoxBrushFaceVertexIds(faceId);
const localCenter = faceVertexIds.reduce(
(accumulator, vertexId) => {
const vertex = getBoxBrushLocalVertexPosition(brush, vertexId);
return {
x: accumulator.x + vertex.x * 0.25,
y: accumulator.y + vertex.y * 0.25,
z: accumulator.z + vertex.z * 0.25
};
},
{ x: 0, y: 0, z: 0 }
);
return transformBoxBrushLocalPointToWorld(brush, localCenter);
}
@@ -199,14 +201,7 @@ export function getBoxBrushFaceIdsForAxis(axis: BoxAxis): BoxFaceId[] {
}
export function getBoxBrushVertexLocalPosition(brush: BoxBrush, vertexId: BoxVertexId): Vec3 {
const halfSize = getBoxBrushHalfSize(brush);
const signs = BOX_VERTEX_SIGNS[vertexId];
return {
x: signs.x * halfSize.x,
y: signs.y * halfSize.y,
z: signs.z * halfSize.z
};
return getBoxBrushLocalVertexPosition(brush, vertexId);
}
export function getBoxBrushVertexWorldPosition(brush: BoxBrush, vertexId: BoxVertexId): Vec3 {

View File

@@ -1,7 +1,7 @@
import { Euler, MathUtils, Vector3 } from "three";
import type { Vec3 } from "../core/vector";
import { type BoxBrush } from "../document/brushes";
import { BOX_VERTEX_IDS, type BoxBrush } from "../document/brushes";
import { getBoxBrushLocalVertexPosition } from "./box-brush-mesh";
export interface BoxBrushBounds {
@@ -45,17 +45,8 @@ export function getBoxBrushCornerPositions(brush: BoxBrush): Vec3[] {
MathUtils.degToRad(brush.rotationDegrees.z),
"XYZ"
);
const offsets = [
"negX_negY_negZ",
"posX_negY_negZ",
"negX_posY_negZ",
"posX_posY_negZ",
"negX_negY_posZ",
"posX_negY_posZ",
"negX_posY_posZ",
"posX_posY_posZ"
].map((vertexId) => {
const localVertex = getBoxBrushLocalVertexPosition(brush, vertexId as keyof BoxBrush["geometry"]["vertices"] & never);
const offsets = BOX_VERTEX_IDS.map((vertexId) => {
const localVertex = getBoxBrushLocalVertexPosition(brush, vertexId);
return new Vector3(localVertex.x, localVertex.y, localVertex.z);
});