setDraft(event.currentTarget.value)}
onBlur={commit}
@@ -1091,3 +1098,39 @@ function SketchImageRange({
);
}
+
+function SketchImagePositionField({
+ label,
+ value,
+ accuracy,
+ onChange,
+}: {
+ label: string;
+ value: number;
+ accuracy: 1 | 2 | 3;
+ onChange: (value: number) => void;
+}) {
+ const formatted = formatDimension(value, accuracy);
+ const [draft, setDraft] = useState(formatted);
+ useEffect(() => setDraft(formatted), [formatted]);
+ const commit = () => {
+ const parsed = parseMeasurementInput(draft);
+ const next = Number.isFinite(parsed) ? parsed : value;
+ onChange(next);
+ setDraft(formatDimension(next, accuracy));
+ };
+
+ return (
+
+ );
+}
diff --git a/apps/web/src/components/WorkplaneViewport.tsx b/apps/web/src/components/WorkplaneViewport.tsx
index f7001e1..ed85fbd 100644
--- a/apps/web/src/components/WorkplaneViewport.tsx
+++ b/apps/web/src/components/WorkplaneViewport.tsx
@@ -17,8 +17,10 @@ import optimerBoldFontJson from "three/examples/fonts/optimer_bold.typeface.json
import { AlignOverlay, MirrorOverlay, type AlignOverlayState, type MirrorOverlayState } from "@/components/workplane/ActionOverlays";
import { ShapeInspector, SnapGridControl, type ShapeInspectorUpdateOptions } from "@/components/workplane/ShapeInspector";
import { WorkspaceSettingsModal } from "@/components/workplane/WorkspaceSettingsModal";
+import { createGearGeometry } from "@/lib/gearGeometry";
+import { parseMeasurementInput } from "@/lib/measurementUnits";
import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE, normalizeSnapGrid, normalizeWorkspaceSettings, workplaneSettingsFingerprint, workspaceHydrationSyncDecision } from "@/lib/workplaneSettings";
-import { interiorWorkplaneGridCoordinates, workplaneGridPalette, WORKPLANE_LINE_ELEVATION } from "@/lib/workplaneGrid";
+import { interiorWorkplaneGridCoordinates, workplaneGridPalette, WORKPLANE_LINE_ELEVATION, WORKPLANE_MAJOR_GRID_INTERVAL } from "@/lib/workplaneGrid";
import { cleanNearZero, cleanRotationDegrees, fallbackSolidColor, mirroredAxisCount, mirrorSign, preservesEdgeTreatmentSize, proportionalResizeScale, resizedImportedCoordinates, resizedImportedMeshPositions, resizedShapeSize, shapeDepth, shapeWidth } from "@/lib/workplaneShapes";
import { sphereTessellation } from "@/lib/sphereTessellation";
import type { SketchForgeMcpViewFace } from "@/lib/sketchforgeMcpProtocol";
@@ -68,6 +70,7 @@ const SHAPE_KINDS = new Set
([
"halfSphere",
"torus",
"tube",
+ "gear",
"ring",
"wedge",
"polygon",
@@ -566,6 +569,13 @@ function rulerShapeTopologyKey(shape: WorkplaneShape): string {
segments: shape.segments,
topRadius: shape.topRadius,
baseRadius: shape.baseRadius,
+ teeth: shape.teeth,
+ toothSize: shape.toothSize,
+ toothWidth: shape.toothWidth,
+ centerHoleSize: shape.centerHoleSize,
+ gearType: shape.gearType,
+ helixAngle: shape.helixAngle,
+ helixQuality: shape.helixQuality,
text: shape.text,
font: shape.font,
mesh: [positions.length, positionSample],
@@ -2743,7 +2753,7 @@ export function WorkplaneViewport({
setEditingDimension(null);
return;
}
- const value = Number.parseFloat(edit.value);
+ const value = parseMeasurementInput(edit.value);
if (edit.axis === "elevation") {
if (Number.isFinite(value)) {
const frame = selectionFrameForShapes(shapesRef.current, selectedIdsRef.current);
@@ -2803,7 +2813,7 @@ export function WorkplaneViewport({
if (!edit) {
return;
}
- const value = Number.parseFloat(edit.value);
+ const value = parseMeasurementInput(edit.value);
if (Number.isFinite(value)) {
selectedIdsRef.current.forEach((id) => onUpdateShape(id, { ...rotationPatchForAxis(edit.axis, value), bakeTransform: true }));
}
@@ -3977,14 +3987,13 @@ function createGridLines(width = WORKPLANE_WIDTH, depth = WORKPLANE_DEPTH, block
points.push(...from, ...to);
};
const step = clamp(blockSize, MIN_GRID_BLOCK_SIZE, MAX_GRID_BLOCK_SIZE);
- const majorEvery = 4;
for (const { coordinate: centeredX, index } of interiorWorkplaneGridCoordinates(width, step)) {
- const points = centeredX === 0 ? axisPoints : index % majorEvery === 0 ? majorPoints : minorPoints;
+ const points = centeredX === 0 ? axisPoints : index % WORKPLANE_MAJOR_GRID_INTERVAL === 0 ? majorPoints : minorPoints;
pushLine(points, [centeredX, WORKPLANE_LINE_ELEVATION, -depth / 2], [centeredX, WORKPLANE_LINE_ELEVATION, depth / 2]);
}
for (const { coordinate: centeredZ, index } of interiorWorkplaneGridCoordinates(depth, step)) {
- const points = centeredZ === 0 ? axisPoints : index % majorEvery === 0 ? majorPoints : minorPoints;
+ const points = centeredZ === 0 ? axisPoints : index % WORKPLANE_MAJOR_GRID_INTERVAL === 0 ? majorPoints : minorPoints;
pushLine(points, [-width / 2, WORKPLANE_LINE_ELEVATION, centeredZ], [width / 2, WORKPLANE_LINE_ELEVATION, centeredZ]);
}
@@ -5224,6 +5233,20 @@ function createShapeObject(shape: WorkplaneShape, showEdges = false, onTextureRe
case "tube":
addMesh(group, createHollowCylinderGeometry(width, height, depth, shape.bevel ?? 4, 144), material, shape);
break;
+ case "gear":
+ addMesh(group, 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,
+ }), material, shape);
+ break;
case "wedge":
addMesh(group, createWedgeGeometry(width, height, depth), material, shape);
break;
@@ -5334,7 +5357,7 @@ function addMesh(
const complexEdges =
shape.kind === "mesh" ||
Boolean(shape.importedMesh) ||
- ["cone", "pyramid", "roof", "roundRoof", "halfSphere", "torus", "tube", "ring", "wedge"].includes(shape.kind);
+ ["cone", "pyramid", "roof", "roundRoof", "halfSphere", "torus", "tube", "ring", "gear", "wedge"].includes(shape.kind);
const importedTriangleCount = shape.importedMesh?.triangleCount ?? 0;
const skipHeavyImportedEdges = Boolean(shape.importedMesh) && importedTriangleCount > IMPORTED_SELECTED_EDGE_TRIANGLE_LIMIT;
if ((group.userData.showEdges || complexEdges) && !skipHeavyImportedEdges) {
diff --git a/apps/web/src/components/workplane/EdgeModifierPanel.tsx b/apps/web/src/components/workplane/EdgeModifierPanel.tsx
index dc6d25d..fbb5a6c 100644
--- a/apps/web/src/components/workplane/EdgeModifierPanel.tsx
+++ b/apps/web/src/components/workplane/EdgeModifierPanel.tsx
@@ -2,7 +2,7 @@
import { useEffect, useState, type CSSProperties } from "react";
import { Check, LoaderCircle, Minus, Plus, RotateCcw, X } from "lucide-react";
-import { displayStepFromMillimeters, displayToMillimeters, formatMeasurementNumber, lengthDisplayUnit, millimetersToDisplay } from "@/lib/measurementUnits";
+import { displayStepFromMillimeters, displayToMillimeters, formatMeasurementNumber, lengthDisplayUnit, millimetersToDisplay, parseMeasurementInput } from "@/lib/measurementUnits";
import type { CadModifierKind, CadModifierQuality } from "@/lib/cadModifierTypes";
import { CAD_MODIFIER_MAX_SHARP_ANGLE, edgeModifierSelectionStatus } from "@/lib/cadModifierRuntime";
import type { WorkplaneWorkspaceSettings } from "@/types/sketchforge";
@@ -71,7 +71,7 @@ function EdgeModifierSlider({
const toModelValue = (nextValue: number) => length ? displayToMillimeters(nextValue, workspace) : nextValue;
const commitDraft = () => {
- const next = Number(draft);
+ const next = parseMeasurementInput(draft);
const finiteNext = Number.isFinite(next) ? next : controlValue;
onChange(clamp(toModelValue(finiteNext), safeMin, safeMax));
setEditing(false);
@@ -89,10 +89,7 @@ function EdgeModifierSlider({
{label}
= [
+ { value: "spur", label: "Spur gear" },
+ { value: "helical", label: "Helical gear" },
+ { value: "bevel", label: "Bevel gear" },
+];
type RangePropertyConfig = {
type?: "range";
@@ -80,7 +104,7 @@ function formatPropertyNumber(value: number, accuracy: MeasurementAccuracy, step
}
function propertyUsesLengthUnit(label: string) {
- return ["Radius", "Length", "Width", "Height", "Bevel", "Top Radius", "Base Radius", "Thickness"].includes(label);
+ return ["Radius", "Length", "Width", "Height", "Bevel", "Top Radius", "Base Radius", "Thickness", "Tooth Size", "Tooth Width", "Center Hole"].includes(label);
}
function getShapeProperties(shape: WorkplaneShape, onUpdate: ShapeInspectorUpdate): ShapePropertyConfig[] {
@@ -95,6 +119,20 @@ function getShapeProperties(shape: WorkplaneShape, onUpdate: ShapeInspectorUpdat
};
const setHeight = (height: number) => onUpdate({ height }, { resizeAxis: "height" });
+ if (shape.sketchOperation === "revolve" || shape.sketchRevolve) {
+ const settings = normalizeSketchRevolveSettings(shape.sketchRevolve);
+ const updateRevolve = (patch: Partial) => onUpdate({ sketchRevolve: normalizeSketchRevolveSettings({ ...settings, ...patch }) });
+ return [
+ { label: "Start Angle", value: settings.startAngle, min: 0, max: 359, step: 1, onChange: (startAngle) => updateRevolve({ startAngle }) },
+ { label: "Sweep", value: settings.sweepAngle, min: -360, max: 360, step: 1, onChange: (sweepAngle) => updateRevolve({ sweepAngle }) },
+ { label: "Sides", value: settings.sides, min: 3, max: 128, step: 1, onChange: (sides) => updateRevolve({ sides }) },
+ { label: "Thickness", value: settings.thickness, min: 0.1, max: 20, step: 0.1, onChange: (thickness) => updateRevolve({ thickness }) },
+ { label: "Length", value: depth, min: MIN_SHAPE_SIZE, max: 160, onChange: setDepth },
+ { label: "Width", value: width, min: MIN_SHAPE_SIZE, max: 160, onChange: setWidth },
+ { label: "Height", value: shape.height, min: MIN_SHAPE_SIZE, max: 160, onChange: setHeight },
+ ];
+ }
+
if (shape.kind === "box") {
return [
{ label: "Length", value: depth, min: MIN_SHAPE_SIZE, max: 160, onChange: setDepth },
@@ -168,6 +206,92 @@ function getShapeProperties(shape: WorkplaneShape, onUpdate: ShapeInspectorUpdat
];
}
+ if (shape.kind === "gear") {
+ const setGearWidth = (value: number) => {
+ const toothSize = normalizeGearToothSize(shape.toothSize, value, depth);
+ const toothWidth = normalizeGearToothWidth(shape.toothWidth, value, depth, shape.teeth);
+ const centerHoleSize = normalizeGearCenterHoleSize(shape.centerHoleSize, value, depth, toothSize);
+ onUpdate({ width: value, size: resizedShapeSize(value, depth), toothSize, toothWidth, centerHoleSize }, { resizeAxis: "width" });
+ };
+ const setGearDepth = (value: number) => {
+ const toothSize = normalizeGearToothSize(shape.toothSize, width, value);
+ const toothWidth = normalizeGearToothWidth(shape.toothWidth, width, value, shape.teeth);
+ const centerHoleSize = normalizeGearCenterHoleSize(shape.centerHoleSize, width, value, toothSize);
+ onUpdate({ depth: value, size: resizedShapeSize(width, value), toothSize, toothWidth, centerHoleSize }, { resizeAxis: "depth" });
+ };
+ const teeth = shape.teeth ?? DEFAULT_GEAR_TEETH;
+ const toothPitch = gearToothPitch(width, depth, teeth);
+ const toothSize = normalizeGearToothSize(shape.toothSize ?? DEFAULT_GEAR_TOOTH_SIZE, width, depth);
+ const centerHoleLimits = gearCenterHoleLimits(width, depth, toothSize);
+ const properties: ShapePropertyConfig[] = [
+ {
+ label: "Teeth",
+ value: teeth,
+ min: 6,
+ max: 64,
+ step: 1,
+ onChange: (value) => {
+ const nextTeeth = Math.round(value);
+ onUpdate({
+ teeth: nextTeeth,
+ toothWidth: normalizeGearToothWidth(shape.toothWidth, width, depth, nextTeeth),
+ });
+ },
+ },
+ {
+ label: "Tooth Size",
+ value: toothSize,
+ min: 0.2,
+ max: Math.max(0.2, Math.min(width, depth) * 0.22),
+ step: 0.1,
+ onChange: (nextToothSize) => onUpdate({
+ toothSize: nextToothSize,
+ centerHoleSize: normalizeGearCenterHoleSize(shape.centerHoleSize, width, depth, nextToothSize),
+ }),
+ },
+ {
+ label: "Tooth Width",
+ value: normalizeGearToothWidth(shape.toothWidth, width, depth, teeth),
+ min: toothPitch * 0.12,
+ max: toothPitch * 0.82,
+ step: 0.1,
+ onChange: (toothWidth) => onUpdate({ toothWidth }),
+ },
+ ];
+ if (normalizeGearType(shape.gearType) === "helical") {
+ properties.push({
+ label: "Helix Angle",
+ value: normalizeGearHelixAngle(shape.helixAngle ?? DEFAULT_GEAR_HELIX_ANGLE),
+ min: MIN_GEAR_HELIX_ANGLE,
+ max: MAX_GEAR_HELIX_ANGLE,
+ step: 1,
+ onChange: (helixAngle) => onUpdate({ helixAngle }),
+ });
+ properties.push({
+ label: "Quality",
+ value: normalizeGearHelixQuality(shape.helixQuality ?? DEFAULT_GEAR_HELIX_QUALITY),
+ min: MIN_GEAR_HELIX_QUALITY,
+ max: MAX_GEAR_HELIX_QUALITY,
+ step: 1,
+ onChange: (helixQuality) => onUpdate({ helixQuality: Math.round(helixQuality) }),
+ });
+ }
+ properties.push(
+ {
+ label: "Center Hole",
+ value: normalizeGearCenterHoleSize(shape.centerHoleSize, width, depth, toothSize),
+ min: centerHoleLimits.min,
+ max: centerHoleLimits.max,
+ step: 0.1,
+ onChange: (centerHoleSize) => onUpdate({ centerHoleSize }),
+ },
+ { label: "Length", value: depth, min: MIN_SHAPE_SIZE, max: 160, onChange: setGearDepth },
+ { label: "Width", value: width, min: MIN_SHAPE_SIZE, max: 160, onChange: setGearWidth },
+ { label: "Height", value: shape.height, min: MIN_SHAPE_SIZE, max: 160, onChange: setHeight },
+ );
+ return properties;
+ }
+
if (shape.kind === "text") {
return [
{
@@ -222,14 +346,31 @@ export function ShapeInspector({
const solidColor = shape.hole ? fallbackSolidColor(shape) : shape.color;
const locked = Boolean(shape.locked);
const properties = getShapeProperties(shape, onUpdate);
+ const gearType = shape.kind === "gear" ? normalizeGearType(shape.gearType) : null;
+ const primaryProperties = shape.kind === "gear"
+ ? properties.filter((property) => ["Center Hole", "Length", "Width", "Height"].includes(property.label))
+ : properties;
+ const gearTeethProperties = shape.kind === "gear"
+ ? properties.filter((property) => ["Teeth", "Tooth Size", "Tooth Width"].includes(property.label))
+ : [];
+ const gearHelixProperties = shape.kind === "gear"
+ ? properties.filter((property) => ["Helix Angle", "Quality"].includes(property.label))
+ : [];
+ const isSketchRevolve = shape.sketchOperation === "revolve" || Boolean(shape.sketchRevolve);
+ const inspectorRef = useRef(null);
const [propertiesOpen, setPropertiesOpen] = useState(true);
+ const [gearTeethOpen, setGearTeethOpen] = useState(true);
+ const [gearHelixOpen, setGearHelixOpen] = useState(true);
const [colorOpen, setColorOpen] = useState(false);
const [minimized, setMinimized] = useState(false);
useEffect(() => () => onInteractionActiveChange?.(false), [onInteractionActiveChange]);
+ useLayoutEffect(() => {
+ inspectorRef.current?.scrollTo({ top: 0, left: 0 });
+ }, [isSketchRevolve, shape.id]);
return (
-