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),
22 modes shaded/wire/net/iso. palette.ts: per-face colors.
23src/export/ meshWriters.ts (OBJ/PLY/STL, dependency-free), nurbsJson.ts.
24src/App.tsx sidebar + viewport; keeps the OpenCascade instance and the
25 (NURBS-converted) mesh shape in refs for re-tessellation.
bd00eacAdd Random CAD model source drawing from abc-step-1000Jeremy Magland 26src/abcDataset.ts "Random CAD model" source: fetches index.json from
27 https://concept-collection.github.io/abc-step-1000/ (first 1000
28 ABC-dataset STEP files, gzip-served), picks a random file ≤2 MB,
29 gunzips via DecompressionStream, hands bytes to importCadFile.
8a92adcInitial commit: mesh-studio POC (OpenCASCADE.js + three.js, NURBS extraction)Jeremy Magland 30```
32## Key gotchas
34- **OCCT is typed as `any`** (`src/occ/types.ts`). opencascade.js ships a huge
35 generated `.d.ts`, and the overload-suffixed member names (`_1`, `_2`, …) are
36 only verifiable at runtime. Keep all OCCT calls in `src/occ/*`; everything
37 else is strictly typed against `SurfaceModel`. The **build gate is `tsc -b &&
38 vite build`** — runtime correctness of OCCT calls must be checked in a real
39 browser (`npm run dev`).
40- **opencascade.js is pinned to the beta** (`2.0.0-beta.b5ff984`). `latest`
41 (1.1.1) is an older, different API. Overload suffixes and the `?url` wasm
42 recipe follow the beta and its examples (donalffons/opencascade.js-examples).
43- **NURBS extraction is best-effort.** Rendering only needs the BRepMesh
44 triangulation, which always runs. `extractNurbs` is wrapped in try/catch per
45 face and returns null on any failure; the sidebar shows "N/M faces" coverage.
46 If a binding is missing in the build, coverage drops but the app still works.
47- **Mesh density uses BRepMesh relative mode** (`isRelative = true`), so the
48 quality slider is a dimensionless fraction independent of model scale — no
49 bounding-box computation needed. `retessellate` calls `BRepTools.Clean` first
50 (in a try/catch) so a finer deflection actually refines.
4b6e89dMove Random CAD model button below Open STEP/IGESJeremy Magland 51- **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 52 ABC-dataset STEP file and runs it through `importCadFile` — the quickest
53 end-to-end check of the CAD import path (needs network + the abc-step-1000
54 Pages site). The old "Sample STEP" round-trip button was removed 2026-07-09;
55 STEP export is still exercised via Export → STEP.
8a92adcInitial commit: mesh-studio POC (OpenCASCADE.js + three.js, NURBS extraction)Jeremy Magland 56
57## Verification
59Browser is the real verification surface (WASM). `npm run build` confirms TS +
60bundling (including the OCCT wasm asset). Then `npm run dev` and:
61- load each primitive; toggle shaded / wireframe / control-net / isocurves;
62- drag the resolution slider (faceting should visibly change);
63- click a face → the inspector shows degree / poles / knots;
5e04862Remove Sample STEP button; make Random CAD model the primary source buttonJeremy Magland 64- "Random CAD model" downloads from abc-step-1000 and renders (needs the
65 network); an uploaded STEP/IGES file renders;
8a92adcInitial commit: mesh-studio POC (OpenCASCADE.js + three.js, NURBS extraction)Jeremy Magland 66- export OBJ/PLY/STL/NURBS-JSON/STEP.
68Not yet deployed to the org Pages site (same procedure as mesh-converter /
69mesh-pde-solver when ready).