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
Add toolbar buttons ruler and cut previews
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 17 KiB |
@@ -985,11 +985,34 @@ button {
|
|||||||
|
|
||||||
.toolbar-icon svg,
|
.toolbar-icon svg,
|
||||||
.toolbar-icon .toolbar-sprite-icon,
|
.toolbar-icon .toolbar-sprite-icon,
|
||||||
.toolbar-icon .vector-toolbar-sprite-icon {
|
.toolbar-icon .vector-toolbar-sprite-icon,
|
||||||
|
.toolbar-icon .toolbar-command-icon {
|
||||||
width: 32px;
|
width: 32px;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toolbar-command-icon {
|
||||||
|
display: block;
|
||||||
|
object-fit: contain;
|
||||||
|
opacity: 0.96;
|
||||||
|
transition: filter 120ms ease, opacity 120ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-icon.disabled .toolbar-command-icon {
|
||||||
|
filter: grayscale(1) brightness(1.25);
|
||||||
|
opacity: 0.22;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-icon:not(.disabled):hover .toolbar-command-icon {
|
||||||
|
filter: contrast(1.08) brightness(0.94) drop-shadow(0 0 4px rgba(0, 156, 222, 0.3));
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-icon.active .toolbar-command-icon {
|
||||||
|
filter: contrast(1.12) brightness(0.9) drop-shadow(0 0 5px rgba(0, 156, 222, 0.38));
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.toolbar-sprite-icon {
|
.toolbar-sprite-icon {
|
||||||
display: block;
|
display: block;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
@@ -1482,7 +1505,7 @@ button {
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
top: 173px;
|
top: 173px;
|
||||||
left: 8px;
|
left: 8px;
|
||||||
z-index: 4;
|
z-index: 8;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
}
|
}
|
||||||
@@ -1505,6 +1528,14 @@ button {
|
|||||||
border-color: #c4d2dc;
|
border-color: #c4d2dc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.camera-controls button.active,
|
||||||
|
.camera-controls button[aria-pressed="true"] {
|
||||||
|
color: #007eae;
|
||||||
|
background: #e8f8fd;
|
||||||
|
border-color: #63cbe8;
|
||||||
|
box-shadow: 0 0 0 3px rgba(0, 159, 207, 0.14), 0 1px 2px rgba(30, 50, 70, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
.workplane-wrap {
|
.workplane-wrap {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
@@ -1539,6 +1570,11 @@ button {
|
|||||||
cursor: crosshair;
|
cursor: crosshair;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.workplane-wrap.ruler-mode .three-workplane-host,
|
||||||
|
.workplane-wrap.ruler-mode .three-workplane-host:active {
|
||||||
|
cursor: crosshair;
|
||||||
|
}
|
||||||
|
|
||||||
.three-workplane-host canvas {
|
.three-workplane-host canvas {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -1554,6 +1590,78 @@ button {
|
|||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ruler-overlay {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 7;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ruler-guides {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
overflow: visible;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ruler-segment {
|
||||||
|
stroke: #173b5a;
|
||||||
|
stroke-width: 2;
|
||||||
|
vector-effect: non-scaling-stroke;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ruler-segment-hit {
|
||||||
|
stroke: transparent;
|
||||||
|
stroke-width: 14;
|
||||||
|
vector-effect: non-scaling-stroke;
|
||||||
|
pointer-events: stroke;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ruler-point,
|
||||||
|
.ruler-hover-point {
|
||||||
|
fill: #ffffff;
|
||||||
|
stroke: #008fbe;
|
||||||
|
stroke-width: 2.4;
|
||||||
|
vector-effect: non-scaling-stroke;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ruler-point {
|
||||||
|
pointer-events: all;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ruler-point.pending {
|
||||||
|
fill: #00a7d8;
|
||||||
|
stroke: #ffffff;
|
||||||
|
filter: drop-shadow(0 0 3px rgba(0, 126, 174, 0.72));
|
||||||
|
}
|
||||||
|
|
||||||
|
.ruler-hover-point {
|
||||||
|
fill: rgba(0, 167, 216, 0.28);
|
||||||
|
stroke-dasharray: 3 2;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ruler-label {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 2;
|
||||||
|
min-width: 46px;
|
||||||
|
padding: 5px 9px;
|
||||||
|
color: #16283a;
|
||||||
|
background: rgba(255, 255, 255, 0.96);
|
||||||
|
border: 1px solid rgba(190, 211, 224, 0.96);
|
||||||
|
border-radius: 999px;
|
||||||
|
box-shadow: 0 1px 4px rgba(20, 42, 58, 0.12);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1;
|
||||||
|
text-align: center;
|
||||||
|
pointer-events: none;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
}
|
||||||
|
|
||||||
.transform-overlay {
|
.transform-overlay {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
@@ -2732,9 +2840,11 @@ button {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-tool svg {
|
.sidebar-tool svg,
|
||||||
|
.sidebar-tool .toolbar-command-icon {
|
||||||
width: 58px;
|
width: 58px;
|
||||||
height: 58px;
|
height: 58px;
|
||||||
|
object-fit: contain;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-tool:hover {
|
.sidebar-tool:hover {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { Clock3, FileUp, Grid3X3, HomeIcon, List, Plus, Search, Settings, Slider
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { SketchForgeEditor, importedShapeFromStl } from "@/components/SketchForgeEditor";
|
import { SketchForgeEditor, importedShapeFromStl } from "@/components/SketchForgeEditor";
|
||||||
import { createLocalId } from "@/lib/localIds";
|
import { createLocalId } from "@/lib/localIds";
|
||||||
|
import { importExtensionSupported } from "@/lib/stlImport";
|
||||||
import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE, normalizeSnapGrid, normalizeWorkspaceSettings } from "@/lib/workplaneSettings";
|
import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE, normalizeSnapGrid, normalizeWorkspaceSettings } from "@/lib/workplaneSettings";
|
||||||
import type { GridSize, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
|
import type { GridSize, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
|
||||||
|
|
||||||
@@ -512,8 +513,7 @@ export default function Home() {
|
|||||||
|
|
||||||
const importStlFileFromDashboard = useCallback(
|
const importStlFileFromDashboard = useCallback(
|
||||||
async (file: File) => {
|
async (file: File) => {
|
||||||
const extension = file.name.split(".").pop()?.toLowerCase();
|
if (!importExtensionSupported(file.name)) {
|
||||||
if (extension !== "stl") {
|
|
||||||
setDashboardNotice("Unsupported file type. Use STL.");
|
setDashboardNotice("Unsupported file type. Use STL.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { ChevronDown, Search } from "lucide-react";
|
import { ChevronDown, Search } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { NotesToolIcon, RulerToolIcon, WorkplaneToolIcon } from "./icons";
|
import { NotesToolIcon, WorkplaneToolIcon } from "./icons";
|
||||||
import type { ShapeAsset } from "@/types/sketchforge";
|
import type { ShapeAsset } from "@/types/sketchforge";
|
||||||
|
|
||||||
const categories = [
|
const categories = [
|
||||||
@@ -55,9 +55,6 @@ export function ShapesSidebar({ onAddShape }: ShapesSidebarProps) {
|
|||||||
<button className="sidebar-tool" aria-label="Workplane">
|
<button className="sidebar-tool" aria-label="Workplane">
|
||||||
<WorkplaneToolIcon />
|
<WorkplaneToolIcon />
|
||||||
</button>
|
</button>
|
||||||
<button className="sidebar-tool" aria-label="Ruler">
|
|
||||||
<RulerToolIcon />
|
|
||||||
</button>
|
|
||||||
<button className="sidebar-tool" aria-label="Notes">
|
<button className="sidebar-tool" aria-label="Notes">
|
||||||
<NotesToolIcon />
|
<NotesToolIcon />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -23,22 +23,22 @@ import {
|
|||||||
ToolbarCaretDownIcon,
|
ToolbarCaretDownIcon,
|
||||||
ToolbarCopyIcon,
|
ToolbarCopyIcon,
|
||||||
ToolbarDuplicateIcon,
|
ToolbarDuplicateIcon,
|
||||||
|
ToolbarDropToWorkplaneIcon,
|
||||||
ToolbarExportIcon,
|
ToolbarExportIcon,
|
||||||
ToolbarGroupIcon,
|
ToolbarGroupIcon,
|
||||||
ToolbarHideSelectedIcon,
|
ToolbarHideSelectedIcon,
|
||||||
ToolbarImportIcon,
|
ToolbarImportIcon,
|
||||||
ToolbarMagnetIcon,
|
|
||||||
ToolbarMirrorIcon,
|
ToolbarMirrorIcon,
|
||||||
ToolbarPasteIcon,
|
ToolbarPasteIcon,
|
||||||
ToolbarRedoIcon,
|
ToolbarRedoIcon,
|
||||||
ToolbarBringForwardIcon,
|
ToolbarSnapGridIcon,
|
||||||
ToolbarSendBackwardIcon,
|
|
||||||
ToolbarSettingsIcon,
|
ToolbarSettingsIcon,
|
||||||
ToolbarShapeAddIcon,
|
ToolbarShapeAddIcon,
|
||||||
ToolbarTrashIcon,
|
ToolbarTrashIcon,
|
||||||
ToolbarUngroupIcon,
|
ToolbarUngroupIcon,
|
||||||
ToolbarUndoIcon,
|
ToolbarUndoIcon,
|
||||||
ToolbarVectorExportIcon,
|
ToolbarVectorExportIcon,
|
||||||
|
ToolbarWorkplaneIcon,
|
||||||
} from "./icons";
|
} from "./icons";
|
||||||
import { WorkplaneViewport } from "./WorkplaneViewport";
|
import { WorkplaneViewport } from "./WorkplaneViewport";
|
||||||
import {
|
import {
|
||||||
@@ -56,7 +56,7 @@ import {
|
|||||||
} from "@/lib/workplaneShapes";
|
} from "@/lib/workplaneShapes";
|
||||||
import { createLocalId } from "@/lib/localIds";
|
import { createLocalId } from "@/lib/localIds";
|
||||||
import { makeShapeFromAsset, sceneShape, toolbarShapeAssets, type ToolbarShapeAsset } from "@/lib/shapeCatalog";
|
import { makeShapeFromAsset, sceneShape, toolbarShapeAssets, type ToolbarShapeAsset } from "@/lib/shapeCatalog";
|
||||||
import { importedShapeFromStl } from "@/lib/stlImport";
|
import { importedShapeFromStl, importExtensionSupported } from "@/lib/stlImport";
|
||||||
import type { AlignAxis, AlignHandleStatus, AlignTarget, GridSize, ShapeAsset, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
|
import type { AlignAxis, AlignHandleStatus, AlignTarget, GridSize, ShapeAsset, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
|
||||||
|
|
||||||
export { importedShapeFromStl };
|
export { importedShapeFromStl };
|
||||||
@@ -4833,8 +4833,7 @@ export function SketchForgeEditor({
|
|||||||
}, [commitShapes, shapes]);
|
}, [commitShapes, shapes]);
|
||||||
|
|
||||||
const selectFile = useCallback(async (file: File) => {
|
const selectFile = useCallback(async (file: File) => {
|
||||||
const extension = file.name.split(".").pop()?.toLowerCase();
|
if (!importExtensionSupported(file.name)) {
|
||||||
if (extension !== "stl") {
|
|
||||||
setNotice("Unsupported file type. Use STL.");
|
setNotice("Unsupported file type. Use STL.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -5311,9 +5310,9 @@ function SecondaryToolbar({
|
|||||||
{ label: "Ungroup", icon: ToolbarUngroupIcon, action: onUngroup, enabled: canUngroup },
|
{ label: "Ungroup", icon: ToolbarUngroupIcon, action: onUngroup, enabled: canUngroup },
|
||||||
{ label: "Align", icon: ToolbarAlignIcon, action: onAlign, enabled: canAlign, active: alignMode },
|
{ label: "Align", icon: ToolbarAlignIcon, action: onAlign, enabled: canAlign, active: alignMode },
|
||||||
{ label: "Mirror", icon: ToolbarMirrorIcon, action: onMirror, enabled: hasSelection, active: mirrorMode },
|
{ label: "Mirror", icon: ToolbarMirrorIcon, action: onMirror, enabled: hasSelection, active: mirrorMode },
|
||||||
{ label: "Snap to grid", icon: ToolbarMagnetIcon, action: onSnap, enabled: hasSelection },
|
{ label: "Snap to grid", icon: ToolbarSnapGridIcon, action: onSnap, enabled: hasSelection },
|
||||||
{ label: "Workplane", icon: ToolbarSendBackwardIcon, action: onWorkplaneTool, enabled: true, active: workplaneMode },
|
{ label: "Workplane", icon: ToolbarWorkplaneIcon, action: onWorkplaneTool, enabled: true, active: workplaneMode },
|
||||||
{ label: "Drop to workplane", icon: ToolbarBringForwardIcon, action: onDropToWorkplane, enabled: hasSelection },
|
{ label: "Drop to workplane", icon: ToolbarDropToWorkplaneIcon, action: onDropToWorkplane, enabled: hasSelection },
|
||||||
];
|
];
|
||||||
const renderToolButton = (tool: (typeof leftTools)[number] | (typeof rightTools)[number]) => {
|
const renderToolButton = (tool: (typeof leftTools)[number] | (typeof rightTools)[number]) => {
|
||||||
const { icon: Icon, action, enabled, label } = tool;
|
const { icon: Icon, action, enabled, label } = tool;
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Box, Check, Expand, Home, Minus, Plus } from "lucide-react";
|
import { Home, Minus, Plus } from "lucide-react";
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState, type Dispatch, type DragEvent, type MutableRefObject, type PointerEvent as ReactPointerEvent, type SetStateAction } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState, type Dispatch, type DragEvent, type MutableRefObject, type PointerEvent as ReactPointerEvent, type SetStateAction } from "react";
|
||||||
import * as THREE from "three";
|
import * as THREE from "three";
|
||||||
|
import { Brush, Evaluator, HOLLOW_INTERSECTION } from "three-bvh-csg";
|
||||||
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
||||||
import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry.js";
|
import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry.js";
|
||||||
import { TextGeometry } from "three/examples/jsm/geometries/TextGeometry.js";
|
import { TextGeometry } from "three/examples/jsm/geometries/TextGeometry.js";
|
||||||
@@ -208,6 +209,49 @@ type MarqueeState = {
|
|||||||
hasMoved: boolean;
|
hasMoved: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type RulerPoint = {
|
||||||
|
id: string;
|
||||||
|
x: number;
|
||||||
|
z: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type RulerSegment = {
|
||||||
|
id: string;
|
||||||
|
startId: string;
|
||||||
|
endId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type RulerModel = {
|
||||||
|
points: RulerPoint[];
|
||||||
|
segments: RulerSegment[];
|
||||||
|
startPointId: string | null;
|
||||||
|
hover: { x: number; z: number } | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type RulerOverlayState = {
|
||||||
|
points: Array<RulerPoint & { screenX: number; screenY: number }>;
|
||||||
|
segments: Array<RulerSegment & { x1: number; y1: number; x2: number; y2: number; labelX: number; labelY: number; label: string }>;
|
||||||
|
hover: { screenX: number; screenY: number } | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type RulerCandidate = {
|
||||||
|
x: number;
|
||||||
|
z: number;
|
||||||
|
pointId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function RulerGlyph() {
|
||||||
|
return (
|
||||||
|
<svg viewBox="0 0 32 32" width="30" height="30" aria-hidden="true">
|
||||||
|
<path d="M5 9.5 24.5 5 27 16 7.5 20.5 5 9.5Z" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinejoin="round" />
|
||||||
|
<path d="m10 8.5 1 4.2m4-5.3.7 2.9m4.3-4 .9 4.2m-12.3 7 1.7-3.8m4.1 2.8 1.2-2.7m4 1.6 1.5-3.5" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" />
|
||||||
|
<circle cx="7.5" cy="24.5" r="2" fill="currentColor" />
|
||||||
|
<circle cx="24.5" cy="24.5" r="2" fill="currentColor" />
|
||||||
|
<path d="M9.5 24.5h13" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
type RotationHandleSide = "near" | "right" | "far" | "left";
|
type RotationHandleSide = "near" | "right" | "far" | "left";
|
||||||
type RotationHandleSides = Record<RotationAxis, RotationHandleSide>;
|
type RotationHandleSides = Record<RotationAxis, RotationHandleSide>;
|
||||||
type ShapeUpdatePatch = Partial<WorkplaneShape> & { bakeTransform?: boolean };
|
type ShapeUpdatePatch = Partial<WorkplaneShape> & { bakeTransform?: boolean };
|
||||||
@@ -445,6 +489,117 @@ function projectToScreen(point: THREE.Vector3, state: ThreeState) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function syncRulerOverlay(
|
||||||
|
state: ThreeState,
|
||||||
|
model: RulerModel,
|
||||||
|
overlayRef: MutableRefObject<RulerOverlayState | null>,
|
||||||
|
setOverlay: Dispatch<SetStateAction<RulerOverlayState | null>>,
|
||||||
|
) {
|
||||||
|
const projectedPoints = new Map<string, { screenX: number; screenY: number }>();
|
||||||
|
const points = model.points.map((point) => {
|
||||||
|
const screen = projectToScreen(new THREE.Vector3(point.x, 0.12, point.z), state);
|
||||||
|
const projected = { screenX: screen.x, screenY: screen.y };
|
||||||
|
projectedPoints.set(point.id, projected);
|
||||||
|
return { ...point, ...projected };
|
||||||
|
});
|
||||||
|
const segments = model.segments.flatMap((segment) => {
|
||||||
|
const start = model.points.find((point) => point.id === segment.startId);
|
||||||
|
const end = model.points.find((point) => point.id === segment.endId);
|
||||||
|
const startScreen = projectedPoints.get(segment.startId);
|
||||||
|
const endScreen = projectedPoints.get(segment.endId);
|
||||||
|
if (!start || !end || !startScreen || !endScreen) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
...segment,
|
||||||
|
x1: startScreen.screenX,
|
||||||
|
y1: startScreen.screenY,
|
||||||
|
x2: endScreen.screenX,
|
||||||
|
y2: endScreen.screenY,
|
||||||
|
labelX: (startScreen.screenX + endScreen.screenX) / 2,
|
||||||
|
labelY: (startScreen.screenY + endScreen.screenY) / 2 - 18,
|
||||||
|
label: formatMeasure(Math.hypot(end.x - start.x, end.z - start.z)),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
|
const hoverScreen = model.hover ? projectToScreen(new THREE.Vector3(model.hover.x, 0.14, model.hover.z), state) : null;
|
||||||
|
const next: RulerOverlayState = {
|
||||||
|
points,
|
||||||
|
segments,
|
||||||
|
hover: hoverScreen ? { screenX: hoverScreen.x, screenY: hoverScreen.y } : null,
|
||||||
|
};
|
||||||
|
const previous = overlayRef.current;
|
||||||
|
const unchanged =
|
||||||
|
previous &&
|
||||||
|
previous.points.length === next.points.length &&
|
||||||
|
previous.segments.length === next.segments.length &&
|
||||||
|
previous.points.every((point, index) => {
|
||||||
|
const candidate = next.points[index];
|
||||||
|
return point.id === candidate.id && Math.abs(point.screenX - candidate.screenX) < 0.2 && Math.abs(point.screenY - candidate.screenY) < 0.2;
|
||||||
|
}) &&
|
||||||
|
previous.segments.every((segment, index) => {
|
||||||
|
const candidate = next.segments[index];
|
||||||
|
return segment.id === candidate.id && Math.abs(segment.labelX - candidate.labelX) < 0.2 && Math.abs(segment.labelY - candidate.labelY) < 0.2;
|
||||||
|
}) &&
|
||||||
|
((!previous.hover && !next.hover) ||
|
||||||
|
(previous.hover && next.hover && Math.abs(previous.hover.screenX - next.hover.screenX) < 0.2 && Math.abs(previous.hover.screenY - next.hover.screenY) < 0.2));
|
||||||
|
if (!unchanged) {
|
||||||
|
overlayRef.current = next;
|
||||||
|
setOverlay(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function RulerOverlay({
|
||||||
|
overlay,
|
||||||
|
startPointId,
|
||||||
|
active,
|
||||||
|
onPointPointerDown,
|
||||||
|
onSegmentPointerDown,
|
||||||
|
}: {
|
||||||
|
overlay: RulerOverlayState;
|
||||||
|
startPointId: string | null;
|
||||||
|
active: boolean;
|
||||||
|
onPointPointerDown: (event: ReactPointerEvent<SVGCircleElement>, pointId: string) => void;
|
||||||
|
onSegmentPointerDown: (event: ReactPointerEvent<SVGLineElement>, segmentId: string) => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className={`ruler-overlay ${active ? "active" : ""}`} aria-label="Ruler measurements">
|
||||||
|
<svg className="ruler-guides" width="100%" height="100%" aria-hidden="true">
|
||||||
|
{overlay.segments.map((segment) => (
|
||||||
|
<g key={segment.id}>
|
||||||
|
<line className="ruler-segment" x1={segment.x1} y1={segment.y1} x2={segment.x2} y2={segment.y2} />
|
||||||
|
<line
|
||||||
|
className="ruler-segment-hit"
|
||||||
|
x1={segment.x1}
|
||||||
|
y1={segment.y1}
|
||||||
|
x2={segment.x2}
|
||||||
|
y2={segment.y2}
|
||||||
|
onPointerDown={(event) => onSegmentPointerDown(event, segment.id)}
|
||||||
|
/>
|
||||||
|
</g>
|
||||||
|
))}
|
||||||
|
{overlay.points.map((point) => (
|
||||||
|
<circle
|
||||||
|
key={point.id}
|
||||||
|
className={`ruler-point ${point.id === startPointId ? "pending" : ""}`}
|
||||||
|
cx={point.screenX}
|
||||||
|
cy={point.screenY}
|
||||||
|
r="5"
|
||||||
|
onPointerDown={(event) => onPointPointerDown(event, point.id)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
{active && overlay.hover ? <circle className="ruler-hover-point" cx={overlay.hover.screenX} cy={overlay.hover.screenY} r="5" /> : null}
|
||||||
|
</svg>
|
||||||
|
{overlay.segments.map((segment) => (
|
||||||
|
<span key={`${segment.id}-label`} className="ruler-label" style={{ left: segment.labelX, top: segment.labelY }}>
|
||||||
|
{segment.label}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function shapeCenter(shape: WorkplaneShape) {
|
function shapeCenter(shape: WorkplaneShape) {
|
||||||
return new THREE.Vector3(shape.x, (shape.elevation ?? 0) + shape.height / 2, shape.z);
|
return new THREE.Vector3(shape.x, (shape.elevation ?? 0) + shape.height / 2, shape.z);
|
||||||
}
|
}
|
||||||
@@ -942,6 +1097,9 @@ export function WorkplaneViewport({
|
|||||||
const [pinnedRotationWheelView, setPinnedRotationWheelView] = useState<PinnedRotationWheelView | null>(null);
|
const [pinnedRotationWheelView, setPinnedRotationWheelView] = useState<PinnedRotationWheelView | null>(null);
|
||||||
const [editingDimension, setEditingDimension] = useState<EditingDimension>(null);
|
const [editingDimension, setEditingDimension] = useState<EditingDimension>(null);
|
||||||
const [editingRotation, setEditingRotation] = useState<EditingRotation>(null);
|
const [editingRotation, setEditingRotation] = useState<EditingRotation>(null);
|
||||||
|
const [rulerMode, setRulerMode] = useState(false);
|
||||||
|
const [rulerModel, setRulerModel] = useState<RulerModel>({ points: [], segments: [], startPointId: null, hover: null });
|
||||||
|
const [rulerOverlay, setRulerOverlay] = useState<RulerOverlayState | null>(null);
|
||||||
const hostRef = useRef<HTMLDivElement | null>(null);
|
const hostRef = useRef<HTMLDivElement | null>(null);
|
||||||
const threeRef = useRef<ThreeState | null>(null);
|
const threeRef = useRef<ThreeState | null>(null);
|
||||||
const shapesRef = useRef(shapes);
|
const shapesRef = useRef(shapes);
|
||||||
@@ -961,6 +1119,10 @@ export function WorkplaneViewport({
|
|||||||
const transformOverlayRef = useRef<TransformOverlayState | null>(null);
|
const transformOverlayRef = useRef<TransformOverlayState | null>(null);
|
||||||
const alignOverlayRef = useRef<AlignOverlayState | null>(null);
|
const alignOverlayRef = useRef<AlignOverlayState | null>(null);
|
||||||
const mirrorOverlayRef = useRef<MirrorOverlayState | null>(null);
|
const mirrorOverlayRef = useRef<MirrorOverlayState | null>(null);
|
||||||
|
const rulerModeRef = useRef(false);
|
||||||
|
const rulerModelRef = useRef(rulerModel);
|
||||||
|
const rulerOverlayRef = useRef<RulerOverlayState | null>(null);
|
||||||
|
const rulerIdRef = useRef(0);
|
||||||
const alignModeRef = useRef(alignMode);
|
const alignModeRef = useRef(alignMode);
|
||||||
const alignAnchorIdRef = useRef(alignAnchorId);
|
const alignAnchorIdRef = useRef(alignAnchorId);
|
||||||
const alignHandlesRef = useRef(alignHandles);
|
const alignHandlesRef = useRef(alignHandles);
|
||||||
@@ -1026,7 +1188,7 @@ export function WorkplaneViewport({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
shapesRef.current = shapes;
|
shapesRef.current = shapes;
|
||||||
rebuildShapes(threeRef.current, shapes, selectedIdsRef.current);
|
rebuildShapes(threeRef.current, shapes, selectedIdsRef.current, !transformRef.current && !dragRef.current);
|
||||||
if (threeRef.current) {
|
if (threeRef.current) {
|
||||||
syncTransformOverlay(threeRef.current, shapes, selectedIdsRef.current, transformOverlayRef, setTransformOverlay, Boolean(transformRef.current || dragRef.current));
|
syncTransformOverlay(threeRef.current, shapes, selectedIdsRef.current, transformOverlayRef, setTransformOverlay, Boolean(transformRef.current || dragRef.current));
|
||||||
syncAlignOverlay(threeRef.current, alignReferenceShapesRef.current, selectedIdsRef.current, alignModeRef.current, alignAnchorIdRef.current, alignHandlesRef.current, alignOverlayRef, setAlignOverlay);
|
syncAlignOverlay(threeRef.current, alignReferenceShapesRef.current, selectedIdsRef.current, alignModeRef.current, alignAnchorIdRef.current, alignHandlesRef.current, alignOverlayRef, setAlignOverlay);
|
||||||
@@ -1065,7 +1227,7 @@ export function WorkplaneViewport({
|
|||||||
setActiveTransformKind(null);
|
setActiveTransformKind(null);
|
||||||
}
|
}
|
||||||
selectedIdsRef.current = selectedIds;
|
selectedIdsRef.current = selectedIds;
|
||||||
rebuildShapes(threeRef.current, shapesRef.current, selectedIds);
|
rebuildShapes(threeRef.current, shapesRef.current, selectedIds, !transformRef.current && !dragRef.current);
|
||||||
if (threeRef.current) {
|
if (threeRef.current) {
|
||||||
syncTransformOverlay(threeRef.current, shapesRef.current, selectedIds, transformOverlayRef, setTransformOverlay, Boolean(transformRef.current || dragRef.current));
|
syncTransformOverlay(threeRef.current, shapesRef.current, selectedIds, transformOverlayRef, setTransformOverlay, Boolean(transformRef.current || dragRef.current));
|
||||||
syncAlignOverlay(threeRef.current, alignReferenceShapesRef.current, selectedIds, alignModeRef.current, alignAnchorIdRef.current, alignHandlesRef.current, alignOverlayRef, setAlignOverlay);
|
syncAlignOverlay(threeRef.current, alignReferenceShapesRef.current, selectedIds, alignModeRef.current, alignAnchorIdRef.current, alignHandlesRef.current, alignOverlayRef, setAlignOverlay);
|
||||||
@@ -1096,6 +1258,18 @@ export function WorkplaneViewport({
|
|||||||
snapRef.current = snap;
|
snapRef.current = snap;
|
||||||
}, [snap]);
|
}, [snap]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
rulerModeRef.current = rulerMode;
|
||||||
|
}, [rulerMode]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
rulerModelRef.current = rulerModel;
|
||||||
|
if (threeRef.current) {
|
||||||
|
syncRulerOverlay(threeRef.current, rulerModel, rulerOverlayRef, setRulerOverlay);
|
||||||
|
threeRef.current.needsRender = true;
|
||||||
|
}
|
||||||
|
}, [rulerModel]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
placementElevationRef.current = placementElevation;
|
placementElevationRef.current = placementElevation;
|
||||||
}, [placementElevation]);
|
}, [placementElevation]);
|
||||||
@@ -1163,6 +1337,7 @@ export function WorkplaneViewport({
|
|||||||
);
|
);
|
||||||
syncAlignOverlay(state, alignReferenceShapesRef.current, selectedIdsRef.current, alignModeRef.current, alignAnchorIdRef.current, alignHandlesRef.current, alignOverlayRef, setAlignOverlay);
|
syncAlignOverlay(state, alignReferenceShapesRef.current, selectedIdsRef.current, alignModeRef.current, alignAnchorIdRef.current, alignHandlesRef.current, alignOverlayRef, setAlignOverlay);
|
||||||
syncMirrorOverlay(state, mirrorReferenceShapesRef.current, selectedIdsRef.current, mirrorModeRef.current, mirrorOverlayRef, setMirrorOverlay);
|
syncMirrorOverlay(state, mirrorReferenceShapesRef.current, selectedIdsRef.current, mirrorModeRef.current, mirrorOverlayRef, setMirrorOverlay);
|
||||||
|
syncRulerOverlay(state, rulerModelRef.current, rulerOverlayRef, setRulerOverlay);
|
||||||
state.lastOverlaySync = now;
|
state.lastOverlaySync = now;
|
||||||
}
|
}
|
||||||
const renderStart = performance.now();
|
const renderStart = performance.now();
|
||||||
@@ -1259,6 +1434,166 @@ export function WorkplaneViewport({
|
|||||||
}, [toRawPlanePoint]);
|
}, [toRawPlanePoint]);
|
||||||
const toPlanePoint = useCallback((clientX: number, clientY: number) => toPlanePointAtY(clientX, clientY, 0), [toPlanePointAtY]);
|
const toPlanePoint = useCallback((clientX: number, clientY: number) => toPlanePointAtY(clientX, clientY, 0), [toPlanePointAtY]);
|
||||||
|
|
||||||
|
const storeRulerModel = useCallback((next: RulerModel) => {
|
||||||
|
rulerModelRef.current = next;
|
||||||
|
setRulerModel(next);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const setRulerActive = useCallback((active: boolean) => {
|
||||||
|
rulerModeRef.current = active;
|
||||||
|
setRulerMode(active);
|
||||||
|
if (!active) {
|
||||||
|
const current = rulerModelRef.current;
|
||||||
|
storeRulerModel({ ...current, startPointId: null, hover: null });
|
||||||
|
}
|
||||||
|
}, [storeRulerModel]);
|
||||||
|
|
||||||
|
const resolveRulerCandidate = useCallback(
|
||||||
|
(clientX: number, clientY: number): RulerCandidate | null => {
|
||||||
|
const state = threeRef.current;
|
||||||
|
if (!state) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const raw = toRawPlanePoint(clientX, clientY, state.dragPlane);
|
||||||
|
if (!raw) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const step = snapStep(snapRef.current);
|
||||||
|
const bounds = workspaceRef.current;
|
||||||
|
const snapped = {
|
||||||
|
x: clamp(snapValue(raw.x, step), -bounds.width / 2, bounds.width / 2),
|
||||||
|
z: clamp(snapValue(raw.z, step), -bounds.depth / 2, bounds.depth / 2),
|
||||||
|
};
|
||||||
|
|
||||||
|
const model = rulerModelRef.current;
|
||||||
|
const rect = state.renderer.domElement.getBoundingClientRect();
|
||||||
|
const localX = clientX - rect.left;
|
||||||
|
const localY = clientY - rect.top;
|
||||||
|
const closestPoint = model.points.reduce<{ point: RulerPoint; distance: number } | null>((closest, point) => {
|
||||||
|
const screen = projectToScreen(new THREE.Vector3(point.x, 0.12, point.z), state);
|
||||||
|
const distance = Math.hypot(screen.x - localX, screen.y - localY);
|
||||||
|
if (distance <= 12 && (!closest || distance < closest.distance)) {
|
||||||
|
return { point, distance };
|
||||||
|
}
|
||||||
|
return closest;
|
||||||
|
}, null);
|
||||||
|
if (closestPoint) {
|
||||||
|
return { x: closestPoint.point.x, z: closestPoint.point.z, pointId: closestPoint.point.id };
|
||||||
|
}
|
||||||
|
|
||||||
|
const closestSegment = model.segments.reduce<{ segment: RulerSegment; distance: number } | null>((closest, segment) => {
|
||||||
|
const start = model.points.find((point) => point.id === segment.startId);
|
||||||
|
const end = model.points.find((point) => point.id === segment.endId);
|
||||||
|
if (!start || !end) {
|
||||||
|
return closest;
|
||||||
|
}
|
||||||
|
const a = projectToScreen(new THREE.Vector3(start.x, 0.12, start.z), state);
|
||||||
|
const b = projectToScreen(new THREE.Vector3(end.x, 0.12, end.z), state);
|
||||||
|
const dx = b.x - a.x;
|
||||||
|
const dy = b.y - a.y;
|
||||||
|
const amount = dx * dx + dy * dy > 0.001 ? clamp(((localX - a.x) * dx + (localY - a.y) * dy) / (dx * dx + dy * dy), 0, 1) : 0;
|
||||||
|
const distance = Math.hypot(localX - (a.x + dx * amount), localY - (a.y + dy * amount));
|
||||||
|
if (distance <= 10 && (!closest || distance < closest.distance)) {
|
||||||
|
return { segment, distance };
|
||||||
|
}
|
||||||
|
return closest;
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
if (closestSegment) {
|
||||||
|
const start = model.points.find((point) => point.id === closestSegment.segment.startId);
|
||||||
|
const end = model.points.find((point) => point.id === closestSegment.segment.endId);
|
||||||
|
if (start && end) {
|
||||||
|
const dx = end.x - start.x;
|
||||||
|
const dz = end.z - start.z;
|
||||||
|
const length = Math.hypot(dx, dz);
|
||||||
|
if (length > 0.001) {
|
||||||
|
const directionX = dx / length;
|
||||||
|
const directionZ = dz / length;
|
||||||
|
const rawAlong = clamp((raw.x - start.x) * directionX + (raw.z - start.z) * directionZ, 0, length);
|
||||||
|
const along = clamp(step > 0 ? snapValue(rawAlong, step) : rawAlong, 0, length);
|
||||||
|
const x = start.x + directionX * along;
|
||||||
|
const z = start.z + directionZ * along;
|
||||||
|
const existing = model.points.find((point) => Math.hypot(point.x - x, point.z - z) < 0.001);
|
||||||
|
return { x, z, pointId: existing?.id };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = model.points.find((point) => Math.hypot(point.x - snapped.x, point.z - snapped.z) < 0.001);
|
||||||
|
return { ...snapped, pointId: existing?.id };
|
||||||
|
},
|
||||||
|
[toRawPlanePoint],
|
||||||
|
);
|
||||||
|
|
||||||
|
const selectRulerCandidate = useCallback(
|
||||||
|
(candidate: RulerCandidate) => {
|
||||||
|
const current = rulerModelRef.current;
|
||||||
|
const existing = candidate.pointId ? current.points.find((point) => point.id === candidate.pointId) : current.points.find((point) => Math.hypot(point.x - candidate.x, point.z - candidate.z) < 0.001);
|
||||||
|
const point = existing ?? { id: `ruler-point-${++rulerIdRef.current}`, x: candidate.x, z: candidate.z };
|
||||||
|
const points = existing ? current.points : [...current.points, point];
|
||||||
|
if (!current.startPointId) {
|
||||||
|
storeRulerModel({ ...current, points, startPointId: point.id, hover: { x: point.x, z: point.z } });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (current.startPointId === point.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const duplicate = current.segments.some(
|
||||||
|
(segment) =>
|
||||||
|
(segment.startId === current.startPointId && segment.endId === point.id) ||
|
||||||
|
(segment.startId === point.id && segment.endId === current.startPointId),
|
||||||
|
);
|
||||||
|
const segments = duplicate
|
||||||
|
? current.segments
|
||||||
|
: [...current.segments, { id: `ruler-segment-${++rulerIdRef.current}`, startId: current.startPointId, endId: point.id }];
|
||||||
|
storeRulerModel({ points, segments, startPointId: null, hover: null });
|
||||||
|
rulerModeRef.current = false;
|
||||||
|
setRulerMode(false);
|
||||||
|
},
|
||||||
|
[storeRulerModel],
|
||||||
|
);
|
||||||
|
|
||||||
|
const updateRulerHover = useCallback(
|
||||||
|
(clientX: number, clientY: number) => {
|
||||||
|
if (!rulerModeRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const candidate = resolveRulerCandidate(clientX, clientY);
|
||||||
|
const current = rulerModelRef.current;
|
||||||
|
const hover = candidate ? { x: candidate.x, z: candidate.z } : null;
|
||||||
|
if ((!current.hover && !hover) || (current.hover && hover && Math.hypot(current.hover.x - hover.x, current.hover.z - hover.z) < 0.0001)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
storeRulerModel({ ...current, hover });
|
||||||
|
},
|
||||||
|
[resolveRulerCandidate, storeRulerModel],
|
||||||
|
);
|
||||||
|
|
||||||
|
const removeRulerSegment = useCallback(
|
||||||
|
(segmentId: string) => {
|
||||||
|
const current = rulerModelRef.current;
|
||||||
|
const segments = current.segments.filter((segment) => segment.id !== segmentId);
|
||||||
|
const usedPointIds = new Set(segments.flatMap((segment) => [segment.startId, segment.endId]));
|
||||||
|
const points = current.points.filter((point) => usedPointIds.has(point.id) || point.id === current.startPointId);
|
||||||
|
storeRulerModel({ ...current, points, segments });
|
||||||
|
},
|
||||||
|
[storeRulerModel],
|
||||||
|
);
|
||||||
|
|
||||||
|
const removeRulerPoint = useCallback(
|
||||||
|
(pointId: string) => {
|
||||||
|
const current = rulerModelRef.current;
|
||||||
|
const connected = current.segments.filter((segment) => segment.startId === pointId || segment.endId === pointId);
|
||||||
|
if (connected.length > 0) {
|
||||||
|
removeRulerSegment(connected[connected.length - 1].id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
storeRulerModel({ ...current, points: current.points.filter((point) => point.id !== pointId), startPointId: current.startPointId === pointId ? null : current.startPointId });
|
||||||
|
},
|
||||||
|
[removeRulerSegment, storeRulerModel],
|
||||||
|
);
|
||||||
|
|
||||||
const setMarqueeFromState = useCallback((marquee: MarqueeState | null) => {
|
const setMarqueeFromState = useCallback((marquee: MarqueeState | null) => {
|
||||||
if (!marquee) {
|
if (!marquee) {
|
||||||
setMarqueeRect(null);
|
setMarqueeRect(null);
|
||||||
@@ -1403,6 +1738,8 @@ export function WorkplaneViewport({
|
|||||||
setRotationReadout(null);
|
setRotationReadout(null);
|
||||||
}
|
}
|
||||||
if (state) {
|
if (state) {
|
||||||
|
clearCutPreviewOverlays(state);
|
||||||
|
state.needsRender = true;
|
||||||
state.controls.enabled = false;
|
state.controls.enabled = false;
|
||||||
}
|
}
|
||||||
onInteractionActiveChange?.(true);
|
onInteractionActiveChange?.(true);
|
||||||
@@ -1586,8 +1923,10 @@ export function WorkplaneViewport({
|
|||||||
setPinnedRotationWheelView(null);
|
setPinnedRotationWheelView(null);
|
||||||
setRotationReadout(null);
|
setRotationReadout(null);
|
||||||
if (threeRef.current) {
|
if (threeRef.current) {
|
||||||
|
syncCutPreviewOverlays(threeRef.current, shapesRef.current);
|
||||||
setSelectionHelpersVisible(threeRef.current, true);
|
setSelectionHelpersVisible(threeRef.current, true);
|
||||||
threeRef.current.controls.enabled = true;
|
threeRef.current.controls.enabled = true;
|
||||||
|
threeRef.current.needsRender = true;
|
||||||
}
|
}
|
||||||
onInteractionActiveChange?.(false);
|
onInteractionActiveChange?.(false);
|
||||||
bakeRotatedShapes.forEach((id) => onUpdateShape(id, { bakeTransform: true }));
|
bakeRotatedShapes.forEach((id) => onUpdateShape(id, { bakeTransform: true }));
|
||||||
@@ -1780,6 +2119,15 @@ export function WorkplaneViewport({
|
|||||||
}
|
}
|
||||||
const rect = state.renderer.domElement.getBoundingClientRect();
|
const rect = state.renderer.domElement.getBoundingClientRect();
|
||||||
|
|
||||||
|
if (rulerModeRef.current) {
|
||||||
|
event.preventDefault();
|
||||||
|
const candidate = resolveRulerCandidate(event.clientX, event.clientY);
|
||||||
|
if (candidate) {
|
||||||
|
selectRulerCandidate(candidate);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (workplaneModeRef.current) {
|
if (workplaneModeRef.current) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const id = pickShape(event.clientX, event.clientY);
|
const id = pickShape(event.clientX, event.clientY);
|
||||||
@@ -1900,6 +2248,8 @@ export function WorkplaneViewport({
|
|||||||
} else {
|
} else {
|
||||||
setRotationReadout(null);
|
setRotationReadout(null);
|
||||||
}
|
}
|
||||||
|
clearCutPreviewOverlays(state);
|
||||||
|
state.needsRender = true;
|
||||||
state.controls.enabled = false;
|
state.controls.enabled = false;
|
||||||
onInteractionActiveChange?.(true);
|
onInteractionActiveChange?.(true);
|
||||||
return;
|
return;
|
||||||
@@ -1987,6 +2337,8 @@ export function WorkplaneViewport({
|
|||||||
primaryStartZ: shape.z,
|
primaryStartZ: shape.z,
|
||||||
items,
|
items,
|
||||||
};
|
};
|
||||||
|
clearCutPreviewOverlays(state);
|
||||||
|
state.needsRender = true;
|
||||||
state.controls.enabled = false;
|
state.controls.enabled = false;
|
||||||
onInteractionActiveChange?.(true);
|
onInteractionActiveChange?.(true);
|
||||||
},
|
},
|
||||||
@@ -1998,6 +2350,8 @@ export function WorkplaneViewport({
|
|||||||
onWorkplaneModeChange,
|
onWorkplaneModeChange,
|
||||||
pickShape,
|
pickShape,
|
||||||
pickTransformHandle,
|
pickTransformHandle,
|
||||||
|
resolveRulerCandidate,
|
||||||
|
selectRulerCandidate,
|
||||||
setMarqueeFromState,
|
setMarqueeFromState,
|
||||||
toPlanePoint,
|
toPlanePoint,
|
||||||
toPlanePointAtY,
|
toPlanePointAtY,
|
||||||
@@ -2007,6 +2361,10 @@ export function WorkplaneViewport({
|
|||||||
|
|
||||||
const handlePointerMove = useCallback(
|
const handlePointerMove = useCallback(
|
||||||
(event: ReactPointerEvent<HTMLDivElement>) => {
|
(event: ReactPointerEvent<HTMLDivElement>) => {
|
||||||
|
if (rulerModeRef.current) {
|
||||||
|
updateRulerHover(event.clientX, event.clientY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const transform = transformRef.current;
|
const transform = transformRef.current;
|
||||||
if (transform) {
|
if (transform) {
|
||||||
updateTransform(event.clientX, event.clientY, event.shiftKey, event.altKey);
|
updateTransform(event.clientX, event.clientY, event.shiftKey, event.altKey);
|
||||||
@@ -2072,7 +2430,7 @@ export function WorkplaneViewport({
|
|||||||
threeRef.current.needsRender = true;
|
threeRef.current.needsRender = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[setMarqueeFromState, toPlanePoint, updateTransform],
|
[setMarqueeFromState, toPlanePoint, updateRulerHover, updateTransform],
|
||||||
);
|
);
|
||||||
|
|
||||||
const finishDrag = useCallback(
|
const finishDrag = useCallback(
|
||||||
@@ -2097,8 +2455,10 @@ export function WorkplaneViewport({
|
|||||||
setActiveTransformKind(null);
|
setActiveTransformKind(null);
|
||||||
setRotationReadout(null);
|
setRotationReadout(null);
|
||||||
if (state) {
|
if (state) {
|
||||||
|
syncCutPreviewOverlays(state, shapesRef.current);
|
||||||
setSelectionHelpersVisible(state, true);
|
setSelectionHelpersVisible(state, true);
|
||||||
state.controls.enabled = true;
|
state.controls.enabled = true;
|
||||||
|
state.needsRender = true;
|
||||||
}
|
}
|
||||||
onInteractionActiveChange?.(false);
|
onInteractionActiveChange?.(false);
|
||||||
return;
|
return;
|
||||||
@@ -2161,7 +2521,9 @@ export function WorkplaneViewport({
|
|||||||
|
|
||||||
dragRef.current = null;
|
dragRef.current = null;
|
||||||
if (state) {
|
if (state) {
|
||||||
|
syncCutPreviewOverlays(state, previewShapesForDrag(shapesRef.current, drag));
|
||||||
state.controls.enabled = true;
|
state.controls.enabled = true;
|
||||||
|
state.needsRender = true;
|
||||||
}
|
}
|
||||||
onInteractionActiveChange?.(false);
|
onInteractionActiveChange?.(false);
|
||||||
},
|
},
|
||||||
@@ -2209,6 +2571,61 @@ export function WorkplaneViewport({
|
|||||||
state.needsRender = true;
|
state.needsRender = true;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const toggleRulerMode = useCallback(() => {
|
||||||
|
const next = !rulerModeRef.current;
|
||||||
|
rulerModeRef.current = next;
|
||||||
|
setRulerMode(next);
|
||||||
|
const current = rulerModelRef.current;
|
||||||
|
storeRulerModel({ ...current, startPointId: null, hover: null });
|
||||||
|
if (next) {
|
||||||
|
onWorkplaneModeChange(false);
|
||||||
|
onSelectShape(null);
|
||||||
|
}
|
||||||
|
}, [onSelectShape, onWorkplaneModeChange, storeRulerModel]);
|
||||||
|
|
||||||
|
const handleRulerPointPointerDown = useCallback(
|
||||||
|
(event: ReactPointerEvent<SVGCircleElement>, pointId: string) => {
|
||||||
|
if (event.button === 1) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
removeRulerPoint(pointId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.button !== 0 || !rulerModeRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const point = rulerModelRef.current.points.find((candidate) => candidate.id === pointId);
|
||||||
|
if (!point) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
selectRulerCandidate({ x: point.x, z: point.z, pointId });
|
||||||
|
},
|
||||||
|
[removeRulerPoint, selectRulerCandidate],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleRulerSegmentPointerDown = useCallback(
|
||||||
|
(event: ReactPointerEvent<SVGLineElement>, segmentId: string) => {
|
||||||
|
if (event.button === 1) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
removeRulerSegment(segmentId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.button !== 0 || !rulerModeRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
const candidate = resolveRulerCandidate(event.clientX, event.clientY);
|
||||||
|
if (candidate) {
|
||||||
|
selectRulerCandidate(candidate);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[removeRulerSegment, resolveRulerCandidate, selectRulerCandidate],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const isTypingTarget = (target: EventTarget | null) => {
|
const isTypingTarget = (target: EventTarget | null) => {
|
||||||
if (!(target instanceof HTMLElement)) {
|
if (!(target instanceof HTMLElement)) {
|
||||||
@@ -2223,7 +2640,10 @@ export function WorkplaneViewport({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const key = event.key.toLowerCase();
|
const key = event.key.toLowerCase();
|
||||||
if (key === "f" || event.key === "Home") {
|
if (event.key === "Escape" && rulerModeRef.current) {
|
||||||
|
event.preventDefault();
|
||||||
|
setRulerActive(false);
|
||||||
|
} else if (key === "f" || event.key === "Home") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
resetView();
|
resetView();
|
||||||
} else if (event.key === "+" || event.key === "=") {
|
} else if (event.key === "+" || event.key === "=") {
|
||||||
@@ -2237,7 +2657,7 @@ export function WorkplaneViewport({
|
|||||||
|
|
||||||
window.addEventListener("keydown", handleKeyDown);
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
return () => window.removeEventListener("keydown", handleKeyDown);
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||||
}, [resetView, zoomCamera]);
|
}, [resetView, setRulerActive, zoomCamera]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="workplane-stage">
|
<main className="workplane-stage">
|
||||||
@@ -2256,21 +2676,18 @@ export function WorkplaneViewport({
|
|||||||
<button aria-label="Home" onClick={resetView}>
|
<button aria-label="Home" onClick={resetView}>
|
||||||
<Home size={28} />
|
<Home size={28} />
|
||||||
</button>
|
</button>
|
||||||
<button aria-label="Fit view" onClick={resetView}>
|
|
||||||
<Expand size={24} />
|
|
||||||
</button>
|
|
||||||
<button aria-label="Zoom in" onClick={() => zoomCamera(0.7)}>
|
<button aria-label="Zoom in" onClick={() => zoomCamera(0.7)}>
|
||||||
<Plus size={33} />
|
<Plus size={33} />
|
||||||
</button>
|
</button>
|
||||||
<button aria-label="Zoom out" onClick={() => zoomCamera(1.35)}>
|
<button aria-label="Zoom out" onClick={() => zoomCamera(1.35)}>
|
||||||
<Minus size={33} />
|
<Minus size={33} />
|
||||||
</button>
|
</button>
|
||||||
<button aria-label="Camera mode" onClick={resetView}>
|
<button className={rulerMode ? "active" : ""} aria-label="Ruler" title="Ruler" aria-pressed={rulerMode} onClick={toggleRulerMode}>
|
||||||
<Box size={27} />
|
<RulerGlyph />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section className={`workplane-wrap ${workplaneMode ? "placing-workplane" : ""}`} aria-label="Workplane">
|
<section className={`workplane-wrap ${workplaneMode ? "placing-workplane" : ""} ${rulerMode ? "ruler-mode" : ""}`} aria-label="Workplane">
|
||||||
<div className="workplane-plane">
|
<div className="workplane-plane">
|
||||||
<div
|
<div
|
||||||
className="three-workplane-host"
|
className="three-workplane-host"
|
||||||
@@ -2286,7 +2703,7 @@ export function WorkplaneViewport({
|
|||||||
onPointerCancel={finishDrag}
|
onPointerCancel={finishDrag}
|
||||||
/>
|
/>
|
||||||
{marqueeRect ? <div className="selection-marquee" style={marqueeRect} /> : null}
|
{marqueeRect ? <div className="selection-marquee" style={marqueeRect} /> : null}
|
||||||
{transformOverlay && !alignMode && !mirrorMode ? (
|
{transformOverlay && !alignMode && !mirrorMode && !rulerMode ? (
|
||||||
<TransformOverlay
|
<TransformOverlay
|
||||||
box={transformOverlay}
|
box={transformOverlay}
|
||||||
measureKey={pinnedMeasureKey ?? hoverMeasureKey}
|
measureKey={pinnedMeasureKey ?? hoverMeasureKey}
|
||||||
@@ -2316,6 +2733,15 @@ export function WorkplaneViewport({
|
|||||||
) : null}
|
) : null}
|
||||||
{alignOverlay ? <AlignOverlay overlay={alignOverlay} onAlign={onAlignSelection} onPreview={onAlignPreview} onPreviewClear={onAlignPreviewClear} /> : null}
|
{alignOverlay ? <AlignOverlay overlay={alignOverlay} onAlign={onAlignSelection} onPreview={onAlignPreview} onPreviewClear={onAlignPreviewClear} /> : null}
|
||||||
{mirrorOverlay ? <MirrorOverlay overlay={mirrorOverlay} onMirror={onMirrorSelection} onPreview={onMirrorPreview} onPreviewClear={onMirrorPreviewClear} /> : null}
|
{mirrorOverlay ? <MirrorOverlay overlay={mirrorOverlay} onMirror={onMirrorSelection} onPreview={onMirrorPreview} onPreviewClear={onMirrorPreviewClear} /> : null}
|
||||||
|
{rulerOverlay && (rulerOverlay.points.length > 0 || rulerOverlay.hover) ? (
|
||||||
|
<RulerOverlay
|
||||||
|
overlay={rulerOverlay}
|
||||||
|
startPointId={rulerModel.startPointId}
|
||||||
|
active={rulerMode}
|
||||||
|
onPointPointerDown={handleRulerPointPointerDown}
|
||||||
|
onSegmentPointerDown={handleRulerSegmentPointerDown}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -2593,7 +3019,206 @@ function linesFromPoints(points: number[], material: THREE.LineBasicMaterial) {
|
|||||||
return new THREE.LineSegments(geometry, material);
|
return new THREE.LineSegments(geometry, material);
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuildShapes(state: ThreeState | null, shapes: WorkplaneShape[], selectedIds: string[]) {
|
type CutPreviewShapeFrame = {
|
||||||
|
shape: WorkplaneShape;
|
||||||
|
worldBounds: THREE.Box3;
|
||||||
|
};
|
||||||
|
|
||||||
|
function shapeCutPreviewFrames(state: ThreeState, shapes: WorkplaneShape[]) {
|
||||||
|
return shapes.reduce<Record<string, CutPreviewShapeFrame>>((frames, shape) => {
|
||||||
|
const object = findShapeObject(state, shape.id);
|
||||||
|
if (!object) {
|
||||||
|
return frames;
|
||||||
|
}
|
||||||
|
object.updateMatrixWorld(true);
|
||||||
|
const worldBounds = new THREE.Box3().setFromObject(object);
|
||||||
|
if (!worldBounds.isEmpty()) {
|
||||||
|
frames[shape.id] = { shape, worldBounds };
|
||||||
|
}
|
||||||
|
return frames;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
type CutPreviewBrushCacheEntry = {
|
||||||
|
signature: string;
|
||||||
|
brush: Brush;
|
||||||
|
};
|
||||||
|
|
||||||
|
const cutPreviewBrushCache = new WeakMap<THREE.Object3D, CutPreviewBrushCacheEntry>();
|
||||||
|
const cutPreviewEvaluator = new Evaluator();
|
||||||
|
cutPreviewEvaluator.useGroups = false;
|
||||||
|
cutPreviewEvaluator.attributes = ["position", "normal"];
|
||||||
|
|
||||||
|
function cutPreviewObjectSignature(root: THREE.Object3D) {
|
||||||
|
const parts: string[] = [];
|
||||||
|
root.updateMatrixWorld(true);
|
||||||
|
const inverseRoot = root.matrixWorld.clone().invert();
|
||||||
|
root.traverse((child) => {
|
||||||
|
if (!(child instanceof THREE.Mesh) || !child.visible || !(child.geometry instanceof THREE.BufferGeometry)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const relativeMatrix = inverseRoot.clone().multiply(child.matrixWorld);
|
||||||
|
parts.push(child.geometry.uuid, ...relativeMatrix.elements.map((value) => value.toFixed(5)));
|
||||||
|
});
|
||||||
|
return parts.join(":");
|
||||||
|
}
|
||||||
|
|
||||||
|
function cutPreviewBrushFromObject(root: THREE.Object3D) {
|
||||||
|
const signature = cutPreviewObjectSignature(root);
|
||||||
|
const cached = cutPreviewBrushCache.get(root);
|
||||||
|
if (cached?.signature === signature) {
|
||||||
|
cached.brush.matrixAutoUpdate = false;
|
||||||
|
cached.brush.matrix.copy(root.matrixWorld);
|
||||||
|
cached.brush.matrixWorld.copy(root.matrixWorld);
|
||||||
|
return cached.brush;
|
||||||
|
}
|
||||||
|
|
||||||
|
const positions: number[] = [];
|
||||||
|
const point = new THREE.Vector3();
|
||||||
|
const inverseRoot = root.matrixWorld.clone().invert();
|
||||||
|
root.traverse((child) => {
|
||||||
|
if (!(child instanceof THREE.Mesh) || !child.visible || !(child.geometry instanceof THREE.BufferGeometry)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const position = child.geometry.getAttribute("position");
|
||||||
|
if (!position) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const index = child.geometry.getIndex();
|
||||||
|
const count = index?.count ?? position.count;
|
||||||
|
const relativeMatrix = inverseRoot.clone().multiply(child.matrixWorld);
|
||||||
|
const mirrored = relativeMatrix.determinant() < 0;
|
||||||
|
for (let offset = 0; offset + 2 < count; offset += 3) {
|
||||||
|
const triangle = [0, 1, 2].map((corner) => {
|
||||||
|
const vertexIndex = index ? index.getX(offset + corner) : offset + corner;
|
||||||
|
return point
|
||||||
|
.set(position.getX(vertexIndex), position.getY(vertexIndex), position.getZ(vertexIndex))
|
||||||
|
.applyMatrix4(relativeMatrix)
|
||||||
|
.toArray();
|
||||||
|
});
|
||||||
|
if (mirrored) {
|
||||||
|
[triangle[1], triangle[2]] = [triangle[2], triangle[1]];
|
||||||
|
}
|
||||||
|
positions.push(...triangle[0], ...triangle[1], ...triangle[2]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (positions.length < 9) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const geometry = new THREE.BufferGeometry();
|
||||||
|
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
|
||||||
|
geometry.computeVertexNormals();
|
||||||
|
const brush = new Brush(geometry);
|
||||||
|
brush.matrixAutoUpdate = false;
|
||||||
|
brush.matrix.copy(root.matrixWorld);
|
||||||
|
brush.matrixWorld.copy(root.matrixWorld);
|
||||||
|
if (cached) {
|
||||||
|
cached.brush.geometry.dispose();
|
||||||
|
}
|
||||||
|
cutPreviewBrushCache.set(root, { signature, brush });
|
||||||
|
return brush;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cutPreviewActualIntersectionGeometry(state: ThreeState, solid: WorkplaneShape, hole: WorkplaneShape) {
|
||||||
|
const solidObject = findShapeObject(state, solid.id);
|
||||||
|
const holeObject = findShapeObject(state, hole.id);
|
||||||
|
if (!solidObject || !holeObject) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const solidBrush = cutPreviewBrushFromObject(solidObject);
|
||||||
|
const holeBrush = cutPreviewBrushFromObject(holeObject);
|
||||||
|
if (!solidBrush || !holeBrush) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = cutPreviewEvaluator.evaluate(solidBrush, holeBrush, HOLLOW_INTERSECTION);
|
||||||
|
const position = result.geometry.getAttribute("position");
|
||||||
|
if (!position || position.count < 3) {
|
||||||
|
result.geometry.dispose();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const geometry = result.geometry.clone();
|
||||||
|
geometry.applyMatrix4(result.matrixWorld);
|
||||||
|
result.geometry.dispose();
|
||||||
|
geometry.computeVertexNormals();
|
||||||
|
return geometry;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addCutPreviewOverlays(state: ThreeState, holeFrame: CutPreviewShapeFrame, solidFrames: CutPreviewShapeFrame[]) {
|
||||||
|
solidFrames.forEach((solidFrame) => {
|
||||||
|
if (!holeFrame.worldBounds.intersectsBox(solidFrame.worldBounds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const geometry = cutPreviewActualIntersectionGeometry(state, solidFrame.shape, holeFrame.shape);
|
||||||
|
if (!geometry) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const preview = new THREE.Mesh(
|
||||||
|
geometry,
|
||||||
|
new THREE.MeshBasicMaterial({
|
||||||
|
color: "#30363a",
|
||||||
|
transparent: true,
|
||||||
|
opacity: 0.34,
|
||||||
|
depthTest: false,
|
||||||
|
depthWrite: false,
|
||||||
|
side: THREE.DoubleSide,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
preview.name = "CutPreviewOverlay";
|
||||||
|
preview.renderOrder = 18;
|
||||||
|
preview.userData.cutPreview = true;
|
||||||
|
preview.raycast = () => undefined;
|
||||||
|
state.shapeLayer.add(preview);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearCutPreviewOverlays(state: ThreeState) {
|
||||||
|
const overlays: THREE.Object3D[] = [];
|
||||||
|
state.shapeLayer.traverse((child) => {
|
||||||
|
if (child.userData.cutPreview) {
|
||||||
|
overlays.push(child);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
overlays.forEach((overlay) => {
|
||||||
|
overlay.parent?.remove(overlay);
|
||||||
|
disposeObject(overlay);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncCutPreviewOverlays(state: ThreeState, shapes: WorkplaneShape[]) {
|
||||||
|
clearCutPreviewOverlays(state);
|
||||||
|
const visibleShapes = shapes.filter((shape) => !shape.hidden);
|
||||||
|
const cutFrames = shapeCutPreviewFrames(state, visibleShapes);
|
||||||
|
const solidFrames = visibleShapes
|
||||||
|
.filter((shape) => !shape.hole)
|
||||||
|
.map((shape) => cutFrames[shape.id])
|
||||||
|
.filter((frame): frame is CutPreviewShapeFrame => Boolean(frame));
|
||||||
|
|
||||||
|
if (solidFrames.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
visibleShapes.forEach((shape) => {
|
||||||
|
if (!shape.hole) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const holeFrame = cutFrames[shape.id];
|
||||||
|
if (holeFrame) {
|
||||||
|
addCutPreviewOverlays(state, holeFrame, solidFrames);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function rebuildShapes(state: ThreeState | null, shapes: WorkplaneShape[], selectedIds: string[], showCutPreviews = true) {
|
||||||
if (!state) {
|
if (!state) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2601,16 +3226,17 @@ function rebuildShapes(state: ThreeState | null, shapes: WorkplaneShape[], selec
|
|||||||
disposeChildren(state.shapeLayer);
|
disposeChildren(state.shapeLayer);
|
||||||
|
|
||||||
const selected = new Set(selectedIds);
|
const selected = new Set(selectedIds);
|
||||||
shapes.forEach((shape) => {
|
const visibleShapes = shapes.filter((shape) => !shape.hidden);
|
||||||
if (shape.hidden) {
|
visibleShapes.forEach((shape) => {
|
||||||
return;
|
|
||||||
}
|
|
||||||
const object = createShapeObject(shape, selected.has(shape.id), () => {
|
const object = createShapeObject(shape, selected.has(shape.id), () => {
|
||||||
state.needsRender = true;
|
state.needsRender = true;
|
||||||
});
|
});
|
||||||
state.shapeLayer.add(object);
|
state.shapeLayer.add(object);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
if (showCutPreviews) {
|
||||||
|
syncCutPreviewOverlays(state, visibleShapes);
|
||||||
|
}
|
||||||
|
|
||||||
rebuildSelectionHelpers(state, shapes, selectedIds);
|
rebuildSelectionHelpers(state, shapes, selectedIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,26 +107,14 @@ export function BlocksModeIcon(props: IconProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function WorkplaneToolIcon(props: IconProps) {
|
type ToolbarCommandImageProps = { file: string; className?: string };
|
||||||
return (
|
|
||||||
<svg viewBox="0 0 55 55" aria-hidden="true" {...props}>
|
function ToolbarCommandImage({ file, className }: ToolbarCommandImageProps) {
|
||||||
<path
|
return <img aria-hidden="true" className={["toolbar-command-icon", className].filter(Boolean).join(" ")} src={"/assets/sketchforge/" + file} alt="" draggable={false} />;
|
||||||
fill="currentColor"
|
|
||||||
d="m3.4 7.1 42.5-3.3-0.5 46.3-39.8-3.3-2.2-39.7zm8.2 38.4-0.2-5.4-4.4-0.2 0.3 5.3 4.3 0.3zm-0.2-6.1-0.1-4.9-4.5-0.1 0.2 4.7 4.4 0.3zm-0.2-5.6-0.1-4.9-4.5-0.1 0.2 5h4.4zm-0.2-5.8-0.1-5.6-4.6 0.1 0.3 5.4 4.4 0.1zm-0.2-6.2-0.1-6.1-4.8 0.3 0.4 6 4.5-0.2zm-0.1-6.7-0.2-6.5-4.9 0.4 0.3 6.4 4.8-0.3zm5.8 30.8-0.1-5.4-4.3-0.3 0.2 5.3 4.2 0.4zm-0.1-6.1v-4.9l-4.5-0.2 0.2 4.9 4.3 0.2zm-0.1-5.6v-5.2l-4.6-0.1 0.2 5.1 4.4 0.2zm0-6.2v-5.8l-4.7 0.2 0.1 5.5 4.6 0.1zm0-6.3-0.1-6.4-4.8 0.3 0.2 6.3 4.7-0.2zm-0.1-7-0.1-6.6-4.9 0.4 0.2 6.5 4.8-0.3zm6.7 31.7-0.1-5.4-5.4-0.3 0.2 5.3 5.3 0.4zm-0.2-6.1-0.1-5.4-5.2-0.1v5.1l5.3 0.4zm-0.1-6.1v-5.1l-5.3-0.1v5.1l5.3 0.1zm-0.1-6.2v-6l-5.6 0.1 0.1 5.8 5.5 0.1zm-0.1-6.6-0.1-6.5-5.4 0.3 0.1 6.4 5.4-0.2zm-0.2-7.2-0.1-6.5-5.3 0.4 0.1 6.4 5.3-0.3zm7.4 32.7v-5.6l-5.7-0.3 0.1 5.5 5.6 0.4zm-0.1-6.2v-5.4l-5.7-0.3 0.1 5.3 5.6 0.4zm0-6v-5.8h-5.8l0.1 5.5 5.7 0.3zm-0.1-6.7v-6.3l-5.8 0.2 0.1 6 5.7 0.1zm-0.1-6.8v-6.8l-5.8 0.3 0.1 6.7 5.7-0.2zm0-7.4v-6.7l-5.9 0.4 0.1 6.7 5.8-0.4zm7.2 33.7v-5.8l-6.2-0.3v5.6l6.2 0.5zm0-6.4v-5.7l-6.2-0.1v5.5l6.2 0.3zm0-6.3v-5.8l-6.2-0.1v5.8l6.2 0.1zm0-6.8v-6.5l-6.4 0.1v6.3l6.4 0.1zm0-7v-7.1l-6.6 0.4v6.9l6.6-0.2zm0-7.7v-6.7l-6.7 0.4 0.1 6.7 6.6-0.4zm7.1 34.6v-5.7l-6.4-0.4v5.7l6.4 0.4zm0-6.3v-5.9l-6.4-0.2v5.8l6.4 0.3zm0.1-6.5v-5.9l-6.5-0.1v5.8l6.5 0.2zm0.1-6.9v-6.8l-6.6 0.2v6.4l6.6 0.2zm0-7.3 0.1-7.5-6.7 0.4v7.3l6.6-0.2zm0.1-8.2v-6.7l-6.7 0.4v6.8l6.7-0.5z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RulerToolIcon(props: IconProps) {
|
export function WorkplaneToolIcon() {
|
||||||
return (
|
return <ToolbarCommandImage file="toolbar-workplane.png" className="workplane-command-icon" />;
|
||||||
<svg viewBox="98 0 60 55" aria-hidden="true" {...props}>
|
|
||||||
<path
|
|
||||||
fill="currentColor"
|
|
||||||
d="m104.8 7.1 11.4-0.5 2.1 30 32.2 1.4-0.4 12.8-42.4-3.5-2.9-40.2zm43.1 41.6 0.3-8.7-6.9-0.4v3.5h-1.4v-3.6l-7.1-0.3v5.5l-1.2-0.1v-5.5l-6.9-0.3v3.6h-1.3v-3.7l-5.7-0.3 0.2 5.3h-1.3l-0.2-5.5-4.8-0.1v-1.3l4.6 0.1-0.5-6.8-3.1 0.1v-1.2l3.1-0.1-0.4-6.4-4.9 0.2-0.1-1.2 4.9-0.2-0.5-5.4h-3.2v-1.4h3.1l-0.4-5.8-7.2 0.2 2.7 36.6 38.2 3.2z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function NotesToolIcon(props: IconProps) {
|
export function NotesToolIcon(props: IconProps) {
|
||||||
@@ -140,16 +128,16 @@ export function NotesToolIcon(props: IconProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarCopyIcon(props: IconProps) {
|
export function ToolbarCopyIcon() {
|
||||||
return <ToolbarSpriteIcon rect={{ x: 0, y: 6.7, width: 26.1, height: 33.3 }} {...props} />;
|
return <ToolbarCommandImage file="toolbar-copy.png" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarPasteIcon(props: IconProps) {
|
export function ToolbarPasteIcon(props: IconProps) {
|
||||||
return <ToolbarSpriteIcon rect={{ x: 33.5, y: 6.7, width: 22.9, height: 33.3 }} {...props} />;
|
return <ToolbarSpriteIcon rect={{ x: 33.5, y: 6.7, width: 22.9, height: 33.3 }} {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarDuplicateIcon(props: IconProps) {
|
export function ToolbarDuplicateIcon() {
|
||||||
return <ToolbarSpriteIcon rect={{ x: 65, y: 6.7, width: 27.5, height: 33.3 }} {...props} />;
|
return <ToolbarCommandImage file="toolbar-duplicate.png" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarTrashIcon(props: IconProps) {
|
export function ToolbarTrashIcon(props: IconProps) {
|
||||||
@@ -216,12 +204,12 @@ export function ToolbarCaretDownIcon(props: IconProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarGroupIcon(props: IconProps) {
|
export function ToolbarGroupIcon() {
|
||||||
return <ToolbarSpriteIcon rect={{ x: 30.3, y: 46.7, width: 29.1, height: 32.5 }} {...props} />;
|
return <ToolbarCommandImage file="toolbar-group.png" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarUngroupIcon(props: IconProps) {
|
export function ToolbarUngroupIcon() {
|
||||||
return <ToolbarSpriteIcon rect={{ x: 65.4, y: 46.7, width: 26.5, height: 32.5 }} {...props} />;
|
return <ToolbarCommandImage file="toolbar-ungroup.png" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarAlignIcon(props: IconProps) {
|
export function ToolbarAlignIcon(props: IconProps) {
|
||||||
@@ -232,8 +220,8 @@ export function ToolbarMirrorIcon(props: IconProps) {
|
|||||||
return <ToolbarSpriteIcon rect={{ x: 131.4, y: 46.7, width: 27, height: 32.5 }} {...props} />;
|
return <ToolbarSpriteIcon rect={{ x: 131.4, y: 46.7, width: 27, height: 32.5 }} {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarMagnetIcon(props: IconProps) {
|
export function ToolbarSnapGridIcon() {
|
||||||
return <ToolbarSpriteIcon rect={{ x: 167.8, y: 46.7, width: 20.8, height: 32.5 }} {...props} />;
|
return <ToolbarCommandImage file="toolbar-snap-grid.png" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarPaintIcon(props: IconProps) {
|
export function ToolbarPaintIcon(props: IconProps) {
|
||||||
@@ -255,10 +243,10 @@ export function ToolbarExportIcon(props: IconProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarSendBackwardIcon(props: IconProps) {
|
export function ToolbarWorkplaneIcon() {
|
||||||
return <ToolbarSpriteIcon rect={{ x: 198.3, y: 46.7, width: 27.4, height: 32.5 }} {...props} />;
|
return <ToolbarCommandImage file="toolbar-workplane.png" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToolbarBringForwardIcon(props: IconProps) {
|
export function ToolbarDropToWorkplaneIcon() {
|
||||||
return <ToolbarSpriteIcon rect={{ x: 231.5, y: 46.7, width: 25.7, height: 32.3 }} {...props} />;
|
return <ToolbarCommandImage file="toolbar-drop-workplane.png" />;
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,20 @@ import { createLocalId } from "@/lib/localIds";
|
|||||||
import type { WorkplaneShape } from "@/types/sketchforge";
|
import type { WorkplaneShape } from "@/types/sketchforge";
|
||||||
|
|
||||||
const stlLoader = new STLLoader();
|
const stlLoader = new STLLoader();
|
||||||
|
const SUPPORTED_IMPORT_EXTENSIONS = new Set(["stl"]);
|
||||||
|
|
||||||
export function importedShapeFromStl(fileName: string, buffer: ArrayBuffer): WorkplaneShape {
|
function fileExtension(fileName: string) {
|
||||||
const rawGeometry = stlLoader.parse(buffer);
|
return fileName.split(".").pop()?.toLowerCase() ?? "";
|
||||||
const geometry = rawGeometry.index ? rawGeometry.toNonIndexed() : rawGeometry.clone();
|
}
|
||||||
|
|
||||||
|
function importedShapeFromTriangleSoup(fileName: string, rawPositions: number[], rawNormals: number[] | undefined): WorkplaneShape {
|
||||||
|
const geometry = new THREE.BufferGeometry();
|
||||||
|
geometry.setAttribute("position", new THREE.Float32BufferAttribute(rawPositions, 3));
|
||||||
|
if (rawNormals?.length === rawPositions.length) {
|
||||||
|
geometry.setAttribute("normal", new THREE.Float32BufferAttribute(rawNormals, 3));
|
||||||
|
} else {
|
||||||
|
geometry.computeVertexNormals();
|
||||||
|
}
|
||||||
geometry.computeBoundingBox();
|
geometry.computeBoundingBox();
|
||||||
|
|
||||||
const box = geometry.boundingBox;
|
const box = geometry.boundingBox;
|
||||||
@@ -70,3 +80,25 @@ export function importedShapeFromStl(fileName: string, buffer: ArrayBuffer): Wor
|
|||||||
hidden: false,
|
hidden: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function importExtensionSupported(fileName: string) {
|
||||||
|
return SUPPORTED_IMPORT_EXTENSIONS.has(fileExtension(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function importedShapeFromStl(fileName: string, buffer: ArrayBuffer): WorkplaneShape {
|
||||||
|
const rawGeometry = stlLoader.parse(buffer);
|
||||||
|
const geometry = rawGeometry.index ? rawGeometry.toNonIndexed() : rawGeometry.clone();
|
||||||
|
const position = geometry.getAttribute("position");
|
||||||
|
const normal = geometry.getAttribute("normal");
|
||||||
|
const rawPositions: number[] = [];
|
||||||
|
const rawNormals: number[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < position.count; i += 1) {
|
||||||
|
rawPositions.push(position.getX(i), position.getY(i), position.getZ(i));
|
||||||
|
if (normal) {
|
||||||
|
rawNormals.push(normal.getX(i), normal.getY(i), normal.getZ(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return importedShapeFromTriangleSoup(fileName, rawPositions, rawNormals.length ? rawNormals : undefined);
|
||||||
|
}
|
||||||