Contents

tomasf/manifold-swift

A Swift interface to the [Manifold geometry library](https://github.com/elalish/manifold), for manipulation of solid 3D meshes.

Usage

Add the package as a dependency in your Package.swift (or Xcode project). Because the library interfaces with C++, you need to enable C++ interoperability.

let package = Package(
    name: "manifold-swift-example",
    dependencies: [
        .package(url: "https://github.com/tomasf/manifold-swift.git", from: "1.0.0")
    ],
    targets: [
        .executableTarget(
            name: "manifold-swift-example",
            dependencies: [.product(name: "Manifold", package: "manifold-swift")],
            swiftSettings: [.interoperabilityMode(.Cxx)]
        )
    ]
)

Example

The library uses protocols for vectors and matrices. The Manifold and CrossSection types are generic over V, so you can plug in your own vector type.

struct MyVector: Vector3 {
    let x, y, z: Double
}

let box = Manifold.cube(size: MyVector(x: 12, y: 20, z: 20))
    .rotate(MyVector(x: 20, y: 25, z: 0))

let difference = Manifold.sphere(radius: 10, segmentCount: 25)
    .boolean(.difference, with: box)

let meshGL = difference.meshGL()
// Render or save meshGL.vertices, meshGL.triangles, etc.

Note: For APIs that accept segmentCount / circularSegments, passing nil means "choose automatically from the current Quality circular settings."

Read the Manifold documentation for more information.

Contributions

Contributions are welcome! Submit pull requests or open issues to discuss improvements or report bugs.

Package Metadata

Repository: tomasf/manifold-swift

Default branch: main

README: README.md