Import STEP and IGES
STEP/IGES readers live in @huukhanhnguyen/io. They return solid JSON documents — the exact strings Brep.* from @huukhanhnguyen/geometry consumes. The chain is: file text → readStep → Brep.* → tessellate or export.
import { readStep } from '@huukhanhnguyen/io'
import { Brep } from '@huukhanhnguyen/geometry'
const solid = readStep(stepFileText)
Brep.isClosed(solid) // true
Brep.freeEdgeCount(solid) // 0
const [vertices, edges, , faces] = Brep.entityCounts(solid)
const eps = Brep.measurementDefaultEps()
console.log(Brep.volume(solid, eps), Brep.surfaceArea(solid, eps))
// Edit it like any native solid:
const drilled = Brep.subtract(solid, Brep.cylinder(5, 100))
const mesh = Brep.tessellate(drilled, 0.5)The multi-body caveat
readStep(content) reads one solid. A file holding more than one solid body is a multi-body assembly — rather than silently dropping bodies, readStep throws and points at readStepSolids, which returns them all:
import { readStepSolids } from '@huukhanhnguyen/io'
const solids: string[] = readStepSolids(stepFileText) // one document per solid body
for (const body of solids) console.log(Brep.volume(body, eps))Pick the door by what you expect: readStep for single-part files (loud failure on assemblies is a feature), readStepSolids when assemblies are legitimate input.
Open sheets
STEP files can carry open shell surfaces, which are not solids. readStepShells reads both open and closed shells but can only return closed ones (an open sheet is refused with its free-edge count); readStepShellDocuments is the door that hands open sheets back as documents. If your import path must tolerate surface models, use those instead of readStep.
IGES
Same shape, one solid per file — there is no multi-body IGES door:
import { readIges, writeIges } from '@huukhanhnguyen/io'
const solid = readIges(igesFileText)
const roundTrip = writeIges(solid) // IGES text from any Shell documentWriting STEP
Any live Shell document goes back out:
import { writeStep, writeStepCompound } from '@huukhanhnguyen/io'
const one = writeStep(Brep.box(2, 3, 4))
const assembly = writeStepCompound([Brep.box(2, 3, 4), Brep.cylinder(1, 2)])Limits and notes
- Readers accept an optional
maxEntitiesguard (default 5 000 000) against hostile files. - STEP text must be read as UTF-8 before the call — the doors take
string, not bytes. - Import is exact B-Rep, not faceted: curved faces stay curved until you tessellate.
Where next
- Mesh formats (STL/OBJ/PLY) — faceted interchange.
- Create and measure solids — what to do with the document.
- Concepts: B-Rep documents — what the string actually contains.