apple/SwiftUsd
A Swift Package for using OpenUSD in Swift
Getting Started
Before you can start using SwiftUsd, you need to add it as a dependency to your Xcode project or Swift Package, and then configure a few build settings.
Xcode project
- To use SwiftUsd in an Xcode project, select File > Add Package Dependency, and enter
https://github.com/apple/SwiftUsdas the URL. - In the build settings for your target, set
C++ and Objective-C InteroperabilitytoC++ / Objective-C++(SWIFT_OBJC_INTEROP_MODE=objcxx). - In the build settings for your target, set
C++ Language DialecttoGNU++17 [-std=gnu++17](CLANG_CXX_LANGUAGE_STANDARD=gnu++17).
Swift Package
- To use SwiftUsd in a Swift Package, first add it as a dependency:
dependencies: [
.package(url: "https://github.com/apple/SwiftUsd", from: "6.1.0"),
]- Then enable Swift-Cxx interoperability on your Swift targets:
.target(name: "MyTarget",
dependencies: [.product(name: "OpenUSD", package: "SwiftUsd")],
swiftSettings: [
.interoperabilityMode(.Cxx)
]),- Then set the C++ language standard to GNU++17:
let package = Package(
name: "MyPackage",
targets: [...],
cxxLanguageStandard: .gnucxx17
)Using SwiftUsd
Once you've added SwiftUsd as a package depedency to your Xcode project or Swift Package, enabled Swift-Cxx interop, and set the C++ version to GNU++17, you're ready to start using SwiftUsd:
import OpenUSD
func makeHelloWorldString() -> String {
let stage = Overlay.Dereference(pxr.UsdStage.CreateInMemory())
stage.DefinePrim("/hello", .UsdGeomTokens.Xform)
stage.DefinePrim("/hello/world", .UsdGeomTokens.Sphere)
return stage.ExportToString() ?? "nil"
}Documentation
See the online documentation here. Alternatively, open the included SwiftUsd.doccarchive in Xcode for local viewing.
Package Metadata
Repository: apple/SwiftUsd
Homepage: https://apple.github.io/SwiftUsd/documentation/openusd/
Stars: 75
Forks: 11
Open issues: 1
Default branch: main
Primary language: c++
License: Apache-2.0
README: README.md