diff --git a/.github/SETUP.md b/.github/SETUP.md index 340cc0f..0818de7 100644 --- a/.github/SETUP.md +++ b/.github/SETUP.md @@ -32,7 +32,7 @@ permissions: ## Create a release -Push a tag such as `v1.0.4`, or run `Desktop Release` with `workflow_dispatch` and enter `1.0.4`. +Push a tag such as `v1.0.5`, or run `Desktop Release` with `workflow_dispatch` and enter `1.0.5`. The workflow builds these packages: diff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.yml index 4f9b0ec..8d6736f 100644 --- a/.github/workflows/desktop-release.yml +++ b/.github/workflows/desktop-release.yml @@ -8,7 +8,7 @@ on: workflow_dispatch: inputs: version: - description: "Version to release (for example 1.0.4)" + description: "Version to release (for example 1.0.5)" required: true type: string diff --git a/README.md b/README.md index c0fbecf..50dc8f4 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Star SketchForge on GitHub Sponsor SketchForge on GitHub Local first - Version v1.0.4 + Version v1.0.5

diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css index 525c711..6c95e7a 100644 --- a/apps/web/src/app/globals.css +++ b/apps/web/src/app/globals.css @@ -4737,8 +4737,8 @@ button { .rotate-handle { z-index: 3; - width: 42px; - height: 42px; + width: 52px; + height: 52px; color: rgba(47, 61, 70, 0.6); background: transparent; border: 0; @@ -4746,7 +4746,7 @@ button { box-shadow: none; cursor: grab; opacity: 1; - transform: translate3d(var(--overlay-x, 0), var(--overlay-y, 0), 0) translate(-50%, -50%) rotate(var(--rotate-handle-angle, 0deg)); + transform: translate3d(var(--overlay-x, 0), var(--overlay-y, 0), 0) translate(-50%, -50%); } .rotate-handle:hover { @@ -4756,8 +4756,8 @@ button { .rotate-handle-icon, .rotate-handle-icon svg { display: block; - width: 18px; - height: 18px; + width: 26px; + height: 26px; } .rotate-handle-icon { @@ -4769,6 +4769,16 @@ button { .rotate-handle-icon svg { fill: currentColor; + transform: matrix( + var(--rotate-plane-a, 1), + var(--rotate-plane-b, 0), + var(--rotate-plane-c, 0), + var(--rotate-plane-d, 1), + 0, + 0 + ); + transform-box: fill-box; + transform-origin: center; } .rotation-edit { diff --git a/apps/web/src/components/WorkplaneViewport.tsx b/apps/web/src/components/WorkplaneViewport.tsx index 4bb5fc5..9dd001f 100644 --- a/apps/web/src/components/WorkplaneViewport.tsx +++ b/apps/web/src/components/WorkplaneViewport.tsx @@ -42,7 +42,7 @@ import { type PlacementWorkplane, } from "@/lib/placementWorkplane"; import { regularPolygonFootprintScale } from "@/lib/regularPolygonFootprint"; -import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE, normalizeSnapGrid, normalizeWorkspaceSettings, workplaneSettingsFingerprint, workspaceHydrationSyncDecision } from "@/lib/workplaneSettings"; +import { canBeginShapeDrag, DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE, normalizeSnapGrid, normalizeWorkspaceSettings, workplaneSettingsFingerprint, workspaceHydrationSyncDecision } from "@/lib/workplaneSettings"; import { interiorWorkplaneGridCoordinates, workplaneThemePalette, WORKPLANE_LINE_ELEVATION, WORKPLANE_MAJOR_GRID_INTERVAL } from "@/lib/workplaneGrid"; import { cleanNearZero, cleanRotationDegrees, fallbackSolidColor, mirroredAxisCount, mirrorSign, preservesEdgeTreatmentSize, proportionalResizeScale, resizedImportedCoordinates, resizedImportedMeshPositions, resizedShapeSize, shapeDepth, shapeHasTaper, shapeOverallFootprintDimensions, shapeTaperDimensions, shapeTaperScaleAt, shapeWidth } from "@/lib/workplaneShapes"; import { sphereTessellation } from "@/lib/sphereTessellation"; @@ -51,6 +51,7 @@ import { TransformOverlay, getElevationMeasureKey, measureKeyForHandle, + normalizedRotationPlaneBasis, type DimensionMark, type EditingDimension, type EditingRotation, @@ -1837,8 +1838,6 @@ function signedAngleAroundAxis(start: THREE.Vector3, current: THREE.Vector3, axi const ROTATION_HANDLE_SIDE_HYSTERESIS = 0.22; const ROTATION_HANDLE_DOMINANCE_HYSTERESIS = 0.18; -const ROTATION_UPPER_HANDLE_ICON_ANGLE = 0; -const ROTATION_BOTTOM_HANDLE_ICON_ANGLE = 0; function signedRotationSide(value: number, previous: RotationHandleSide | undefined, positiveSide: RotationHandleSide, negativeSide: RotationHandleSide) { if (previous === positiveSide && value > -ROTATION_HANDLE_SIDE_HYSTERESIS) { return previous; @@ -1896,9 +1895,10 @@ function rotationHandleSidesForCamera( const viewZ = viewZRaw / length; const previous = state.rotationHandleSides ?? undefined; const next: RotationHandleSides = { - x: signedRotationSide(viewX, previous?.x, "right", "left"), + // Keep the two upper rotation handles on the faces opposite the camera. + x: signedRotationSide(viewX, previous?.x, "left", "right"), y: dominantRotationSide(viewX, viewZ, previous?.y), - z: signedRotationSide(viewZ, previous?.z, "near", "far"), + z: signedRotationSide(viewZ, previous?.z, "far", "near"), }; state.rotationHandleSides = next; return next; @@ -4262,6 +4262,9 @@ export function WorkplaneViewport({ if (!alreadySelected) { onSelectShape(id); } + if (!canBeginShapeDrag(workspaceRef.current.selectBeforeMove, alreadySelected)) { + return; + } if (shape.locked) { return; } @@ -6231,7 +6234,10 @@ function updateTransformOverlayDom(state: ThreeState, next: TransformOverlayStat } element.style.setProperty("--overlay-x", `${handle.x}px`); element.style.setProperty("--overlay-y", `${handle.y}px`); - element.style.setProperty("--rotate-handle-angle", `${handle.angle}deg`); + element.style.setProperty("--rotate-plane-a", String(handle.plane.a)); + element.style.setProperty("--rotate-plane-b", String(handle.plane.b)); + element.style.setProperty("--rotate-plane-c", String(handle.plane.c)); + element.style.setProperty("--rotate-plane-d", String(handle.plane.d)); }); } @@ -6438,37 +6444,34 @@ function syncTransformOverlay( }; const rotateLeft = screenOffsetFromCenter(project(sidePoint(rotationSides.x, frame.max.y)), 24); const rotateRight = screenOffsetFromCenter(project(sidePoint(rotationSides.z, frame.max.y)), 28); - const rotateBottom = screenOffsetFromCenter(project(sidePoint(rotationSides.y, footprintY)), 34); + const rotateBottomAnchor = screenOffsetFromCenter(project(sidePoint(rotationSides.y, footprintY)), 26); + const rotateBottom = { ...rotateBottomAnchor, y: rotateBottomAnchor.y - 5 }; const xFaceCenter = sidePoint(rotationSides.x, 0); const zFaceCenter = sidePoint(rotationSides.z, 0); const yFaceCenter = bottomCenterWorld; - const projectedAxisAngle = (centerWorld: THREE.Vector3, axis: THREE.Vector3) => { - const from = project(centerWorld.clone().addScaledVector(axis, -1)); - const to = project(centerWorld.clone().addScaledVector(axis, 1)); - return THREE.MathUtils.radToDeg(Math.atan2(to.y - from.y, to.x - from.x)); - }; - const rotateWithWorkplane = !placementWorkplaneIsBase(activeWorkplane); - const xRotateAngle = rotateWithWorkplane - ? projectedAxisAngle(xFaceCenter, zFootAxis) - : ROTATION_UPPER_HANDLE_ICON_ANGLE; - const zRotateAngle = rotateWithWorkplane - ? projectedAxisAngle(zFaceCenter, xFootAxis) - : ROTATION_UPPER_HANDLE_ICON_ANGLE; - const yRotateTangent = rotationSides.y === "right" || rotationSides.y === "left" - ? zFootAxis - : xFootAxis; - const yRotateAngle = rotateWithWorkplane - ? projectedAxisAngle(yFaceCenter, yRotateTangent) - : ROTATION_BOTTOM_HANDLE_ICON_ANGLE; + const yRotationAxes = rotationSides.y === "near" + ? { u: xFootAxis, v: zFootAxis } + : rotationSides.y === "far" + ? { u: xFootAxis.clone().multiplyScalar(-1), v: zFootAxis.clone().multiplyScalar(-1) } + : rotationSides.y === "right" + ? { u: zFootAxis.clone().multiplyScalar(-1), v: xFootAxis } + : { u: zFootAxis, v: xFootAxis.clone().multiplyScalar(-1) }; const planeRadius = 154; - const planeWorldStep = Math.max(12, Math.max(frame.width, frame.depth, frame.height) * 0.78); + const planeWorldStep = Math.max(0.1, cameraDistance * 0.01); const makePlaneView = (centerWorld: THREE.Vector3, uAxis: THREE.Vector3, vAxis: THREE.Vector3): RotationPlaneView => { const screenCenter = project(centerWorld); - const u = project(centerWorld.clone().add(uAxis.clone().multiplyScalar(planeWorldStep))); - const v = project(centerWorld.clone().add(vAxis.clone().multiplyScalar(planeWorldStep))); - const du = { x: u.x - screenCenter.x, y: u.y - screenCenter.y }; - const dv = { x: v.x - screenCenter.x, y: v.y - screenCenter.y }; - const longest = Math.max(12, Math.hypot(du.x, du.y), Math.hypot(dv.x, dv.y)); + const uOffset = uAxis.clone().multiplyScalar(planeWorldStep); + const vOffset = vAxis.clone().multiplyScalar(planeWorldStep); + const uStart = project(centerWorld.clone().sub(uOffset)); + const uEnd = project(centerWorld.clone().add(uOffset)); + const vStart = project(centerWorld.clone().sub(vOffset)); + const vEnd = project(centerWorld.clone().add(vOffset)); + const du = { x: (uEnd.x - uStart.x) / 2, y: (uEnd.y - uStart.y) / 2 }; + const dv = { x: (vEnd.x - vStart.x) / 2, y: (vEnd.y - vStart.y) / 2 }; + const longest = Math.max(Math.hypot(du.x, du.y), Math.hypot(dv.x, dv.y)); + if (!Number.isFinite(longest) || longest < 0.000001) { + return { x: screenCenter.x, y: screenCenter.y, a: 1, b: 0, c: 0, d: 1 }; + } const scale = planeRadius / longest / 100; return { x: screenCenter.x, @@ -6499,6 +6502,19 @@ function syncTransformOverlay( y: makePlaneView(yFaceCenter, xFootAxis, zFootAxis), z: makePlaneView(zFaceCenter, xFootAxis, yFootAxis), }; + const makeCameraPlaneView = (uAxis: THREE.Vector3, vAxis: THREE.Vector3): RotationPlaneView => { + const u = uAxis.clone().transformDirection(state.camera.matrixWorldInverse); + const v = vAxis.clone().transformDirection(state.camera.matrixWorldInverse); + return { x: 0, y: 0, a: u.x, b: -u.y, c: v.x, d: -v.y }; + }; + const rotationHandlePlanes: Record = { + // Project only the two plane axes through the camera rotation. Ignoring + // perspective translation keeps glyph appearance independent of object + // length and screen position while preserving camera foreshortening. + x: makeCameraPlaneView(zFootAxis, yFootAxis), + y: makeCameraPlaneView(yRotationAxes.u, yRotationAxes.v), + z: makeCameraPlaneView(xFootAxis, yFootAxis), + }; const next = { id: frame.ids.join("|"), @@ -6521,9 +6537,9 @@ function syncTransformOverlay( { key: liftHandleKey, className: showLowerHandles ? "height-lift lower" : "height-lift", kind: "lift" as const, x: liftPoint.x, y: liftPoint.y, title: "Lift", angle: liftHandleAngle }, ], rotateHandles: [ - { key: "rotate-left", className: "screen-left", x: rotateLeft.x, y: rotateLeft.y, angle: xRotateAngle }, - { key: "rotate-right", className: "screen-right", x: rotateRight.x, y: rotateRight.y, angle: zRotateAngle }, - { key: "rotate-bottom", className: "screen-bottom", x: rotateBottom.x, y: rotateBottom.y, angle: yRotateAngle }, + { key: "rotate-left", className: "screen-left", x: rotateLeft.x, y: rotateLeft.y, plane: normalizedRotationPlaneBasis(rotationHandlePlanes.x, true) }, + { key: "rotate-right", className: "screen-right", x: rotateRight.x, y: rotateRight.y, plane: normalizedRotationPlaneBasis(rotationHandlePlanes.z, true) }, + { key: "rotate-bottom", className: "screen-bottom", x: rotateBottom.x, y: rotateBottom.y, plane: normalizedRotationPlaneBasis(rotationHandlePlanes.y, true) }, ], dimensions: dimensionMarks, rotationWheel: rotationWheels.y, diff --git a/apps/web/src/components/workplane/TransformOverlay.tsx b/apps/web/src/components/workplane/TransformOverlay.tsx index bccf294..998397a 100644 --- a/apps/web/src/components/workplane/TransformOverlay.tsx +++ b/apps/web/src/components/workplane/TransformOverlay.tsx @@ -9,11 +9,13 @@ import { export { getElevationMeasureKey, measureKeyForHandle, + normalizedRotationPlaneBasis, type DimensionMark, type EditingDimension, type EditingRotation, type PinnedRotationWheelView, type RotationAxis, + type RotationPlaneBasis, type RotationPlaneView, type RotationReadout, type RotationWheelView, @@ -240,7 +242,14 @@ export function TransformOverlay({