-
-
-
- ) : null}
-
{marqueeRect ? : null}
{transformOverlay && !alignMode && !mirrorMode && !rulerMode && !modifierActive ? (
@@ -2909,12 +2984,14 @@ export function WorkplaneViewport({
shape={selectedShape}
snap={snap}
snapOpen={snapOpen}
- accuracy={workspace.accuracy}
+ workspace={workspace}
onUpdate={(patch, options) => onUpdateShape(selectedShape.id, patchWithResizeAnchor(selectedShape, patch, options?.resizeAxis, lastResizeAnchorRef.current))}
onClose={() => onSelectShape(null)}
onSnapChange={setSnap}
onSnapOpenChange={setSnapOpen}
onEditSketch={selectedShape.sketchProfile ? onEditSketch : undefined}
+ canSeparateParts={canSeparateParts}
+ onSeparateParts={onSeparateParts}
/>
) : null}
@@ -3442,7 +3519,16 @@ function rebuildShapes(state: ThreeState | null, shapes: WorkplaneShape[], selec
rebuildSelectionHelpers(state, shapes, selectedIds);
}
-function rebuildModifierEdges(state: ThreeState | null, edges: CadModifierEdge[], selectedIds: number[], previewActive = false) {
+function modifierEdgeMaterialStyle(active: boolean, hovered: boolean, previewActive: boolean) {
+ const subduedSelectedPreviewEdge = previewActive && active && !hovered;
+ return {
+ color: active ? (hovered ? "#ffbf45" : "#ff8a1d") : hovered ? "#84edff" : "#17b7e5",
+ opacity: subduedSelectedPreviewEdge ? 0.18 : active || hovered ? 1 : 0.72,
+ linewidth: active || hovered ? 3 : 1,
+ };
+}
+
+function rebuildModifierEdges(state: ThreeState | null, edges: CadModifierEdge[], selectedIds: number[], previewActive = false, hoverId: number | null = null) {
if (!state) return;
disposeChildren(state.modifierLayer);
const selected = new Set(selectedIds);
@@ -3451,17 +3537,19 @@ function rebuildModifierEdges(state: ThreeState | null, edges: CadModifierEdge[]
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(edge.points, 3));
const active = selected.has(edge.id);
- const subduedSelectedPreviewEdge = previewActive && active;
+ const hovered = hoverId === edge.id;
+ const style = modifierEdgeMaterialStyle(active, hovered, previewActive);
const material = new THREE.LineBasicMaterial({
- color: active ? "#ff8a1d" : "#17b7e5",
+ color: style.color,
depthTest: false,
depthWrite: false,
transparent: true,
- opacity: subduedSelectedPreviewEdge ? 0.18 : active ? 1 : 0.82,
+ opacity: style.opacity,
+ linewidth: style.linewidth,
});
const line = new THREE.Line(geometry, material);
line.userData.modifierEdgeId = edge.id;
- line.renderOrder = active ? 1002 : 1001;
+ line.renderOrder = hovered ? 1003 : active ? 1002 : 1001;
state.modifierLayer.add(line);
});
state.needsRender = true;
@@ -4089,6 +4177,39 @@ function findSelectedGroundFootprint(state: ThreeState, id: string) {
return state.helperLayer.children.find((child) => child.name === "SelectedGroundFootprint" && child.userData.shapeId === id) ?? null;
}
+function applyDragItemPreview(state: ThreeState, item: DragItem) {
+ if (!item.visual || !item.visual.parent) {
+ item.visual = findShapeObject(state, item.id);
+ }
+ if (!item.helper || !item.helper.parent) {
+ item.helper = findSelectionHelper(state, item.id);
+ item.helperBox = item.helper ? item.helper.box.clone() : null;
+ }
+
+ if (item.visual) {
+ if (!item.hadPreviewSimplified) {
+ setComplexEdgeVisibility(item.visual, false);
+ item.hadPreviewSimplified = true;
+ }
+ item.visual.position.x = item.nextX;
+ item.visual.position.z = item.nextZ;
+ item.visual.updateMatrixWorld(true);
+ }
+
+ if (item.helper && item.helperBox) {
+ item.helper.box.copy(item.helperBox);
+ item.helper.box.translate(new THREE.Vector3(item.nextX - item.startX, 0, item.nextZ - item.startZ));
+ item.helper.updateMatrixWorld(true);
+ }
+}
+
+function refreshDragPreviewObjects(state: ThreeState | null, drag: DragState | null) {
+ if (!state || !drag) return;
+ drag.items.forEach((item) => applyDragItemPreview(state, item));
+ updateSelectedGroundFootprintPreviews(state, drag);
+ state.needsRender = true;
+}
+
function updateSelectedGroundFootprintPreviews(state: ThreeState, drag: DragState) {
drag.items.forEach((item) => {
const footprint = findSelectedGroundFootprint(state, item.id);
@@ -4822,8 +4943,9 @@ function createHalfSphereGeometry(width: number, height: number, depth: number,
function disposeChildren(group: THREE.Group) {
while (group.children.length > 0) {
- const child = group.children.pop();
+ const child = group.children[group.children.length - 1];
if (child) {
+ group.remove(child);
disposeObject(child);
}
}
diff --git a/apps/web/src/components/icons.tsx b/apps/web/src/components/icons.tsx
index adbccba..df689d8 100644
--- a/apps/web/src/components/icons.tsx
+++ b/apps/web/src/components/icons.tsx
@@ -148,24 +148,12 @@ export function ToolbarMirrorIcon() {
return ;
}
-export function ToolbarChamferIcon(props: IconProps) {
- return (
-
- );
+export function ToolbarChamferIcon() {
+ return ;
}
-export function ToolbarFilletIcon(props: IconProps) {
- return (
-
- );
+export function ToolbarFilletIcon() {
+ return ;
}
export function ToolbarPreserveEdgeIcon(props: IconProps) {
diff --git a/apps/web/src/components/workplane/EdgeModifierPanel.tsx b/apps/web/src/components/workplane/EdgeModifierPanel.tsx
index b2c719d..eeda9ed 100644
--- a/apps/web/src/components/workplane/EdgeModifierPanel.tsx
+++ b/apps/web/src/components/workplane/EdgeModifierPanel.tsx
@@ -1,7 +1,128 @@
"use client";
-import { Check, LoaderCircle, X } from "lucide-react";
+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 type { CadModifierKind, CadModifierQuality } from "@/lib/cadModifierTypes";
+import type { WorkplaneWorkspaceSettings } from "@/types/sketchforge";
+
+const MIN_EDGE_MODIFIER_AMOUNT = 0.001;
+const EDGE_MODIFIER_AMOUNT_STEP = 0.001;
+
+function clamp(value: number, min: number, max: number) {
+ return Math.min(max, Math.max(min, value));
+}
+
+function formatSliderValue(value: number, accuracy: WorkplaneWorkspaceSettings["accuracy"], step: number) {
+ if (step >= 1) return String(Math.round(value));
+ return formatMeasurementNumber(value, accuracy, step);
+}
+
+type EdgeHistoryOption = {
+ id: string;
+ label: string;
+ targetName: string;
+ removesNewerCount: number;
+};
+
+function EdgeModifierSlider({
+ label,
+ value,
+ min,
+ max,
+ step,
+ unit,
+ workspace,
+ length = false,
+ onChange,
+}: {
+ label: string;
+ value: number;
+ min: number;
+ max: number;
+ step: number;
+ unit?: string;
+ workspace: WorkplaneWorkspaceSettings;
+ length?: boolean;
+ onChange: (value: number) => void;
+}) {
+ const safeMin = Number.isFinite(min) ? min : 0;
+ const safeMax = Math.max(safeMin, Number.isFinite(max) ? max : safeMin);
+ const actualValue = Number.isFinite(value) ? value : safeMin;
+ const controlValue = length ? millimetersToDisplay(actualValue, workspace) : actualValue;
+ const controlMin = length ? millimetersToDisplay(safeMin, workspace) : safeMin;
+ const controlMax = length ? millimetersToDisplay(safeMax, workspace) : safeMax;
+ const controlStep = length ? displayStepFromMillimeters(step, workspace) : step;
+ const sliderValue = clamp(controlValue, controlMin, controlMax);
+ const position = ((sliderValue - controlMin) / Math.max(Number.EPSILON, controlMax - controlMin)) * 100;
+ const [editing, setEditing] = useState(false);
+ const [draft, setDraft] = useState(formatSliderValue(controlValue, workspace.accuracy, controlStep));
+ const unitLabel = length ? lengthDisplayUnit(workspace).label : unit;
+
+ useEffect(() => {
+ if (!editing) {
+ setDraft(formatSliderValue(controlValue, workspace.accuracy, controlStep));
+ }
+ }, [controlStep, controlValue, editing, workspace.accuracy]);
+
+ const toModelValue = (nextValue: number) => length ? displayToMillimeters(nextValue, workspace) : nextValue;
+
+ const commitDraft = () => {
+ const next = Number(draft);
+ const finiteNext = Number.isFinite(next) ? next : controlValue;
+ onChange(clamp(toModelValue(finiteNext), safeMin, safeMax));
+ setEditing(false);
+ };
+
+ const handleSliderChange = (nextValue: number) => {
+ const next = clamp(Number.isFinite(nextValue) ? nextValue : controlMin, controlMin, controlMax);
+ onChange(clamp(toModelValue(next), safeMin, safeMax));
+ setDraft(formatSliderValue(next, workspace.accuracy, controlStep));
+ };
+
+ return (
+
+ );
+}
export function EdgeModifierPanel({
kind,
@@ -10,12 +131,14 @@ export function EdgeModifierPanel({
chamferAngle,
quality,
sharpAngle,
+ workspace,
tangentChain,
preserveEdgeSize,
targetName,
groupedCount,
appliedFeatureCount,
reversibleFeatureCount,
+ historyOptions,
selectedCount,
availableCount,
busy,
@@ -28,7 +151,7 @@ export function EdgeModifierPanel({
onPreserveEdgeSizeChange,
onSelectAll,
onClear,
- onRemoveLastFeature,
+ onRemoveFeature,
onApply,
onCancel,
}: {
@@ -38,12 +161,14 @@ export function EdgeModifierPanel({
chamferAngle: number;
quality: CadModifierQuality;
sharpAngle: number;
+ workspace: WorkplaneWorkspaceSettings;
tangentChain: boolean;
preserveEdgeSize: boolean;
targetName: string;
groupedCount: number;
appliedFeatureCount: number;
reversibleFeatureCount: number;
+ historyOptions: EdgeHistoryOption[];
selectedCount: number;
availableCount: number;
busy: boolean;
@@ -56,11 +181,14 @@ export function EdgeModifierPanel({
onPreserveEdgeSizeChange: (value: boolean) => void;
onSelectAll: () => void;
onClear: () => void;
- onRemoveLastFeature: () => void;
+ onRemoveFeature: (id: string) => void;
onApply: () => void;
onCancel: () => void;
}) {
+ const [historyOpen, setHistoryOpen] = useState(false);
const title = kind === "fillet" ? "Fillet edges" : "Chamfer edges";
+ const amountMin = Math.min(MIN_EDGE_MODIFIER_AMOUNT, Math.max(Number.EPSILON, maxAmount));
+ const amountMax = Math.max(amountMin, maxAmount);
return (