Bitbybit Docs
    Preparing search index...

    Class OCCTWIO

    Чтение и запись CAD-файлов с помощью OCCT: все, что io предлагает в ядре, плюс загрузчики, которые принимают файл STEP или IGES как объект File или как его текст и возвращают форму. Файлы по соглашению ориентированы осью Z вверх, поэтому adjustZtoY поворачивает загруженную форму к ориентации этой библиотеки с осью Y вверх, если не установлен в 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; smaller values follow curved surfaces more closely and make a bigger file. adjustYtoZ turns Y-up into Z-up. fileName names the download, tryDownload false skips it. saveShapeStlAndReturn gives the text instead.

      Parameters

      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 });
      
    • Triangulates a shape and writes it as STL, the mesh format 3D printers and slicers read, returning the file's text.

      precision is the meshing tolerance in model units; smaller values follow curved surfaces more closely and make a bigger file. adjustYtoZ turns the shape so Y-up becomes Z-up. fileName and tryDownload only matter where a download can start.

      Parameters

      Returns Promise<string>

      The STL file as text

      const stl = await bitbybit.occt.io.saveShapeStlAndReturn({ shape: box, fileName: "box.stl", precision: 0.01, adjustYtoZ: true, tryDownload: false });
      
    • Читает файл STEP или IGES, заданный как File, в одну форму.

      Расширение файла определяет тип: .step, .stp - STEP, .iges, .igs - IGES. adjustZtoY превращает Z-вверх файла в Y-вверх. Файл, который нельзя прочитать, дает undefined.

      Parameters

      Returns Promise<TopoDSShapePointer>

      Загруженная форма

      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 });
    • Читает файл STEP или IGES, заданный его текстом, в одну форму; fileType говорит, в каком из двух форматов текст.

      adjustZtoY превращает Z-вверх файла в Y-вверх. Текст, который нельзя прочитать, дает undefined.

      Parameters

      Returns Promise<TopoDSShapePointer>

      Загруженная форма

      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 });