diff --git a/README.md b/README.md index c11ebd2..4e49516 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ On Windows, you can open PowerShell in the folder by opening the folder, clickin ## Docker / FabLab Server (Recommended) -Docker is the easiest way to run SketchForge for a classroom, workshop, or FabLab. It packages the build tools, static website, Nginx server, health check, and restart behavior together. +Docker is the easiest way to run SketchForge for a classroom, workshop, or FabLab. It packages the build tools, Next.js server, health check, persistent shared-project storage, and restart behavior together. ### What You Need @@ -130,6 +130,8 @@ http://127.0.0.1:3000/ If that works, SketchForge is running. +The container listens on port `3000`. It also accepts connections on port `80` for backward compatibility with older UnRAID templates and forwards them to the same server. New Docker and UnRAID configurations should use container port `3000`. + ### Shared Docker Projects Docker deployments include a shared `.skf` project library. Private projects still autosave in each user's browser. The **Shared** dashboard section lists files stored in `/data/projects`, and **Export → SKF → Save to shared** writes the current project there. diff --git a/apps/web/public/assets/sketchforge/gear-types/bevel.png b/apps/web/public/assets/sketchforge/gear-types/bevel.png new file mode 100644 index 0000000..5ab314d Binary files /dev/null and b/apps/web/public/assets/sketchforge/gear-types/bevel.png differ diff --git a/apps/web/public/assets/sketchforge/gear-types/helical.png b/apps/web/public/assets/sketchforge/gear-types/helical.png new file mode 100644 index 0000000..81ad5d3 Binary files /dev/null and b/apps/web/public/assets/sketchforge/gear-types/helical.png differ diff --git a/apps/web/public/assets/sketchforge/gear-types/spur.png b/apps/web/public/assets/sketchforge/gear-types/spur.png new file mode 100644 index 0000000..61de3f6 Binary files /dev/null and b/apps/web/public/assets/sketchforge/gear-types/spur.png differ diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css index 2ee3c25..6a1bc3c 100644 --- a/apps/web/src/app/globals.css +++ b/apps/web/src/app/globals.css @@ -877,6 +877,22 @@ button { background: #edf2f6; } +.dashboard-version-row { + display: flex; + align-items: center; + justify-content: space-between; + padding-top: 13px; + color: #52697d; + border-top: 1px solid #dce5ec; + font-size: 13px; + font-weight: 800; +} + +.dashboard-version-row strong { + color: #263f57; + font-size: 14px; +} + @media (max-width: 860px) { .dashboard-topbar { grid-template-columns: 1fr auto; @@ -1363,7 +1379,7 @@ button { } .sketch-start-section { - min-width: 250px; + min-width: 260px; } .sketch-finish-section { @@ -1477,6 +1493,75 @@ button { cursor: default; } +.sketch-create-menu { + position: relative; + height: 43px; +} + +.sketch-create-menu-trigger { + position: relative; + min-width: 112px; + padding-right: 20px; +} + +.sketch-create-menu-trigger.active { + color: #17405d; + background: #e7f5fb; + border-color: #bcdce8; +} + +.sketch-command-button .sketch-create-menu-chevron { + position: absolute; + right: 4px; + bottom: 5px; + width: 13px; + height: 13px; +} + +.sketch-create-dropdown { + position: absolute; + top: calc(100% + 5px); + left: 0; + z-index: 70; + display: grid; + width: 232px; + padding: 5px; + background: rgba(250, 252, 253, 0.99); + border: 1px solid #cbd9e3; + border-radius: 7px; + box-shadow: 0 12px 28px rgba(26, 47, 66, 0.22); +} + +.sketch-create-dropdown button { + display: grid; + gap: 3px; + width: 100%; + padding: 9px 10px; + color: #314b61; + background: transparent; + border: 0; + border-radius: 5px; + cursor: pointer; + text-align: left; +} + +.sketch-create-dropdown button:hover, +.sketch-create-dropdown button:focus-visible { + background: #e7f5fb; + outline: none; +} + +.sketch-create-dropdown strong { + font-size: 12px; + font-weight: 900; +} + +.sketch-create-dropdown span { + color: #708395; + font-size: 10px; + font-weight: 700; +} + .toolbar-icon.disabled .sketch-reference-icon, .toolbar-icon:disabled .sketch-reference-icon, .sketch-command-button.disabled .sketch-reference-icon, @@ -2683,6 +2768,51 @@ button { pointer-events: none; } +.sketch-revolve-preview { + position: absolute; + top: 18px; + right: 22px; + z-index: 8; + width: clamp(210px, 25vw, 330px); + height: clamp(170px, 28vh, 270px); + overflow: hidden; + background: rgba(250, 253, 254, 0.94); + border: 1px solid rgba(166, 190, 204, 0.9); + border-radius: 12px; + box-shadow: 0 12px 34px rgba(34, 67, 86, 0.16); + pointer-events: none; +} + +.sketch-revolve-preview-title { + position: absolute; + top: 10px; + left: 12px; + z-index: 1; + color: #49647a; + font-size: 11px; + font-weight: 900; + letter-spacing: 0.04em; + text-transform: uppercase; +} + +.sketch-revolve-preview canvas { + display: block; + width: 100%; + height: 100%; + background: radial-gradient(circle at 50% 48%, rgba(255, 255, 255, 0.98), rgba(229, 240, 245, 0.92)); +} + +.sketch-revolve-preview-empty { + display: grid; + height: 100%; + place-items: center; + padding: 34px; + color: #718696; + font-size: 13px; + font-weight: 750; + text-align: center; +} + .sketch-plate-wrap { position: absolute; inset: 14px 14px 42px; @@ -2746,6 +2876,24 @@ button { stroke-width: 1.6; } +.sketch-revolve-guide rect { + fill: rgba(248, 251, 252, 0.66); +} + +.sketch-revolve-guide line { + stroke: #c838bc; + stroke-width: 2.5; + stroke-dasharray: 8 5; + vector-effect: non-scaling-stroke; +} + +.sketch-revolve-guide text { + fill: #9e2996; + font-weight: 900; + letter-spacing: 0.08em; + text-anchor: end; +} + .sketch-reference-shapes rect, .sketch-reference-shapes ellipse { fill: rgba(207, 142, 42, 0.22); @@ -3971,6 +4119,17 @@ button { overflow: hidden; } +.shape-inspector.sketch-revolve-inspector, +.shape-inspector.gear-inspector { + overflow-anchor: none; + scrollbar-width: none; +} + +.shape-inspector.sketch-revolve-inspector::-webkit-scrollbar, +.shape-inspector.gear-inspector::-webkit-scrollbar { + display: none; +} + .shape-inspector-header { display: flex; align-items: center; @@ -4185,6 +4344,8 @@ button { gap: 8px; width: calc(100% - 20px); height: 38px; + min-height: 38px; + flex-shrink: 0; margin: 0 10px 12px; color: #28516d; background: #ffffff; @@ -4215,6 +4376,10 @@ button { border-radius: 8px; } +.property-card.collapsed { + padding-bottom: 0; +} + .property-card-header { display: flex; align-items: center; @@ -4247,6 +4412,62 @@ button { gap: 17px; } +.gear-type-property { + display: grid; + gap: 8px; + color: #586a7d; + font-size: 15px; + font-weight: 650; +} + +.gear-type-options { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 7px; +} + +.gear-type-options button { + display: grid; + min-width: 0; + min-height: 84px; + place-items: center; + gap: 3px; + padding: 5px 3px 7px; + color: #53687a; + background: #f6f9fb; + border: 1px solid #cbd7e0; + border-radius: 7px; + cursor: pointer; + font-size: 11px; + font-weight: 800; + transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease, color 120ms ease; +} + +.gear-type-options button:hover:not(:disabled) { + color: #176f94; + background: #eef9fc; + border-color: #8fc9dc; +} + +.gear-type-options button.selected { + color: #0b789f; + background: #eaf8fc; + border-color: #40aad0; + box-shadow: 0 0 0 2px rgba(0, 159, 211, 0.12); +} + +.gear-type-options button:disabled { + cursor: default; + opacity: 0.5; +} + +.gear-type-options img { + display: block; + width: 62px; + height: 62px; + object-fit: contain; +} + .range-property { display: grid; gap: 7px; diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx index e1e2057..061fcf1 100644 --- a/apps/web/src/app/page.tsx +++ b/apps/web/src/app/page.tsx @@ -6,7 +6,7 @@ import { SketchForgeEditor, importedShapeFromStl, importedShapeFromSvg } from "@ import { hydrateEditorHistoryState, type EditorHistoryEntry } from "@/lib/editorHistory"; import { createLocalId } from "@/lib/localIds"; import { attachProjectAsset, dedupeProjectAssets, projectAssetFromBytes, sourceFormatForFileName } from "@/lib/projectAssets"; -import { importSkfProject } from "@/lib/skfProject"; +import { importSkfProject, SKF_CREATED_WITH_VERSION } from "@/lib/skfProject"; import { importExtensionSupported } from "@/lib/stlImport"; import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE, normalizeSnapGrid, normalizeWorkspaceSettings, workplaneSettingsFingerprint } from "@/lib/workplaneSettings"; import type { GridSize, ProjectAsset, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge"; @@ -1062,7 +1062,7 @@ function Dashboard({ Challenges - @@ -1275,10 +1275,10 @@ function Dashboard({ ) : null} {settingsOpen ? ( -
+
- Download settings -
@@ -1301,6 +1301,10 @@ function Dashboard({ placeholder="C:\\Users\\username\\Downloads" /> +
+ SketchForge version + {SKF_CREATED_WITH_VERSION} +
) : null} diff --git a/apps/web/src/components/SketchForgeEditor.tsx b/apps/web/src/components/SketchForgeEditor.tsx index f19c5d3..5ee8c57 100644 --- a/apps/web/src/components/SketchForgeEditor.tsx +++ b/apps/web/src/components/SketchForgeEditor.tsx @@ -18,6 +18,7 @@ import optimerBoldFontJson from "three/examples/fonts/optimer_bold.typeface.json import { manifoldModuleSource } from "@/generated/manifoldModuleSource"; import { manifoldWasmBase64 } from "@/generated/manifoldWasmBase64"; import { sphereTessellation } from "@/lib/sphereTessellation"; +import { createGearGeometry } from "@/lib/gearGeometry"; import { ToolbarAlignIcon, ToolbarChamferIcon, @@ -80,6 +81,7 @@ import { createLocalId } from "@/lib/localIds"; import { projectExportFileName } from "@/lib/exportNames"; import { attachProjectAsset, dedupeProjectAssets, projectAssetFromBytes, sourceFormatForFileName } from "@/lib/projectAssets"; import { findSketchOutlineIntersection } from "@/lib/sketchProfileValidation"; +import { buildSketchRevolveMesh, DEFAULT_SKETCH_REVOLVE_SETTINGS, normalizeSketchRevolveSettings, type SketchRevolveMesh } from "@/lib/sketchRevolve"; import { exportSkfProject, SKF_MEDIA_TYPE } from "@/lib/skfProject"; import { makeShapeFromAsset, sceneShape, toolbarShapeAssets, type ToolbarShapeAsset } from "@/lib/shapeCatalog"; import { importedShapeFromStl, importExtensionSupported } from "@/lib/stlImport"; @@ -95,7 +97,7 @@ import { type SketchForgeMcpViewFace, } from "@/lib/sketchforgeMcpProtocol"; import type { CadModifierComponentMesh, CadModifierDisplayEdge, CadModifierEdge, CadModifierKind, CadModifierMeshPart, CadModifierPrimitivePart, CadModifierQuality, CadModifierWorkerRequest, CadModifierWorkerResponse } from "@/lib/cadModifierTypes"; -import type { AlignAxis, AlignHandleStatus, AlignTarget, GridSize, ProjectAsset, ShapeAsset, SketchImage, SketchPoint, SketchProfile, SketchSegment, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge"; +import type { AlignAxis, AlignHandleStatus, AlignTarget, GridSize, ProjectAsset, ShapeAsset, SketchImage, SketchOperation, SketchPoint, SketchProfile, SketchRevolveSettings, SketchSegment, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge"; export { importedShapeFromStl, importedShapeFromSvg }; @@ -390,6 +392,7 @@ async function shapeFromResolvedSketchProfile( sourceFormat: "json", }, sketchProfile: cloneSketchProfile(profile), + sketchOperation: "extrude", } satisfies WorkplaneShape); } finally { [...new Set(disposable)].reverse().forEach(disposeManifold); @@ -505,6 +508,50 @@ async function shapeFromSketchProfile(profile: SketchProfile, height: number, ex sourceFormat: "json", }, sketchProfile: cloneSketchProfile(profile), + sketchOperation: "extrude", + } satisfies WorkplaneShape); +} + +async function shapeFromRevolvedSketchProfile( + profile: SketchProfile, + settings: Partial, + existing?: WorkplaneShape | null, +) { + const runtime = await getManifoldRuntime(); + const normalizedSettings = normalizeSketchRevolveSettings(settings); + const mesh = buildSketchRevolveMesh(runtime, profile, normalizedSettings); + return canonicalizeShape({ + id: existing?.id ?? createLocalId("sketch-revolve"), + name: existing?.name ?? "Sketch revolve", + kind: "mesh", + color: existing?.color ?? "#78b96b", + hole: existing?.hole, + x: existing?.x ?? 0, + z: existing?.z ?? 0, + elevation: existing?.elevation ?? 0, + size: Math.max(mesh.width, mesh.depth), + width: mesh.width, + depth: mesh.depth, + height: mesh.height, + rotation: existing?.rotation ?? 0, + rotationX: existing?.rotationX ?? 0, + rotationZ: existing?.rotationZ ?? 0, + mirrorX: existing?.mirrorX, + mirrorY: existing?.mirrorY, + mirrorZ: existing?.mirrorZ, + importedMesh: { + positions: mesh.positions, + baseWidth: mesh.width, + baseDepth: mesh.depth, + baseHeight: mesh.height, + triangleCount: mesh.triangleCount, + sourceFormat: "json", + }, + sketchProfile: cloneSketchProfile(profile), + sketchOperation: "revolve", + sketchRevolve: normalizedSettings, + locked: existing?.locked ?? false, + hidden: existing?.hidden ?? false, } satisfies WorkplaneShape); } @@ -2029,6 +2076,20 @@ function geometryMeshForShape(shape: WorkplaneShape): MeshData | null { case "tube": geometry = createBooleanHollowCylinderGeometry(width, height, depth, shape.bevel ?? 4, 144); break; + case "gear": + geometry = createGearGeometry({ + width, + depth, + height, + teeth: shape.teeth, + toothSize: shape.toothSize, + toothWidth: shape.toothWidth, + centerHoleSize: shape.centerHoleSize, + gearType: shape.gearType, + helixAngle: shape.helixAngle, + helixQuality: shape.helixQuality, + }); + break; case "wedge": geometry = createBooleanWedgeGeometry(width, height, depth); break; @@ -5229,6 +5290,12 @@ export function SketchForgeEditor({ const [projectInteractionActive, setProjectInteractionActive] = useState(false); const [toolbarMode, setToolbarMode] = useState("geometry"); const [sketchActive, setSketchActive] = useState(false); + const [sketchOperation, setSketchOperation] = useState("extrude"); + const [sketchRevolveSettings, setSketchRevolveSettings] = useState(() => ({ ...DEFAULT_SKETCH_REVOLVE_SETTINGS })); + const [sketchRevolvePreview, setSketchRevolvePreview] = useState(null); + const sketchRevolvePreviewRequestRef = useRef(0); + const sketchRevolveUpdateRequestRef = useRef(new Map()); + const sketchRevolveUpdateTimerRef = useRef(new Map()); const [sketchTool, setSketchTool] = useState("line"); const [sketchProfile, setSketchProfile] = useState(() => emptySketchProfile()); const [sketchHistory, setSketchHistory] = useState([emptySketchProfile()]); @@ -5532,6 +5599,26 @@ export function SketchForgeEditor({ edgeModifierRef.current = edgeModifier; }, [edgeModifier]); + useEffect(() => { + const requestId = sketchRevolvePreviewRequestRef.current + 1; + sketchRevolvePreviewRequestRef.current = requestId; + if (!sketchActive || sketchOperation !== "revolve" || sketchProfile.segments.length === 0) { + setSketchRevolvePreview(null); + return; + } + const timer = window.setTimeout(() => { + void getManifoldRuntime() + .then((runtime) => buildSketchRevolveMesh(runtime, sketchProfile, sketchRevolveSettings)) + .then((mesh) => { + if (sketchRevolvePreviewRequestRef.current === requestId) setSketchRevolvePreview(mesh); + }) + .catch(() => { + if (sketchRevolvePreviewRequestRef.current === requestId) setSketchRevolvePreview(null); + }); + }, 90); + return () => window.clearTimeout(timer); + }, [sketchActive, sketchOperation, sketchProfile, sketchRevolveSettings]); + useEffect(() => { setWorkspaceSettings(normalizeWorkspaceSettings(initialWorkspace)); }, [initialWorkspace]); @@ -5854,10 +5941,13 @@ export function SketchForgeEditor({ [], ); - const beginSketch = useCallback((profile?: SketchProfile, editingId: string | null = null) => { + const beginSketch = useCallback((operation: SketchOperation, profile?: SketchProfile, editingId: string | null = null, revolveSettings?: Partial) => { const initial = cloneSketchProfile(profile ?? emptySketchProfile()); setToolbarMode("sketch"); setSketchActive(true); + setSketchOperation(operation); + setSketchRevolveSettings(normalizeSketchRevolveSettings(revolveSettings)); + setSketchRevolvePreview(null); setSketchTool(profile?.segments.length ? "select" : "line"); setSketchProfile(initial); const initialHistory = [cloneSketchProfile(initial)]; @@ -5870,7 +5960,7 @@ export function SketchForgeEditor({ setSketchMeasureStart(null); setSketchMeasurement(null); setEditingSketchShapeId(editingId); - setNotice(editingId ? "Editing sketch profile" : "Sketch started: place the first point"); + setNotice(editingId ? `Editing ${operation} sketch profile` : operation === "revolve" ? "Revolve sketch started: draw on the left side of the axis" : "Sketch started: place the first point"); }, []); const beginSketchEdit = useCallback(() => { @@ -5878,7 +5968,8 @@ export function SketchForgeEditor({ setNotice("Select one shape created from a sketch to edit it"); return; } - beginSketch(selectedShape.sketchProfile, selectedShape.id); + const operation = selectedShape.sketchOperation ?? (selectedShape.sketchRevolve ? "revolve" : "extrude"); + beginSketch(operation, selectedShape.sketchProfile, selectedShape.id, selectedShape.sketchRevolve); }, [beginSketch, selectedShape, selectedShapes.length]); const cancelSketch = useCallback(() => { @@ -5888,6 +5979,7 @@ export function SketchForgeEditor({ setSketchMeasureStart(null); setSketchMeasurement(null); setEditingSketchShapeId(null); + setSketchRevolvePreview(null); setNotice("Sketch cancelled"); }, []); @@ -6228,23 +6320,27 @@ export function SketchForgeEditor({ const finishSketch = useCallback(async () => { const existing = editingSketchShapeId ? shapes.find((shape) => shape.id === editingSketchShapeId) ?? null : null; const height = existing?.height ?? 10; - let extruded: WorkplaneShape | null; + let resolved: WorkplaneShape | null; try { - extruded = await shapeFromSketchProfile(sketchProfile, height, existing); + resolved = sketchOperation === "revolve" + ? await shapeFromRevolvedSketchProfile(sketchProfile, sketchRevolveSettings, existing) + : await shapeFromSketchProfile(sketchProfile, height, existing); } catch (error) { - setNotice(error instanceof Error ? error.message : "The sketch profile cannot be converted to 3D"); + setNotice(error instanceof Error ? error.message : `The sketch profile cannot be ${sketchOperation === "revolve" ? "revolved" : "extruded"} to 3D`); return; } - if (!extruded) { + if (!resolved) { setNotice("Close at least one profile before finishing the sketch"); return; } - const nextShapes = existing ? shapes.map((shape) => (shape.id === existing.id ? extruded : shape)) : [...shapes, extruded]; - commitShapes(nextShapes, extruded.id, existing ? "Sketch updated" : "Sketch created at 10 mm height"); + const nextShapes = existing ? shapes.map((shape) => (shape.id === existing.id ? resolved : shape)) : [...shapes, resolved]; + const action = sketchOperation === "revolve" ? "Revolve sketch" : "Sketch"; + commitShapes(nextShapes, resolved.id, existing ? `${action} updated` : sketchOperation === "revolve" ? "Revolved sketch created" : "Sketch created at 10 mm height"); setSketchActive(false); + setSketchRevolvePreview(null); setEditingSketchShapeId(null); setToolbarMode("geometry"); - }, [commitShapes, editingSketchShapeId, shapes, sketchProfile]); + }, [commitShapes, editingSketchShapeId, shapes, sketchOperation, sketchProfile, sketchRevolveSettings]); useEffect(() => { if (!projectId) { @@ -6313,6 +6409,8 @@ export function SketchForgeEditor({ if (interactionHistoryTimerRef.current !== null) { window.clearTimeout(interactionHistoryTimerRef.current); } + sketchRevolveUpdateTimerRef.current.forEach((timer) => window.clearTimeout(timer)); + sketchRevolveUpdateTimerRef.current.clear(); }; }, []); @@ -6324,10 +6422,72 @@ export function SketchForgeEditor({ [commitShapes, placementElevation, shapes], ); + const scheduleRevolveShapeUpdate = useCallback((id: string, settings: SketchRevolveSettings) => { + const previousTimer = sketchRevolveUpdateTimerRef.current.get(id); + if (previousTimer !== undefined) window.clearTimeout(previousTimer); + const requestId = (sketchRevolveUpdateRequestRef.current.get(id) ?? 0) + 1; + sketchRevolveUpdateRequestRef.current.set(id, requestId); + const timer = window.setTimeout(() => { + sketchRevolveUpdateTimerRef.current.delete(id); + const source = shapesRef.current.find((shape) => shape.id === id); + if (!source?.sketchProfile || source.sketchOperation !== "revolve") return; + setNotice("Updating revolve preview…"); + void shapeFromRevolvedSketchProfile(source.sketchProfile, settings, source) + .then((generated) => { + if (sketchRevolveUpdateRequestRef.current.get(id) !== requestId) return; + const current = shapesRef.current.find((shape) => shape.id === id); + if (!current?.importedMesh || current.sketchOperation !== "revolve") return; + const widthScale = current.width / Math.max(0.001, current.importedMesh.baseWidth); + const depthScale = current.depth / Math.max(0.001, current.importedMesh.baseDepth); + const heightScale = current.height / Math.max(0.001, current.importedMesh.baseHeight); + const width = generated.width * widthScale; + const depth = generated.depth * depthScale; + const height = generated.height * heightScale; + const updated = canonicalizeShape({ + ...generated, + id: current.id, + name: current.name, + color: current.color, + hole: current.hole, + x: current.x, + z: current.z, + elevation: current.elevation, + width, + depth, + height, + size: Math.max(width, depth), + rotation: current.rotation, + rotationX: current.rotationX, + rotationZ: current.rotationZ, + mirrorX: current.mirrorX, + mirrorY: current.mirrorY, + mirrorZ: current.mirrorZ, + locked: current.locked, + hidden: current.hidden, + sketchRevolve: settings, + }); + commitShapes(shapesRef.current.map((shape) => shape.id === id ? updated : shape), selectedIdsRef.current, "Revolve updated"); + }) + .catch((error) => { + if (sketchRevolveUpdateRequestRef.current.get(id) === requestId) { + setNotice(error instanceof Error ? error.message : "The revolve settings could not be applied"); + } + }); + }, 120); + sketchRevolveUpdateTimerRef.current.set(id, timer); + }, [commitShapes]); + const updateShape = useCallback( (id: string, patch: ShapeUpdatePatch) => { const bakeTransform = Boolean(patch.bakeTransform); const cleanedPatch = cleanShapePatch(patch); + if (cleanedPatch.sketchRevolve) { + const source = shapesRef.current.find((shape) => shape.id === id); + if (source?.sketchOperation === "revolve" && source.sketchProfile) { + scheduleRevolveShapeUpdate(id, normalizeSketchRevolveSettings(cleanedPatch.sketchRevolve)); + return; + } + } const applyPatch = (current: WorkplaneShape[]) => { let changed = false; const next = current.map((shape) => { @@ -6365,7 +6525,7 @@ export function SketchForgeEditor({ commitShapes(next, selectedIds); } }, - [commitShapes, selectedIds, shapes], + [commitShapes, scheduleRevolveShapeUpdate, selectedIds, shapes], ); const deleteSelected = useCallback(() => { @@ -8309,11 +8469,12 @@ export function SketchForgeEditor({ edgeModifierKind={edgeModifier?.kind ?? null} mirrorMode={mirrorMode} sketchActive={sketchActive} + sketchOperation={sketchOperation} sketchTool={sketchTool} sketchCanUndo={sketchHistoryIndex > 0} sketchCanRedo={sketchHistoryIndex < sketchHistory.length - 1} canEditSketch={selectedShapes.length === 1 && Boolean(selectedShape?.sketchProfile)} - onStartSketch={() => beginSketch()} + onStartSketch={(operation) => beginSketch(operation)} onEditSketch={beginSketchEdit} onSketchTool={setActiveSketchTool} onSketchImage={() => { @@ -8364,6 +8525,8 @@ export function SketchForgeEditor({ {toolbarMode === "sketch" && sketchActive ? ( shape.id !== editingSketchShapeId)} tool={sketchTool} activePointId={sketchActivePointId} @@ -8599,6 +8762,7 @@ function SecondaryToolbar({ hasSelection, mirrorMode, sketchActive, + sketchOperation, sketchTool, sketchCanUndo, sketchCanRedo, @@ -8649,11 +8813,12 @@ function SecondaryToolbar({ hasSelection: boolean; mirrorMode: boolean; sketchActive: boolean; + sketchOperation: SketchOperation; sketchTool: SketchTool; sketchCanUndo: boolean; sketchCanRedo: boolean; canEditSketch: boolean; - onStartSketch: () => void; + onStartSketch: (operation: SketchOperation) => void; onEditSketch: () => void; onSketchTool: (tool: SketchTool) => void; onSketchImage: () => void; @@ -8685,10 +8850,13 @@ function SecondaryToolbar({ onAddShape: (shape: ShapeAsset) => void; }) { const [shapesOpen, setShapesOpen] = useState(false); + const [sketchCreateOpen, setSketchCreateOpen] = useState(false); + const sketchCreateMenuRef = useRef(null); const touchShapeStartRef = useRef<{ id: string; x: number; y: number } | null>(null); const suppressNextShapeClickRef = useRef(false); const selectToolbarMode = (mode: "geometry" | "sketch") => { setShapesOpen(false); + setSketchCreateOpen(false); onTopPanel(null); onToolbarModeChange(mode); }; @@ -8696,6 +8864,28 @@ function SecondaryToolbar({ onAddShape(shape); setShapesOpen(false); }; + const startSketch = (operation: SketchOperation) => { + setSketchCreateOpen(false); + onStartSketch(operation); + }; + useEffect(() => { + if (!sketchCreateOpen) return; + const closeOnPointerDown = (event: PointerEvent) => { + if (!sketchCreateMenuRef.current?.contains(event.target as Node)) setSketchCreateOpen(false); + }; + const closeOnEscape = (event: KeyboardEvent) => { + if (event.key === "Escape") setSketchCreateOpen(false); + }; + window.addEventListener("pointerdown", closeOnPointerDown); + window.addEventListener("keydown", closeOnEscape); + return () => { + window.removeEventListener("pointerdown", closeOnPointerDown); + window.removeEventListener("keydown", closeOnEscape); + }; + }, [sketchCreateOpen]); + useEffect(() => { + if (sketchActive) setSketchCreateOpen(false); + }, [sketchActive]); const leftTools = [ { label: "Copy", icon: ToolbarCopyIcon, action: onCopy, enabled: hasSelection }, { label: "Paste", icon: ToolbarPasteIcon, action: onPaste, enabled: hasClipboard }, @@ -8945,7 +9135,7 @@ function SecondaryToolbar({
+
+ + {sketchCreateOpen ? ( +
+ + +
+ ) : null} +
@@ -702,8 +710,15 @@ export function SketchWorkspace({ {workspace.showGrid ? ( - {verticalLines.map((x, index) => )} - {horizontalLines.map((z, index) => )} + {verticalLines.map((x, index) => )} + {horizontalLines.map((z, index) => )} + + ) : null} + {operation === "revolve" ? ( + + + + REVOLVE AXIS ) : null} @@ -1027,14 +1042,8 @@ function SketchImageInspector({ onUpdate({ opacity: opacity / 100 }, "Sketch image opacity updated")} /> - - + onUpdate({ x }, "Sketch image moved")} /> + onUpdate({ z }, "Sketch image moved")} />
+ {shape.kind === "gear" ? ( +
+ + {gearTeethOpen ? ( +
+ +
+ ) : null} +
+ ) : null} + {gearType === "helical" ? ( +
+ + {gearHelixOpen ? ( +
+ +
+ ) : null} +
+ ) : null}
@@ -368,6 +546,28 @@ export function ShapeInspector({ ); } +function ShapePropertyRows({ + properties, + workspace, + disabled, + onInteractionActiveChange, +}: { + properties: ShapePropertyConfig[]; + workspace: WorkplaneWorkspaceSettings; + disabled?: boolean; + onInteractionActiveChange?: (active: boolean) => void; +}) { + return properties.map((property) => { + if (property.type === "text") { + return ; + } + if (property.type === "select") { + return ; + } + return ; + }); +} + export function SnapGridControl({ snap, snapOpen, @@ -437,7 +637,7 @@ function RangeProperty({ }, [accuracy, controlStep, controlValue, editing]); const toModelValue = (nextValue: number) => isLength ? displayToMillimeters(nextValue, workspace) : nextValue; const commitDraft = () => { - const next = Number(draft); + const next = parseMeasurementInput(draft); const finiteNext = Number.isFinite(next) ? next : controlValue; const nextModelValue = toModelValue(finiteNext); onChange(allowsAboveSliderMax ? Math.max(min, nextModelValue) : clamp(nextModelValue, min, max)); @@ -455,10 +655,7 @@ function RangeProperty({ {label} ); } + +function GearTypePreview({ type }: { type: GearType }) { + return ; +} + +function GearTypeSelector({ value, disabled, onChange }: { value: GearType; disabled?: boolean; onChange: (value: GearType) => void }) { + return ( +
+ Gear Type +
+ {GEAR_TYPE_OPTIONS.map((option) => ( + + ))} +
+
+ ); +} diff --git a/apps/web/src/components/workplane/TransformOverlay.tsx b/apps/web/src/components/workplane/TransformOverlay.tsx index 156e5a2..b73e4e2 100644 --- a/apps/web/src/components/workplane/TransformOverlay.tsx +++ b/apps/web/src/components/workplane/TransformOverlay.tsx @@ -155,6 +155,7 @@ export function TransformOverlay({ style={{ "--overlay-x": `${editingDimension.x}px`, "--overlay-y": `${editingDimension.y}px` } as CSSProperties} value={editingDimension.value} autoFocus + inputMode="decimal" onPointerDown={(event) => event.stopPropagation()} onChange={(event) => onEditingDimensionChange(event.target.value)} onBlur={onCommitDimensionEdit} diff --git a/apps/web/src/components/workplane/WorkspaceSettingsModal.tsx b/apps/web/src/components/workplane/WorkspaceSettingsModal.tsx index b231946..fcc6391 100644 --- a/apps/web/src/components/workplane/WorkspaceSettingsModal.tsx +++ b/apps/web/src/components/workplane/WorkspaceSettingsModal.tsx @@ -2,7 +2,7 @@ import { Grid3X3, Palette, Ruler, X } from "lucide-react"; import { useEffect, useState } from "react"; -import { normalizeScaleForUnits, scaleOptionsForUnits, WORKSPACE_UNIT_OPTIONS } from "@/lib/measurementUnits"; +import { normalizeScaleForUnits, parseMeasurementInput, scaleOptionsForUnits, WORKSPACE_UNIT_OPTIONS } from "@/lib/measurementUnits"; import { DEFAULT_WORKPLANE_WORKSPACE } from "@/lib/workplaneSettings"; import type { GridSize, WorkplaneWorkspaceSettings } from "@/types/sketchforge"; @@ -56,6 +56,7 @@ export function WorkspaceSettingsModal({ width: workspace.width.toFixed(workspace.accuracy), depth: workspace.depth.toFixed(workspace.accuracy), })); + const [gridBlockSizeDraft, setGridBlockSizeDraft] = useState(() => workspace.gridBlockSize.toFixed(workspace.accuracy)); const scaleOptions = scaleOptionsForUnits(workspace.units); const scaleValue = normalizeScaleForUnits(workspace.units, workspace.scale); useEffect(() => { @@ -64,13 +65,16 @@ export function WorkspaceSettingsModal({ depth: workspace.depth.toFixed(workspace.accuracy), }); }, [workspace.accuracy, workspace.depth, workspace.width]); + useEffect(() => { + setGridBlockSizeDraft(workspace.gridBlockSize.toFixed(workspace.accuracy)); + }, [workspace.accuracy, workspace.gridBlockSize]); const patchWorkspace = (patch: Partial) => { setDefaultSaved(false); const next = { ...workspace, ...patch }; onWorkspaceChange({ ...next, scale: normalizeScaleForUnits(next.units, next.scale) }); }; const setDimension = (key: "width" | "depth", value: string) => { - const parsed = Number.parseFloat(value); + const parsed = parseMeasurementInput(value); const next = clamp(Number.isFinite(parsed) ? parsed : workspace[key], MIN_WORKSPACE_SIZE, MAX_WORKSPACE_SIZE); setDimensionDrafts((current) => ({ ...current, [key]: next.toFixed(workspace.accuracy) })); patchWorkspace({ [key]: next, sizePreset: "Custom" } as Partial); @@ -87,7 +91,9 @@ export function WorkspaceSettingsModal({ patchWorkspace({ gridBlockPreset, gridBlockSize: gridBlockSizeForPreset(gridBlockPreset, workspace.gridBlockSize) }); }; const setGridBlockSize = (value: string) => { - const next = clamp(Number.parseFloat(value) || DEFAULT_WORKPLANE_WORKSPACE.gridBlockSize, MIN_GRID_BLOCK_SIZE, MAX_GRID_BLOCK_SIZE); + const parsed = parseMeasurementInput(value); + const next = clamp(Number.isFinite(parsed) ? parsed : workspace.gridBlockSize, MIN_GRID_BLOCK_SIZE, MAX_GRID_BLOCK_SIZE); + setGridBlockSizeDraft(next.toFixed(workspace.accuracy)); patchWorkspace({ gridBlockPreset: "Custom", gridBlockSize: next }); }; @@ -201,11 +207,9 @@ export function WorkspaceSettingsModal({