Mesh Formats (STL, OBJ, PLY)
Faceted formats trade exact B-Rep for triangles. All doors live in @huukhanhnguyen/io and follow one pattern: write* takes a B-Rep document and tessellates it; read* rebuilds a faceted B-Rep document you can feed back to Brep.*.
STL
import { writeStl, writeStlAscii, readStl } from '@huukhanhnguyen/io'
import { Brep } from '@huukhanhnguyen/geometry'
const box = Brep.box(10, 10, 10)
const binary: Uint8Array = writeStl(box) // binary STL
const ascii: string = writeStlAscii(box) // ASCII STL
const back = readStl(binary) // string | Uint8Array in → faceted B-Rep document
console.log(Brep.isClosed(back)) // watertight input → closed solidOBJ
import { writeObj, readObj } from '@huukhanhnguyen/io'
const objText = writeObj(box) // geometry only, one object
const back = readObj(objText) // faceted B-Rep documentPLY
import { writePly, readPly } from '@huukhanhnguyen/io'
const bin = writePly(box, 'binary') as Uint8Array
const asc = writePly(box, 'ascii') as string
const back = readPly(bin)Round-trip reality
All three readers rebuild through solidFromTriangleMesh(positions, indices): for a watertight closed input the result is a closed two-manifold document. A box survives the round trip in every format — the package tests assert exactly that. What does not survive: analytic surfaces (cylinders become facets), colors, and names. Keep STEP/IGES for exact interchange.
Whole-scene export
When you have entities (from @huukhanhnguyen/model evaluation or scene work) rather than one document, the tessellationTo* doors bake and write the whole set:
import { tessellationToStl, tessellationToObj, type Entity } from '@huukhanhnguyen/io'
const stl: Uint8Array = tessellationToStl(entities, options)
const obj = tessellationToObj(entities, options) // ObjResult — OBJ + MTL, one `o` per sourceKeyentitiesToObj(entities, { tessellate: true }) additionally handles entities whose B-Rep needs baking first.
Related formats
- 3MF —
readThreemf/writeThreemf, same shape as STL. - glTF/GLB — richer (materials, hierarchy); see glTF, USD and drawing export.
- Parametric export re-exports these doors from
@huukhanhnguyen/modeltoo (tessellationToStl,tessellationToObj, …).
Where next
- Import STEP and IGES — exact B-Rep interchange.
- Mesh and memory — what to do with rebuilt documents.