From 38c9d8a8c51a4871a303c528ffa059e61854f7a8 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sun, 5 Apr 2026 01:58:06 +0200 Subject: [PATCH] Update box brush rotation handling --- src/geometry/box-brush-components.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/geometry/box-brush-components.ts b/src/geometry/box-brush-components.ts index 5f6333d2..ad0d7678 100644 --- a/src/geometry/box-brush-components.ts +++ b/src/geometry/box-brush-components.ts @@ -1,4 +1,4 @@ -import { Euler, MathUtils, Vector3 } from "three"; +import { Euler, MathUtils, Quaternion, Vector3 } from "three"; import type { Vec3 } from "../core/vector"; import { @@ -136,18 +136,10 @@ function createBrushRotationEuler(brush: BoxBrush): Euler { ); } -function createInverseBrushRotationEuler(brush: BoxBrush): Euler { - return new Euler( - MathUtils.degToRad(-brush.rotationDegrees.x), - MathUtils.degToRad(-brush.rotationDegrees.y), - MathUtils.degToRad(-brush.rotationDegrees.z), - "ZYX" - ); -} - export function transformBoxBrushWorldVectorToLocal(brush: BoxBrush, worldVector: Vec3): Vec3 { - const inverseRotation = createInverseBrushRotationEuler(brush); - const localVector = new Vector3(worldVector.x, worldVector.y, worldVector.z).applyEuler(inverseRotation); + const rotation = createBrushRotationEuler(brush); + const inverseRotation = new Quaternion().setFromEuler(rotation).invert(); + const localVector = new Vector3(worldVector.x, worldVector.y, worldVector.z).applyQuaternion(inverseRotation); return { x: localVector.x,