8a92adcInitial commit: mesh-studio POC (OpenCASCADE.js + three.js, NURBS extraction)Jeremy Magland 1# CLAUDE.md
3Tips for future agents working in this repo.
5## Architecture
7```
8src/occ/ ALL OpenCASCADE.js access lives here. The rest of the app never
9 touches OCCT — it only sees the SurfaceModel from src/model.
10 loader.ts initOpenCascade({ mainWasm: wasmUrl }) once; wasm imported with
11 `?url` so Vite emits it as a static asset. Lazy on first use.
12 primitives.ts BRepPrimAPI_* builders returning TopoDS_Shape.
13 importCad.ts STEP/IGES via FS.createDataFile + STEPControl_Reader/IGESControl_Reader.
14 exportCad.ts STEPControl_Writer -> bytes.
15 extract.ts shape -> SurfaceModel. Runs BRepMesh (triangulation, always) and
16 BRepBuilderAPI_NurbsConvert + Geom_BSplineSurface reads (per-face,
17 best-effort). retessellate() re-meshes at a new quality reusing NURBS.
18src/model/ types.ts: SurfaceModel = list of Patch (discriminated union).
19 v1 emits `nurbs` patches. tessellate.ts: pure geometry helpers
20 (modelBounds, controlNet, mergeTriMeshes) — no three, no OCCT.
21src/render/ SurfaceView.tsx: plain three.js, one mesh per patch (for picking),
7f0745dMove view controls into viewport overlay; add anaglyph 3D toggleJeremy Magland 22 modes shaded/wire/net/iso, optional red/cyan anaglyph
23 (AnaglyphEffect; planeDistance/eyeSep tracked to orbit distance —
24 the defaults double the image). palette.ts: per-face colors.
8a92adcInitial commit: mesh-studio POC (OpenCASCADE.js + three.js, NURBS extraction)Jeremy Magland 25src/export/ meshWriters.ts (OBJ/PLY/STL, dependency-free), nurbsJson.ts.
26src/App.tsx sidebar + viewport; keeps the OpenCascade instance and the
27 (NURBS-converted) mesh shape in refs for re-tessellation.
bd00eacAdd Random CAD model source drawing from abc-step-1000Jeremy Magland 28src/abcDataset.ts "Random CAD model" source: fetches index.json from
29 https://concept-collection.github.io/abc-step-1000/ (first 1000
30 ABC-dataset STEP files, gzip-served), picks a random file ≤2 MB,
31 gunzips via DecompressionStream, hands bytes to importCadFile.
8a92adcInitial commit: mesh-studio POC (OpenCASCADE.js + three.js, NURBS extraction)Jeremy Magland 32```
34## Key gotchas
36- **OCCT is typed as `any`** (`src/occ/types.ts`). opencascade.js ships a huge
37 generated `.d.ts`, and the overload-suffixed member names (`_1`, `_2`, …) are
38 only verifiable at runtime. Keep all OCCT calls in `src/occ/*`; everything
39 else is strictly typed against `SurfaceModel`. The **build gate is `tsc -b &&
40 vite build`** — runtime correctness of OCCT calls must be checked in a real
41 browser (`npm run dev`).
42- **opencascade.js is pinned to the beta** (`2.0.0-beta.b5ff984`). `latest`
43 (1.1.1) is an older, different API. Overload suffixes and the `?url` wasm
44 recipe follow the beta and its examples (donalffons/opencascade.js-examples).
45- **NURBS extraction is best-effort.** Rendering only needs the BRepMesh
46 triangulation, which always runs. `extractNurbs` is wrapped in try/catch per
47 face and returns null on any failure; the sidebar shows "N/M faces" coverage.
48 If a binding is missing in the build, coverage drops but the app still works.
49- **Mesh density uses BRepMesh relative mode** (`isRelative = true`), so the
50 quality slider is a dimensionless fraction independent of model scale — no
51 bounding-box computation needed. `retessellate` calls `BRepTools.Clean` first
52 (in a try/catch) so a finer deflection actually refines.
4b6e89dMove Random CAD model button below Open STEP/IGESJeremy Magland 53- **The "Random CAD model" button** (primary, below Open STEP/IGES) downloads a real
5e04862Remove Sample STEP button; make Random CAD model the primary source buttonJeremy Magland 54 ABC-dataset STEP file and runs it through `importCadFile` — the quickest
55 end-to-end check of the CAD import path (needs network + the abc-step-1000
56 Pages site). The old "Sample STEP" round-trip button was removed 2026-07-09;
57 STEP export is still exercised via Export → STEP.
8a92adcInitial commit: mesh-studio POC (OpenCASCADE.js + three.js, NURBS extraction)Jeremy Magland 58
59## Verification
61Browser is the real verification surface (WASM). `npm run build` confirms TS +
62bundling (including the OCCT wasm asset). Then `npm run dev` and:
7f0745dMove view controls into viewport overlay; add anaglyph 3D toggleJeremy Magland 63- load each primitive; toggle shaded / wireframe / control-net / isocurves and
64 the 3D (anaglyph) button — all in the overlay at the viewport's upper right;
8a92adcInitial commit: mesh-studio POC (OpenCASCADE.js + three.js, NURBS extraction)Jeremy Magland 65- drag the resolution slider (faceting should visibly change);
66- click a face → the inspector shows degree / poles / knots;
5e04862Remove Sample STEP button; make Random CAD model the primary source buttonJeremy Magland 67- "Random CAD model" downloads from abc-step-1000 and renders (needs the
68 network); an uploaded STEP/IGES file renders;
8a92adcInitial commit: mesh-studio POC (OpenCASCADE.js + three.js, NURBS extraction)Jeremy Magland 69- export OBJ/PLY/STL/NURBS-JSON/STEP.
71Not yet deployed to the org Pages site (same procedure as mesh-converter /
72mesh-pde-solver when ready).