Bitbybit Docs
    Preparing search index...

    Class OCCTIO

    Reading and writing OpenCascade shapes in exchange formats: STEP, IGES, STL and BREP in; STEP, STL, BREP, OBJ, PLY, SVG and DXF out; STEP to glTF conversion with the assembly tree, colors and names preserved, and a STEP assembly structure as JSON. Files travel as text or binary data, never as paths. OpenCascade treats Z as up while this library treats Y as up, so the adjustYtoZ and adjustZtoY flags swap the axes on the way out and in.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    occWorkerManager: OCCTWorkerManager

    assembly

    • Converts a STEP file into a binary glTF (GLB), keeping the assembly tree as glTF nodes along with part names, colors, materials and placements.

      stepData is the file as text, ArrayBuffer or Uint8Array. The mesh settings say how finely curved surfaces are triangulated: meshPrecision is the deflection, meshAngle the angular deflection. Z-up becomes glTF's Y-up. Failure throws.

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The GLB file as bytes

      const glb = await bitbybit.occt.io.convertStepToGltf({ stepData: stepText, meshPrecision: 0.005, meshAngle: 0.5, meshRelative: true, internalVerticesMode: false, controlSurfaceDeflection: false });
      
    • Converts a STEP file into a binary glTF (GLB) like convertStepToGltf, with every option exposed.

      The read flags choose what to take from the file (colors, names, materials, layers, properties), the mesh settings how finely to triangulate, the export settings how the glTF is written (merged faces, 16-bit indexes, naming, scale). Switch off what you do not need.

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The GLB file as bytes

      const options = new Bit.Inputs.OCCT.ConvertStepToGltfAdvancedDto();
      options.stepData = stepText;
      options.readColors = true;
      options.readNames = true;
      options.meshDeflection = 0.005;
      options.mergeFaces = true;
      options.adjustZtoY = true;
      const glb = await bitbybit.occt.io.convertStepToGltfAdvanced(options);
    • Converts a STEP file into a binary glTF (GLB) like convertStepToGltf and compresses the geometry with Draco, which makes the file much smaller at the cost of a Draco-capable loader.

      The Draco settings set the compression level and how many bits positions, normals, texture coordinates and colors keep; fewer bits mean a smaller file and less precision.

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The GLB file as bytes

      const options = new Bit.Inputs.OCCT.ConvertStepToGltfWithDracoDto();
      options.stepData = stepText;
      options.meshPrecision = 0.005;
      options.dracoCompressionLevel = 7;
      options.dracoQuantizePositionBits = 14;
      const glb = await bitbybit.occt.io.convertStepToGltfWithDraco(options);
    • Converts a STEP file into a binary glTF (GLB) with every reading, meshing and writing option exposed, as convertStepToGltfAdvanced does, and compresses the geometry with Draco.

      The Draco settings set the compression level and how many bits positions, normals, texture coordinates and colors keep; fewer bits mean a smaller file and less precision.

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The GLB file as bytes

      const options = new Bit.Inputs.OCCT.ConvertStepToGltfAdvancedWithDracoDto();
      options.stepData = stepText;
      options.readColors = true;
      options.meshDeflection = 0.005;
      options.dracoCompressionLevel = 7;
      const glb = await bitbybit.occt.io.convertStepToGltfAdvancedWithDraco(options);
    • Reads the assembly structure of a STEP file without building geometry: every part and sub-assembly as a node with its id, name, whether it is an assembly, its visibility, its color and its placement matrix.

      The nodes come in depth-first order, so children follow their parent. A file that cannot be parsed reports its error in the result.

      Parameters

      Returns Promise<AssemblyJsonResult>

      The list of nodes, the format version and any error

      const tree = await bitbybit.occt.io.parseStepToJson({ stepData: stepText });
      console.log(tree.nodes.map(n => n.name));

    dxf

    • Turns the wires of a shape into DXF path records, the first step of a 2D DXF export.

      The shape must lie flat on the XZ ground plane, since DXF drawings are two-dimensional. The deflection settings say how closely curved edges are followed. Give the paths a layer with dxfPathsWithLayer and write the file with dxfCreate.

      Parameters

      Returns Promise<DxfPathDto[]>

      The DXF paths

      const paths = await bitbybit.occt.io.shapeToDxfPaths({
      shape: flatOutline,
      angularDeflection: 0.1,
      curvatureDeflection: 0.1,
      minimumOfPoints: 2,
      uTolerance: 1e-9,
      minimumLength: 1e-7,
      });
    • Puts DXF paths on a named layer with a color, making one part of a DXF drawing.

      A drawing may hold several parts, each with its own layer and color; dxfCreate writes them into one file.

      Parameters

      Returns Promise<DxfPathsPartDto>

      The paths as one layered part

      const part = await bitbybit.occt.io.dxfPathsWithLayer({ paths, layer: "cut", color: "#ff0000" });
      
    • Writes DXF parts into one DXF file and returns its text.

      colorFormat chooses AutoCAD's indexed colors or true color, acadVersion the DXF version: AC1009 is R12, the most widely readable, AC1015 is 2000, which can also state the drawing's unit. fileName and tryDownload matter only where a browser download can be started.

      Parameters

      • inputs: DxfPathsPartsListDto

        The layered parts, the color format, the DXF version, the unit and the download options

      Returns Promise<string>

      The DXF file as text

      const dxf = await bitbybit.occt.io.dxfCreate({
      pathsParts: [part],
      colorFormat: Bit.Inputs.OCCT.dxfColorFormatEnum.aci,
      acadVersion: Bit.Inputs.OCCT.dxfAcadVersionEnum.AC1009,
      fileName: "drawing.dxf",
      tryDownload: false,
      });

    io

    • Writes a shape as STEP, the exchange format for exact CAD geometry, and starts a browser download of the file.

      With adjustYtoZ true, Y and Z swap, mirroring the shape; turn it 90 degrees about X with transforms.rotate first to keep it as built. The file is in millimetres, another unit scaled to them; saveShapeSTEPAndReturn returns the text.

      Parameters

      Returns Promise<void>

      Nothing; the download starts when the file is ready

      await bitbybit.occt.io.saveShapeSTEP({ shape: box, fileName: "box.step", adjustYtoZ: true, tryDownload: true });
      
    • Writes a shape as STEP, the exchange format for exact CAD geometry, and returns its text.

      With adjustYtoZ true, Y and Z swap so Y-up becomes STEP's Z-up, mirroring the shape; turn it 90 degrees about X with transforms.rotate first to keep it as built. The file is in millimetres, a shape in another unit scaled to them.

      Parameters

      Returns Promise<string>

      The STEP file as text

      const step = await bitbybit.occt.io.saveShapeSTEPAndReturn({ shape: box, fileName: "box.step", adjustYtoZ: true, tryDownload: false });
      
    • Triangulates a shape, writes it as STL, the mesh format 3D printers read, and starts a browser download of the file.

      precision is the meshing tolerance in model units, adjustYtoZ swaps Y and Z, which mirrors the shape, and binary writes the smaller binary form. fileName names the download, tryDownload false skips it. saveShapeStlAndReturn gives the file instead.

      Parameters

      • inputs: SaveStlDto<TopoDSShapePointer>

        The shape, the file name, the meshing precision, the axis adjustment, the form and the download options

      Returns Promise<void>

      Nothing; the download starts when the file is ready

      await bitbybit.occt.io.saveShapeStl({ shape: box, fileName: "box.stl", precision: 0.01, adjustYtoZ: true, tryDownload: true, binary: true });
      
    • Triangulates a shape and writes it as STL, the mesh format 3D printers and slicers read, returning the file's text, or its bytes when binary is true.

      precision is the meshing tolerance in model units; smaller values follow curved surfaces more closely. adjustYtoZ swaps Y and Z, which mirrors the shape. fileName and tryDownload matter only for a download.

      Parameters

      • inputs: SaveStlDto<TopoDSShapePointer>

        The shape, the file name, the meshing precision, the axis adjustment, the form and the download options

      Returns Promise<string | Uint8Array<ArrayBufferLike>>

      The STL file as text, or as bytes when binary is true

      const stl = await bitbybit.occt.io.saveShapeStlAndReturn({ shape: box, fileName: "box.stl", precision: 0.01, adjustYtoZ: true, tryDownload: false });
      const bytes = await bitbybit.occt.io.saveShapeStlAndReturn({ shape: box, fileName: "box.stl", precision: 0.01, adjustYtoZ: true, tryDownload: false, binary: true });
    • Writes a shape as BREP, the text format that keeps its exact geometry and topology, and starts a browser download of the file.

      io.loadBrep reads the file back into the same shape. fileName names the download and tryDownload false skips it; saveShapeBrepAndReturn gives the text instead.

      Parameters

      Returns Promise<void>

      Nothing; the download starts when the file is ready

      await bitbybit.occt.io.saveShapeBrep({ shape: box, fileName: "box.brep", tryDownload: true });
      
    • Writes a shape as BREP, the text format that keeps its exact geometry and topology, and returns the file's text.

      io.loadBrep reads the text back into the same shape, placement and orientation included. fileName and tryDownload only matter where a download can start.

      Parameters

      Returns Promise<string>

      The BREP file as text

      const brep = await bitbybit.occt.io.saveShapeBrepAndReturn({ shape: box, fileName: "box.brep", tryDownload: false });
      const copy = await bitbybit.occt.io.loadBrep({ brepData: brep });
    • Writes a shape as binary BREP, the exact geometry and topology saveShapeBrep writes as text, in bytes, and starts a browser download of the file.

      io.loadBrepBinary reads the file back into the same shape. fileName names the download and tryDownload false skips it; saveShapeBrepBinaryAndReturn gives the bytes instead.

      Parameters

      Returns Promise<void>

      Nothing; the download starts when the file is ready

      await bitbybit.occt.io.saveShapeBrepBinary({ shape: box, fileName: "box.bbrep", tryDownload: true, withTriangulation: false });
      
    • Writes a shape as binary BREP, the exact geometry and topology saveShapeBrep writes as text, in bytes, and returns them.

      io.loadBrepBinary reads them back with every face and edge at the same index. withTriangulation false leaves out the mesh.

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The binary BREP file's bytes

      const bytes = await bitbybit.occt.io.saveShapeBrepBinaryAndReturn({ shape: box, fileName: "box.bbrep", tryDownload: false, withTriangulation: false });
      const copy = await bitbybit.occt.io.loadBrepBinary({ brepData: bytes });
    • Triangulates a shape, writes it as OBJ, the mesh format most 3D programs read, and starts a browser download of the file.

      precision is the meshing tolerance in model units and adjustYtoZ swaps Y and Z, which mirrors the shape. The file name may hold no spaces or slashes; tryDownload false skips the download, and saveShapeObjAndReturn gives the text instead.

      Parameters

      Returns Promise<void>

      Nothing; the download starts when the file is ready

      await bitbybit.occt.io.saveShapeObj({ shape: box, fileName: "box.obj", precision: 0.01, adjustYtoZ: false, tryDownload: true });
      
    • Triangulates a shape and writes it as OBJ, the mesh format most 3D programs read, returning the file's text.

      precision is the meshing tolerance in model units, adjustYtoZ swaps Y and Z, which mirrors the shape, and coordinates keep six decimals. mtl stays empty, since a shape carries no colors; assembly.manager.exportDocumentToObj writes colored parts.

      Parameters

      Returns Promise<ObjFiles>

      The OBJ text, with an empty material library text

      const files = await bitbybit.occt.io.saveShapeObjAndReturn({ shape: box, fileName: "box.obj", precision: 0.01, adjustYtoZ: false, tryDownload: false });
      console.log(files.obj);
    • Triangulates a shape, writes it as ASCII PLY with a normal per vertex, and starts a browser download of the file.

      precision is the meshing tolerance in model units and adjustYtoZ swaps Y and Z, which mirrors the shape. fileName names the download and tryDownload false skips it; saveShapePlyAndReturn gives the text instead.

      Parameters

      Returns Promise<void>

      Nothing; the download starts when the file is ready

      await bitbybit.occt.io.saveShapePly({ shape: box, fileName: "box.ply", precision: 0.01, adjustYtoZ: false, tryDownload: true });
      
    • Triangulates a shape and writes it as ASCII PLY with a normal per vertex, a mesh format scanning tools read, returning the file's text.

      Coordinates keep six significant digits, so past 1000 units they keep two decimals. precision is the meshing tolerance in model units and adjustYtoZ swaps Y and Z, which mirrors the shape.

      Parameters

      Returns Promise<string>

      The PLY file as text

      const ply = await bitbybit.occt.io.saveShapePlyAndReturn({ shape: box, fileName: "box.ply", precision: 0.01, adjustYtoZ: false, tryDownload: false });
      
    • Draws the edges a view of a shape sees as an SVG drawing, with the hidden edges dashed when asked, and starts a browser download of the file.

      The drawing shows the view from the frame's normal side, x along its direction; with the shape's unit, it states its true width and height. saveShapeSvgAndReturn gives the text instead.

      Parameters

      Returns Promise<void>

      Nothing; the download starts when the file is ready

      const view = { origin: [0, 0, 0], normal: [0, 1, 0], direction: [1, 0, 0] };
      await bitbybit.occt.io.saveShapeSvg({ shape: part, frame: view, drawHidden: true, precision: 0.01, fileName: "top.svg", tryDownload: true });
    • Draws the edges a view of a shape sees as SVG, hidden ones dashed when asked, and returns the file's text.

      The view looks from the frame's normal side, x along the frame's direction and y up, so each point is written as x and minus y. With the shape's unit, it states its true width and height.

      Parameters

      Returns Promise<string>

      The SVG file as text

      const view = { origin: [0, 0, 0], normal: [1, 1, 1], direction: [1, -1, 0] };
      const svg = await bitbybit.occt.io.saveShapeSvgAndReturn({ shape: box, frame: view, drawHidden: true, precision: 0.01, fileName: "box.svg", tryDownload: false });
    • Reads the unit a STEP or IGES file writes its lengths in, without building its geometry.

      Millimetres, centimetres, metres and inches are told; a file in another unit, one whose parts disagree, or one that states none gives undefined. io.loadSTEPorIGES reads any of them into the unit it is asked for.

      Parameters

      Returns Promise<unitOfLengthEnum>

      The file's unit, or undefined when it is none of these or cannot be told

      const unit = await bitbybit.occt.io.fileLengthUnit({ filetext: stepText, fileName: "bracket.step" });
      const shape = await bitbybit.occt.io.loadSTEPorIGES({ filetext: stepText, fileName: "bracket.step", unit: unit ?? Bit.Inputs.Base.unitOfLengthEnum.millimetre });
    • Reads an STL file, ASCII or binary, into a shape: one planar face per triangle, or one face that carries the whole mesh.

      With asFaces true the faces share their corners' edges in a compound that shapeFix.sewWithReport can join into a shell. adjustZtoY turns Z-up into Y-up, and a file without triangles is refused.

      Parameters

      • inputs: LoadStlDto

        The STL file, the face option and the axis adjustment

      Returns Promise<TopoDSShapePointer>

      A compound of triangular faces, or one face that carries the mesh

      const mesh = await bitbybit.occt.io.loadStl({ stlData: stlText, asFaces: true, adjustZtoY: true });
      const sewn = await bitbybit.occt.shapeFix.sewWithReport({ shapes: [mesh], tolerance: 1e-6 });
    • Reads a BREP file, the text format that keeps a shape's exact geometry and topology, back into the shape io.saveShapeBrep wrote.

      The shape keeps its placement and orientation. Text that is not a whole BREP file, such as one cut short, is refused, and so is a damaged one, with where it is damaged.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The shape the file holds

      const brep = await bitbybit.occt.io.saveShapeBrepAndReturn({ shape: box, fileName: "box.brep", tryDownload: false });
      const copy = await bitbybit.occt.io.loadBrep({ brepData: brep });
    • Reads a binary BREP file, the bytes io.saveShapeBrepBinary writes, back into the shape it holds, with its faces and edges in the same order.

      The bytes are checked first: damaged ones, or ones not in version 4, are refused, saying where.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The shape the file holds

      const bytes = await bitbybit.occt.io.saveShapeBrepBinaryAndReturn({ shape: box, fileName: "box.bbrep", tryDownload: false, withTriangulation: true });
      const copy = await bitbybit.occt.io.loadBrepBinary({ brepData: bytes });