concept-collection / mesh-studio
mesh-studio / src / occ / exportCad.ts
25 lines · 703 BBlameHistoryRaw
1/**
2 * Write an OCCT shape out as a STEP file (used for primitive sources, which
3 * have no original file to hand back).
4 */
5import type { OpenCascade, Shape } from './types'
7export function shapeToStep(oc: OpenCascade, shape: Shape): Uint8Array {
8 const writer = new oc.STEPControl_Writer_1()
9 writer.Transfer(
10 shape,
11 oc.STEPControl_StepModelType.STEPControl_AsIs,
12 true,
13 new oc.Message_ProgressRange_1(),
14 )
15 const fname = 'export.step'
16 writer.Write(fname)
17 const bytes: Uint8Array = oc.FS.readFile(`/${fname}`)
18 try {
19 oc.FS.unlink(`/${fname}`)
20 } catch {
21 /* ignore */
22 }
23 // Copy out of the WASM heap view into a standalone buffer.
24 return new Uint8Array(bytes)