Bitbybit Docs
    Preparing search index...

    Class OCCTWIO

    Reading and writing CAD files with OCCT: everything io offers on the kernel, plus loaders that take a STEP or IGES file as a File object or as its text and give back a shape. Files are Z-up by convention, so adjustZtoY turns the loaded shape to this library's Y-up unless it is set false.

    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. fileName and tryDownload matter only where a browser download can be started.

      Parameters

      • inputs: DxfPathsPartsListDto

        The layered parts, the color format, the DXF version 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 standard exchange format for exact CAD geometry, and starts a browser download of the file.

      With adjustYtoZ true the shape is turned so this library's Y-up becomes STEP's Z-up; fromRightHanded skips the mirror that swap otherwise includes. fileName names the download and tryDownload false skips it. saveShapeSTEPAndReturn gives the file's text instead.

      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 standard exchange format for exact CAD geometry, and returns the file's text.

      With adjustYtoZ true the shape is turned so this library's Y-up becomes STEP's Z-up; fromRightHanded skips the mirror that swap otherwise includes. fileName and tryDownload matter only where a browser download can be started.

      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 turns Y-up into Z-up 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 turns Y-up into Z-up. fileName and tryDownload only matter where a download can start.

      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 });
    • 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 turns Y-up into Z-up. 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 turns Y-up into Z-up, 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 turns Y-up into Z-up. 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 turns Y-up into Z-up.

      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 running right along its direction. tryDownload false skips the download; 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 an SVG drawing, with the hidden edges dashed when asked, and returns the file's text.

      It shows the view from the frame's normal side in model units, x running right along the frame's direction and y up, so the file holds each point as x and minus y.

      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 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 STEP or IGES file, given as a File, into one shape.

      The file's extension decides the kind: .step, .stp are STEP, .iges, .igs are IGES. adjustZtoY turns the file's Z-up into Y-up. A file that cannot be read gives undefined.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The loaded shape

      const file = await bitbybit.asset.getFile({ fileName: "part.step" });
      const shape = await bitbybit.occt.io.loadSTEPorIGES({ assetFile: file, adjustZtoY: true });
      await bitbybit.draw.drawAnyAsync({ entity: shape });
    • Reads a STEP or IGES file, given as its text, into one shape; fileType says which of the two formats the text is in.

      adjustZtoY turns the file's Z-up into Y-up. Text that cannot be read gives undefined.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The loaded shape

      const text = await bitbybit.asset.fetchText({ url: "https://example.com/models/part.step" });
      const shape = await bitbybit.occt.io.loadSTEPorIGESFromText({ text, fileType: Bit.Inputs.OCCT.fileTypeEnum.step, adjustZtoY: true });