Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
release: publish v0.9.0 modeling update
This commit is contained in:
@@ -1745,7 +1745,7 @@ button {
|
||||
}
|
||||
|
||||
.sketch-start-section {
|
||||
min-width: 260px;
|
||||
min-width: 360px;
|
||||
}
|
||||
|
||||
.sketch-finish-section {
|
||||
@@ -1839,6 +1839,13 @@ button {
|
||||
height: 27px;
|
||||
}
|
||||
|
||||
.sketch-command-button .toolbar-command-icon {
|
||||
width: 29px;
|
||||
height: 29px;
|
||||
object-fit: contain;
|
||||
transform: translateY(var(--toolbar-art-offset-y, 0));
|
||||
}
|
||||
|
||||
.sketch-command-button:hover:not(:disabled) {
|
||||
color: #17405d;
|
||||
background: #e7f5fb;
|
||||
@@ -2012,6 +2019,84 @@ button {
|
||||
min-width: 78px;
|
||||
}
|
||||
|
||||
.toolbar-visibility-section {
|
||||
min-width: 92px;
|
||||
}
|
||||
|
||||
.visibility-dropdown {
|
||||
position: fixed;
|
||||
z-index: 70;
|
||||
width: min(276px, calc(100vw - 24px));
|
||||
padding: 8px;
|
||||
color: #263f56;
|
||||
background: rgba(255, 255, 255, 0.98);
|
||||
border: 1px solid #c9d8e3;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 14px 34px rgba(29, 48, 66, 0.22);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.visibility-dropdown-action {
|
||||
display: grid;
|
||||
width: 100%;
|
||||
min-height: 42px;
|
||||
padding: 9px 10px;
|
||||
grid-template-columns: 26px minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
color: #263f56;
|
||||
text-align: left;
|
||||
background: #eef8fc;
|
||||
border: 1px solid #c9e1ec;
|
||||
border-radius: 7px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.visibility-dropdown-action:hover:not(:disabled),
|
||||
.visibility-dropdown-action:focus-visible {
|
||||
color: #123f5a;
|
||||
background: #e2f4fb;
|
||||
border-color: #9acfe2;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.visibility-dropdown-action:disabled {
|
||||
color: #7a8e9f;
|
||||
background: #f3f6f8;
|
||||
border-color: #dce5eb;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.visibility-dropdown-action strong {
|
||||
font-size: 12px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.visibility-dropdown-help {
|
||||
display: flex;
|
||||
padding: 7px 8px 1px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
color: #5d7284;
|
||||
font-size: 9px;
|
||||
font-weight: 700;
|
||||
line-height: 1.35;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.visibility-dropdown-help kbd {
|
||||
padding: 1px 3px;
|
||||
color: #29465f;
|
||||
background: #eef2f5;
|
||||
border: 1px solid #cfdae2;
|
||||
border-bottom-width: 2px;
|
||||
border-radius: 4px;
|
||||
font-family: inherit;
|
||||
font-size: 8px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.toolbar-section-label {
|
||||
order: 1;
|
||||
height: 24px;
|
||||
@@ -3182,8 +3267,7 @@ button {
|
||||
.sketch-plate-wrap {
|
||||
position: absolute;
|
||||
inset: 14px 14px 42px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@@ -3191,6 +3275,8 @@ button {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
overflow: visible;
|
||||
touch-action: none;
|
||||
cursor: crosshair;
|
||||
@@ -3819,12 +3905,12 @@ button {
|
||||
box-shadow: inset 3px 0 0 #079bc6;
|
||||
}
|
||||
|
||||
.ruler-control-group {
|
||||
.workplane-control-group {
|
||||
position: relative;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.ruler-control-group::before {
|
||||
.workplane-control-group::before {
|
||||
position: absolute;
|
||||
top: -5px;
|
||||
right: 8px;
|
||||
@@ -3834,6 +3920,10 @@ button {
|
||||
background: rgba(117, 144, 160, 0.28);
|
||||
}
|
||||
|
||||
.ruler-control-group {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.ruler-tool-popover {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
@@ -3943,6 +4033,48 @@ button {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.move-dimension-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 6;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.move-dimension-guides {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
overflow: visible;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.move-dimension-line {
|
||||
stroke: #263846;
|
||||
stroke-width: 1.8;
|
||||
stroke-linecap: round;
|
||||
vector-effect: non-scaling-stroke;
|
||||
filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.7));
|
||||
}
|
||||
|
||||
.move-dimension-projection {
|
||||
stroke: rgba(38, 56, 70, 0.38);
|
||||
stroke-width: 1.25;
|
||||
stroke-linecap: round;
|
||||
vector-effect: non-scaling-stroke;
|
||||
}
|
||||
|
||||
.move-dimension-guides marker path {
|
||||
fill: #263846;
|
||||
}
|
||||
|
||||
.move-dimension-overlay.active .move-dimension-value {
|
||||
pointer-events: none;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.move-dimension-input {
|
||||
appearance: textfield;
|
||||
}
|
||||
|
||||
.ruler-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
@@ -4219,7 +4351,7 @@ button {
|
||||
text-align: center;
|
||||
pointer-events: auto;
|
||||
cursor: text;
|
||||
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%);
|
||||
will-change: transform;
|
||||
box-shadow: 0 1px 4px rgba(20, 42, 58, 0.09);
|
||||
}
|
||||
@@ -4327,6 +4459,7 @@ button {
|
||||
background: #e9eef1;
|
||||
border: 1.5px solid #293743;
|
||||
box-shadow: 0 1px 2px rgba(20, 30, 40, 0.16);
|
||||
transform: translate3d(var(--overlay-x, 0), var(--overlay-y, 0), 0) translate(-50%, -50%) rotate(var(--transform-handle-angle, 0deg));
|
||||
}
|
||||
|
||||
.transform-handle.corner,
|
||||
@@ -4378,7 +4511,7 @@ button {
|
||||
box-shadow: none;
|
||||
cursor: grab;
|
||||
opacity: 1;
|
||||
transform: translate3d(var(--overlay-x, 0), var(--overlay-y, 0), 0) translate(-50%, -50%);
|
||||
transform: translate3d(var(--overlay-x, 0), var(--overlay-y, 0), 0) translate(-50%, -50%) rotate(var(--rotate-handle-angle, 0deg));
|
||||
}
|
||||
|
||||
.rotate-handle:hover {
|
||||
@@ -4582,12 +4715,12 @@ button {
|
||||
display: block;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
border: 4px solid transparent;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.large-solid-swatch {
|
||||
background: var(--swatch);
|
||||
border: 4px solid #7bb8ff;
|
||||
box-shadow: inset 0 0 0 4px white;
|
||||
}
|
||||
|
||||
@@ -4596,6 +4729,11 @@ button {
|
||||
box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.55);
|
||||
}
|
||||
|
||||
.shape-state-card button.active .large-solid-swatch,
|
||||
.shape-state-card button.active .large-hole-swatch {
|
||||
border-color: #7bb8ff;
|
||||
}
|
||||
|
||||
.shape-state-card button:disabled,
|
||||
.range-property input:disabled {
|
||||
cursor: default;
|
||||
@@ -6288,6 +6426,19 @@ html[data-theme="dark"] {
|
||||
--shadow: 0 3px 12px rgba(0, 0, 0, 0.32);
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .move-dimension-line {
|
||||
stroke: #dceaf2;
|
||||
filter: drop-shadow(0 1px 1px rgba(2, 12, 18, 0.72));
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .move-dimension-guides marker path {
|
||||
fill: #dceaf2;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .move-dimension-projection {
|
||||
stroke: rgba(220, 234, 242, 0.38);
|
||||
}
|
||||
|
||||
html[data-theme="dark"] body,
|
||||
html[data-theme="dark"] .dashboard-shell,
|
||||
html[data-theme="dark"] .sketchforge-editor,
|
||||
@@ -6445,6 +6596,7 @@ html[data-theme="dark"] .toolbar-workspace-tabs button:hover {
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .shape-menu-dropdown,
|
||||
html[data-theme="dark"] .visibility-dropdown,
|
||||
html[data-theme="dark"] .top-action-panel,
|
||||
html[data-theme="dark"] .edge-modifier-panel,
|
||||
html[data-theme="dark"] .camera-controls,
|
||||
@@ -6457,6 +6609,35 @@ html[data-theme="dark"] .snap-menu {
|
||||
box-shadow: 0 14px 38px rgba(0, 0, 0, 0.34);
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .visibility-dropdown-action {
|
||||
color: #d9e7f0;
|
||||
background: #213541;
|
||||
border-color: #3b5665;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .visibility-dropdown-action:hover:not(:disabled),
|
||||
html[data-theme="dark"] .visibility-dropdown-action:focus-visible {
|
||||
color: #ecf9ff;
|
||||
background: #294653;
|
||||
border-color: #4b7385;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .visibility-dropdown-action:disabled {
|
||||
color: #8398a6;
|
||||
background: #192832;
|
||||
border-color: #334753;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .visibility-dropdown-help {
|
||||
color: #9eb2bf;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .visibility-dropdown-help kbd {
|
||||
color: #dceaf2;
|
||||
background: #182832;
|
||||
border-color: #415763;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .shape-menu-item,
|
||||
html[data-theme="dark"] .top-action-body button,
|
||||
html[data-theme="dark"] .top-action-body .open-skf-project-button,
|
||||
|
||||
@@ -6,6 +6,12 @@ import { SketchForgeEditor, importedShapeFromStl, importedShapeFromSvg } from "@
|
||||
import { applyAppTheme, readStoredAppTheme, resolveAppTheme, storeAppTheme, type AppThemePreference, type ResolvedAppTheme } from "@/lib/appTheme";
|
||||
import { hydrateEditorHistoryState, type EditorHistoryEntry } from "@/lib/editorHistory";
|
||||
import { createLocalId } from "@/lib/localIds";
|
||||
import {
|
||||
horizontalPlacementWorkplane,
|
||||
normalizePlacementWorkplane,
|
||||
placementWorkplaneFingerprint,
|
||||
type PlacementWorkplane,
|
||||
} from "@/lib/placementWorkplane";
|
||||
import { attachProjectAsset, dedupeProjectAssets, projectAssetFromBytes, sourceFormatForFileName } from "@/lib/projectAssets";
|
||||
import { hydrateProjectShapeState, type ImportedMeshResource } from "@/lib/projectShapePersistence";
|
||||
import { exportSkfProject, importSkfProject, SKF_CREATED_WITH_VERSION } from "@/lib/skfProject";
|
||||
@@ -31,6 +37,8 @@ type DashboardProject = {
|
||||
workspace?: WorkplaneWorkspaceSettings;
|
||||
snapGrid?: GridSize;
|
||||
placementElevation?: number;
|
||||
placementWorkplane?: PlacementWorkplane;
|
||||
sketchPlacementWorkplane?: PlacementWorkplane;
|
||||
sharedProject?: { fileName: string; revision: string };
|
||||
};
|
||||
|
||||
@@ -73,6 +81,8 @@ type ProjectShapeSaveContext = {
|
||||
workspace: WorkplaneWorkspaceSettings;
|
||||
snapGrid: GridSize;
|
||||
placementElevation: number;
|
||||
placementWorkplane: PlacementWorkplane;
|
||||
sketchPlacementWorkplane: PlacementWorkplane;
|
||||
};
|
||||
|
||||
type ProjectShapeResourceRecord =
|
||||
@@ -152,13 +162,16 @@ function projectShapeCacheEntryFromEditor(
|
||||
};
|
||||
}
|
||||
|
||||
function projectShapeSaveContext(project: Pick<DashboardProject, "name" | "createdAt" | "workspace" | "snapGrid" | "placementElevation">): ProjectShapeSaveContext {
|
||||
function projectShapeSaveContext(project: Pick<DashboardProject, "name" | "createdAt" | "workspace" | "snapGrid" | "placementElevation" | "placementWorkplane" | "sketchPlacementWorkplane">): ProjectShapeSaveContext {
|
||||
const placementElevation = Number.isFinite(project.placementElevation) ? project.placementElevation ?? 0 : 0;
|
||||
return {
|
||||
projectName: project.name,
|
||||
createdAt: project.createdAt,
|
||||
workspace: normalizeWorkspaceSettings(project.workspace),
|
||||
snapGrid: normalizeSnapGrid(project.snapGrid),
|
||||
placementElevation: Number.isFinite(project.placementElevation) ? project.placementElevation ?? 0 : 0,
|
||||
placementElevation,
|
||||
placementWorkplane: normalizePlacementWorkplane(project.placementWorkplane, placementElevation),
|
||||
sketchPlacementWorkplane: normalizePlacementWorkplane(project.sketchPlacementWorkplane),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -284,6 +297,8 @@ async function saveProjectShapes(projectId: string, entry: ProjectShapeCacheEntr
|
||||
workspace: context.workspace,
|
||||
snapGrid: context.snapGrid,
|
||||
placementElevation: context.placementElevation,
|
||||
placementWorkplane: context.placementWorkplane,
|
||||
sketchPlacementWorkplane: context.sketchPlacementWorkplane,
|
||||
compressionLevel: 1,
|
||||
});
|
||||
const database = await openProjectShapesDb();
|
||||
@@ -382,6 +397,8 @@ function readStoredProjects() {
|
||||
workspace: normalizeWorkspaceSettings(project.workspace),
|
||||
snapGrid: normalizeSnapGrid(project.snapGrid),
|
||||
placementElevation: typeof project.placementElevation === "number" && Number.isFinite(project.placementElevation) ? project.placementElevation : 0,
|
||||
placementWorkplane: normalizePlacementWorkplane(project.placementWorkplane, project.placementElevation),
|
||||
sketchPlacementWorkplane: normalizePlacementWorkplane(project.sketchPlacementWorkplane),
|
||||
sharedProject: typeof project.sharedProject?.fileName === "string" && typeof project.sharedProject.revision === "string"
|
||||
? { fileName: project.sharedProject.fileName, revision: project.sharedProject.revision }
|
||||
: undefined,
|
||||
@@ -416,6 +433,8 @@ function mergeProjectForStorage(project: DashboardProject, storedProject?: Dashb
|
||||
workspace: storedProject.workspace ?? project.workspace,
|
||||
snapGrid: storedProject.snapGrid ?? project.snapGrid,
|
||||
placementElevation: storedProject.placementElevation ?? project.placementElevation,
|
||||
placementWorkplane: storedProject.placementWorkplane ?? project.placementWorkplane,
|
||||
sketchPlacementWorkplane: storedProject.sketchPlacementWorkplane ?? project.sketchPlacementWorkplane,
|
||||
sharedProject: project.sharedProject ?? storedProject.sharedProject,
|
||||
};
|
||||
}
|
||||
@@ -434,6 +453,8 @@ function projectForStorage(project: DashboardProject): DashboardProject {
|
||||
workspace: normalizeWorkspaceSettings(project.workspace),
|
||||
snapGrid: normalizeSnapGrid(project.snapGrid),
|
||||
placementElevation: typeof project.placementElevation === "number" && Number.isFinite(project.placementElevation) ? project.placementElevation : 0,
|
||||
placementWorkplane: normalizePlacementWorkplane(project.placementWorkplane, project.placementElevation),
|
||||
sketchPlacementWorkplane: normalizePlacementWorkplane(project.sketchPlacementWorkplane),
|
||||
sharedProject: project.sharedProject,
|
||||
};
|
||||
}
|
||||
@@ -457,6 +478,8 @@ function newProject(name: string, index: number, shapeCount = 0): DashboardProje
|
||||
workspace: DEFAULT_WORKPLANE_WORKSPACE,
|
||||
snapGrid: DEFAULT_SNAP_GRID,
|
||||
placementElevation: 0,
|
||||
placementWorkplane: horizontalPlacementWorkplane(),
|
||||
sketchPlacementWorkplane: horizontalPlacementWorkplane(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -757,6 +780,8 @@ export default function Home() {
|
||||
workspace: WorkplaneWorkspaceSettings;
|
||||
snapGrid: GridSize;
|
||||
placementElevation: number;
|
||||
placementWorkplane: PlacementWorkplane;
|
||||
sketchPlacementWorkplane: PlacementWorkplane;
|
||||
}) => {
|
||||
const revision = Math.max(Date.now(), nextProjectRevisionRef.current + 1);
|
||||
nextProjectRevisionRef.current = revision;
|
||||
@@ -779,6 +804,8 @@ export default function Home() {
|
||||
workspace: normalizeWorkspaceSettings(snapshot.workspace),
|
||||
snapGrid: normalizeSnapGrid(snapshot.snapGrid),
|
||||
placementElevation: Number.isFinite(snapshot.placementElevation) ? snapshot.placementElevation : 0,
|
||||
placementWorkplane: normalizePlacementWorkplane(snapshot.placementWorkplane, snapshot.placementElevation),
|
||||
sketchPlacementWorkplane: normalizePlacementWorkplane(snapshot.sketchPlacementWorkplane),
|
||||
};
|
||||
const queuedSave = previousSave.catch(() => undefined).then(() => saveProjectShapesWhenIdle(snapshot.projectId, entry, saveContext));
|
||||
projectShapeSaveQueuesRef.current[snapshot.projectId] = queuedSave;
|
||||
@@ -805,7 +832,14 @@ export default function Home() {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const updateProjectWorkspace = useCallback((snapshot: { projectId: string; workspace: WorkplaneWorkspaceSettings; snap: GridSize; placementElevation?: number }) => {
|
||||
const updateProjectWorkspace = useCallback((snapshot: {
|
||||
projectId: string;
|
||||
workspace: WorkplaneWorkspaceSettings;
|
||||
snap: GridSize;
|
||||
placementElevation?: number;
|
||||
placementWorkplane?: PlacementWorkplane;
|
||||
sketchPlacementWorkplane?: PlacementWorkplane;
|
||||
}) => {
|
||||
const version = Math.max(Date.now(), nextProjectRevisionRef.current + 1);
|
||||
nextProjectRevisionRef.current = version;
|
||||
const workspace = normalizeWorkspaceSettings(snapshot.workspace);
|
||||
@@ -813,7 +847,9 @@ export default function Home() {
|
||||
const placementElevation = typeof snapshot.placementElevation === "number" && Number.isFinite(snapshot.placementElevation)
|
||||
? snapshot.placementElevation
|
||||
: 0;
|
||||
const nextFingerprint = `${workplaneSettingsFingerprint(workspace, snapGrid)}:${placementElevation}`;
|
||||
const placementWorkplane = normalizePlacementWorkplane(snapshot.placementWorkplane, placementElevation);
|
||||
const sketchPlacementWorkplane = normalizePlacementWorkplane(snapshot.sketchPlacementWorkplane);
|
||||
const nextFingerprint = `${workplaneSettingsFingerprint(workspace, snapGrid)}:${placementElevation}:${placementWorkplaneFingerprint(placementWorkplane)}:${placementWorkplaneFingerprint(sketchPlacementWorkplane)}`;
|
||||
setProjects((current) => {
|
||||
let changed = false;
|
||||
const next = current.map((project) => {
|
||||
@@ -821,7 +857,7 @@ export default function Home() {
|
||||
const currentFingerprint = `${workplaneSettingsFingerprint(
|
||||
normalizeWorkspaceSettings(project.workspace),
|
||||
normalizeSnapGrid(project.snapGrid),
|
||||
)}:${project.placementElevation ?? 0}`;
|
||||
)}:${project.placementElevation ?? 0}:${placementWorkplaneFingerprint(normalizePlacementWorkplane(project.placementWorkplane, project.placementElevation))}:${placementWorkplaneFingerprint(normalizePlacementWorkplane(project.sketchPlacementWorkplane))}`;
|
||||
if (currentFingerprint === nextFingerprint) return project;
|
||||
changed = true;
|
||||
return {
|
||||
@@ -829,6 +865,8 @@ export default function Home() {
|
||||
workspace,
|
||||
snapGrid,
|
||||
placementElevation,
|
||||
placementWorkplane,
|
||||
sketchPlacementWorkplane,
|
||||
updatedAt: version,
|
||||
revision: version,
|
||||
};
|
||||
@@ -876,6 +914,8 @@ export default function Home() {
|
||||
workspace: restored.workspace,
|
||||
snapGrid: restored.snapGrid,
|
||||
placementElevation: restored.placementElevation,
|
||||
placementWorkplane: restored.placementWorkplane,
|
||||
sketchPlacementWorkplane: restored.sketchPlacementWorkplane,
|
||||
sharedProject: sharedProject ? { fileName: sharedProject.fileName, revision: sharedProject.revision } : undefined,
|
||||
};
|
||||
const entry = projectShapeCacheEntry(now, restored.shapes, restored.history, restored.historyIndex, restored.assets);
|
||||
@@ -1153,6 +1193,7 @@ export default function Home() {
|
||||
initialSnap={activeProject?.snapGrid ?? DEFAULT_SNAP_GRID}
|
||||
initialWorkspace={activeProject?.workspace ?? DEFAULT_WORKPLANE_WORKSPACE}
|
||||
initialPlacementElevation={activeProject?.placementElevation ?? 0}
|
||||
initialPlacementWorkplane={activeProject?.placementWorkplane}
|
||||
onHome={openDashboard}
|
||||
onOpenSkfProjectFile={openSkfProjectFromFile}
|
||||
onSaveSharedProject={saveActiveProjectToShared}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { Check, CloudUpload, Download, FolderOpen, X } from "lucide-react";
|
||||
import { Check, CloudUpload, Download, Eye, FolderOpen, X } from "lucide-react";
|
||||
import type manifoldModule from "manifold-3d";
|
||||
import type { ManifoldToplevel } from "manifold-3d";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
@@ -20,6 +20,7 @@ import { manifoldModuleSource } from "@/generated/manifoldModuleSource";
|
||||
import { manifoldWasmBase64 } from "@/generated/manifoldWasmBase64";
|
||||
import { sphereTessellation } from "@/lib/sphereTessellation";
|
||||
import { createGearGeometry } from "@/lib/gearGeometry";
|
||||
import { regularPolygonFootprintScale } from "@/lib/regularPolygonFootprint";
|
||||
import {
|
||||
ToolbarAlignIcon,
|
||||
ToolbarChamferIcon,
|
||||
@@ -44,7 +45,6 @@ import {
|
||||
ToolbarUngroupIcon,
|
||||
ToolbarUndoIcon,
|
||||
ToolbarVectorExportIcon,
|
||||
ToolbarWorkplaneIcon,
|
||||
} from "./icons";
|
||||
import { WorkplaneViewport } from "./WorkplaneViewport";
|
||||
import { SketchWorkspace, type SketchMeasurement, type SketchSelection, type SketchTool } from "./SketchWorkspace";
|
||||
@@ -71,6 +71,7 @@ import { hasOneToOneCadComponentMapping } from "@/lib/cadModifierGroups";
|
||||
import {
|
||||
CAD_MODIFIER_MAX_SHARP_ANGLE,
|
||||
CAD_MODIFIER_REQUEST_TIMEOUT_MS,
|
||||
cadModifierPrepareTimeoutMs,
|
||||
cadModifierTimeoutMessage,
|
||||
cadModifierWorkerFailureMessage,
|
||||
defaultCadModifierTangentChain,
|
||||
@@ -91,6 +92,17 @@ import { importedShapeFromStl, importExtensionSupported } from "@/lib/stlImport"
|
||||
import { importedShapeFromSvg, invalidSvgMeshReason } from "@/lib/svgImport";
|
||||
import { toSvgProjection, type SvgProjectionLayer } from "@/lib/svgExport";
|
||||
import { normalizeSnapGrid, normalizeWorkspaceSettings, workplaneSettingsFingerprint } from "@/lib/workplaneSettings";
|
||||
import {
|
||||
normalizePlacementWorkplane,
|
||||
placementPatchForNewShape,
|
||||
placementWorkplaneCoordinates,
|
||||
placementWorkplaneFromSurface,
|
||||
placementWorkplaneIsBase,
|
||||
translationToWorkplane,
|
||||
type PlacementPoint,
|
||||
type PlacementWorkplane,
|
||||
} from "@/lib/placementWorkplane";
|
||||
import { placeSketchExtrusion } from "@/lib/sketchPlacement";
|
||||
import {
|
||||
SKETCHFORGE_MCP_POLL_MS,
|
||||
SKETCHFORGE_MCP_ROUTE,
|
||||
@@ -104,7 +116,7 @@ import type { AlignAxis, AlignHandleStatus, AlignTarget, GridSize, ProjectAsset,
|
||||
|
||||
export { importedShapeFromStl, importedShapeFromSvg };
|
||||
|
||||
type TopPanel = "import" | "export" | "tips" | "profile" | "settings" | null;
|
||||
type TopPanel = "import" | "export" | "profile" | "settings" | null;
|
||||
type ExportFormat = "stl" | "obj" | "step" | "svg" | "skf";
|
||||
type DirectExportFormat = Exclude<ExportFormat, "step" | "skf">;
|
||||
type SkfHistoryLimit = EditorHistoryExportLimit;
|
||||
@@ -1857,9 +1869,10 @@ function createBooleanWedgeGeometry(width: number, height: number, depth: number
|
||||
function createBooleanPyramidGeometry(width: number, height: number, depth: number, sides = 4) {
|
||||
const count = Math.max(3, Math.round(sides));
|
||||
if (count !== 4) {
|
||||
const radius = Math.min(width, depth) / 2;
|
||||
const geometry = new THREE.ConeGeometry(radius, height, count);
|
||||
geometry.translate(0, height / 2, 0);
|
||||
const footprintScale = regularPolygonFootprintScale(width, depth, count);
|
||||
const geometry = new THREE.ConeGeometry(1, height, count);
|
||||
geometry.scale(footprintScale.x, 1, footprintScale.z);
|
||||
geometry.translate(footprintScale.offsetX, height / 2, footprintScale.offsetZ);
|
||||
return geometry;
|
||||
}
|
||||
|
||||
@@ -2146,6 +2159,63 @@ function meshForShape(shape: WorkplaneShape): MeshData {
|
||||
return transformMesh(raw, shape);
|
||||
}
|
||||
|
||||
function sketchReferenceShapeOnWorkplane(shape: WorkplaneShape, workplane: PlacementWorkplane): WorkplaneShape {
|
||||
const mesh = meshForShape(shape);
|
||||
const projectedVertices = mesh.vertices.map(([x, y, z]) => {
|
||||
const local = placementWorkplaneCoordinates(workplane, { x, y, z });
|
||||
return { x: local.x, y: -local.y, z: local.z };
|
||||
});
|
||||
const minX = Math.min(...projectedVertices.map((vertex) => vertex.x));
|
||||
const maxX = Math.max(...projectedVertices.map((vertex) => vertex.x));
|
||||
const minY = Math.min(...projectedVertices.map((vertex) => vertex.y));
|
||||
const maxY = Math.max(...projectedVertices.map((vertex) => vertex.y));
|
||||
const minZ = Math.min(...projectedVertices.map((vertex) => vertex.z));
|
||||
const maxZ = Math.max(...projectedVertices.map((vertex) => vertex.z));
|
||||
const centerX = (minX + maxX) / 2;
|
||||
const centerY = (minY + maxY) / 2;
|
||||
const centerZ = (minZ + maxZ) / 2;
|
||||
const positions = mesh.faces.flatMap(([a, b, c]) => [a, b, c].flatMap((index) => {
|
||||
const vertex = projectedVertices[index];
|
||||
return [vertex.x - centerX, vertex.y - centerY, vertex.z - centerZ];
|
||||
}));
|
||||
const width = Math.max(0.01, maxX - minX);
|
||||
const depth = Math.max(0.01, maxZ - minZ);
|
||||
const height = Math.max(0.01, maxY - minY);
|
||||
|
||||
return canonicalizeShape({
|
||||
...shape,
|
||||
kind: "mesh",
|
||||
x: centerX,
|
||||
z: centerZ,
|
||||
elevation: 0,
|
||||
size: Math.max(width, depth),
|
||||
width,
|
||||
depth,
|
||||
height,
|
||||
rotation: 0,
|
||||
rotationX: 0,
|
||||
rotationZ: 0,
|
||||
mirrorX: undefined,
|
||||
mirrorY: undefined,
|
||||
mirrorZ: undefined,
|
||||
importedMesh: {
|
||||
positions,
|
||||
baseWidth: width,
|
||||
baseDepth: depth,
|
||||
baseHeight: height,
|
||||
triangleCount: mesh.faces.length,
|
||||
sourceFormat: "json",
|
||||
},
|
||||
groupedShapes: undefined,
|
||||
edgeTreatments: undefined,
|
||||
edgeTreatmentHistory: undefined,
|
||||
cadDisplayEdges: undefined,
|
||||
cadBrep: undefined,
|
||||
cadBrepFrame: undefined,
|
||||
cadPrimitiveFrame: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
function appendMeshData(vertices: Vec3[], faces: [number, number, number][], mesh: MeshData) {
|
||||
const offset = vertices.length;
|
||||
for (let i = 0; i < mesh.vertices.length; i += 1) {
|
||||
@@ -5195,6 +5265,7 @@ export function SketchForgeEditor({
|
||||
initialSnap,
|
||||
initialWorkspace,
|
||||
initialPlacementElevation = 0,
|
||||
initialPlacementWorkplane,
|
||||
onHome,
|
||||
onOpenSkfProjectFile,
|
||||
onSaveSharedProject,
|
||||
@@ -5218,6 +5289,7 @@ export function SketchForgeEditor({
|
||||
initialSnap?: GridSize;
|
||||
initialWorkspace?: WorkplaneWorkspaceSettings;
|
||||
initialPlacementElevation?: number;
|
||||
initialPlacementWorkplane?: PlacementWorkplane;
|
||||
onHome?: () => void;
|
||||
onOpenSkfProjectFile?: (file: File) => Promise<{ ok: boolean; message: string } | void> | { ok: boolean; message: string } | void;
|
||||
onSaveSharedProject?: (request: { exportName: string; bytes: Uint8Array }) => Promise<string>;
|
||||
@@ -5232,9 +5304,18 @@ export function SketchForgeEditor({
|
||||
workspace: WorkplaneWorkspaceSettings;
|
||||
snapGrid: GridSize;
|
||||
placementElevation: number;
|
||||
placementWorkplane: PlacementWorkplane;
|
||||
sketchPlacementWorkplane: PlacementWorkplane;
|
||||
}) => void;
|
||||
onProjectSnapshot?: (snapshot: { image: string; projectId: string; shapes: number }) => void;
|
||||
onProjectWorkspaceChange?: (snapshot: { projectId: string; workspace: WorkplaneWorkspaceSettings; snap: GridSize; placementElevation?: number }) => void;
|
||||
onProjectWorkspaceChange?: (snapshot: {
|
||||
projectId: string;
|
||||
workspace: WorkplaneWorkspaceSettings;
|
||||
snap: GridSize;
|
||||
placementElevation?: number;
|
||||
placementWorkplane?: PlacementWorkplane;
|
||||
sketchPlacementWorkplane?: PlacementWorkplane;
|
||||
}) => void;
|
||||
projectId?: string | null;
|
||||
projectName?: string;
|
||||
projectCreatedAt?: number;
|
||||
@@ -5266,6 +5347,9 @@ export function SketchForgeEditor({
|
||||
const [history, setHistory] = useState<EditorHistoryEntry[]>(() => (initialHistoryStateRef.current as EditorHistoryState).entries);
|
||||
const [historyIndex, setHistoryIndex] = useState(() => (initialHistoryStateRef.current as EditorHistoryState).index);
|
||||
const [placementElevation, setPlacementElevation] = useState(() => Number.isFinite(initialPlacementElevation) ? initialPlacementElevation : 0);
|
||||
const [placementWorkplane, setPlacementWorkplane] = useState<PlacementWorkplane>(
|
||||
() => normalizePlacementWorkplane(initialPlacementWorkplane, initialPlacementElevation),
|
||||
);
|
||||
const [workspaceSettings, setWorkspaceSettings] = useState<WorkplaneWorkspaceSettings>(() => normalizeWorkspaceSettings(initialWorkspace));
|
||||
const [snapGrid, setSnapGrid] = useState<GridSize>(() => normalizeSnapGrid(initialSnap));
|
||||
const [workplaneMode, setWorkplaneMode] = useState(false);
|
||||
@@ -5298,6 +5382,7 @@ export function SketchForgeEditor({
|
||||
const workspaceSettingsRef = useRef(workspaceSettings);
|
||||
const snapGridRef = useRef(snapGrid);
|
||||
const placementElevationRef = useRef(placementElevation);
|
||||
const placementWorkplaneRef = useRef(placementWorkplane);
|
||||
const noticeRef = useRef(notice);
|
||||
const projectInfoRef = useRef({ projectId: projectId ?? null, projectName, projectCreatedAt });
|
||||
const historyIndexRef = useRef(historyIndex);
|
||||
@@ -5309,6 +5394,9 @@ export function SketchForgeEditor({
|
||||
const [projectInteractionActive, setProjectInteractionActive] = useState(false);
|
||||
const [toolbarMode, setToolbarMode] = useState<ToolbarMode>("geometry");
|
||||
const [sketchActive, setSketchActive] = useState(false);
|
||||
const [activeSketchWorkplane, setActiveSketchWorkplane] = useState<PlacementWorkplane>(
|
||||
() => normalizePlacementWorkplane(initialPlacementWorkplane, initialPlacementElevation),
|
||||
);
|
||||
const [sketchOperation, setSketchOperation] = useState<SketchOperation>("extrude");
|
||||
const [sketchRevolveSettings, setSketchRevolveSettings] = useState<SketchRevolveSettings>(() => ({ ...DEFAULT_SKETCH_REVOLVE_SETTINGS }));
|
||||
const [sketchRevolvePreview, setSketchRevolvePreview] = useState<SketchRevolveMesh | null>(null);
|
||||
@@ -5352,7 +5440,7 @@ export function SketchForgeEditor({
|
||||
cadModifierWatchdogRef.current = null;
|
||||
}, []);
|
||||
|
||||
const armCadModifierWatchdog = useCallback((requestId: number, phase: CadModifierRequestPhase) => {
|
||||
const armCadModifierWatchdog = useCallback((requestId: number, phase: CadModifierRequestPhase, timeoutMs = CAD_MODIFIER_REQUEST_TIMEOUT_MS) => {
|
||||
clearCadModifierWatchdog();
|
||||
const timer = window.setTimeout(() => {
|
||||
const active = cadModifierWatchdogRef.current;
|
||||
@@ -5370,7 +5458,7 @@ export function SketchForgeEditor({
|
||||
error: message,
|
||||
} : current);
|
||||
setNotice(message);
|
||||
}, CAD_MODIFIER_REQUEST_TIMEOUT_MS);
|
||||
}, timeoutMs);
|
||||
cadModifierWatchdogRef.current = { requestId, phase, timer };
|
||||
}, [clearCadModifierWatchdog]);
|
||||
|
||||
@@ -5598,6 +5686,10 @@ export function SketchForgeEditor({
|
||||
placementElevationRef.current = placementElevation;
|
||||
}, [placementElevation]);
|
||||
|
||||
useEffect(() => {
|
||||
placementWorkplaneRef.current = placementWorkplane;
|
||||
}, [placementWorkplane]);
|
||||
|
||||
useEffect(() => {
|
||||
noticeRef.current = notice;
|
||||
}, [notice]);
|
||||
@@ -5712,6 +5804,14 @@ export function SketchForgeEditor({
|
||||
: shapes,
|
||||
[alignMode, alignPreview, edgeModifier?.preview, effectiveAlignAnchorId, mirrorMode, mirrorPreviewAxis, selectedIds, selectedShapes, shapes],
|
||||
);
|
||||
const sketchReferenceShapes = useMemo(
|
||||
() => sketchOperation === "revolve" || placementWorkplaneIsBase(activeSketchWorkplane)
|
||||
? shapes
|
||||
: shapes.map((shape) => shape.hidden || shape.id === editingSketchShapeId
|
||||
? shape
|
||||
: sketchReferenceShapeOnWorkplane(shape, activeSketchWorkplane)),
|
||||
[activeSketchWorkplane, editingSketchShapeId, shapes, sketchOperation],
|
||||
);
|
||||
const debugState = useMemo(
|
||||
() =>
|
||||
JSON.stringify({
|
||||
@@ -5828,6 +5928,8 @@ export function SketchForgeEditor({
|
||||
workspace: workspaceSettingsRef.current,
|
||||
snapGrid: snapGridRef.current,
|
||||
placementElevation: placementElevationRef.current,
|
||||
placementWorkplane: placementWorkplaneRef.current,
|
||||
sketchPlacementWorkplane: placementWorkplaneRef.current,
|
||||
});
|
||||
projectSyncTimerRef.current = null;
|
||||
}, 120);
|
||||
@@ -5944,7 +6046,14 @@ export function SketchForgeEditor({
|
||||
if (!projectId || !onProjectWorkspaceChange) {
|
||||
return;
|
||||
}
|
||||
onProjectWorkspaceChange({ projectId, workspace: nextWorkspace, snap: settings.snap, placementElevation });
|
||||
onProjectWorkspaceChange({
|
||||
projectId,
|
||||
workspace: nextWorkspace,
|
||||
snap: settings.snap,
|
||||
placementElevation,
|
||||
placementWorkplane: placementWorkplaneRef.current,
|
||||
sketchPlacementWorkplane: placementWorkplaneRef.current,
|
||||
});
|
||||
},
|
||||
[onProjectWorkspaceChange, placementElevation, projectId],
|
||||
);
|
||||
@@ -5956,8 +6065,10 @@ export function SketchForgeEditor({
|
||||
workspace: workspaceSettingsRef.current,
|
||||
snap: snapGrid,
|
||||
placementElevation,
|
||||
placementWorkplane,
|
||||
sketchPlacementWorkplane: placementWorkplane,
|
||||
});
|
||||
}, [onProjectWorkspaceChange, placementElevation, projectId, snapGrid]);
|
||||
}, [onProjectWorkspaceChange, placementElevation, placementWorkplane, projectId, snapGrid]);
|
||||
|
||||
const commitShapes = useCallback(
|
||||
(next: WorkplaneShape[], nextSelection: string | string[] | null = selectedIds, message?: string) => {
|
||||
@@ -6035,8 +6146,16 @@ export function SketchForgeEditor({
|
||||
[],
|
||||
);
|
||||
|
||||
const beginSketch = useCallback((operation: SketchOperation, profile?: SketchProfile, editingId: string | null = null, revolveSettings?: Partial<SketchRevolveSettings>) => {
|
||||
const beginSketch = useCallback((
|
||||
operation: SketchOperation,
|
||||
profile?: SketchProfile,
|
||||
editingId: string | null = null,
|
||||
revolveSettings?: Partial<SketchRevolveSettings>,
|
||||
workplaneOverride?: PlacementWorkplane,
|
||||
) => {
|
||||
const initial = cloneSketchProfile(profile ?? emptySketchProfile());
|
||||
setWorkplaneMode(false);
|
||||
setActiveSketchWorkplane(normalizePlacementWorkplane(workplaneOverride ?? placementWorkplaneRef.current));
|
||||
setToolbarMode("sketch");
|
||||
setSketchActive(true);
|
||||
setSketchOperation(operation);
|
||||
@@ -6063,7 +6182,34 @@ export function SketchForgeEditor({
|
||||
return;
|
||||
}
|
||||
const operation = selectedShape.sketchOperation ?? (selectedShape.sketchRevolve ? "revolve" : "extrude");
|
||||
beginSketch(operation, selectedShape.sketchProfile, selectedShape.id, selectedShape.sketchRevolve);
|
||||
let editWorkplane: PlacementWorkplane | undefined;
|
||||
if (operation === "extrude") {
|
||||
const quaternion = quaternionForShape(selectedShape);
|
||||
const normal = new THREE.Vector3(0, 1, 0).applyQuaternion(quaternion).normalize();
|
||||
const xAxis = new THREE.Vector3(1, 0, 0).applyQuaternion(quaternion).normalize();
|
||||
const zAxis = new THREE.Vector3(0, 0, 1).applyQuaternion(quaternion).normalize();
|
||||
const points = selectedShape.sketchProfile.points;
|
||||
const profileCenterX = points.length
|
||||
? (Math.min(...points.map((point) => point.x)) + Math.max(...points.map((point) => point.x))) / 2
|
||||
: 0;
|
||||
const profileCenterZ = points.length
|
||||
? (Math.min(...points.map((point) => point.z)) + Math.max(...points.map((point) => point.z))) / 2
|
||||
: 0;
|
||||
const origin = new THREE.Vector3(
|
||||
selectedShape.x,
|
||||
(selectedShape.elevation ?? 0) + selectedShape.height / 2,
|
||||
selectedShape.z,
|
||||
)
|
||||
.addScaledVector(normal, -selectedShape.height / 2)
|
||||
.addScaledVector(xAxis, -profileCenterX)
|
||||
.addScaledVector(zAxis, -profileCenterZ);
|
||||
editWorkplane = placementWorkplaneFromSurface(
|
||||
{ x: origin.x, y: origin.y, z: origin.z },
|
||||
{ x: normal.x, y: normal.y, z: normal.z },
|
||||
{ x: xAxis.x, y: xAxis.y, z: xAxis.z },
|
||||
);
|
||||
}
|
||||
beginSketch(operation, selectedShape.sketchProfile, selectedShape.id, selectedShape.sketchRevolve, editWorkplane);
|
||||
}, [beginSketch, selectedShape, selectedShapes.length]);
|
||||
|
||||
const cancelSketch = useCallback(() => {
|
||||
@@ -6416,9 +6562,12 @@ export function SketchForgeEditor({
|
||||
const height = existing?.height ?? 10;
|
||||
let resolved: WorkplaneShape | null;
|
||||
try {
|
||||
resolved = sketchOperation === "revolve"
|
||||
? await shapeFromRevolvedSketchProfile(sketchProfile, sketchRevolveSettings, existing)
|
||||
: await shapeFromSketchProfile(sketchProfile, height, existing);
|
||||
if (sketchOperation === "revolve") {
|
||||
resolved = await shapeFromRevolvedSketchProfile(sketchProfile, sketchRevolveSettings, existing);
|
||||
} else {
|
||||
const extrusion = await shapeFromSketchProfile(sketchProfile, height, existing);
|
||||
resolved = extrusion ? placeSketchExtrusion(extrusion, activeSketchWorkplane, existing) : null;
|
||||
}
|
||||
} catch (error) {
|
||||
setNotice(error instanceof Error ? error.message : `The sketch profile cannot be ${sketchOperation === "revolve" ? "revolved" : "extruded"} to 3D`);
|
||||
return;
|
||||
@@ -6434,7 +6583,7 @@ export function SketchForgeEditor({
|
||||
setSketchRevolvePreview(null);
|
||||
setEditingSketchShapeId(null);
|
||||
setToolbarMode("geometry");
|
||||
}, [commitShapes, editingSketchShapeId, shapes, sketchOperation, sketchProfile, sketchRevolveSettings]);
|
||||
}, [activeSketchWorkplane, commitShapes, editingSketchShapeId, shapes, sketchOperation, sketchProfile, sketchRevolveSettings]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!projectId) {
|
||||
@@ -6454,7 +6603,9 @@ export function SketchForgeEditor({
|
||||
const nextAssets = dedupeProjectAssets(initialAssets);
|
||||
projectAssetsRef.current = nextAssets;
|
||||
setProjectAssets(nextAssets);
|
||||
setPlacementElevation(Number.isFinite(initialPlacementElevation) ? initialPlacementElevation : 0);
|
||||
const nextPlacementElevation = Number.isFinite(initialPlacementElevation) ? initialPlacementElevation : 0;
|
||||
setPlacementElevation(nextPlacementElevation);
|
||||
setPlacementWorkplane(normalizePlacementWorkplane(initialPlacementWorkplane, nextPlacementElevation));
|
||||
}
|
||||
const incoming = initialShapes.map(canonicalizeShape);
|
||||
const incomingSerialized = projectShapesFingerprint(incoming);
|
||||
@@ -6487,7 +6638,7 @@ export function SketchForgeEditor({
|
||||
setHistory(hydratedHistory.entries);
|
||||
setHistoryIndex(hydratedHistory.index);
|
||||
setNotice("Ready");
|
||||
}, [initialAssets, initialHistory, initialHistoryIndex, initialPlacementElevation, initialShapes, projectId, projectRevision]);
|
||||
}, [initialAssets, initialHistory, initialHistoryIndex, initialPlacementElevation, initialPlacementWorkplane, initialShapes, projectId, projectRevision]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!projectId || !onProjectShapesChange) {
|
||||
@@ -6514,11 +6665,15 @@ export function SketchForgeEditor({
|
||||
}, []);
|
||||
|
||||
const addShape = useCallback(
|
||||
(asset: ShapeAsset, point?: { x: number; z: number; elevation?: number }) => {
|
||||
const nextShape = makeShapeFromAsset(asset, point ?? { x: 0, z: 0, elevation: placementElevation });
|
||||
(asset: ShapeAsset, point?: PlacementPoint) => {
|
||||
const shape = makeShapeFromAsset(asset);
|
||||
const nextShape = {
|
||||
...shape,
|
||||
...placementPatchForNewShape(shape, placementWorkplane, point ?? placementWorkplane.origin),
|
||||
};
|
||||
commitShapes([...shapes, nextShape], nextShape.id, `${asset.name} added`);
|
||||
},
|
||||
[commitShapes, placementElevation, shapes],
|
||||
[commitShapes, placementWorkplane, shapes],
|
||||
);
|
||||
|
||||
const scheduleRevolveShapeUpdate = useCallback((id: string, settings: SketchRevolveSettings) => {
|
||||
@@ -6976,7 +7131,7 @@ export function SketchForgeEditor({
|
||||
return;
|
||||
}
|
||||
cadModifierPrepareRef.current = prepareRequestId;
|
||||
armCadModifierWatchdog(prepareRequestId, "prepare");
|
||||
armCadModifierWatchdog(prepareRequestId, "prepare", cadModifierPrepareTimeoutMs(triangleCount));
|
||||
}, [armCadModifierWatchdog, invalidateCadModifierSession, postCadModifierRequest, selectedShape, selectedShapes.length]);
|
||||
|
||||
const prepareCadModifierForMcp = useCallback(async (shape: WorkplaneShape, sharpAngle: number) => {
|
||||
@@ -7017,7 +7172,7 @@ export function SketchForgeEditor({
|
||||
parts,
|
||||
sharpAngle,
|
||||
suppressTreatmentDetailEdges: appliedEdgeTreatmentCount > 0,
|
||||
}, transfer);
|
||||
}, transfer, cadModifierPrepareTimeoutMs(triangleCount));
|
||||
if (response.type !== "ready") {
|
||||
throw new Error("The CAD worker did not return an edge list");
|
||||
}
|
||||
@@ -7313,12 +7468,15 @@ export function SketchForgeEditor({
|
||||
return;
|
||||
}
|
||||
const selected = new Set(selectedIds);
|
||||
const normal = placementWorkplane.normal;
|
||||
commitShapes(
|
||||
shapes.map((shape) =>
|
||||
selected.has(shape.id) && !shape.locked
|
||||
? {
|
||||
...shape,
|
||||
elevation: Math.max(0, Math.min(180, (shape.elevation ?? 0) + delta)),
|
||||
x: cleanNearZero(shape.x + normal.x * delta),
|
||||
z: cleanNearZero(shape.z + normal.z * delta),
|
||||
elevation: cleanNearZero((shape.elevation ?? 0) + normal.y * delta),
|
||||
}
|
||||
: shape,
|
||||
),
|
||||
@@ -7326,7 +7484,7 @@ export function SketchForgeEditor({
|
||||
delta > 0 ? "Moved selection up" : "Moved selection down",
|
||||
);
|
||||
},
|
||||
[commitShapes, hasSelection, selectedIds, shapes],
|
||||
[commitShapes, hasSelection, placementWorkplane, selectedIds, shapes],
|
||||
);
|
||||
|
||||
const dropSelectedToWorkplane = useCallback(() => {
|
||||
@@ -7336,23 +7494,52 @@ export function SketchForgeEditor({
|
||||
}
|
||||
const selected = new Set(selectedIds);
|
||||
commitShapes(
|
||||
shapes.map((shape) => (selected.has(shape.id) && !shape.locked ? { ...shape, ...dropPatchForShape(shape, placementElevation) } : shape)),
|
||||
shapes.map((shape) => {
|
||||
if (!selected.has(shape.id) || shape.locked) return shape;
|
||||
const translation = translationToWorkplane(
|
||||
placementWorkplane,
|
||||
meshForShape(shape).vertices.map(([x, y, z]) => ({ x, y, z })),
|
||||
);
|
||||
return {
|
||||
...shape,
|
||||
x: cleanNearZero(shape.x + translation.x),
|
||||
z: cleanNearZero(shape.z + translation.z),
|
||||
elevation: cleanNearZero((shape.elevation ?? 0) + translation.y),
|
||||
};
|
||||
}),
|
||||
selectedIds,
|
||||
placementElevation === 0 ? "Dropped selection to the workplane" : `Dropped selection to ${placementElevation.toFixed(2)} mm workplane`,
|
||||
"Dropped selection to the workplane",
|
||||
);
|
||||
}, [commitShapes, hasSelection, placementElevation, selectedIds, shapes]);
|
||||
}, [commitShapes, hasSelection, placementWorkplane, selectedIds, shapes]);
|
||||
|
||||
const activateWorkplaneTool = useCallback(() => {
|
||||
setWorkplaneMode((active) => {
|
||||
const next = !active;
|
||||
setNotice(next ? "Workplane tool: click a shape top or empty grid" : "Workplane tool cancelled");
|
||||
setNotice(next ? "Workplane tool: click a face or empty grid; hold Shift to reverse" : "Workplane tool cancelled");
|
||||
return next;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const setPlacementWorkplane = useCallback((elevation: number, source: "shape" | "base") => {
|
||||
setPlacementElevation(elevation);
|
||||
setNotice(source === "shape" ? `Workplane set to ${elevation.toFixed(2)} mm` : "Workplane reset to base");
|
||||
const setActivePlacementWorkplane = useCallback((next: PlacementWorkplane, source: "shape" | "base") => {
|
||||
placementWorkplaneRef.current = next;
|
||||
setPlacementWorkplane(next);
|
||||
const horizontalElevation = Math.abs(next.normal.x) < 1e-6
|
||||
&& Math.abs(next.normal.y - 1) < 1e-6
|
||||
&& Math.abs(next.normal.z) < 1e-6
|
||||
? next.origin.y
|
||||
: 0;
|
||||
setPlacementElevation(horizontalElevation);
|
||||
setNotice(source === "shape"
|
||||
? "Workplane set to selected face"
|
||||
: placementWorkplaneIsBase(next) ? "Workplane reset to base" : "Workplane updated");
|
||||
}, []);
|
||||
|
||||
const setViewportPlacementWorkplane = useCallback((next: PlacementWorkplane, source: "shape" | "base") => {
|
||||
setActivePlacementWorkplane(next, source);
|
||||
}, [setActivePlacementWorkplane]);
|
||||
|
||||
const closeViewportWorkplaneMode = useCallback((active: boolean) => {
|
||||
setWorkplaneMode(active);
|
||||
}, []);
|
||||
|
||||
const groupSelected = useCallback(async () => {
|
||||
@@ -8145,6 +8332,8 @@ export function SketchForgeEditor({
|
||||
workspace: workspaceSettingsRef.current,
|
||||
snapGrid,
|
||||
placementElevation,
|
||||
placementWorkplane,
|
||||
sketchPlacementWorkplane: placementWorkplane,
|
||||
});
|
||||
if (target === "shared" && onSaveSharedProject) {
|
||||
setNotice(await onSaveSharedProject({ exportName: exportName.trim() || projectName, bytes }));
|
||||
@@ -8158,7 +8347,7 @@ export function SketchForgeEditor({
|
||||
} finally {
|
||||
setSkfExporting(false);
|
||||
}
|
||||
}, [onSaveSharedProject, placementElevation, projectCreatedAt, projectModifiedAt, projectName, skfExporting, snapGrid]);
|
||||
}, [onSaveSharedProject, placementElevation, placementWorkplane, projectCreatedAt, projectModifiedAt, projectName, skfExporting, snapGrid]);
|
||||
|
||||
const clearDesign = useCallback(() => {
|
||||
commitShapes([], [], "New empty design");
|
||||
@@ -8336,13 +8525,19 @@ export function SketchForgeEditor({
|
||||
return;
|
||||
}
|
||||
const selected = new Set(selectedIds);
|
||||
const translation = {
|
||||
x: placementWorkplane.xAxis.x * deltaX + placementWorkplane.zAxis.x * deltaZ,
|
||||
y: placementWorkplane.xAxis.y * deltaX + placementWorkplane.zAxis.y * deltaZ,
|
||||
z: placementWorkplane.xAxis.z * deltaX + placementWorkplane.zAxis.z * deltaZ,
|
||||
};
|
||||
commitShapes(
|
||||
shapes.map((shape) =>
|
||||
selected.has(shape.id) && !shape.locked
|
||||
? {
|
||||
...shape,
|
||||
x: Math.max(-110, Math.min(110, shape.x + deltaX)),
|
||||
z: Math.max(-110, Math.min(110, shape.z + deltaZ)),
|
||||
x: cleanNearZero(shape.x + translation.x),
|
||||
z: cleanNearZero(shape.z + translation.z),
|
||||
elevation: cleanNearZero((shape.elevation ?? 0) + translation.y),
|
||||
}
|
||||
: shape,
|
||||
),
|
||||
@@ -8350,7 +8545,7 @@ export function SketchForgeEditor({
|
||||
`Moved ${selectedShapes.length} shape${selectedShapes.length === 1 ? "" : "s"}`,
|
||||
);
|
||||
},
|
||||
[commitShapes, hasSelection, selectedIds, selectedShapes.length, shapes],
|
||||
[commitShapes, hasSelection, placementWorkplane, selectedIds, selectedShapes.length, shapes],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -8552,6 +8747,7 @@ export function SketchForgeEditor({
|
||||
toolbarMode={toolbarMode}
|
||||
onToolbarModeChange={(mode) => {
|
||||
setToolbarMode(mode);
|
||||
setWorkplaneMode(false);
|
||||
setTopPanel(null);
|
||||
setMenuOpen(false);
|
||||
}}
|
||||
@@ -8562,6 +8758,8 @@ export function SketchForgeEditor({
|
||||
canUngroup={selectedShapes.some((shape) => Boolean(shape.groupedShapes?.length))}
|
||||
hasClipboard={clipboard.length > 0 || systemClipboardSupported}
|
||||
hasSelection={hasSelection}
|
||||
hiddenShapeCount={shapes.filter((shape) => shape.hidden).length}
|
||||
selectionHidden={hasSelection && selectedShapes.every((shape) => shape.hidden)}
|
||||
alignMode={alignMode}
|
||||
canAlign={selectedShapes.length > 1}
|
||||
canEdgeModify={selectedShapes.length === 1 && Boolean(selectedShape && !selectedShape.locked && !selectedShape.hole)}
|
||||
@@ -8601,15 +8799,10 @@ export function SketchForgeEditor({
|
||||
onPaste={pasteShape}
|
||||
onRedo={redo}
|
||||
onSnap={snapSelected}
|
||||
onTips={() => {
|
||||
setTopPanel(topPanel === "tips" ? null : "tips");
|
||||
setMenuOpen(false);
|
||||
}}
|
||||
onShowHidden={showHidden}
|
||||
onToggleHidden={toggleHidden}
|
||||
onUngroup={ungroupSelected}
|
||||
onUndo={undo}
|
||||
onWorkplaneTool={activateWorkplaneTool}
|
||||
workplaneMode={workplaneMode}
|
||||
onTopPanel={(panel) => {
|
||||
setTopPanel((current) => (current === panel ? null : panel));
|
||||
setMenuOpen(false);
|
||||
@@ -8626,7 +8819,7 @@ export function SketchForgeEditor({
|
||||
profile={sketchProfile}
|
||||
operation={sketchOperation}
|
||||
revolvePreviewPositions={sketchRevolvePreview?.positions ?? null}
|
||||
referenceShapes={shapes.filter((shape) => shape.id !== editingSketchShapeId)}
|
||||
referenceShapes={sketchReferenceShapes.filter((shape) => shape.id !== editingSketchShapeId)}
|
||||
tool={sketchTool}
|
||||
activePointId={sketchActivePointId}
|
||||
selected={sketchSelection}
|
||||
@@ -8671,7 +8864,7 @@ export function SketchForgeEditor({
|
||||
alignReferenceShapes={shapes}
|
||||
mirrorMode={mirrorMode}
|
||||
mirrorReferenceShapes={shapes}
|
||||
placementElevation={placementElevation}
|
||||
placementWorkplane={placementWorkplane}
|
||||
workplaneMode={workplaneMode}
|
||||
initialSnap={snapGrid}
|
||||
initialWorkspace={workspaceSettings}
|
||||
@@ -8685,14 +8878,15 @@ export function SketchForgeEditor({
|
||||
onMirrorPreviewClear={clearMirrorPreview}
|
||||
onMirrorSelection={mirrorSelectionAcross}
|
||||
onSelectShape={selectShape}
|
||||
onSetPlacementElevation={setPlacementWorkplane}
|
||||
onSetPlacementWorkplane={setViewportPlacementWorkplane}
|
||||
onToggleWorkplaneTool={activateWorkplaneTool}
|
||||
onInteractionActiveChange={updateProjectInteractionActive}
|
||||
onEditSketch={beginSketchEdit}
|
||||
canSeparateParts={canSeparateSelectedParts}
|
||||
onSeparateParts={separateSelectedParts}
|
||||
onUpdateShape={updateShape}
|
||||
onWorkspaceSettingsChange={updateProjectWorkspaceSettings}
|
||||
onWorkplaneModeChange={setWorkplaneMode}
|
||||
onWorkplaneModeChange={closeViewportWorkplaneMode}
|
||||
modifierActive={Boolean(edgeModifier)}
|
||||
modifierPreviewActive={Boolean(edgeModifier?.preview)}
|
||||
modifierEdges={edgeModifier?.edges.filter((edge) => modifierAvailableEdgeIds.includes(edge.id)) ?? []}
|
||||
@@ -8862,6 +9056,8 @@ function SecondaryToolbar({
|
||||
canUndo,
|
||||
hasClipboard,
|
||||
hasSelection,
|
||||
hiddenShapeCount,
|
||||
selectionHidden,
|
||||
mirrorMode,
|
||||
sketchActive,
|
||||
sketchOperation,
|
||||
@@ -8891,12 +9087,10 @@ function SecondaryToolbar({
|
||||
onPaste,
|
||||
onRedo,
|
||||
onSnap,
|
||||
onTips,
|
||||
onShowHidden,
|
||||
onToggleHidden,
|
||||
onUngroup,
|
||||
onUndo,
|
||||
onWorkplaneTool,
|
||||
workplaneMode,
|
||||
onTopPanel,
|
||||
onAddShape,
|
||||
}: {
|
||||
@@ -8913,6 +9107,8 @@ function SecondaryToolbar({
|
||||
canUndo: boolean;
|
||||
hasClipboard: boolean;
|
||||
hasSelection: boolean;
|
||||
hiddenShapeCount: number;
|
||||
selectionHidden: boolean;
|
||||
mirrorMode: boolean;
|
||||
sketchActive: boolean;
|
||||
sketchOperation: SketchOperation;
|
||||
@@ -8942,23 +9138,25 @@ function SecondaryToolbar({
|
||||
onPaste: () => void;
|
||||
onRedo: () => void;
|
||||
onSnap: () => void;
|
||||
onTips: () => void;
|
||||
onShowHidden: () => void;
|
||||
onToggleHidden: () => void;
|
||||
onUngroup: () => void;
|
||||
onUndo: () => void;
|
||||
onWorkplaneTool: () => void;
|
||||
workplaneMode: boolean;
|
||||
onTopPanel: (panel: TopPanel) => void;
|
||||
onAddShape: (shape: ShapeAsset) => void;
|
||||
}) {
|
||||
const [shapesOpen, setShapesOpen] = useState(false);
|
||||
const [sketchCreateOpen, setSketchCreateOpen] = useState(false);
|
||||
const [visibilityOpen, setVisibilityOpen] = useState(false);
|
||||
const [visibilityMenuPosition, setVisibilityMenuPosition] = useState({ top: 0, left: 0 });
|
||||
const sketchCreateMenuRef = useRef<HTMLDivElement>(null);
|
||||
const visibilityMenuRef = useRef<HTMLDivElement>(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);
|
||||
setVisibilityOpen(false);
|
||||
onTopPanel(null);
|
||||
onToolbarModeChange(mode);
|
||||
};
|
||||
@@ -8988,6 +9186,51 @@ function SecondaryToolbar({
|
||||
useEffect(() => {
|
||||
if (sketchActive) setSketchCreateOpen(false);
|
||||
}, [sketchActive]);
|
||||
useEffect(() => {
|
||||
if (!visibilityOpen) return;
|
||||
const closeOnPointerDown = (event: PointerEvent) => {
|
||||
if (!visibilityMenuRef.current?.contains(event.target as Node)) setVisibilityOpen(false);
|
||||
};
|
||||
const closeOnEscape = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") setVisibilityOpen(false);
|
||||
};
|
||||
const closeOnViewportChange = () => setVisibilityOpen(false);
|
||||
window.addEventListener("pointerdown", closeOnPointerDown);
|
||||
window.addEventListener("keydown", closeOnEscape);
|
||||
window.addEventListener("resize", closeOnViewportChange);
|
||||
window.addEventListener("scroll", closeOnViewportChange, true);
|
||||
return () => {
|
||||
window.removeEventListener("pointerdown", closeOnPointerDown);
|
||||
window.removeEventListener("keydown", closeOnEscape);
|
||||
window.removeEventListener("resize", closeOnViewportChange);
|
||||
window.removeEventListener("scroll", closeOnViewportChange, true);
|
||||
};
|
||||
}, [visibilityOpen]);
|
||||
const toggleVisibilityMenu = () => {
|
||||
if (visibilityOpen) {
|
||||
setVisibilityOpen(false);
|
||||
return;
|
||||
}
|
||||
const triggerBounds = visibilityMenuRef.current?.getBoundingClientRect();
|
||||
if (triggerBounds) {
|
||||
const viewportGutter = 12;
|
||||
const menuWidth = Math.min(276, Math.max(0, window.innerWidth - viewportGutter * 2));
|
||||
setVisibilityMenuPosition({
|
||||
top: triggerBounds.bottom + 8,
|
||||
left: Math.max(
|
||||
viewportGutter,
|
||||
Math.min(
|
||||
triggerBounds.left + triggerBounds.width / 2 - menuWidth / 2,
|
||||
window.innerWidth - menuWidth - viewportGutter,
|
||||
),
|
||||
),
|
||||
});
|
||||
}
|
||||
setShapesOpen(false);
|
||||
setSketchCreateOpen(false);
|
||||
onTopPanel(null);
|
||||
setVisibilityOpen(true);
|
||||
};
|
||||
const leftTools = [
|
||||
{ label: "Copy", icon: ToolbarCopyIcon, action: onCopy, enabled: hasSelection },
|
||||
{ label: "Paste", icon: ToolbarPasteIcon, action: onPaste, enabled: hasClipboard },
|
||||
@@ -8997,8 +9240,15 @@ function SecondaryToolbar({
|
||||
{ label: "Redo", icon: ToolbarRedoIcon, action: onRedo, enabled: canRedo },
|
||||
];
|
||||
const visibilityTools = [
|
||||
{ label: "Hide selected", icon: ToolbarHideSelectedIcon, action: onToggleHidden, enabled: hasSelection },
|
||||
{ label: "Visibility options", icon: ToolbarCaretDownIcon, action: onTips, enabled: hasSelection },
|
||||
{
|
||||
label: selectionHidden ? "Show selected" : "Hide selected",
|
||||
icon: ToolbarHideSelectedIcon,
|
||||
action: () => {
|
||||
setVisibilityOpen(false);
|
||||
onToggleHidden();
|
||||
},
|
||||
enabled: hasSelection,
|
||||
},
|
||||
];
|
||||
const combineTools = [
|
||||
{ label: "Group", icon: ToolbarGroupIcon, action: onGroup, enabled: canGroup },
|
||||
@@ -9013,7 +9263,6 @@ function SecondaryToolbar({
|
||||
{ label: "Fillet", icon: ToolbarFilletIcon, action: onFillet, enabled: canEdgeModify, active: edgeModifierKind === "fillet" },
|
||||
];
|
||||
const arrangeTools = [
|
||||
{ label: "Workplane", icon: ToolbarWorkplaneIcon, action: onWorkplaneTool, enabled: true, active: workplaneMode },
|
||||
{ label: "Drop to workplane", icon: ToolbarDropToWorkplaneIcon, action: onDropToWorkplane, enabled: hasSelection },
|
||||
];
|
||||
const renderToolButton = (tool: (typeof leftTools)[number] | (typeof visibilityTools)[number] | (typeof combineTools)[number] | (typeof modifyTools)[number] | (typeof arrangeTools)[number]) => {
|
||||
@@ -9059,7 +9308,10 @@ function SecondaryToolbar({
|
||||
className={`shape-menu-trigger ${shapesOpen ? "active" : ""}`}
|
||||
aria-label="Add shape"
|
||||
aria-expanded={shapesOpen}
|
||||
onClick={() => setShapesOpen((value) => !value)}
|
||||
onClick={() => {
|
||||
setVisibilityOpen(false);
|
||||
setShapesOpen((value) => !value);
|
||||
}}
|
||||
>
|
||||
<ToolbarShapeAddIcon />
|
||||
</button>
|
||||
@@ -9138,9 +9390,49 @@ function SecondaryToolbar({
|
||||
</div>
|
||||
<div className="toolbar-spacer" />
|
||||
<div className="tool-group right">
|
||||
<div className="toolbar-section compact">
|
||||
<div className="toolbar-section compact toolbar-visibility-section" ref={visibilityMenuRef}>
|
||||
<div className="toolbar-section-label">Visibility</div>
|
||||
<div className="toolbar-section-tools">{visibilityTools.map(renderToolButton)}</div>
|
||||
<div className="toolbar-section-tools">
|
||||
{visibilityTools.map(renderToolButton)}
|
||||
<button
|
||||
className={`toolbar-icon visibility-menu-trigger ${visibilityOpen ? "active" : ""}`}
|
||||
type="button"
|
||||
aria-label="Visibility options"
|
||||
title="Visibility options"
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={visibilityOpen}
|
||||
onClick={toggleVisibilityMenu}
|
||||
>
|
||||
<ToolbarCaretDownIcon />
|
||||
</button>
|
||||
</div>
|
||||
{visibilityOpen ? (
|
||||
<div
|
||||
className="visibility-dropdown"
|
||||
role="menu"
|
||||
aria-label="Visibility options"
|
||||
style={visibilityMenuPosition}
|
||||
>
|
||||
<button
|
||||
className="visibility-dropdown-action"
|
||||
type="button"
|
||||
role="menuitem"
|
||||
disabled={hiddenShapeCount === 0}
|
||||
onClick={() => {
|
||||
setVisibilityOpen(false);
|
||||
onShowHidden();
|
||||
}}
|
||||
>
|
||||
<Eye size={20} aria-hidden="true" />
|
||||
<strong>{hiddenShapeCount === 0 ? "Nothing hidden" : `Show all hidden (${hiddenShapeCount})`}</strong>
|
||||
</button>
|
||||
<div className="visibility-dropdown-help">
|
||||
<span>Eye again: selected</span>
|
||||
<span aria-hidden="true">·</span>
|
||||
<span><kbd>Ctrl/Cmd</kbd> + <kbd>Shift</kbd> + <kbd>H</kbd>: all</span>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="toolbar-section">
|
||||
<div className="toolbar-section-label">Combine</div>
|
||||
@@ -9353,11 +9645,9 @@ function TopActionPanel({
|
||||
? "Profile"
|
||||
: panel === "settings"
|
||||
? "Settings"
|
||||
: panel === "tips"
|
||||
? "Tips"
|
||||
: panel === "export"
|
||||
? "Export"
|
||||
: "Import";
|
||||
: panel === "export"
|
||||
? "Export"
|
||||
: "Import";
|
||||
|
||||
const exportDetails: Record<ExportFormat, { label: string; description: string; note: string }> = {
|
||||
stl: {
|
||||
@@ -9544,11 +9834,6 @@ function TopActionPanel({
|
||||
</footer>
|
||||
</div>
|
||||
) : null}
|
||||
{panel === "tips" ? (
|
||||
<div className="top-action-body">
|
||||
<p>Click a shape to select it. Use the inspector for dimensions, rotation, solid/hole, color, duplicate, and delete.</p>
|
||||
</div>
|
||||
) : null}
|
||||
{panel === "settings" ? (
|
||||
<div className="top-action-body">
|
||||
<p>Workspace preferences</p>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,115 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState, type CSSProperties, type KeyboardEvent, type PointerEvent } from "react";
|
||||
import type { MoveDimensionAxis, MoveDimensionOverlayData } from "@/lib/moveDimensionLines";
|
||||
|
||||
export function MoveDimensionOverlay({
|
||||
overlay,
|
||||
active,
|
||||
onCommit,
|
||||
}: {
|
||||
overlay: MoveDimensionOverlayData;
|
||||
active: boolean;
|
||||
onCommit: (axis: MoveDimensionAxis, value: string) => void;
|
||||
}) {
|
||||
const [editing, setEditing] = useState<{ axis: MoveDimensionAxis; value: string } | null>(null);
|
||||
const nextEditingAxisRef = useRef<MoveDimensionAxis | null>(null);
|
||||
const cancelEditRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (active) {
|
||||
setEditing(null);
|
||||
}
|
||||
}, [active]);
|
||||
|
||||
const stopPointerPropagation = (event: PointerEvent<HTMLElement>) => {
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
event.currentTarget.blur();
|
||||
} else if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
cancelEditRef.current = true;
|
||||
event.currentTarget.blur();
|
||||
} else if (event.key === "Tab" && overlay.lines.length > 1) {
|
||||
event.preventDefault();
|
||||
const currentIndex = overlay.lines.findIndex((line) => line.axis === editing?.axis);
|
||||
const direction = event.shiftKey ? -1 : 1;
|
||||
const nextIndex = (currentIndex + direction + overlay.lines.length) % overlay.lines.length;
|
||||
nextEditingAxisRef.current = overlay.lines[nextIndex].axis;
|
||||
event.currentTarget.blur();
|
||||
}
|
||||
};
|
||||
|
||||
const styleForLine = (line: MoveDimensionOverlayData["lines"][number]) => ({
|
||||
"--overlay-x": `${line.labelX}px`,
|
||||
"--overlay-y": `${line.labelY}px`,
|
||||
}) as CSSProperties;
|
||||
|
||||
return (
|
||||
<div className={`move-dimension-overlay ${active ? "active" : "settled"}`} aria-label="Movement dimensions">
|
||||
{overlay.lines.map((line) => {
|
||||
if (editing?.axis === line.axis) {
|
||||
return (
|
||||
<input
|
||||
key={`edit-${line.axis}`}
|
||||
className="dimension-input move-dimension-input"
|
||||
aria-label={`${line.axis.toUpperCase()} movement`}
|
||||
value={editing.value}
|
||||
autoFocus
|
||||
inputMode="decimal"
|
||||
spellCheck={false}
|
||||
style={styleForLine(line)}
|
||||
onChange={(event) => setEditing({ axis: line.axis, value: event.target.value })}
|
||||
onBlur={() => {
|
||||
const nextAxis = nextEditingAxisRef.current;
|
||||
nextEditingAxisRef.current = null;
|
||||
if (!cancelEditRef.current) {
|
||||
onCommit(line.axis, editing.value);
|
||||
}
|
||||
cancelEditRef.current = false;
|
||||
const nextLine = nextAxis ? overlay.lines.find((candidate) => candidate.axis === nextAxis) : null;
|
||||
setEditing(nextLine ? { axis: nextLine.axis, value: nextLine.label } : null);
|
||||
}}
|
||||
onKeyDown={handleKeyDown}
|
||||
onPointerDown={stopPointerPropagation}
|
||||
onContextMenu={(event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return active ? (
|
||||
<span
|
||||
key={line.axis}
|
||||
className="dimension-label move-dimension-value"
|
||||
style={styleForLine(line)}
|
||||
>
|
||||
{line.label}
|
||||
</span>
|
||||
) : (
|
||||
<button
|
||||
key={line.axis}
|
||||
className="dimension-label move-dimension-value"
|
||||
type="button"
|
||||
aria-label={`${line.axis.toUpperCase()} movement`}
|
||||
style={styleForLine(line)}
|
||||
onClick={() => setEditing({ axis: line.axis, value: line.label })}
|
||||
onPointerDown={stopPointerPropagation}
|
||||
onContextMenu={(event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}}
|
||||
>
|
||||
{line.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
gearToothPitch,
|
||||
} from "@/lib/gearGeometry";
|
||||
import { displayStepFromMillimeters, displayToMillimeters, formatMeasurementNumber, lengthDisplayUnit, millimetersToDisplay, parseMeasurementInput } from "@/lib/measurementUnits";
|
||||
import { fallbackSolidColor, resizedShapeSize, shapeDepth, shapeWidth } from "@/lib/workplaneShapes";
|
||||
import { resizedShapeSize, shapeDepth, shapeWidth } from "@/lib/workplaneShapes";
|
||||
import { normalizeSketchRevolveSettings } from "@/lib/sketchRevolve";
|
||||
import type { GearType, GridSize, MeasurementAccuracy, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
|
||||
|
||||
@@ -343,7 +343,7 @@ export function ShapeInspector({
|
||||
onSeparateParts?: () => void;
|
||||
onInteractionActiveChange?: (active: boolean) => void;
|
||||
}) {
|
||||
const solidColor = shape.hole ? fallbackSolidColor(shape) : shape.color;
|
||||
const solidColor = shape.color;
|
||||
const locked = Boolean(shape.locked);
|
||||
const properties = getShapeProperties(shape, onUpdate);
|
||||
const gearType = shape.kind === "gear" ? normalizeGearType(shape.gearType) : null;
|
||||
@@ -427,7 +427,7 @@ export function ShapeInspector({
|
||||
<button
|
||||
className={shape.hole ? "active hole-choice" : "hole-choice"}
|
||||
onClick={() => {
|
||||
onUpdate({ hole: true, color: "#b8c2cc" });
|
||||
onUpdate({ hole: true });
|
||||
setColorOpen(false);
|
||||
}}
|
||||
disabled={locked}
|
||||
|
||||
@@ -204,7 +204,11 @@ export function TransformOverlay({
|
||||
<button
|
||||
key={handle.key}
|
||||
className={`transform-handle ${handle.className}`}
|
||||
style={{ "--overlay-x": `${handle.x}px`, "--overlay-y": `${handle.y}px` } as CSSProperties}
|
||||
style={{
|
||||
"--overlay-x": `${handle.x}px`,
|
||||
"--overlay-y": `${handle.y}px`,
|
||||
"--transform-handle-angle": `${handle.angle ?? 0}deg`,
|
||||
} as CSSProperties}
|
||||
title={handle.title}
|
||||
onPointerEnter={(event) => {
|
||||
if ((event.buttons & 4) !== 0) {
|
||||
|
||||
@@ -48,18 +48,22 @@ export function WorkspaceSettingsModal({
|
||||
workspace,
|
||||
snap,
|
||||
themePreference,
|
||||
moveDimensionsEnabled,
|
||||
onWorkspaceChange,
|
||||
onSnapChange,
|
||||
onThemePreferenceChange,
|
||||
onMoveDimensionsEnabledChange,
|
||||
onMakeDefault,
|
||||
onClose,
|
||||
}: {
|
||||
workspace: WorkspaceSettings;
|
||||
snap: GridSize;
|
||||
themePreference: AppThemePreference;
|
||||
moveDimensionsEnabled: boolean;
|
||||
onWorkspaceChange: (next: WorkspaceSettings) => void;
|
||||
onSnapChange: (next: GridSize) => void;
|
||||
onThemePreferenceChange?: (preference: AppThemePreference) => void;
|
||||
onMoveDimensionsEnabledChange: (enabled: boolean) => void;
|
||||
onMakeDefault: () => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
@@ -193,6 +197,11 @@ export function WorkspaceSettingsModal({
|
||||
</select>
|
||||
</label>
|
||||
<p className="workspace-global-note">Theme applies across SketchForge and all projects.</p>
|
||||
<WorkspaceToggle
|
||||
label="Show movement dimensions"
|
||||
checked={moveDimensionsEnabled}
|
||||
onChange={onMoveDimensionsEnabledChange}
|
||||
/>
|
||||
<WorkspaceToggle label="Show shadows" checked={workspace.showShadows} onChange={(showShadows) => patchWorkspace({ showShadows })} />
|
||||
<WorkspaceToggle
|
||||
label="Cruise when adding new shapes"
|
||||
@@ -367,7 +376,7 @@ export function WorkspaceSettingsModal({
|
||||
</label>
|
||||
) : null}
|
||||
<p className="workspace-history-note">
|
||||
Unlimited is the default. Lower limits permanently discard older Undo states from this project.
|
||||
100 actions is the default. Lower limits permanently discard older Undo states from this project.
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -45,7 +45,7 @@ export type TransformOverlayState = {
|
||||
width: number;
|
||||
height: number;
|
||||
guides: Array<{ x1: number; y1: number; x2: number; y2: number }>;
|
||||
handles: Array<{ key: string; className: string; kind: TransformHandleKind; x: number; y: number; title: string }>;
|
||||
handles: Array<{ key: string; className: string; kind: TransformHandleKind; x: number; y: number; title: string; angle?: number }>;
|
||||
rotateHandles: Array<{ key: string; className: string; x: number; y: number; angle: number }>;
|
||||
dimensions: Record<string, DimensionMark[]>;
|
||||
rotationWheel: RotationWheelView | null;
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { CadModifierEdge } from "@/lib/cadModifierTypes";
|
||||
|
||||
export const CAD_MODIFIER_RUNTIME_BASE = "/occt";
|
||||
export const CAD_MODIFIER_REQUEST_TIMEOUT_MS = 30_000;
|
||||
export const CAD_MODIFIER_MAX_PREPARE_TIMEOUT_MS = 180_000;
|
||||
export const CAD_MODIFIER_MAX_SHARP_ANGLE = 90;
|
||||
|
||||
export type CadModifierRequestPhase = "prepare" | "preview";
|
||||
@@ -62,11 +63,23 @@ export function edgeModifierSelectionStatus(prepared: boolean, selectedCount: nu
|
||||
return prepared ? `${selectedCount} of ${availableCount} sharp edges selected` : "Preparing edges\u2026";
|
||||
}
|
||||
|
||||
export function cadModifierPrepareTimeoutMs(meshTriangleCount: number) {
|
||||
if (!Number.isFinite(meshTriangleCount) || meshTriangleCount <= 0) {
|
||||
return CAD_MODIFIER_REQUEST_TIMEOUT_MS;
|
||||
}
|
||||
const normalizedTriangleCount = Math.max(0, Math.floor(meshTriangleCount));
|
||||
const meshPreparationBudget = 45_000 + normalizedTriangleCount * 0.75;
|
||||
return Math.min(
|
||||
CAD_MODIFIER_MAX_PREPARE_TIMEOUT_MS,
|
||||
Math.max(60_000, Math.ceil(meshPreparationBudget)),
|
||||
);
|
||||
}
|
||||
|
||||
export function cadModifierTimeoutMessage(phase: CadModifierRequestPhase) {
|
||||
if (phase === "preview") {
|
||||
return "The edge preview timed out. Cancel the tool and try again.";
|
||||
}
|
||||
return "Edge preparation timed out. Update to Firefox 121+, Chrome/Brave 114+, or Safari 17.2+, then try again.";
|
||||
return "Edge preparation timed out. This mesh needs more CAD processing than the interactive limit allows. Try a repaired or lower-detail STL.";
|
||||
}
|
||||
|
||||
export function cadModifierWorkerFailureMessage() {
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
export type MoveDimensionAxis = "x" | "z";
|
||||
|
||||
export type MoveDimensionScreenPoint = {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
|
||||
export type MoveDimensionLine = {
|
||||
axis: MoveDimensionAxis;
|
||||
value: number;
|
||||
label: string;
|
||||
x1: number;
|
||||
y1: number;
|
||||
x2: number;
|
||||
y2: number;
|
||||
labelX: number;
|
||||
labelY: number;
|
||||
};
|
||||
|
||||
export type MoveDimensionGuide = {
|
||||
axis: MoveDimensionAxis;
|
||||
x1: number;
|
||||
y1: number;
|
||||
x2: number;
|
||||
y2: number;
|
||||
};
|
||||
|
||||
export type MoveDimensionOverlayData = {
|
||||
width: number;
|
||||
height: number;
|
||||
lines: MoveDimensionLine[];
|
||||
guides: MoveDimensionGuide[];
|
||||
};
|
||||
|
||||
type MoveDimensionWorldPoint = {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
};
|
||||
|
||||
type CreateMoveDimensionOverlayOptions = {
|
||||
originX: number;
|
||||
originZ: number;
|
||||
planeY: number;
|
||||
deltaX: number;
|
||||
deltaZ: number;
|
||||
accuracy: number;
|
||||
width: number;
|
||||
height: number;
|
||||
project: (point: MoveDimensionWorldPoint) => MoveDimensionScreenPoint;
|
||||
};
|
||||
|
||||
function clamp(value: number, min: number, max: number) {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
export function formatMoveDimension(value: number, accuracy: number) {
|
||||
const zeroThreshold = 0.5 * 10 ** -accuracy;
|
||||
const normalized = Math.abs(value) < zeroThreshold ? 0 : value;
|
||||
return normalized.toFixed(accuracy);
|
||||
}
|
||||
|
||||
function dimensionLabelPosition(
|
||||
origin: MoveDimensionScreenPoint,
|
||||
endpoint: MoveDimensionScreenPoint,
|
||||
otherEndpoint: MoveDimensionScreenPoint,
|
||||
hasOtherDimension: boolean,
|
||||
width: number,
|
||||
height: number,
|
||||
) {
|
||||
const midpoint = {
|
||||
x: (origin.x + endpoint.x) / 2,
|
||||
y: (origin.y + endpoint.y) / 2,
|
||||
};
|
||||
const dx = endpoint.x - origin.x;
|
||||
const dy = endpoint.y - origin.y;
|
||||
const length = Math.max(1, Math.hypot(dx, dy));
|
||||
const normal = { x: -dy / length, y: dx / length };
|
||||
const towardOther = (otherEndpoint.x - midpoint.x) * normal.x + (otherEndpoint.y - midpoint.y) * normal.y;
|
||||
const side = hasOtherDimension && Math.abs(towardOther) > 0.5
|
||||
? towardOther >= 0 ? -1 : 1
|
||||
: 1;
|
||||
const offset = 30;
|
||||
|
||||
return {
|
||||
x: clamp(midpoint.x + normal.x * offset * side, 48, Math.max(48, width - 48)),
|
||||
y: clamp(midpoint.y + normal.y * offset * side, 24, Math.max(24, height - 24)),
|
||||
};
|
||||
}
|
||||
|
||||
function dimensionLineStart(origin: MoveDimensionScreenPoint, endpoint: MoveDimensionScreenPoint) {
|
||||
const dx = endpoint.x - origin.x;
|
||||
const dy = endpoint.y - origin.y;
|
||||
const length = Math.max(1, Math.hypot(dx, dy));
|
||||
const overrun = 12;
|
||||
return {
|
||||
x: origin.x - (dx / length) * overrun,
|
||||
y: origin.y - (dy / length) * overrun,
|
||||
};
|
||||
}
|
||||
|
||||
export function createMoveDimensionOverlay({
|
||||
originX,
|
||||
originZ,
|
||||
planeY,
|
||||
deltaX,
|
||||
deltaZ,
|
||||
accuracy,
|
||||
width,
|
||||
height,
|
||||
project,
|
||||
}: CreateMoveDimensionOverlayOptions): MoveDimensionOverlayData | null {
|
||||
const zeroThreshold = 0.5 * 10 ** -accuracy;
|
||||
if (Math.abs(deltaX) < zeroThreshold && Math.abs(deltaZ) < zeroThreshold) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const safeScreenPoint = (point: MoveDimensionScreenPoint) => ({
|
||||
x: Number.isFinite(point.x) ? point.x : width / 2,
|
||||
y: Number.isFinite(point.y) ? point.y : height / 2,
|
||||
});
|
||||
const origin = safeScreenPoint(project({ x: originX, y: planeY, z: originZ }));
|
||||
const xEndpoint = safeScreenPoint(project({ x: originX + deltaX, y: planeY, z: originZ }));
|
||||
const zEndpoint = safeScreenPoint(project({ x: originX, y: planeY, z: originZ + deltaZ }));
|
||||
const currentAnchor = safeScreenPoint(project({ x: originX + deltaX, y: planeY, z: originZ + deltaZ }));
|
||||
const lines: MoveDimensionLine[] = [];
|
||||
const guides: MoveDimensionGuide[] = [];
|
||||
const hasXDimension = Math.abs(deltaX) >= zeroThreshold;
|
||||
const hasZDimension = Math.abs(deltaZ) >= zeroThreshold;
|
||||
|
||||
if (hasXDimension) {
|
||||
const label = dimensionLabelPosition(origin, xEndpoint, zEndpoint, hasZDimension, width, height);
|
||||
const start = dimensionLineStart(origin, xEndpoint);
|
||||
lines.push({
|
||||
axis: "x",
|
||||
value: deltaX,
|
||||
label: formatMoveDimension(deltaX, accuracy),
|
||||
x1: start.x,
|
||||
y1: start.y,
|
||||
x2: xEndpoint.x,
|
||||
y2: xEndpoint.y,
|
||||
labelX: label.x,
|
||||
labelY: label.y,
|
||||
});
|
||||
if (Math.hypot(currentAnchor.x - xEndpoint.x, currentAnchor.y - xEndpoint.y) >= 1) {
|
||||
guides.push({
|
||||
axis: "x",
|
||||
x1: xEndpoint.x,
|
||||
y1: xEndpoint.y,
|
||||
x2: currentAnchor.x,
|
||||
y2: currentAnchor.y,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (hasZDimension) {
|
||||
const label = dimensionLabelPosition(origin, zEndpoint, xEndpoint, hasXDimension, width, height);
|
||||
const start = dimensionLineStart(origin, zEndpoint);
|
||||
lines.push({
|
||||
axis: "z",
|
||||
value: deltaZ,
|
||||
label: formatMoveDimension(deltaZ, accuracy),
|
||||
x1: start.x,
|
||||
y1: start.y,
|
||||
x2: zEndpoint.x,
|
||||
y2: zEndpoint.y,
|
||||
labelX: label.x,
|
||||
labelY: label.y,
|
||||
});
|
||||
if (Math.hypot(currentAnchor.x - zEndpoint.x, currentAnchor.y - zEndpoint.y) >= 1) {
|
||||
guides.push({
|
||||
axis: "z",
|
||||
x1: zEndpoint.x,
|
||||
y1: zEndpoint.y,
|
||||
x2: currentAnchor.x,
|
||||
y2: currentAnchor.y,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return lines.length > 0 ? { width, height, lines, guides } : null;
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
import * as THREE from "three";
|
||||
import type { WorkplaneShape } from "@/types/sketchforge";
|
||||
|
||||
export type PlacementPoint = { x: number; y: number; z: number };
|
||||
|
||||
export type PlacementWorkplane = {
|
||||
origin: PlacementPoint;
|
||||
normal: PlacementPoint;
|
||||
xAxis: PlacementPoint;
|
||||
zAxis: PlacementPoint;
|
||||
};
|
||||
|
||||
const EPSILON = 1e-8;
|
||||
|
||||
function vector(point: PlacementPoint) {
|
||||
return new THREE.Vector3(point.x, point.y, point.z);
|
||||
}
|
||||
|
||||
function point(value: THREE.Vector3): PlacementPoint {
|
||||
return {
|
||||
x: value.x === 0 ? 0 : value.x,
|
||||
y: value.y === 0 ? 0 : value.y,
|
||||
z: value.z === 0 ? 0 : value.z,
|
||||
};
|
||||
}
|
||||
|
||||
function clean(value: number) {
|
||||
const rounded = Number(value.toFixed(6));
|
||||
return Math.abs(rounded) < 1e-6 ? 0 : rounded;
|
||||
}
|
||||
|
||||
function finitePoint(value: unknown): PlacementPoint | null {
|
||||
if (!value || typeof value !== "object") return null;
|
||||
const candidate = value as Partial<PlacementPoint>;
|
||||
if (![candidate.x, candidate.y, candidate.z].every((coordinate) => typeof coordinate === "number" && Number.isFinite(coordinate))) {
|
||||
return null;
|
||||
}
|
||||
return { x: candidate.x as number, y: candidate.y as number, z: candidate.z as number };
|
||||
}
|
||||
|
||||
export function horizontalPlacementWorkplane(elevation = 0): PlacementWorkplane {
|
||||
return {
|
||||
origin: { x: 0, y: Number.isFinite(elevation) ? elevation : 0, z: 0 },
|
||||
normal: { x: 0, y: 1, z: 0 },
|
||||
xAxis: { x: 1, y: 0, z: 0 },
|
||||
zAxis: { x: 0, y: 0, z: 1 },
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizePlacementWorkplane(value: unknown, fallbackElevation = 0): PlacementWorkplane {
|
||||
if (!value || typeof value !== "object") return horizontalPlacementWorkplane(fallbackElevation);
|
||||
const candidate = value as Partial<PlacementWorkplane>;
|
||||
const origin = finitePoint(candidate.origin);
|
||||
const normal = finitePoint(candidate.normal);
|
||||
const xAxis = finitePoint(candidate.xAxis);
|
||||
if (!origin || !normal || !xAxis || vector(normal).lengthSq() < EPSILON || vector(xAxis).lengthSq() < EPSILON) {
|
||||
return horizontalPlacementWorkplane(fallbackElevation);
|
||||
}
|
||||
return placementWorkplaneFromSurface(origin, normal, xAxis);
|
||||
}
|
||||
|
||||
export function placementWorkplaneFingerprint(workplane: PlacementWorkplane) {
|
||||
return [
|
||||
workplane.origin.x, workplane.origin.y, workplane.origin.z,
|
||||
workplane.normal.x, workplane.normal.y, workplane.normal.z,
|
||||
workplane.xAxis.x, workplane.xAxis.y, workplane.xAxis.z,
|
||||
workplane.zAxis.x, workplane.zAxis.y, workplane.zAxis.z,
|
||||
].map(clean).join(":");
|
||||
}
|
||||
|
||||
export function placementWorkplaneFromSurface(
|
||||
origin: PlacementPoint,
|
||||
surfaceNormal: PlacementPoint,
|
||||
tangentHint: PlacementPoint,
|
||||
reverse = false,
|
||||
): PlacementWorkplane {
|
||||
const normal = vector(surfaceNormal).normalize();
|
||||
if (reverse) normal.negate();
|
||||
|
||||
let xAxis = vector(tangentHint).projectOnPlane(normal);
|
||||
if (xAxis.lengthSq() < EPSILON) {
|
||||
const candidates = [
|
||||
new THREE.Vector3(1, 0, 0),
|
||||
new THREE.Vector3(0, 0, 1),
|
||||
new THREE.Vector3(0, 1, 0),
|
||||
];
|
||||
xAxis = candidates.reduce((best, candidate) => {
|
||||
const projected = candidate.clone().projectOnPlane(normal);
|
||||
return projected.lengthSq() > best.lengthSq() ? projected : best;
|
||||
}, new THREE.Vector3());
|
||||
}
|
||||
xAxis.normalize();
|
||||
const zAxis = xAxis.clone().cross(normal).normalize();
|
||||
|
||||
return {
|
||||
origin: { x: origin.x, y: origin.y, z: origin.z },
|
||||
normal: point(normal),
|
||||
xAxis: point(xAxis),
|
||||
zAxis: point(zAxis),
|
||||
};
|
||||
}
|
||||
|
||||
export function snapPlacementWorkplaneOrigin(
|
||||
workplane: PlacementWorkplane,
|
||||
step: number,
|
||||
referenceOrigin: PlacementPoint = { x: 0, y: 0, z: 0 },
|
||||
): PlacementWorkplane {
|
||||
if (!Number.isFinite(step) || step <= 0) return workplane;
|
||||
|
||||
const normal = vector(workplane.normal);
|
||||
const xAxis = vector(workplane.xAxis);
|
||||
const zAxis = vector(workplane.zAxis);
|
||||
const origin = vector(workplane.origin);
|
||||
const reference = vector(referenceOrigin);
|
||||
const anchor = reference.clone().addScaledVector(
|
||||
normal,
|
||||
origin.clone().sub(reference).dot(normal),
|
||||
);
|
||||
const offset = origin.clone().sub(anchor);
|
||||
const snappedOrigin = anchor
|
||||
.addScaledVector(xAxis, Math.round(offset.dot(xAxis) / step) * step)
|
||||
.addScaledVector(zAxis, Math.round(offset.dot(zAxis) / step) * step);
|
||||
|
||||
return {
|
||||
...workplane,
|
||||
origin: point(snappedOrigin),
|
||||
};
|
||||
}
|
||||
|
||||
export function placementWorkplaneQuaternion(workplane: PlacementWorkplane) {
|
||||
const basis = new THREE.Matrix4().makeBasis(
|
||||
vector(workplane.xAxis),
|
||||
vector(workplane.normal),
|
||||
vector(workplane.zAxis),
|
||||
);
|
||||
return new THREE.Quaternion().setFromRotationMatrix(basis).normalize();
|
||||
}
|
||||
|
||||
export function placementWorkplaneCoordinates(workplane: PlacementWorkplane, worldPoint: PlacementPoint) {
|
||||
const relative = vector(worldPoint).sub(vector(workplane.origin));
|
||||
return {
|
||||
x: relative.dot(vector(workplane.xAxis)),
|
||||
y: relative.dot(vector(workplane.normal)),
|
||||
z: relative.dot(vector(workplane.zAxis)),
|
||||
};
|
||||
}
|
||||
|
||||
export function placementWorkplanePoint(workplane: PlacementWorkplane, x: number, z: number): PlacementPoint {
|
||||
const world = vector(workplane.origin)
|
||||
.addScaledVector(vector(workplane.xAxis), x)
|
||||
.addScaledVector(vector(workplane.zAxis), z);
|
||||
return point(world);
|
||||
}
|
||||
|
||||
export function placementPatchForNewShape(
|
||||
shape: Pick<WorkplaneShape, "height">,
|
||||
workplane: PlacementWorkplane,
|
||||
basePoint: PlacementPoint = workplane.origin,
|
||||
): Pick<WorkplaneShape, "x" | "z" | "elevation" | "rotation" | "rotationX" | "rotationZ"> {
|
||||
const quaternion = placementWorkplaneQuaternion(workplane);
|
||||
const euler = new THREE.Euler().setFromQuaternion(quaternion, "XYZ");
|
||||
const center = vector(basePoint).addScaledVector(vector(workplane.normal), shape.height / 2);
|
||||
return {
|
||||
x: clean(center.x),
|
||||
z: clean(center.z),
|
||||
elevation: clean(center.y - shape.height / 2),
|
||||
rotation: clean(THREE.MathUtils.radToDeg(euler.y)),
|
||||
rotationX: clean(THREE.MathUtils.radToDeg(euler.x)),
|
||||
rotationZ: clean(THREE.MathUtils.radToDeg(euler.z)),
|
||||
};
|
||||
}
|
||||
|
||||
export function translationToWorkplane(
|
||||
workplane: PlacementWorkplane,
|
||||
worldVertices: PlacementPoint[],
|
||||
): PlacementPoint {
|
||||
if (worldVertices.length === 0) return { x: 0, y: 0, z: 0 };
|
||||
const origin = vector(workplane.origin);
|
||||
const normal = vector(workplane.normal);
|
||||
const minimumDistance = worldVertices.reduce(
|
||||
(minimum, vertex) => Math.min(minimum, vector(vertex).sub(origin).dot(normal)),
|
||||
Number.POSITIVE_INFINITY,
|
||||
);
|
||||
const translation = normal.multiplyScalar(-minimumDistance);
|
||||
return point(translation);
|
||||
}
|
||||
|
||||
export function placementWorkplaneIsBase(workplane: PlacementWorkplane) {
|
||||
return (
|
||||
Math.abs(workplane.origin.x) < 1e-6
|
||||
&& Math.abs(workplane.origin.y) < 1e-6
|
||||
&& Math.abs(workplane.origin.z) < 1e-6
|
||||
&& Math.abs(workplane.normal.x) < 1e-6
|
||||
&& Math.abs(workplane.normal.y - 1) < 1e-6
|
||||
&& Math.abs(workplane.normal.z) < 1e-6
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
export type RegularPolygonFootprintScale = {
|
||||
x: number;
|
||||
z: number;
|
||||
offsetX: number;
|
||||
offsetZ: number;
|
||||
};
|
||||
|
||||
export function regularPolygonFootprintScale(
|
||||
width: number,
|
||||
depth: number,
|
||||
sides: number,
|
||||
): RegularPolygonFootprintScale {
|
||||
const count = Math.max(3, Math.round(sides));
|
||||
let minX = Number.POSITIVE_INFINITY;
|
||||
let maxX = Number.NEGATIVE_INFINITY;
|
||||
let minZ = Number.POSITIVE_INFINITY;
|
||||
let maxZ = Number.NEGATIVE_INFINITY;
|
||||
|
||||
for (let index = 0; index < count; index += 1) {
|
||||
const angle = (index / count) * Math.PI * 2;
|
||||
const x = Math.sin(angle);
|
||||
const z = Math.cos(angle);
|
||||
minX = Math.min(minX, x);
|
||||
maxX = Math.max(maxX, x);
|
||||
minZ = Math.min(minZ, z);
|
||||
maxZ = Math.max(maxZ, z);
|
||||
}
|
||||
|
||||
const x = Math.max(0.001, width) / Math.max(0.001, maxX - minX);
|
||||
const z = Math.max(0.001, depth) / Math.max(0.001, maxZ - minZ);
|
||||
return {
|
||||
x,
|
||||
z,
|
||||
offsetX: -((minX + maxX) / 2) * x,
|
||||
offsetZ: -((minZ + maxZ) / 2) * z,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import {
|
||||
placementPatchForNewShape,
|
||||
placementWorkplanePoint,
|
||||
type PlacementWorkplane,
|
||||
} from "@/lib/placementWorkplane";
|
||||
import { canonicalizeShape } from "@/lib/workplaneShapes";
|
||||
import type { WorkplaneShape } from "@/types/sketchforge";
|
||||
|
||||
export function placeSketchExtrusion(
|
||||
shape: WorkplaneShape,
|
||||
workplane: PlacementWorkplane,
|
||||
existing?: WorkplaneShape | null,
|
||||
) {
|
||||
if (existing) {
|
||||
return canonicalizeShape({
|
||||
...shape,
|
||||
x: existing.x,
|
||||
z: existing.z,
|
||||
elevation: existing.elevation ?? 0,
|
||||
rotation: existing.rotation,
|
||||
rotationX: existing.rotationX ?? 0,
|
||||
rotationZ: existing.rotationZ ?? 0,
|
||||
mirrorX: existing.mirrorX,
|
||||
mirrorY: existing.mirrorY,
|
||||
mirrorZ: existing.mirrorZ,
|
||||
locked: existing.locked,
|
||||
hidden: existing.hidden,
|
||||
});
|
||||
}
|
||||
|
||||
const basePoint = placementWorkplanePoint(workplane, shape.x, shape.z);
|
||||
return canonicalizeShape({
|
||||
...shape,
|
||||
...placementPatchForNewShape(shape, workplane, basePoint),
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { strFromU8, strToU8, unzip, zip, type AsyncZippable } from "fflate";
|
||||
import { editorHistoryEntry, hydrateEditorHistoryState, type EditorHistoryEntry } from "@/lib/editorHistory";
|
||||
import { normalizePlacementWorkplane, placementWorkplaneIsBase, type PlacementWorkplane } from "@/lib/placementWorkplane";
|
||||
import { normalizeProjectAsset, sha256Hex } from "@/lib/projectAssets";
|
||||
import { canonicalizeShape } from "@/lib/workplaneShapes";
|
||||
import { importedShapeFromStl } from "@/lib/stlImport";
|
||||
@@ -10,7 +11,7 @@ import type { GridSize, ProjectAsset, ProjectAssetSourceFormat, SketchOperation,
|
||||
export const SKF_SCHEMA_ID = "com.sketchforge.project";
|
||||
export const SKF_FORMAT_VERSION = 1;
|
||||
export const SKF_MINIMUM_READER_VERSION = 1;
|
||||
export const SKF_CREATED_WITH_VERSION = "0.7.0";
|
||||
export const SKF_CREATED_WITH_VERSION = "0.9.0";
|
||||
export const SKF_MEDIA_TYPE = "application/vnd.sketchforge.project+zip";
|
||||
|
||||
export const SKF_LIMITS = {
|
||||
@@ -120,6 +121,8 @@ export type SkfProjectDocumentV1 = {
|
||||
snapGrid: GridSize;
|
||||
selectedWorkplaneId: string;
|
||||
placementElevation: number;
|
||||
placementWorkplane?: PlacementWorkplane;
|
||||
sketchPlacementWorkplane?: PlacementWorkplane;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -135,6 +138,8 @@ export type SkfProjectExportInput = {
|
||||
workspace: WorkplaneWorkspaceSettings;
|
||||
snapGrid: GridSize;
|
||||
placementElevation: number;
|
||||
placementWorkplane?: PlacementWorkplane;
|
||||
sketchPlacementWorkplane?: PlacementWorkplane;
|
||||
compressionLevel?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
||||
};
|
||||
|
||||
@@ -150,6 +155,8 @@ export type SkfRestoredProject = {
|
||||
workspace: WorkplaneWorkspaceSettings;
|
||||
snapGrid: GridSize;
|
||||
placementElevation: number;
|
||||
placementWorkplane: PlacementWorkplane;
|
||||
sketchPlacementWorkplane: PlacementWorkplane;
|
||||
migratedFromVersion?: number;
|
||||
};
|
||||
|
||||
@@ -659,7 +666,9 @@ export async function exportSkfProject(input: SkfProjectExportInput) {
|
||||
const indexes = activeProjectIndexes(activeState);
|
||||
const now = Date.now();
|
||||
const placementElevation = Number.isFinite(input.placementElevation) ? input.placementElevation : 0;
|
||||
const selectedWorkplaneId = Math.abs(placementElevation) < 1e-9 ? "workplane-base" : "workplane-active";
|
||||
const placementWorkplane = normalizePlacementWorkplane(input.placementWorkplane, placementElevation);
|
||||
const sketchPlacementWorkplane = normalizePlacementWorkplane(input.sketchPlacementWorkplane);
|
||||
const selectedWorkplaneId = placementWorkplaneIsBase(placementWorkplane) ? "workplane-base" : "workplane-active";
|
||||
const document: SkfProjectDocumentV1 = {
|
||||
schema: SKF_SCHEMA_ID,
|
||||
formatVersion: SKF_FORMAT_VERSION,
|
||||
@@ -689,6 +698,8 @@ export async function exportSkfProject(input: SkfProjectExportInput) {
|
||||
snapGrid: normalizeSnapGrid(input.snapGrid),
|
||||
selectedWorkplaneId,
|
||||
placementElevation,
|
||||
placementWorkplane,
|
||||
sketchPlacementWorkplane,
|
||||
},
|
||||
};
|
||||
builder.files["project.json"] = strToU8(`${JSON.stringify(document, null, 2)}\n`);
|
||||
@@ -973,6 +984,16 @@ async function validateDocumentAndAssets(raw: unknown, files: ArchiveFiles) {
|
||||
validateFeatureGraph(document.features, activeObjectIds);
|
||||
const editor = objectRecord(document.editor, "editor");
|
||||
finiteNumber(editor.placementElevation, "editor.placementElevation");
|
||||
for (const fieldName of ["placementWorkplane", "sketchPlacementWorkplane"] as const) {
|
||||
if (editor[fieldName] === undefined) continue;
|
||||
const workplane = objectRecord(editor[fieldName], `editor.${fieldName}`);
|
||||
for (const field of ["origin", "normal", "xAxis", "zAxis"] as const) {
|
||||
const coordinates = objectRecord(workplane[field], `editor.${fieldName}.${field}`);
|
||||
finiteNumber(coordinates.x, `editor.${fieldName}.${field}.x`);
|
||||
finiteNumber(coordinates.y, `editor.${fieldName}.${field}.y`);
|
||||
finiteNumber(coordinates.z, `editor.${fieldName}.${field}.z`);
|
||||
}
|
||||
}
|
||||
return { document, assetById, stateById };
|
||||
}
|
||||
|
||||
@@ -1118,6 +1139,8 @@ async function restoreV1(document: SkfProjectDocumentV1, assetById: Map<string,
|
||||
workspace: normalizeWorkspaceSettings(document.editor.workspace),
|
||||
snapGrid: normalizeSnapGrid(document.editor.snapGrid),
|
||||
placementElevation: document.editor.placementElevation,
|
||||
placementWorkplane: normalizePlacementWorkplane(document.editor.placementWorkplane, document.editor.placementElevation),
|
||||
sketchPlacementWorkplane: normalizePlacementWorkplane(document.editor.sketchPlacementWorkplane),
|
||||
} satisfies SkfRestoredProject;
|
||||
}
|
||||
|
||||
@@ -1142,6 +1165,11 @@ function migrateV0(raw: Record<string, unknown>): SkfRestoredProject {
|
||||
workspace: normalizeWorkspaceSettings(raw.workspace),
|
||||
snapGrid: normalizeSnapGrid(raw.snapGrid),
|
||||
placementElevation: typeof raw.placementElevation === "number" && Number.isFinite(raw.placementElevation) ? raw.placementElevation : 0,
|
||||
placementWorkplane: normalizePlacementWorkplane(
|
||||
raw.placementWorkplane,
|
||||
typeof raw.placementElevation === "number" && Number.isFinite(raw.placementElevation) ? raw.placementElevation : 0,
|
||||
),
|
||||
sketchPlacementWorkplane: normalizePlacementWorkplane(raw.sketchPlacementWorkplane),
|
||||
migratedFromVersion: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export const DEFAULT_WORKPLANE_WORKSPACE: WorkplaneWorkspaceSettings = {
|
||||
units: "Metric (Default)",
|
||||
scale: "1:1 (millimeters)",
|
||||
accuracy: 2,
|
||||
historyLimit: "unlimited",
|
||||
historyLimit: 100,
|
||||
};
|
||||
|
||||
const snapGridOptions: GridSize[] = ["Off", "0.1 mm", "0.25 mm", "0.5 mm", "1.0 mm", "2.0 mm", "5.0 mm", "Brick"];
|
||||
|
||||
@@ -124,7 +124,7 @@ export function fallbackSolidColor(shape: WorkplaneShape) {
|
||||
}
|
||||
|
||||
export function withHoleMode(shape: WorkplaneShape, hole: boolean, parentColor?: string): WorkplaneShape {
|
||||
const color = hole ? "#b8c2cc" : (parentColor ?? fallbackSolidColor(shape));
|
||||
const color = parentColor ?? shape.color;
|
||||
return {
|
||||
...shape,
|
||||
hole,
|
||||
|
||||
Reference in New Issue
Block a user