mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-07-31 03:05:21 +00:00
| .. | ||
| app | ||
| components | ||
| hooks | ||
| lib | ||
| scripts | ||
| .gitignore | ||
| index.html | ||
| main.jsx | ||
| postcss.config.mjs | ||
| README.md | ||
| vite.config.mjs | ||
CAD Explorer
If you are modifying the viewer, start here.
This folder contains the CAD Explorer web app. The viewer is read-only with respect to files in the active CAD scan directory.
Prompt Workflow
- The viewer discovers displayable entries by scanning the directory from the
?dir=query param, defaulting to the harness CAD directory, then loads package-local render assets and generated URDF/authored DXF XML/text from that tree. - Prompt-ready
@cad[...]refs are expected output from the workspace. The full grammar lives in CAD prompt references. - Common copied ref shapes include whole entries, occurrences, shape/face/edge/corner selectors, and grouped same-occurrence selectors, such as
@cad[<repo-relative-cad-path>],@cad[<repo-relative-cad-path>#o1.2],@cad[<repo-relative-cad-path>#f12], and@cad[<repo-relative-cad-path>#o1.2.f12,f13,e7,v4]. - The path inside
@cad[...]is the repository-relative STEP path without.stepor.stp. - Assembly refs use generated assembly STEP topology, so face/edge/corner copy targets the assembly entry.
- Drawing tools and screenshots are communication aids, not source of truth.
- Agents interpreting
@cad[...]refs should resolve them from source STEP data withskills/cad/scripts/cadref, not against viewer assets.
Data Model
- The viewer discovers entries by scanning existing
.step,.stp,.stl,.dxf, and.urdffiles. It does not inspect Python generators for discovery. - STEP part entries load:
- package-local
<cad-dir>/.../.<step-filename>/model.glbfor display - package-local
<cad-dir>/.../.<step-filename>/topology.json - package-local
<cad-dir>/.../.<step-filename>/topology.bin
- package-local
- STEP assembly entries require package-local
<cad-dir>/.../.<step-filename>/model.glb, load package-local<cad-dir>/.../.<step-filename>/topology.json, and read assembly composition fromassembly.root. Generated Python assemblies link to scanned part GLBs; imported native STEP assemblies use.<step-filename>/components/*.glbURLs embedded in the topology composition. - DXF entries load:
- authored
<cad-dir>/.../*.dxfdirectly
- authored
- STL entries load:
- standalone or configured exported
<cad-dir>/.../*.stlmeshes directly
- standalone or configured exported
- URDF entries load:
- generated
<cad-dir>/.../*.urdfXML directly - referenced URDF STL mesh filenames directly
- generated
- The viewer UI is in
viewer/components/CadViewer.js. - The flat-pattern viewer UI is in
viewer/components/DxfViewer.js. - The workspace UI is in
viewer/components/CadWorkspace.js.
Do not hand-edit package-local generated CAD assets during normal CAD or viewer work.
Persistence
- CAD Explorer persistence is browser-only and is owned by
viewer/lib/workbench/persistence.js. - URL query params are share state:
?file=selects the active CAD entry.?refs=carries prompt references into the workspace.?resetPersistence=1clears CAD Explorer browser state for the current origin, then removes itself from the URL before the app renders.
sessionStoragekeycad-explorer:workbench-session:v2stores the scratch workspace in the canonical shape{ version, global, tabs: { selectedKey, openOrder, byKey } }.localStoragekeycad-explorer:workbench-global:v1stores the global workspace state used across reloads, including search query, expanded directories, sidebar state, and tool widths.localStoragekeycad-explorer:look-settingsstores visual look settings,cad-explorer:workbench-glass-tone:v1stores the workspace glass tone, andcad-explorer-themestores the forced dark theme preference.sessionStoragekeycad-explorer:dxf-bend-overrides:v1stores per-file DXF bend overrides for the active browser tab.- Directory expansion no longer has a separate file-explorer storage key; it is part of workspace global state.
- React state updates immediately. Browser-storage writes are coalesced briefly and flushed on
pagehide,beforeunload, and workspace unmount. If a write fails because storage is blocked or full, the workspace shows a status toast.
Runtime
npm run devstartsvite dev, scans?dir=dynamically, and updates the workspace when matching CAD files or per-STEP viewer assets are added, changed, or removed.npm run buildscansCAD_DIRwhen provided, defaulting tomodels, and bakes that scan into the static app.npm run build:appruns an isolated verification build for viewer-only changes.- Regenerate CAD assets outside the viewer package before these commands when CAD assets need to change.
Hot Reload
- Real-time dev updates come from the Vite CAD catalog endpoint and websocket events, not browser polling.
- When external tools add, remove, or update
.step,.stp,.stl,.dxf,.urdf,.<step-filename>/*.glb,.<step-filename>/topology.json, or.<step-filename>/topology.binfiles under an active scan directory, Vite asks the client to rescan and remount the workspace.
UX Contract
- STEP part and assembly entries expose face/edge/corner picking from selector proxy geometry.
- Shape and occurrence refs are exposed through inspector state, not a separate canvas pick mode.
- DXF entries are read-only flat-pattern views.
- URDF entries are read-only robot views with joint sliders; they do not expose picking, refs, or drawing tools.
- File pickers use canonical suffix labels: STEP parts and assemblies show
.step, STL entries show.stl, URDF entries show.urdf, and DXF entries show.dxf. - The workspace selects one file at a time. Per-file view, reference, drawing, and tool state is still restored from the existing session
tabsstate when a file is selected again. - Sidebar grouping follows the exact directory structure under the active scan directory, not hardcoded part/assembly roots.
Verification For Viewer Changes
- For pure viewer changes, run
cd viewer && npm run build:app. - Run
cd viewer && npm run test:nodewhen the change touches viewer logic, parsing, persistence, catalog scanning, selectors, or kinematics. - Run
cd viewer && npm run buildwhen you need the normal productiondist/output for the current generated CAD snapshot. - If the change depends on fresh CAD-derived assets, regenerate the affected entries separately with
skills/cad/scripts/gen_step_part,skills/cad/scripts/gen_step_assembly,skills/cad/scripts/gen_dxf, orskills/urdf/scripts/gen_urdfbefore viewer verification. - For render-contract changes, inspect the relevant package-local
.<step-filename>/model.glb,.<step-filename>/topology.json,.<step-filename>/topology.bin, native assembly.<step-filename>/components/*.glbmeshes, visible.stl, visible.dxf, or visible.urdffiles.
Run
From repo root:
cd viewer
npm install
npm run dev
Then open:
http://localhost:4178