secondmouseau/occtswiftio
π Documentation: <https://secondmouseau.github.io/OCCTSwiftIO/>
Format coverage
| Format | Read | Write | Product | |---|---|---|---| | STL (ascii+binary) | β
| β
| MeshIO | | OBJ | β
| β
| MeshIO | | PLY (ascii+binary) | β
| β
| MeshIO | | glTF / GLB | β
| β
| MeshIO | | 3MF | β
| β
| MeshIO | | PMX (MikuMikuDance) | β
| β | MeshIO | | DirectX .x | β
| β | MeshIO | | STEP / IGES / BREP | β
| β
* | OCCTSwiftIO | | JWW (Jw_cad, 2D vector) | β
| β | OCCTSwiftIO |
<sub>*OCCTSwiftIO ExportManager exports OCCT Shapes to STEP / BREP / OBJ / PLY / glTF / GLB.</sub>
Install
dependencies: [
.package(url: "https://github.com/SecondMouseAU/OCCTSwiftIO.git", from: "1.4.0"),
],
// then add the product(s) you need:
.target(name: "YourTarget", dependencies: [
.product(name: "MeshIO", package: "OCCTSwiftIO"), // mesh, no OCCT
.product(name: "OCCTSwiftIO", package: "OCCTSwiftIO"), // CAD + JWW (pulls OCCT)
]),MeshIO β pure-Swift mesh I/O
import MeshIO
let mesh = try MeshIO.load(contentsOf: url) // .stl/.obj/.ply/.gltf/.glb/.3mf/.pmx/.x
print(mesh.vertexCount, mesh.triangleCount, mesh.bounds as Any)
try MeshIO.write(mesh, to: outURL) // format inferred from extension
try MeshIO.write(mesh, to: stlURL, format: .stl, asciiSTL: true)Mesh is a value type (positions: [SIMD3<Float>], indices: [UInt32], submeshes: [Submesh]). PMX carries its material sections through as submeshes (empty for every other format, including .x) β isolate one part of a whole-model PMX with sub.indexOffset ..< sub.indexOffset + sub.indexCount. PMX/.x are read via the standalone SwiftPMX / SwiftX packages; 3MF via ThreeMF; glTF read via SwiftGLTF (write is native).
OCCTSwiftIO β CAD + JWW
import OCCTSwift
import OCCTSwiftIO
// STEP / IGES / BREP β shapes + colors + AP242 metadata.
let result = try await ShapeLoader.load(from: stepURL, format: .step)
// JWW (Jw_cad 2D drawing) β a compound of OCCT edges (lines, arcs/circles, points).
let drawing = try await ShapeLoader.load(from: jwwURL, format: .jww)
// Export shapes to STEP / BREP / OBJ / PLY / glTF / GLB.
try await ExportManager.export(shapes: result.shapes, format: .glb, to: outURL)For body-producing loaders (CPU mesh + pick data for AIS), use OCCTSwiftTools, which wraps this package.
Architecture position
OCCTSwiftTools (bridge β Shape β ViewportBody)
β
OCCTSwiftIO β this repo (headless file I/O) MeshIO β pure-Swift mesh (no OCCT)
β β
OCCTSwift (B-Rep kernel) SwiftPMX / SwiftX / ThreeMF / SwiftGLTF / SwiftJWWHard rule: no Viewport dependency in this package. Produce ViewportBodys in OCCTSwiftTools.
License
LGPL-2.1 (inherited from OCCTSwift / OCCT). The mesh-format reader packages carry their own permissive licenses (MIT / BSD-3).
Package Metadata
Repository: secondmouseau/occtswiftio
Default branch: main
README: README.md