/ concept-collection / mesh-studio
Sign in
concept-collection / mesh-studio
mesh-studio / README.md
79 lines · 3.2 KBPreviewCodeBlameHistoryRaw
1# mesh-studio
3A browser playground for **producing surface meshes with different tools and
4inspecting them interactively in 3D** ([three.js](https://threejs.org/)). This
5is a proof-of-concept; the first mesh-producing tool wired in is
6[OpenCASCADE.js](https://ocjs.org/) (the OCCT CAD kernel compiled to WebAssembly).
8Everything runs client-side — no server, no uploads.
10## What's interesting here
12CAD B-rep faces are not triangles: each face carries an underlying **NURBS
13(rational B-spline) surface** — a piecewise polynomial in two parameters. That
14is exactly the "high-order mesh / polynomials on faces" idea. mesh-studio
15extracts those polynomial patches (control points, weights, knots, degree)
16*alongside* the triangulation, so you can:
18- shade the tessellated surface, or view its **wireframe**;
19- see each face's **control net** (the polynomial's control polygon) and its
20 **isocurves** (constant-parameter curves sampled on the true surface);
21- drag a **resolution** slider to re-tessellate the same NURBS faces from
22 coarse-and-faceted to smooth;
23- click a face to read its **degree, pole count, knot structure** and whether it
24 is rational or purely polynomial.
26## Sources (v1)
28- **Built-in primitives** generated in-browser: sphere, torus, cylinder, cone,
29 box, rounded box (free-form fillet faces), and the classic OCCT "bottle".
30- **STEP / IGES import**: open a `.step`/`.stp` or `.iges`/`.igs` file — OCCT
31 reads it natively. "Sample STEP" round-trips a box through OCCT's own writer +
32 reader to demonstrate the import path with no bundled file.
34## Export
36- **OBJ / PLY / STL** — the current triangulation.
37- **NURBS patches (JSON)** — the polynomial-native representation (degrees,
38 poles, weights, knots per face).
39- **STEP** — the B-rep (original bytes for an imported file; re-written from the
40 kernel for primitives).
42## Internal model
44The internal representation is deliberately broader than a triangle mesh so more
45tools can plug in later. A `SurfaceModel` is a list of **patches**, and a patch
46is a discriminated union (`src/model/types.ts`). v1 emits `nurbs` patches (each
47carrying both a triangulation and the B-spline surface); `linear`, `lagrange`
48and `parametric` kinds are reserved growth points for future tools.
50## Develop
52```sh
53npm install
54npm run dev # http://localhost:5173
55npm run build # tsc -b && vite build (bundles the ~30 MB OCCT wasm as an asset)
56npm run lint
57```
59The OpenCASCADE runtime (~30 MB WASM) is loaded lazily on the first source
60action, not at page load.
62## Layout
64```
65src/
66 occ/ OpenCASCADE integration (all OCCT calls confined here)
67 loader.ts lazy singleton initOpenCascade({ mainWasm })
68 primitives.ts BRepPrimAPI shape builders + the tutorial bottle
69 importCad.ts STEP/IGES readers via Emscripten FS
70 exportCad.ts STEPControl_Writer
71 extract.ts shape -> SurfaceModel: BRepMesh triangulation + NURBS extraction
72 model/ types.ts (SurfaceModel/Patch) + tessellate.ts (pure geometry helpers)
73 render/ SurfaceView.tsx (plain three.js) + palette.ts
74 export/ meshWriters.ts (OBJ/PLY/STL) + nurbsJson.ts
75 sources.ts registry of built-in primitives
76 App.tsx sidebar UI + viewport
77```
79Part of the [concept-collection](https://github.com/concept-collection) org.
moveopenescclose