|
| 1 | +# Manifold-Swift |
| 2 | + |
| 3 | +A Swift interface to the [Manifold geometry library](https://github.com/elalish/manifold), for manipulation of solid 3D meshes. |
| 4 | + |
| 5 | +This SPM package includes Manifold, as well as its dependencies Clipper2 and oneTBB as Git submodules, so no additional dependencies are needed beyond the C++ standard library. Manifold-Swift works on macOS, Linux and Windows. The library covers most of the Manifold API, and naming is similar but using Swift conventions. |
| 6 | + |
| 7 | +Due to a bug in Swift that isn't fixed in the latest release (as of 2025-01-13, version 6.0.3), the library requires a development snapshot of Swift to build on Windows. Because the library interfaces with C++, you need to enable C++ interoperability when using Manifold-Swift: |
| 8 | + |
| 9 | +```swift |
| 10 | +let package = Package( |
| 11 | + name: "manifold-swift-example", |
| 12 | + dependencies: [ |
| 13 | + .package(url: "https://github.com/tomasf/manifold-swift.git", .upToNextMinor(from: "0.1.0")) |
| 14 | + ], |
| 15 | + targets: [ |
| 16 | + .executableTarget( |
| 17 | + name: "manifold-swift-example", |
| 18 | + dependencies: [.product(name: "Manifold", package: "manifold-swift")], |
| 19 | + swiftSettings: [.interoperabilityMode(.Cxx)] |
| 20 | + ) |
| 21 | + ] |
| 22 | +) |
| 23 | +``` |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +The library uses protocols for vectors and matrices, so you can add conformance to your own types and send them in without conversion. |
| 28 | + |
| 29 | +```swift |
| 30 | +import Manifold3D |
| 31 | + |
| 32 | +struct V: Vector3 { |
| 33 | + let x: Double |
| 34 | + let y: Double |
| 35 | + let z: Double |
| 36 | +} |
| 37 | + |
| 38 | +let sphere = Manifold.sphere(radius: 10, segmentCount: 25) |
| 39 | +let box = Manifold.cube(size: V(x: 12, y: 20, z: 20)) |
| 40 | + .rotate(V(x: 20, y: 25, z: 0)) |
| 41 | +let difference = sphere.boolean(.difference, with: box) |
| 42 | + |
| 43 | +let meshGL = difference.meshGL() |
| 44 | +// Render or save meshGL.vertices, meshGL.triangles, etc. |
| 45 | +``` |
| 46 | + |
| 47 | +Read the [Manifold documentation](https://manifoldcad.org/docs/html) for more information. |
| 48 | + |
| 49 | +## Contributions |
| 50 | + |
| 51 | +Contributions are welcome! Submit pull requests or open issues to discuss improvements or report bugs. |
0 commit comments