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 v1.0.0
This commit is contained in:
@@ -16,6 +16,7 @@ import gentilisBoldFontJson from "three/examples/fonts/gentilis_bold.typeface.js
|
||||
import helvetikerBoldFontJson from "three/examples/fonts/helvetiker_bold.typeface.json";
|
||||
import optimerBoldFontJson from "three/examples/fonts/optimer_bold.typeface.json";
|
||||
import type { AppThemePreference, ResolvedAppTheme } from "@/lib/appTheme";
|
||||
import type { ChallengeTutorialId } from "@/lib/challenges";
|
||||
import { manifoldModuleSource } from "@/generated/manifoldModuleSource";
|
||||
import { manifoldWasmBase64 } from "@/generated/manifoldWasmBase64";
|
||||
import { sphereTessellation } from "@/lib/sphereTessellation";
|
||||
@@ -84,12 +85,14 @@ import { appendEditorHistorySnapshot, boundedEditorHistoryState, editorHistoryEn
|
||||
import { snapShapeFootprintToVisibleGrid, visibleGridStep } from "@/lib/gridSnap";
|
||||
import { createLocalId } from "@/lib/localIds";
|
||||
import { projectExportFileName } from "@/lib/exportNames";
|
||||
import { exportMeshesToObj } from "@/lib/objExport";
|
||||
import { attachProjectAsset, dedupeProjectAssets, projectAssetFromBytes, sourceFormatForFileName } from "@/lib/projectAssets";
|
||||
import { findSketchOutlineIntersection } from "@/lib/sketchProfileValidation";
|
||||
import { buildSketchRevolveMesh, DEFAULT_SKETCH_REVOLVE_SETTINGS, normalizeSketchRevolveSettings, type SketchRevolveMesh } from "@/lib/sketchRevolve";
|
||||
import { exportSkfProject, SKF_MEDIA_TYPE } from "@/lib/skfProject";
|
||||
import { makeShapeFromAsset, sceneShape, toolbarShapeAssets, type ToolbarShapeAsset } from "@/lib/shapeCatalog";
|
||||
import { importedShapeFromStl, importExtensionSupported } from "@/lib/stlImport";
|
||||
import { exportMeshesToStl } from "@/lib/stlExport";
|
||||
import { importedShapeFromSvg, invalidSvgMeshReason } from "@/lib/svgImport";
|
||||
import { toSvgProjection, type SvgProjectionLayer } from "@/lib/svgExport";
|
||||
import { normalizeSnapGrid, normalizeWorkspaceSettings, workplaneSettingsFingerprint } from "@/lib/workplaneSettings";
|
||||
@@ -113,6 +116,7 @@ import {
|
||||
type SketchForgeMcpViewFace,
|
||||
} from "@/lib/sketchforgeMcpProtocol";
|
||||
import type { CadModifierComponentMesh, CadModifierDisplayEdge, CadModifierEdge, CadModifierKind, CadModifierMeshPart, CadModifierPrimitivePart, CadModifierQuality, CadModifierWorkerRequest, CadModifierWorkerResponse } from "@/lib/cadModifierTypes";
|
||||
import type { SketchCadBuildResponse } from "@/lib/sketchCadTypes";
|
||||
import type { AlignAxis, AlignHandleStatus, AlignTarget, GridSize, ProjectAsset, ShapeAsset, SketchImage, SketchOperation, SketchPoint, SketchProfile, SketchRevolveSettings, SketchSegment, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
|
||||
|
||||
export { importedShapeFromStl, importedShapeFromSvg };
|
||||
@@ -529,6 +533,76 @@ async function shapeFromSketchProfile(profile: SketchProfile, height: number, ex
|
||||
} satisfies WorkplaneShape);
|
||||
}
|
||||
|
||||
let sketchCadWorker: Worker | null = null;
|
||||
let sketchCadRequestId = 0;
|
||||
const sketchCadPending = new Map<number, {
|
||||
resolve: (response: SketchCadBuildResponse) => void;
|
||||
reject: (error: Error) => void;
|
||||
timer: number;
|
||||
}>();
|
||||
|
||||
function ensureSketchCadWorker() {
|
||||
if (sketchCadWorker) return sketchCadWorker;
|
||||
const worker = new Worker(new URL("../workers/sketchCad.worker.ts", import.meta.url), { type: "module" });
|
||||
worker.onmessage = (event: MessageEvent<SketchCadBuildResponse>) => {
|
||||
const pending = sketchCadPending.get(event.data.requestId);
|
||||
if (!pending) return;
|
||||
window.clearTimeout(pending.timer);
|
||||
sketchCadPending.delete(event.data.requestId);
|
||||
pending.resolve(event.data);
|
||||
};
|
||||
worker.onerror = () => {
|
||||
sketchCadPending.forEach((pending) => {
|
||||
window.clearTimeout(pending.timer);
|
||||
pending.reject(new Error("The OpenCascade sketch worker failed to start"));
|
||||
});
|
||||
sketchCadPending.clear();
|
||||
worker.terminate();
|
||||
sketchCadWorker = null;
|
||||
};
|
||||
sketchCadWorker = worker;
|
||||
return worker;
|
||||
}
|
||||
|
||||
async function cadShapeFromSketchProfile(profile: SketchProfile, height: number, existing?: WorkplaneShape | null) {
|
||||
const safeHeight = Math.max(MIN_SHAPE_DIMENSION, height);
|
||||
const worker = ensureSketchCadWorker();
|
||||
const requestId = ++sketchCadRequestId;
|
||||
const response = await new Promise<SketchCadBuildResponse>((resolve, reject) => {
|
||||
const timer = window.setTimeout(() => {
|
||||
sketchCadPending.delete(requestId);
|
||||
reject(new Error("OpenCascade timed out while building the sketch"));
|
||||
}, 30_000);
|
||||
sketchCadPending.set(requestId, { resolve, reject, timer });
|
||||
worker.postMessage({ type: "build", requestId, profile: cloneSketchProfile(profile), height: safeHeight });
|
||||
});
|
||||
if (response.type === "error") throw new Error(response.message);
|
||||
const source = canonicalizeShape({
|
||||
...(existing ?? {
|
||||
id: createLocalId("sketch-extrusion"),
|
||||
name: "Sketch extrusion",
|
||||
kind: "mesh" as const,
|
||||
color: "#d41721",
|
||||
x: 0,
|
||||
z: 0,
|
||||
size: 1,
|
||||
width: 1,
|
||||
depth: 1,
|
||||
height: safeHeight,
|
||||
rotation: 0,
|
||||
}),
|
||||
sketchProfile: cloneSketchProfile(profile),
|
||||
sketchOperation: "extrude",
|
||||
edgeTreatments: undefined,
|
||||
edgeTreatmentHistory: undefined,
|
||||
cadDisplayEdges: undefined,
|
||||
cadDisplayEdgesVersion: undefined,
|
||||
});
|
||||
const shape = shapeFromCadMesh(source, response.positions, response.normals, response.indices, response.brep);
|
||||
if (!shape) throw new Error("OpenCascade returned an empty sketch solid");
|
||||
return { ...shape, sketchProfile: cloneSketchProfile(profile), sketchOperation: "extrude" as const };
|
||||
}
|
||||
|
||||
async function shapeFromRevolvedSketchProfile(
|
||||
profile: SketchProfile,
|
||||
settings: Partial<SketchRevolveSettings>,
|
||||
@@ -2263,7 +2337,10 @@ function cadModifierPrimitiveForShape(shape: WorkplaneShape): CadModifierPrimiti
|
||||
}
|
||||
|
||||
function bakeShapeTransformIntoMesh(shape: WorkplaneShape): WorkplaneShape {
|
||||
if (!shapeHasTransformToBake(shape)) {
|
||||
// Rotation is a non-destructive transform for editable text. Baking it would
|
||||
// change the shape to `kind: "mesh"`, hiding the Text and Font controls even
|
||||
// though the user never grouped or otherwise converted the object.
|
||||
if (shape.kind === "text" || !shapeHasTransformToBake(shape)) {
|
||||
return shape;
|
||||
}
|
||||
|
||||
@@ -2459,53 +2536,6 @@ async function importedShapeFromImage(file: File): Promise<WorkplaneShape> {
|
||||
};
|
||||
}
|
||||
|
||||
function normalFor(a: Vec3, b: Vec3, c: Vec3): Vec3 {
|
||||
const ux = b[0] - a[0];
|
||||
const uy = b[1] - a[1];
|
||||
const uz = b[2] - a[2];
|
||||
const vx = c[0] - a[0];
|
||||
const vy = c[1] - a[1];
|
||||
const vz = c[2] - a[2];
|
||||
const nx = uy * vz - uz * vy;
|
||||
const ny = uz * vx - ux * vz;
|
||||
const nz = ux * vy - uy * vx;
|
||||
const length = Math.hypot(nx, ny, nz) || 1;
|
||||
return [nx / length, ny / length, nz / length];
|
||||
}
|
||||
|
||||
function toStl(meshes: MeshData[]) {
|
||||
const lines = ["solid sketchforge_design"];
|
||||
meshes.forEach((mesh) => {
|
||||
mesh.faces.forEach(([ai, bi, ci]) => {
|
||||
const a = mesh.vertices[ai];
|
||||
const b = mesh.vertices[bi];
|
||||
const c = mesh.vertices[ci];
|
||||
const n = normalFor(a, b, c);
|
||||
lines.push(` facet normal ${n[0]} ${n[1]} ${n[2]}`);
|
||||
lines.push(" outer loop");
|
||||
lines.push(` vertex ${a[0]} ${a[1]} ${a[2]}`);
|
||||
lines.push(` vertex ${b[0]} ${b[1]} ${b[2]}`);
|
||||
lines.push(` vertex ${c[0]} ${c[1]} ${c[2]}`);
|
||||
lines.push(" endloop");
|
||||
lines.push(" endfacet");
|
||||
});
|
||||
});
|
||||
lines.push("endsolid sketchforge_design");
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function toObj(meshes: MeshData[]) {
|
||||
const lines = ["# SketchForge OBJ export"];
|
||||
let offset = 1;
|
||||
meshes.forEach((mesh) => {
|
||||
lines.push(`o ${mesh.name}`);
|
||||
mesh.vertices.forEach(([x, y, z]) => lines.push(`v ${x} ${y} ${z}`));
|
||||
mesh.faces.forEach(([a, b, c]) => lines.push(`f ${a + offset} ${b + offset} ${c + offset}`));
|
||||
offset += mesh.vertices.length;
|
||||
});
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
async function toSvg(shapes: WorkplaneShape[], title: string) {
|
||||
const runtime = await getManifoldRuntime();
|
||||
const layers: SvgProjectionLayer[] = [];
|
||||
@@ -3118,6 +3148,12 @@ function separateMeshParts(shape: WorkplaneShape) {
|
||||
.filter((part): part is WorkplaneShape => Boolean(part));
|
||||
}
|
||||
|
||||
function cadModifierSourceParts(shape: WorkplaneShape) {
|
||||
if (shape.kind !== "text" || shape.importedMesh || shape.cadBrep) return [shape];
|
||||
const glyphParts = separateMeshParts(shape);
|
||||
return glyphParts.length > 1 ? glyphParts : [shape];
|
||||
}
|
||||
|
||||
function separablePartCount(shape: WorkplaneShape) {
|
||||
if (shape.locked || shape.hole) return 0;
|
||||
if (shape.groupedShapes?.length && !shape.importedMesh) return shape.groupedShapes.length;
|
||||
@@ -5279,6 +5315,8 @@ export function SketchForgeEditor({
|
||||
projectModifiedAt = Date.now(),
|
||||
projectRevision = 0,
|
||||
sharedProjectsEnabled = false,
|
||||
challengeTutorial = null,
|
||||
onChallengeTutorialFinish,
|
||||
themePreference = "system",
|
||||
resolvedTheme = "light",
|
||||
onThemePreferenceChange,
|
||||
@@ -5323,6 +5361,8 @@ export function SketchForgeEditor({
|
||||
projectModifiedAt?: number;
|
||||
projectRevision?: number;
|
||||
sharedProjectsEnabled?: boolean;
|
||||
challengeTutorial?: ChallengeTutorialId | null;
|
||||
onChallengeTutorialFinish?: () => void;
|
||||
themePreference?: AppThemePreference;
|
||||
resolvedTheme?: ResolvedAppTheme;
|
||||
onThemePreferenceChange?: (preference: AppThemePreference) => void;
|
||||
@@ -6566,8 +6606,9 @@ export function SketchForgeEditor({
|
||||
if (sketchOperation === "revolve") {
|
||||
resolved = await shapeFromRevolvedSketchProfile(sketchProfile, sketchRevolveSettings, existing);
|
||||
} else {
|
||||
const extrusion = await shapeFromSketchProfile(sketchProfile, height, existing);
|
||||
resolved = extrusion ? placeSketchExtrusion(extrusion, activeSketchWorkplane, existing) : null;
|
||||
setNotice("Building exact sketch geometry…");
|
||||
const extrusion = await cadShapeFromSketchProfile(sketchProfile, height, existing);
|
||||
resolved = placeSketchExtrusion(extrusion, activeSketchWorkplane, existing);
|
||||
}
|
||||
} catch (error) {
|
||||
setNotice(error instanceof Error ? error.message : `The sketch profile cannot be ${sketchOperation === "revolve" ? "revolved" : "extruded"} to 3D`);
|
||||
@@ -6579,7 +6620,7 @@ export function SketchForgeEditor({
|
||||
}
|
||||
const nextShapes = existing ? shapes.map((shape) => (shape.id === existing.id ? resolved : shape)) : [...shapes, resolved];
|
||||
const action = sketchOperation === "revolve" ? "Revolve sketch" : "Sketch";
|
||||
commitShapes(nextShapes, resolved.id, existing ? `${action} updated` : sketchOperation === "revolve" ? "Revolved sketch created" : "Sketch created at 10 mm height");
|
||||
commitShapes(nextShapes, resolved.id, existing ? `${action} updated` : sketchOperation === "revolve" ? "Revolved sketch created" : "Exact sketch created at 10 mm height");
|
||||
setSketchActive(false);
|
||||
setSketchRevolvePreview(null);
|
||||
setEditingSketchShapeId(null);
|
||||
@@ -7072,7 +7113,9 @@ export function SketchForgeEditor({
|
||||
invalidateCadModifierSession();
|
||||
const appliedEdgeTreatmentCount = edgeTreatmentFeatureCount(selectedShape);
|
||||
const hasAppliedEdgeTreatment = Boolean(selectedShape.importedMesh && selectedShape.edgeTreatments?.length);
|
||||
const sourceParts = selectedShape.groupedShapes?.length && !hasAppliedEdgeTreatment ? restoreGroupedChildren(selectedShape) : [selectedShape];
|
||||
const sourceParts = (selectedShape.groupedShapes?.length && !hasAppliedEdgeTreatment
|
||||
? restoreGroupedChildren(selectedShape)
|
||||
: [selectedShape]).flatMap(cadModifierSourceParts);
|
||||
const partInputs: Array<{ shape: WorkplaneShape; mesh?: MeshData; brep?: string; brepTransform?: number[]; primitive?: CadModifierPrimitivePart }> = sourceParts.map((shape) => {
|
||||
const frame = shape.cadBrepFrame;
|
||||
const preserveNeedsRetessellation = preservesEdgeTreatmentSize(shape) && Boolean(frame) && (
|
||||
@@ -7145,7 +7188,9 @@ export function SketchForgeEditor({
|
||||
}
|
||||
const appliedEdgeTreatmentCount = edgeTreatmentFeatureCount(shape);
|
||||
const hasAppliedEdgeTreatment = Boolean(shape.importedMesh && shape.edgeTreatments?.length);
|
||||
const sourceParts = shape.groupedShapes?.length && !hasAppliedEdgeTreatment ? restoreGroupedChildren(shape) : [shape];
|
||||
const sourceParts = (shape.groupedShapes?.length && !hasAppliedEdgeTreatment
|
||||
? restoreGroupedChildren(shape)
|
||||
: [shape]).flatMap(cadModifierSourceParts);
|
||||
const partInputs: Array<{ shape: WorkplaneShape; mesh?: MeshData; brep?: string; brepTransform?: number[]; primitive?: CadModifierPrimitivePart }> = sourceParts.map((partShape) => {
|
||||
const frame = partShape.cadBrepFrame;
|
||||
const preserveNeedsRetessellation = preservesEdgeTreatmentSize(partShape) && Boolean(frame) && (
|
||||
@@ -7711,8 +7756,7 @@ export function SketchForgeEditor({
|
||||
let shape: WorkplaneShape;
|
||||
if (kind === "sketch") {
|
||||
const profile = defaultMcpSketchProfile(width, depth);
|
||||
const extruded = await shapeFromSketchProfile(profile, height);
|
||||
if (!extruded) throw new Error("Could not create the sketch profile");
|
||||
const extruded = await cadShapeFromSketchProfile(profile, height);
|
||||
shape = canonicalizeShape({
|
||||
...extruded,
|
||||
name,
|
||||
@@ -7724,7 +7768,7 @@ export function SketchForgeEditor({
|
||||
rotationX: mcpNumber(params.rotationX, 0),
|
||||
rotationZ: mcpNumber(params.rotationZ, 0),
|
||||
});
|
||||
} else if (kind === "box" || kind === "cylinder") {
|
||||
} else if (kind === "box" || kind === "cylinder" || kind === "text") {
|
||||
shape = sceneShape({
|
||||
name,
|
||||
kind,
|
||||
@@ -7740,9 +7784,13 @@ export function SketchForgeEditor({
|
||||
rotationX: mcpNumber(params.rotationX, 0),
|
||||
rotationZ: mcpNumber(params.rotationZ, 0),
|
||||
sides: kind === "cylinder" ? Math.max(3, Math.floor(mcpNumber(params.sides, 96))) : undefined,
|
||||
text: kind === "text" ? mcpString(params.text, "TEXT") : undefined,
|
||||
font: kind === "text" ? mcpString(params.font, "Multilanguage") : undefined,
|
||||
bevel: kind === "text" ? Math.max(0, mcpNumber(params.bevel, 0)) : undefined,
|
||||
segments: kind === "text" ? Math.max(1, Math.floor(mcpNumber(params.segments, 2))) : undefined,
|
||||
});
|
||||
} else {
|
||||
throw new Error("MCP create_shape currently supports box, cube, cylinder, and sketch");
|
||||
throw new Error("MCP create_shape currently supports box, cube, cylinder, text, and sketch");
|
||||
}
|
||||
const committedShape = canonicalizeShape(bakeShapeTransformIntoMesh(shape));
|
||||
commitShapes([...currentShapes(), committedShape], committedShape.id, `${committedShape.name} added by MCP`);
|
||||
@@ -7822,6 +7870,9 @@ export function SketchForgeEditor({
|
||||
if (typeof params.color === "string") patch.color = params.color;
|
||||
if (typeof params.name === "string") patch.name = params.name;
|
||||
if (typeof params.hole === "boolean") patch.hole = params.hole;
|
||||
if (typeof params.text === "string") patch.text = params.text;
|
||||
if (typeof params.font === "string") patch.font = params.font;
|
||||
if (typeof params.bevel === "number" && Number.isFinite(params.bevel)) patch.bevel = Math.max(0, params.bevel);
|
||||
const nextShapes = currentShapes().map((shape) => {
|
||||
if (shape.id !== target.id) return shape;
|
||||
const patched = { ...shape, ...cleanShapePatch(patch) };
|
||||
@@ -8272,12 +8323,12 @@ export function SketchForgeEditor({
|
||||
}
|
||||
const meshes = exportable.map(meshForShape);
|
||||
if (format === "stl") {
|
||||
void downloadTextFile(projectExportFileName(exportName, "stl"), toStl(meshes), "model/stl")
|
||||
void downloadTextFile(projectExportFileName(exportName, "stl"), exportMeshesToStl(meshes), "model/stl")
|
||||
.then((result) => finishNotice("STL", result))
|
||||
.catch((error: unknown) => failNotice("STL", error));
|
||||
return;
|
||||
}
|
||||
void downloadTextFile(projectExportFileName(exportName, "obj"), toObj(meshes), "text/plain")
|
||||
void downloadTextFile(projectExportFileName(exportName, "obj"), exportMeshesToObj(meshes), "text/plain")
|
||||
.then((result) => finishNotice("OBJ", result))
|
||||
.catch((error: unknown) => failNotice("OBJ", error));
|
||||
}, [hasSelection, projectName, selectedShapes, shapes]);
|
||||
@@ -8897,6 +8948,8 @@ export function SketchForgeEditor({
|
||||
modifierEdges={edgeModifier?.edges.filter((edge) => modifierAvailableEdgeIds.includes(edge.id)) ?? []}
|
||||
selectedModifierEdgeIds={edgeModifier?.selectedEdgeIds ?? []}
|
||||
onModifierEdgeToggle={toggleModifierEdge}
|
||||
challengeTutorial={challengeTutorial}
|
||||
onChallengeTutorialFinish={onChallengeTutorialFinish}
|
||||
themePreference={themePreference}
|
||||
resolvedTheme={resolvedTheme}
|
||||
onThemePreferenceChange={onThemePreferenceChange}
|
||||
@@ -9274,7 +9327,15 @@ function SecondaryToolbar({
|
||||
const { icon: Icon, action, enabled, label } = tool;
|
||||
const active = "active" in tool && Boolean(tool.active);
|
||||
return (
|
||||
<button className={`toolbar-icon ${enabled ? "" : "disabled"} ${active ? "active" : ""}`} key={label} aria-label={label} title={label} onClick={action} disabled={!enabled}>
|
||||
<button
|
||||
className={`toolbar-icon ${enabled ? "" : "disabled"} ${active ? "active" : ""}`}
|
||||
key={label}
|
||||
data-sketchforge-tool={label === "Fillet" ? "fillet" : undefined}
|
||||
aria-label={label}
|
||||
title={label}
|
||||
onClick={action}
|
||||
disabled={!enabled}
|
||||
>
|
||||
<Icon />
|
||||
</button>
|
||||
);
|
||||
|
||||
@@ -608,14 +608,7 @@ export function SketchWorkspace({
|
||||
const end = pointById.get(segment.endId);
|
||||
return Boolean(start && end && (contains(start) || contains(end) || contains({ x: (start.x + end.x) / 2, z: (start.z + end.z) / 2 })));
|
||||
}).map((segment) => segment.id);
|
||||
const imageIds = (profile.images ?? []).filter((image) => {
|
||||
const imageMinX = image.x - image.width / 2;
|
||||
const imageMaxX = image.x + image.width / 2;
|
||||
const imageMinZ = image.z - image.depth / 2;
|
||||
const imageMaxZ = image.z + image.depth / 2;
|
||||
return imageMaxX >= minX && imageMinX <= maxX && imageMaxZ >= minZ && imageMinZ <= maxZ;
|
||||
}).map((image) => image.id);
|
||||
onSelectMany(pointIds, segmentIds, imageIds);
|
||||
onSelectMany(pointIds, segmentIds, []);
|
||||
setPointerAction(null);
|
||||
return;
|
||||
}
|
||||
@@ -745,7 +738,6 @@ export function SketchWorkspace({
|
||||
if (event.button !== 0 || tool !== "select") return;
|
||||
const point = pointFromEvent(event);
|
||||
if (!point) return;
|
||||
onSelectImage(image.id);
|
||||
beginEntityDrag(event, {
|
||||
kind: "move-image",
|
||||
pointerId: event.pointerId,
|
||||
@@ -989,7 +981,7 @@ export function SketchWorkspace({
|
||||
<button type="button" title="Split handles" onClick={() => onSetPointMode(selectedPoint.id, "split")}><Split /><span>Split</span></button>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="grid-settings sketch-grid-settings">
|
||||
<div className="grid-settings">
|
||||
<SnapGridControl snap={snap} snapOpen={snapOpen} onSnapChange={setSnap} onSnapOpenChange={setSnapOpen} />
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -21,8 +21,11 @@ import optimerBoldFontJson from "three/examples/fonts/optimer_bold.typeface.json
|
||||
import { AlignOverlay, MirrorOverlay, type AlignOverlayState, type MirrorOverlayState } from "@/components/workplane/ActionOverlays";
|
||||
import { MoveDimensionOverlay } from "@/components/workplane/MoveDimensionOverlay";
|
||||
import { ShapeInspector, SnapGridControl, type ShapeInspectorUpdateOptions } from "@/components/workplane/ShapeInspector";
|
||||
import { KeyTagTutorialPanel } from "@/components/workplane/KeyTagTutorialPanel";
|
||||
import { NameplateTutorialPanel } from "@/components/workplane/NameplateTutorialPanel";
|
||||
import { WorkspaceSettingsModal } from "@/components/workplane/WorkspaceSettingsModal";
|
||||
import type { AppThemePreference, ResolvedAppTheme } from "@/lib/appTheme";
|
||||
import type { ChallengeTutorialId } from "@/lib/challenges";
|
||||
import { cadModifierPrimitiveForBakedShape, cadTransformFromMatrix, cadTransformToMatrix } from "@/lib/cadBakeMetadata";
|
||||
import { createGearGeometry } from "@/lib/gearGeometry";
|
||||
import { parseMeasurementInput } from "@/lib/measurementUnits";
|
||||
@@ -201,6 +204,8 @@ type WorkplaneViewportProps = {
|
||||
modifierEdges?: CadModifierEdge[];
|
||||
selectedModifierEdgeIds?: number[];
|
||||
onModifierEdgeToggle?: (id: number, singleEdge: boolean) => void;
|
||||
challengeTutorial?: ChallengeTutorialId | null;
|
||||
onChallengeTutorialFinish?: () => void;
|
||||
themePreference?: AppThemePreference;
|
||||
resolvedTheme?: ResolvedAppTheme;
|
||||
onThemePreferenceChange?: (preference: AppThemePreference) => void;
|
||||
@@ -2223,6 +2228,8 @@ export function WorkplaneViewport({
|
||||
modifierEdges = [],
|
||||
selectedModifierEdgeIds = [],
|
||||
onModifierEdgeToggle,
|
||||
challengeTutorial = null,
|
||||
onChallengeTutorialFinish,
|
||||
themePreference = "system",
|
||||
resolvedTheme = "light",
|
||||
onThemePreferenceChange,
|
||||
@@ -2254,6 +2261,12 @@ export function WorkplaneViewport({
|
||||
const [rulerOverlay, setRulerOverlay] = useState<RulerOverlayState | null>(null);
|
||||
const [moveDimensionOverlay, setMoveDimensionOverlay] = useState<MoveDimensionOverlayState | null>(null);
|
||||
const [moveDimensionsEnabled, setMoveDimensionsEnabled] = useState(true);
|
||||
const [challengeTutorialCollapsed, setChallengeTutorialCollapsed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setChallengeTutorialCollapsed(false);
|
||||
}, [challengeTutorial]);
|
||||
|
||||
const hostRef = useRef<HTMLDivElement | null>(null);
|
||||
const threeRef = useRef<ThreeState | null>(null);
|
||||
const shapesRef = useRef(shapes);
|
||||
@@ -3220,6 +3233,7 @@ export function WorkplaneViewport({
|
||||
}
|
||||
return shapesRef.current
|
||||
.filter((shape) => !shape.hidden)
|
||||
.filter((shape) => !shape.imagePlate)
|
||||
.filter((shape) => {
|
||||
const bounds = shapeScreenBounds(state, shape);
|
||||
return bounds ? boundsIntersectRect(bounds, rect) : false;
|
||||
@@ -3778,7 +3792,12 @@ export function WorkplaneViewport({
|
||||
state.raycaster.layers.set(RENDER_LAYER_SHAPES);
|
||||
|
||||
const intersections = state.raycaster.intersectObjects(state.shapeLayer.children, true);
|
||||
const hit = intersections.find((entry) => typeof entry.object.userData.shapeId === "string");
|
||||
const hit = intersections.find((entry) => {
|
||||
const shapeId = entry.object.userData.shapeId;
|
||||
if (typeof shapeId !== "string") return false;
|
||||
const shape = shapesRef.current.find((candidate) => candidate.id === shapeId);
|
||||
return shape ? !shape.imagePlate : false;
|
||||
});
|
||||
if (hit) {
|
||||
return hit.object.userData.shapeId as string;
|
||||
}
|
||||
@@ -3786,6 +3805,7 @@ export function WorkplaneViewport({
|
||||
let nearestId: string | null = null;
|
||||
let nearestDistance = Number.POSITIVE_INFINITY;
|
||||
shapesRef.current.forEach((shape) => {
|
||||
if (shape.imagePlate) return;
|
||||
const center = new THREE.Vector3(shape.x, (shape.elevation ?? 0) + shape.height / 2, shape.z).project(state.camera);
|
||||
const screenX = rect.left + ((center.x + 1) / 2) * rect.width;
|
||||
const screenY = rect.top + ((1 - center.y) / 2) * rect.height;
|
||||
@@ -4757,7 +4777,7 @@ export function WorkplaneViewport({
|
||||
}, [onWorkplaneModeChange, resetView, rulerToolsOpen, setPlacementWorkplaneAtSelection, setRulerActive, togglePlacementWorkplane, toggleProjection, zoomCamera]);
|
||||
|
||||
return (
|
||||
<main className="workplane-stage">
|
||||
<main className={`workplane-stage ${challengeTutorial ? `key-tag-tutorial-active ${challengeTutorialCollapsed ? "key-tag-tutorial-collapsed" : ""}` : ""}`}>
|
||||
<div className="view-cube" aria-label="View orientation cube" onPointerDown={(event) => event.stopPropagation()}>
|
||||
<div className="view-cube-inner" ref={viewCubeRef}>
|
||||
<button type="button" className="cube-face cube-top" aria-label="Bottom view" onClick={() => setViewCubeFace("bottom")}>BOTTOM</button>
|
||||
@@ -4939,6 +4959,20 @@ export function WorkplaneViewport({
|
||||
onClose={() => setSettingsOpen(false)}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{challengeTutorial === "key-tag" ? (
|
||||
<KeyTagTutorialPanel
|
||||
onFinish={onChallengeTutorialFinish}
|
||||
collapsed={challengeTutorialCollapsed}
|
||||
onCollapsedChange={setChallengeTutorialCollapsed}
|
||||
/>
|
||||
) : challengeTutorial === "nameplate" ? (
|
||||
<NameplateTutorialPanel
|
||||
onFinish={onChallengeTutorialFinish}
|
||||
collapsed={challengeTutorialCollapsed}
|
||||
onCollapsedChange={setChallengeTutorialCollapsed}
|
||||
/>
|
||||
) : null}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
"use client";
|
||||
|
||||
import { AlignCenter, Box, CircleDotDashed, Group, LockKeyhole, MoveUp, Type } from "lucide-react";
|
||||
import type { ChallengeTutorialId } from "@/lib/challenges";
|
||||
|
||||
function KeyTagPreview() {
|
||||
return (
|
||||
<>
|
||||
<img
|
||||
className="challenge-key-tag-photo challenge-key-tag-photo-light"
|
||||
src="/assets/challenges/key-tag/card-key-tag-light.webp"
|
||||
alt="Finished red Key Tag model on the SketchForge workplane"
|
||||
/>
|
||||
<img
|
||||
className="challenge-key-tag-photo challenge-key-tag-photo-dark"
|
||||
src="/assets/challenges/key-tag/card-key-tag-dark.webp"
|
||||
alt="Finished red Key Tag model on the dark SketchForge workplane"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function NameplatePreview() {
|
||||
return (
|
||||
<>
|
||||
<img
|
||||
className="challenge-key-tag-photo challenge-key-tag-photo-light"
|
||||
src="/assets/challenges/nameplate/card-nameplate-light.webp"
|
||||
alt="Finished blue ALEX nameplate on the SketchForge workplane"
|
||||
/>
|
||||
<img
|
||||
className="challenge-key-tag-photo challenge-key-tag-photo-dark"
|
||||
src="/assets/challenges/nameplate/card-nameplate-dark.webp"
|
||||
alt="Finished blue ALEX nameplate on the dark SketchForge workplane"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ChallengesDashboard({ onStartChallenge }: { onStartChallenge: (challenge: ChallengeTutorialId) => void }) {
|
||||
return (
|
||||
<div className="challenge-key-tag-page">
|
||||
<div className="challenge-key-tag-rail" aria-hidden="true">
|
||||
<span />
|
||||
<span />
|
||||
</div>
|
||||
|
||||
<div className="challenge-card-stack">
|
||||
<article className="challenge-key-tag-card">
|
||||
<div className="challenge-key-tag-preview">
|
||||
<KeyTagPreview />
|
||||
</div>
|
||||
|
||||
<div className="challenge-key-tag-content">
|
||||
<div className="challenge-key-tag-title-row">
|
||||
<span>01</span>
|
||||
<h2>Key Tag</h2>
|
||||
</div>
|
||||
|
||||
<p>Build your first Key Tag from simple shapes.</p>
|
||||
|
||||
<div className="challenge-key-tag-skills" aria-label="Skills used in this challenge">
|
||||
<span><Box size={16} aria-hidden="true" /> Basic shapes</span>
|
||||
<span><AlignCenter size={16} aria-hidden="true" /> Align</span>
|
||||
<span><CircleDotDashed size={16} aria-hidden="true" /> Hole</span>
|
||||
<span><LockKeyhole size={16} aria-hidden="true" /> Lock</span>
|
||||
<span><Group size={16} aria-hidden="true" /> Group</span>
|
||||
</div>
|
||||
|
||||
<button type="button" className="challenge-key-tag-start" onClick={() => onStartChallenge("key-tag")}>
|
||||
Start Challenge
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article className="challenge-key-tag-card">
|
||||
<div className="challenge-key-tag-preview">
|
||||
<NameplatePreview />
|
||||
</div>
|
||||
|
||||
<div className="challenge-key-tag-content">
|
||||
<div className="challenge-key-tag-title-row">
|
||||
<span>02</span>
|
||||
<h2>Personalized Nameplate</h2>
|
||||
</div>
|
||||
|
||||
<p>Create a printable nameplate with rounded edges and raised custom text.</p>
|
||||
|
||||
<div className="challenge-key-tag-skills" aria-label="Skills used in this challenge">
|
||||
<span><Box size={16} aria-hidden="true" /> Box</span>
|
||||
<span><CircleDotDashed size={16} aria-hidden="true" /> Fillet</span>
|
||||
<span><Type size={16} aria-hidden="true" /> Text</span>
|
||||
<span><MoveUp size={16} aria-hidden="true" /> Elevation</span>
|
||||
<span><AlignCenter size={16} aria-hidden="true" /> Align</span>
|
||||
<span><Group size={16} aria-hidden="true" /> Group</span>
|
||||
</div>
|
||||
|
||||
<button type="button" className="challenge-key-tag-start" onClick={() => onStartChallenge("nameplate")}>
|
||||
Start Challenge
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
"use client";
|
||||
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
|
||||
const KEY_TAG_STEP_STORAGE_KEY = "sketchforge:key-tag-tutorial-step";
|
||||
|
||||
type TutorialDimension = {
|
||||
label: "Length" | "Width" | "Height";
|
||||
value: string;
|
||||
slider: number;
|
||||
};
|
||||
|
||||
type TutorialStep = {
|
||||
eyebrow: string;
|
||||
title: string;
|
||||
body: string;
|
||||
image: string;
|
||||
alt: string;
|
||||
dimensions?: TutorialDimension[];
|
||||
snapGrid?: string;
|
||||
};
|
||||
|
||||
const STEPS: TutorialStep[] = [
|
||||
{
|
||||
eyebrow: "Before you start",
|
||||
title: "Build a Key Tag",
|
||||
body: "Set Snap Grid to 0.5 mm, then build the Key Tag from simple shapes.",
|
||||
image: "/assets/challenges/key-tag/01-finished-target.png",
|
||||
alt: "Finished Key Tag shown in the SketchForge workplane",
|
||||
snapGrid: "0.5 mm",
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 1",
|
||||
title: "Make the middle",
|
||||
body: "Add a Box, then set its size in the shape panel.",
|
||||
image: "/assets/challenges/key-tag/02-middle-box.png",
|
||||
alt: "The middle box of the Key Tag in SketchForge",
|
||||
dimensions: [
|
||||
{ label: "Length", value: "25.50 mm", slider: 38 },
|
||||
{ label: "Width", value: "11.50 mm", slider: 20 },
|
||||
{ label: "Height", value: "1.00 mm", slider: 5 },
|
||||
],
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 2",
|
||||
title: "Add the left round end",
|
||||
body: "Add a solid Cylinder and place half of it over the left end of the box.",
|
||||
image: "/assets/challenges/key-tag/03-left-round-end.png",
|
||||
alt: "A solid cylinder added to the left end of the Key Tag",
|
||||
dimensions: [
|
||||
{ label: "Length", value: "11.50 mm", slider: 20 },
|
||||
{ label: "Width", value: "11.50 mm", slider: 20 },
|
||||
{ label: "Height", value: "1.00 mm", slider: 5 },
|
||||
],
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 3",
|
||||
title: "Make the other end",
|
||||
body: "Duplicate the solid cylinder and place the copy on the right end.",
|
||||
image: "/assets/challenges/key-tag/04-right-round-end.png",
|
||||
alt: "Two solid cylinders forming both rounded ends of the Key Tag",
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 4",
|
||||
title: "Lock the left circle",
|
||||
body: "Select the left solid cylinder and press Lock. It will be the alignment reference.",
|
||||
image: "/assets/challenges/key-tag/05-select-left-circle.png",
|
||||
alt: "The left solid cylinder selected in the SketchForge workplane",
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 5",
|
||||
title: "Create the hole",
|
||||
body: "Add another Cylinder, set its size, then change it from Solid to Hole.",
|
||||
image: "/assets/challenges/key-tag/06-hole-cylinder.png",
|
||||
alt: "The small hole cylinder added near the left end of the Key Tag",
|
||||
dimensions: [
|
||||
{ label: "Length", value: "3.00 mm", slider: 8 },
|
||||
{ label: "Width", value: "3.00 mm", slider: 8 },
|
||||
{ label: "Height", value: "2.00 mm", slider: 7 },
|
||||
],
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 6",
|
||||
title: "Align the hole",
|
||||
body: "Select the hole and the locked left circle. Press Align and choose the middle on both horizontal axes.",
|
||||
image: "/assets/challenges/key-tag/07-align-hole.png",
|
||||
alt: "The hole aligned to the center of the left solid cylinder",
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 7",
|
||||
title: "Unlock the circle",
|
||||
body: "Select the left solid circle again and press Unlock.",
|
||||
image: "/assets/challenges/key-tag/08-unlock-left-circle.png",
|
||||
alt: "The left solid cylinder selected again after the hole has been aligned",
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 8",
|
||||
title: "Group the Key Tag",
|
||||
body: "Select the box, both solid circles, and the hole. Press Group.",
|
||||
image: "/assets/challenges/key-tag/09-grouped-key-tag.png",
|
||||
alt: "The finished grouped Key Tag selected in SketchForge",
|
||||
},
|
||||
];
|
||||
|
||||
function storedStepIndex() {
|
||||
if (typeof window === "undefined") return 0;
|
||||
const parsed = Number.parseInt(window.localStorage.getItem(KEY_TAG_STEP_STORAGE_KEY) ?? "0", 10);
|
||||
return Number.isFinite(parsed) ? Math.max(0, Math.min(STEPS.length - 1, parsed)) : 0;
|
||||
}
|
||||
|
||||
export function KeyTagTutorialPanel({
|
||||
onFinish,
|
||||
collapsed = false,
|
||||
onCollapsedChange,
|
||||
}: {
|
||||
onFinish?: () => void;
|
||||
collapsed?: boolean;
|
||||
onCollapsedChange?: (collapsed: boolean) => void;
|
||||
}) {
|
||||
const [stepIndex, setStepIndex] = useState(storedStepIndex);
|
||||
const step = STEPS[stepIndex];
|
||||
const first = stepIndex === 0;
|
||||
const last = stepIndex === STEPS.length - 1;
|
||||
|
||||
const goToStep = (index: number) => {
|
||||
const next = Math.max(0, Math.min(STEPS.length - 1, index));
|
||||
setStepIndex(next);
|
||||
window.localStorage.setItem(KEY_TAG_STEP_STORAGE_KEY, String(next));
|
||||
};
|
||||
|
||||
if (collapsed) {
|
||||
return (
|
||||
<aside className="key-tag-tutorial-panel key-tag-tutorial-panel-collapsed" aria-label="Key Tag challenge instructions">
|
||||
<button
|
||||
type="button"
|
||||
className="key-tag-tutorial-expand"
|
||||
title="Expand challenge instructions"
|
||||
aria-label="Expand challenge instructions"
|
||||
onClick={() => onCollapsedChange?.(false)}
|
||||
>
|
||||
<ChevronLeft size={19} />
|
||||
</button>
|
||||
<span className="key-tag-tutorial-collapsed-label">Key Tag</span>
|
||||
<span className="key-tag-tutorial-collapsed-count">{stepIndex + 1}/{STEPS.length}</span>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<aside
|
||||
className="key-tag-tutorial-panel"
|
||||
aria-label="Key Tag challenge instructions"
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
onWheel={(event) => event.stopPropagation()}
|
||||
>
|
||||
<header className="key-tag-tutorial-header">
|
||||
<div>
|
||||
<span>Challenge 1</span>
|
||||
<strong>Key Tag</strong>
|
||||
</div>
|
||||
<div className="key-tag-tutorial-header-actions">
|
||||
<span className="key-tag-tutorial-count">{stepIndex + 1} / {STEPS.length}</span>
|
||||
<button
|
||||
type="button"
|
||||
className="key-tag-tutorial-collapse"
|
||||
title="Minimize challenge instructions"
|
||||
aria-label="Minimize challenge instructions"
|
||||
onClick={() => onCollapsedChange?.(true)}
|
||||
>
|
||||
<ChevronRight size={18} />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="key-tag-tutorial-body">
|
||||
<div className="key-tag-tutorial-copy">
|
||||
<span className="key-tag-tutorial-eyebrow">{step.eyebrow}</span>
|
||||
<h2>{step.title}</h2>
|
||||
<p>{step.body}</p>
|
||||
|
||||
{step.snapGrid ? (
|
||||
<div className="key-tag-snap-row" aria-label={`Snap Grid ${step.snapGrid}`}>
|
||||
<span>Snap Grid</span>
|
||||
<strong>{step.snapGrid}</strong>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{step.dimensions ? (
|
||||
<div className="key-tag-tutorial-dimensions" aria-label="Required dimensions">
|
||||
{step.dimensions.map((dimension) => (
|
||||
<div className="key-tag-tutorial-dimension-control" key={dimension.label}>
|
||||
<div className="key-tag-tutorial-dimension-heading">
|
||||
<span>{dimension.label}</span>
|
||||
<strong>{dimension.value}</strong>
|
||||
</div>
|
||||
<div className="key-tag-tutorial-slider" aria-hidden="true">
|
||||
<span style={{ width: `${dimension.slider}%` }} />
|
||||
<i style={{ left: `${dimension.slider}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="key-tag-tutorial-image-box">
|
||||
<img className="key-tag-tutorial-capture" src={step.image} alt={step.alt} draggable={false} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer className="key-tag-tutorial-footer">
|
||||
<button type="button" className="secondary" disabled={first} onClick={() => goToStep(stepIndex - 1)}>
|
||||
<ChevronLeft size={17} /> Previous
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="primary"
|
||||
onClick={() => {
|
||||
if (last) {
|
||||
window.localStorage.removeItem(KEY_TAG_STEP_STORAGE_KEY);
|
||||
onFinish?.();
|
||||
return;
|
||||
}
|
||||
goToStep(stepIndex + 1);
|
||||
}}
|
||||
>
|
||||
{last ? "Finish" : "Next"} {!last ? <ChevronRight size={17} /> : null}
|
||||
</button>
|
||||
</footer>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
"use client";
|
||||
|
||||
import { ArrowUp, ChevronLeft, ChevronRight } from "lucide-react";
|
||||
import { useLayoutEffect, useState } from "react";
|
||||
|
||||
const NAMEPLATE_STEP_STORAGE_KEY = "sketchforge:nameplate-tutorial-step";
|
||||
|
||||
type TutorialDimension = {
|
||||
label: "Length" | "Width" | "Height" | "Elevation";
|
||||
value: string;
|
||||
slider: number;
|
||||
};
|
||||
|
||||
type TutorialStep = {
|
||||
eyebrow: string;
|
||||
title: string;
|
||||
body: string;
|
||||
image: string;
|
||||
alt: string;
|
||||
dimensions?: TutorialDimension[];
|
||||
snapGrid?: string;
|
||||
callout?: string;
|
||||
};
|
||||
|
||||
const STEPS: TutorialStep[] = [
|
||||
{
|
||||
eyebrow: "Before you start",
|
||||
title: "Build a Nameplate",
|
||||
body: "Create a rounded base, personalize a Text object, then combine both parts into one printable design.",
|
||||
image: "/assets/challenges/nameplate/01-finished-target.webp",
|
||||
alt: "Finished blue ALEX nameplate on the SketchForge workplane",
|
||||
snapGrid: "0.5 mm",
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 1",
|
||||
title: "Make the base",
|
||||
body: "Add a Box and enter these dimensions in the shape panel.",
|
||||
image: "/assets/challenges/nameplate/02-base-box.webp",
|
||||
alt: "Plain rectangular blue nameplate base",
|
||||
dimensions: [
|
||||
{ label: "Length", value: "24.00 mm", slider: 24 },
|
||||
{ label: "Width", value: "70.00 mm", slider: 70 },
|
||||
{ label: "Height", value: "3.00 mm", slider: 12 },
|
||||
],
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 2",
|
||||
title: "Round the outside",
|
||||
body: "Select the base, press Fillet, select its outside edges, and apply the treatment.",
|
||||
image: "/assets/challenges/nameplate/03-rounded-base.webp",
|
||||
alt: "Blue nameplate base with softly rounded outer edges",
|
||||
callout: "Use a 1.00 mm fillet amount.",
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 3",
|
||||
title: "Add a Text object",
|
||||
body: "Open Shapes and add Text. The new object starts with the letter T.",
|
||||
image: "/assets/challenges/nameplate/04-text-added.webp",
|
||||
alt: "A red capital T Text object on the blue nameplate base",
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 4",
|
||||
title: "Personalize the text",
|
||||
body: "Change the Text field to your name. This example uses ALEX. Pick any font you like.",
|
||||
image: "/assets/challenges/nameplate/05-text-customized.webp",
|
||||
alt: "Raised red ALEX text placed off-center on the blue base",
|
||||
dimensions: [
|
||||
{ label: "Height", value: "2.00 mm", slider: 9 },
|
||||
],
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 5",
|
||||
title: "Place it on top",
|
||||
body: "Lift the Text object until its bottom sits exactly on the top face of the 3 mm base.",
|
||||
image: "/assets/challenges/nameplate/05-text-customized.webp",
|
||||
alt: "Raised red ALEX text resting on the blue nameplate base",
|
||||
dimensions: [
|
||||
{ label: "Elevation", value: "3.00 mm", slider: 12 },
|
||||
],
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 6",
|
||||
title: "Center the name",
|
||||
body: "Lock the base, select the Text and base, then Align to the middle on both horizontal axes. Unlock the base afterward.",
|
||||
image: "/assets/challenges/nameplate/06-text-centered.webp",
|
||||
alt: "Red ALEX text centered on the blue nameplate base",
|
||||
callout: "The locked base stays fixed as your alignment reference.",
|
||||
},
|
||||
{
|
||||
eyebrow: "Step 7",
|
||||
title: "Group the Nameplate",
|
||||
body: "Select the base and Text object, then press Group to make one finished printable model.",
|
||||
image: "/assets/challenges/nameplate/07-grouped-nameplate.webp",
|
||||
alt: "Finished grouped blue ALEX nameplate",
|
||||
},
|
||||
];
|
||||
|
||||
function storedStepIndex() {
|
||||
if (typeof window === "undefined") return 0;
|
||||
const parsed = Number.parseInt(window.localStorage.getItem(NAMEPLATE_STEP_STORAGE_KEY) ?? "0", 10);
|
||||
return Number.isFinite(parsed) ? Math.max(0, Math.min(STEPS.length - 1, parsed)) : 0;
|
||||
}
|
||||
|
||||
function FilletButtonCoachmark() {
|
||||
const [position, setPosition] = useState<{ left: number; top: number } | null>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const target = document.querySelector<HTMLButtonElement>('button[data-sketchforge-tool="fillet"]');
|
||||
if (!target) return;
|
||||
|
||||
const updatePosition = () => {
|
||||
const rect = target.getBoundingClientRect();
|
||||
setPosition({
|
||||
left: rect.left + rect.width / 2,
|
||||
top: rect.bottom + 42,
|
||||
});
|
||||
};
|
||||
|
||||
target.classList.add("nameplate-fillet-button-target");
|
||||
updatePosition();
|
||||
window.addEventListener("resize", updatePosition);
|
||||
window.addEventListener("scroll", updatePosition, true);
|
||||
const observer = new ResizeObserver(updatePosition);
|
||||
observer.observe(target);
|
||||
|
||||
return () => {
|
||||
target.classList.remove("nameplate-fillet-button-target");
|
||||
window.removeEventListener("resize", updatePosition);
|
||||
window.removeEventListener("scroll", updatePosition, true);
|
||||
observer.disconnect();
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!position) return null;
|
||||
|
||||
return (
|
||||
<div className="nameplate-fillet-coachmark" style={position} role="status">
|
||||
<ArrowUp size={30} strokeWidth={3} aria-hidden="true" />
|
||||
<strong>Click Fillet</strong>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function NameplateTutorialPanel({
|
||||
onFinish,
|
||||
collapsed = false,
|
||||
onCollapsedChange,
|
||||
}: {
|
||||
onFinish?: () => void;
|
||||
collapsed?: boolean;
|
||||
onCollapsedChange?: (collapsed: boolean) => void;
|
||||
}) {
|
||||
const [stepIndex, setStepIndex] = useState(storedStepIndex);
|
||||
const step = STEPS[stepIndex];
|
||||
const first = stepIndex === 0;
|
||||
const last = stepIndex === STEPS.length - 1;
|
||||
|
||||
const goToStep = (index: number) => {
|
||||
const next = Math.max(0, Math.min(STEPS.length - 1, index));
|
||||
setStepIndex(next);
|
||||
window.localStorage.setItem(NAMEPLATE_STEP_STORAGE_KEY, String(next));
|
||||
};
|
||||
|
||||
if (collapsed) {
|
||||
return (
|
||||
<aside className="key-tag-tutorial-panel key-tag-tutorial-panel-collapsed" aria-label="Personalized Nameplate challenge instructions">
|
||||
<button
|
||||
type="button"
|
||||
className="key-tag-tutorial-expand"
|
||||
title="Expand challenge instructions"
|
||||
aria-label="Expand challenge instructions"
|
||||
onClick={() => onCollapsedChange?.(false)}
|
||||
>
|
||||
<ChevronLeft size={19} />
|
||||
</button>
|
||||
<span className="key-tag-tutorial-collapsed-label">Nameplate</span>
|
||||
<span className="key-tag-tutorial-collapsed-count">{stepIndex + 1}/{STEPS.length}</span>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{stepIndex === 2 ? <FilletButtonCoachmark /> : null}
|
||||
<aside
|
||||
className="key-tag-tutorial-panel"
|
||||
aria-label="Personalized Nameplate challenge instructions"
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
onWheel={(event) => event.stopPropagation()}
|
||||
>
|
||||
<header className="key-tag-tutorial-header">
|
||||
<div>
|
||||
<span>Challenge 2</span>
|
||||
<strong>Personalized Nameplate</strong>
|
||||
</div>
|
||||
<div className="key-tag-tutorial-header-actions">
|
||||
<span className="key-tag-tutorial-count">{stepIndex + 1} / {STEPS.length}</span>
|
||||
<button
|
||||
type="button"
|
||||
className="key-tag-tutorial-collapse"
|
||||
title="Minimize challenge instructions"
|
||||
aria-label="Minimize challenge instructions"
|
||||
onClick={() => onCollapsedChange?.(true)}
|
||||
>
|
||||
<ChevronRight size={18} />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="key-tag-tutorial-body">
|
||||
<div className="key-tag-tutorial-copy">
|
||||
<span className="key-tag-tutorial-eyebrow">{step.eyebrow}</span>
|
||||
<h2>{step.title}</h2>
|
||||
<p>{step.body}</p>
|
||||
|
||||
{step.snapGrid ? (
|
||||
<div className="key-tag-snap-row" aria-label={`Snap Grid ${step.snapGrid}`}>
|
||||
<span>Snap Grid</span>
|
||||
<strong>{step.snapGrid}</strong>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{step.callout ? <div className="nameplate-tutorial-callout">{step.callout}</div> : null}
|
||||
|
||||
{step.dimensions ? (
|
||||
<div className="key-tag-tutorial-dimensions" aria-label="Required dimensions">
|
||||
{step.dimensions.map((dimension) => (
|
||||
<div className="key-tag-tutorial-dimension-control" key={dimension.label}>
|
||||
<div className="key-tag-tutorial-dimension-heading">
|
||||
<span>{dimension.label}</span>
|
||||
<strong>{dimension.value}</strong>
|
||||
</div>
|
||||
<div className="key-tag-tutorial-slider" aria-hidden="true">
|
||||
<span style={{ width: `${dimension.slider}%` }} />
|
||||
<i style={{ left: `${dimension.slider}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="key-tag-tutorial-image-box">
|
||||
<img className="key-tag-tutorial-capture" src={step.image} alt={step.alt} draggable={false} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer className="key-tag-tutorial-footer">
|
||||
<button type="button" className="secondary" disabled={first} onClick={() => goToStep(stepIndex - 1)}>
|
||||
<ChevronLeft size={17} /> Previous
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="primary"
|
||||
onClick={() => {
|
||||
if (last) {
|
||||
window.localStorage.removeItem(NAMEPLATE_STEP_STORAGE_KEY);
|
||||
onFinish?.();
|
||||
return;
|
||||
}
|
||||
goToStep(stepIndex + 1);
|
||||
}}
|
||||
>
|
||||
{last ? "Finish" : "Next"} {!last ? <ChevronRight size={17} /> : null}
|
||||
</button>
|
||||
</footer>
|
||||
</aside>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user