From 7e2dff46dcc1db69f186ea41934f4f097f2157b5 Mon Sep 17 00:00:00 2001 From: Michael Pearce Date: Wed, 18 Nov 2026 22:34:34 -0800 Subject: [PATCH 1/2] fix: Add viewport-aligned rotation to Transform --- src/components/CombinedTransform.tsx | 46 +++++++++++++------ src/components/TransformAdjustments.tsx | 4 +- src/core/combined-transform.ts | 9 ++-- tests/e2e/combined-transform.spec.ts | 60 ++++++++++++++++++++++++- 4 files changed, 100 insertions(+), 19 deletions(-) diff --git a/src/components/CombinedTransform.tsx b/src/components/CombinedTransform.tsx index 6917094..03e129e 100644 --- a/src/components/CombinedTransform.tsx +++ b/src/components/CombinedTransform.tsx @@ -109,6 +109,7 @@ export function CombinedTransform({ onPress }: { onPress: () => void }) { [selection, scene], ); const root = useRef(null), + viewRing = useRef(null), worldSize = useRef(1); const { camera, size, invalidate, get, setEvents } = useThree(); const [hover, setHover] = useState(''); @@ -183,6 +184,8 @@ export function CombinedTransform({ onPress }: { onPress: () => void }) { }; }, [finish]); const unavailable = !!selection.blocked || free; + const canRotateInView = + !selection.locks?.some(Boolean) && (selection.kind !== 'warp' || selection.parts.length > 1); useEffect(() => { if (unavailable) finish(); }, [unavailable, finish]); @@ -237,14 +240,13 @@ export function CombinedTransform({ onPress }: { onPress: () => void }) { right.x += 2 / size.width; worldSize.current = right.unproject(camera).distanceTo(root.current.position) * 96; root.current.scale.setScalar(worldSize.current); + const cameraInGizmo = root.current.quaternion.clone().invert().multiply(camera.quaternion); + viewRing.current?.quaternion.copy(cameraInGizmo); // Keep uniform scale clear of the free-move center in every camera orientation. root.current .getObjectByName('transform:scale:uniform') - ?.position.copy( - new Vector3(-0.45, -0.45, 0) - .applyQuaternion(camera.quaternion) - .applyQuaternion(root.current.quaternion.clone().invert()), - ); + ?.position.set(-0.45, -0.45, 0) + .applyQuaternion(cameraInGizmo); const eye = camera.getWorldDirection(new Vector3()).negate(); root.current.traverse((child) => { const normal = child.userData.planeNormal as number | undefined; @@ -275,7 +277,10 @@ export function CombinedTransform({ onPress }: { onPress: () => void }) { const state = useEditor.getState(); if (handle.mode === 'scale' && !usePreferences.getState().transform.scaling) return; if (handle.mode === 'translate' && pinned) return; - if (handle.mode === 'rotate' && handle.axis !== null && selection.locks?.[handle.axis]) + if ( + handle.mode === 'rotate' && + (handle.axis === null ? !canRotateInView : selection.locks?.[handle.axis]) + ) return; const capture = event.target as unknown as Capture; drag.current = { @@ -340,6 +345,23 @@ export function CombinedTransform({ onPress }: { onPress: () => void }) { side={DoubleSide} /> ); + const rotationRing = ( + id: string, + axis: TransformHandle['axis'], + radius: number, + color: string, + ) => ( + <> + + + + + + + {material(id, color)} + + + ); if (unavailable) return null; return ( @@ -380,14 +402,7 @@ export function CombinedTransform({ onPress }: { onPress: () => void }) { userData={{ planeNormal: i }} quaternion={new Quaternion().setFromUnitVectors(new Vector3(0, 0, 1), axis)} > - - - - - - - {material(ring, colors[i])} - + {rotationRing(ring, index, 0.78, colors[i])} ) : null} {scaling ? ( @@ -404,6 +419,9 @@ export function CombinedTransform({ onPress }: { onPress: () => void }) { ); })} + {canRotateInView ? ( + {rotationRing('rotate:view', null, 1.3, '#e2e4e8')} + ) : null} {!pinned ? ( <> diff --git a/src/components/TransformAdjustments.tsx b/src/components/TransformAdjustments.tsx index 16ba9e6..70274d2 100644 --- a/src/components/TransformAdjustments.tsx +++ b/src/components/TransformAdjustments.tsx @@ -118,7 +118,9 @@ export function TransformAdjustments() {

Drag an arrow to move, a ring to rotate{scaling ? ', or a cube to scale' : ''}.{' '} - {scaling ? 'Turn off scaling to hide its handles.' : 'Scale handles are disabled.'} + {!single && !selection.locks?.some(Boolean) + ? 'The outer ring rotates in the plane of the viewport.' + : null}

Shift: fine adjustment ยท Uses Snap and the selected pivot. diff --git a/src/core/combined-transform.ts b/src/core/combined-transform.ts index 19fca42..36b7da3 100644 --- a/src/core/combined-transform.ts +++ b/src/core/combined-transform.ts @@ -7,6 +7,7 @@ import type { TransformTarget } from './transform-selection'; export interface TransformHandle { mode: 'translate' | 'rotate' | 'scale'; + /** A null rotation axis uses the viewport normal. */ axis: 0 | 1 | 2 | null; /** The normal axis of a planar move handle. */ plane?: 0 | 1 | 2; @@ -40,9 +41,11 @@ export class CombinedTransformDrag { this.pointer = pointer.clone(); this.motion = new FreeTransformMotion(this.camera, pivot, width, height); this.worldAxis = - handle.axis === null - ? null - : new Vector3().setComponent(handle.axis, 1).applyQuaternion(orientation); + handle.axis !== null + ? new Vector3().setComponent(handle.axis, 1).applyQuaternion(orientation) + : handle.mode === 'rotate' + ? this.camera.getWorldDirection(new Vector3()).negate() + : null; const normal = handle.plane !== undefined ? new Vector3().setComponent(handle.plane, 1).applyQuaternion(orientation) diff --git a/tests/e2e/combined-transform.spec.ts b/tests/e2e/combined-transform.spec.ts index 1ed278a..30b1353 100644 --- a/tests/e2e/combined-transform.spec.ts +++ b/tests/e2e/combined-transform.spec.ts @@ -1,5 +1,5 @@ import { expect, test, type Page } from '@playwright/test'; -import { BoxGeometry } from 'three'; +import { BoxGeometry, Quaternion, Vector3 } from 'three'; import { serializeGeometry } from '../../src/core/geometry'; const cube = { @@ -82,6 +82,7 @@ async function state(page: Page) { })), enabled: root.controls.enabled, handles, + viewAxis: root.camera.getWorldDirection(root.camera.position.clone()).negate().toArray(), jointErrors: s.scene.joints.map((j: any) => anchorError(s.scene.parts, j)), }; }); @@ -197,6 +198,62 @@ test('removes scaling from display and picking, persists the choice, and keeps m ).toHaveAttribute('aria-checked', 'false'); }); +test('rotates in the viewport plane in perspective and orthographic views', async ({ page }) => { + await open(page); + await page.getByRole('button', { name: 'Local', exact: true }).click(); + const snap = page.getByRole('spinbutton', { name: 'Transform rotation snap', exact: true }); + await snap.fill('15'); + await snap.press('Enter'); + await page.getByRole('button', { name: 'Snap', exact: true }).click(); + await page.getByRole('button', { name: 'Perspective', exact: true }).click(); + await page.getByRole('button', { name: 'Isometric', exact: true }).click(); + + for (const projection of ['Perspective', 'Orthographic']) { + await expect(page.getByRole('button', { name: projection, exact: true })).toBeVisible(); + const before = await state(page); + expect(Math.abs(before.viewAxis[0])).toBeGreaterThan(0.3); + expect(Math.abs(before.viewAxis[1])).toBeGreaterThan(0.3); + const name = 'transform:rotate:view'; + const center = await point(page, name); + const right = await point(page, name, [1.3, 0, 0]); + const top = await point(page, name, [0, 1.3, 0]); + expect(right.y).toBeCloseTo(center.y, 3); + expect(top.x).toBeCloseTo(center.x, 3); + expect(right.x - center.x).toBeCloseTo(center.y - top.y, 3); + + const angle = (40 * Math.PI) / 180; + const end = await point(page, name, [1.3 * Math.cos(angle), 1.3 * Math.sin(angle), 0]); + await drag(page, right, end); + const after = await state(page); + const rotation = new Quaternion().setFromAxisAngle( + new Vector3().fromArray(before.viewAxis), + Math.PI / 4, + ); + const expected = rotation.multiply(new Quaternion().fromArray(before.parts[0].quaternion)); + expect(new Quaternion().fromArray(after.parts[0].quaternion).angleTo(expected)).toBeLessThan( + 1e-6, + ); + const pivot = (p: (typeof after.parts)[number]) => + new Vector3() + .fromArray(cube.pivot) + .applyQuaternion(new Quaternion().fromArray(p.quaternion)) + .add(new Vector3().fromArray(p.position)); + expect(pivot(after.parts[0]).distanceTo(pivot(before.parts[0]))).toBeLessThan(1e-6); + expect(after.parts[0].scale).toEqual(before.parts[0].scale); + expect(after.past).toBe(before.past + 1); + expect(after.enabled).toBe(true); + + if (projection === 'Perspective') { + await page.keyboard.press('5'); + } else { + await page.keyboard.press('Control+z'); + const restored = await state(page); + expect(restored.parts).toEqual(before.parts); + expect(restored.past).toBe(before.past); + } + } +}); + test('preserves redo on a click without motion and restores camera input on interruption', async ({ page, }) => { @@ -235,6 +292,7 @@ test('shows only free joint rotation axes and keeps the anchor connected', async expect(handles).not.toContain('transform:move:X'); expect(handles).not.toContain('transform:rotate:X'); expect(handles).not.toContain('transform:rotate:Z'); + expect(handles).not.toContain('transform:rotate:view'); expect(handles).toContain('transform:rotate:Y'); const from = await point(page, 'transform:rotate:Y', [ 0.78 * Math.cos(Math.PI / 4), From e115ab268bc3f725efa11a8e48a03eec335ac6c8 Mon Sep 17 00:00:00 2001 From: Michael Pearce Date: Wed, 18 Nov 2026 22:51:26 -0800 Subject: [PATCH 2/2] (docs) Document pull request checks for agents --- AGENTS.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..1066590 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,4 @@ +# Pull requests + +- Follow [CONTRIBUTING.md](CONTRIBUTING.md). Use `() ` for PR titles, for example `(fix) Add viewport-aligned rotation to Transform`. Use the same format for commit subjects that will become PR titles. +- Set the PR title explicitly when publishing. Before opening or updating a PR, validate the exact title and description with `PR_TITLE='' PR_BODY_FILE='<body-file>' node scripts/check-pull-request.mjs`.