Skip to content

wabiverse/SwiftUSD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11,305 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUSD

A Swift-native, cross-platform framework for building OpenUSD applications.

Building OpenUSD Apps in Swift

A Swift-native, cross-platform framework for building OpenUSD applications - bringing the USD ecosystem to Android, Linux, Windows, and Apple platforms through syntactically pleasing Swift OpenUSD APIs, a composable Hydra viewport, native UI, and real-time workflows. Unbound from any single vendor's GPU or platform.

To use Pixar's USD in swift, add SwiftUSD as a package dependency in your project's Package.swift file.
dependencies: [
  .package(url: "https://github.com/wabiverse/SwiftUSD.git", from: "24.8.14"),
]
Then, for any target you'd like, add the monolithic USD Pixar product as a target dependency, a complete example.
// swift-tools-version: 5.10
import PackageDescription

let package = Package(
  name: "MySwiftPackage",
  platforms: [
    .macOS(.v14),
    .visionOS(.v1),
    .iOS(.v17),
    .tvOS(.v17),
    .watchOS(.v10)
  ],
  // --- 📦 Package Products. ---
  products: [
    .library(
      name: "MySwiftLibrary",
      targets: ["MySwiftLibrary"]
    ),
    .executable(
      name: "MySwiftApp",
      targets: ["MySwiftApp"]
    ),
  ],
  dependencies: [
    .package(url: "https://github.com/wabiverse/SwiftUSD.git", from: "24.8.14")
  ],
  targets: [
    /* 📕 For library products... */
    .target(
      name: "MySwiftLibrary",
      dependencies: [
        /* add pixar usd as a library dependency. */
        .product(name: "PixarUSD", package: "SwiftUSD"),
      ],
      cxxSettings: [
        /* for windows support, add these three defines until swift's clang is updated. */
        .define("_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH", .when(platforms: [.windows])),
        .define("_ALLOW_KEYWORD_MACROS", to: "1", .when(platforms: [.windows])),
        .define("static_assert(_conditional, ...)", to: "", .when(platforms: [.windows])),
      ],
      swiftSettings: [
        /* enable swift/c++ interop. */
        .interoperabilityMode(.Cxx)
      ]
    ),

    /* 📗 Or executable products... */
    .executableTarget(
      name: "MySwiftApp",
      dependencies: [
        /* add pixar usd as an executable dependency. */
        .product(name: "PixarUSD", package: "SwiftUSD"),
      ],
      cxxSettings: [
        /* for windows support, add these three defines until swift's clang is updated. */
        .define("_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH", .when(platforms: [.windows])),
        .define("_ALLOW_KEYWORD_MACROS", to: "1", .when(platforms: [.windows])),
        .define("static_assert(_conditional, ...)", to: "", .when(platforms: [.windows])),
      ],
      swiftSettings: [
        /* enable swift/c++ interop. */
        .interoperabilityMode(.Cxx)
      ],
      plugins: [
        /* 📙 And, plugins are added like so. */
        .plugin(name: "UsdGenSchemaPlugin", package: "SwiftUSD")
      ]
    ),
  ],
  /* use cxx17 language standard. */
  cxxLanguageStandard: .cxx17
)
@@ Dependency Notes @@
- Library Products allow clients that declare a dependency on this package to use the package’s functionality.
+ Executable Products vend an executable target. Use this only if you want to make the executable available to clients.
! Plugin Products vend plugin targets. This makes the plugin available to clients that integrate the Swift package.
# Swift's package manager, SwiftPM, is capabable of building Swift, Objective-C/C++, and C/C++ code.
Finally, author scene description, this is a working example of creating a new USD stage with a transform and a sphere in swift.
import Foundation
import PixarUSD

@main
enum Creator
{
  static func main()
  {
    /* Setup all usd resources (python, plugins, resources). */

    Pixar.Bundler.shared.setup(.resources)

    /* Create a new USD stage with a transform and a sphere. */

    let stage = Usd.Stage.createNew("HelloPixarUSD.usda")

    UsdGeom.Xform.define(stage, path: "/Hello")
    UsdGeom.Sphere.define(stage, path: "/Hello/World")

    stage.getPseudoRoot().set(doc: "Hello World Example (Swift)!")

    stage.save()
  }
}
Or, if you prefer those swifty declarative APIs...
import Foundation
import PixarUSD

@main
enum Creator
{
  static func main()
  {
    /* Setup all usd resources (python, plugins, resources). */

    Pixar.Bundler.shared.setup(.resources)

    /* Create a new USD stage with a transform and a sphere. */

    USDStage("HelloPixarUSD", ext: .usda)
    {
      USDPrim("Hello", type: .xform)
      {
        USDPrim("World", type: .sphere)
      }
    }
    .set(doc: "Stay Swifty.")
    .save()
  }
}

UsdView (Under Development)

Screenshot_2026-06-06_at_8 44 04_PM
Simulator Screenshot - Apple Vision Pro - 2026-06-08 at 17 32 46
usdview_on_ios

A "run everywhere" USD viewer, written entirely in Swift. UsdView pairs Hydra - Pixar's USD imaging engine - with SwiftCrossUI to bring one SwiftUI-style codebase to every platform Swift reaches: macOS, iOS, visionOS, Linux, Windows, and Android. Browsing, inspecting, and orbiting USD stages with platform native UI everywhere.

Linux

Important

The bundler is currently in development to support bundling apps on Linux, until then please follow these instructions to run UsdView on Linux:

git clone https://github.com/wabiverse/SwiftUSD
cd SwiftUSD

swift run -c release UsdView

Apple Devices (macOS, visionOS, iOS)

Tip

Install the bundler locally by running the following commands in your terminal:

git clone https://github.com/stackotter/swift-bundler
cd swift-bundler

swift build -c release
sudo cp .build/release/swift-bundler /usr/local/bin/

Finally, to run and bundle UsdView or any other app (such as your own!) with the bundler installed locally, run the following commands:

git clone https://github.com/wabiverse/SwiftUSD
cd SwiftUSD

macOS

Run and bundle UsdView on macOS.

swift bundler run -c release UsdView

visionOS or iOS

Run and bundle UsdView on visionOS or iOS.

# list available iOS and visionOS simulators.
swift bundler simulators

# boot a simulator from the list.
swift bundler simulators boot [id-of-device]

# if you booted a visionOS device.
swift bundler run -p visionOSSimulator -c release UsdView

# if you booted a iOS device.
swift bundler run -p iOSSimulator -c release UsdView

Android Devices

Run and bundle UsdView on Android.

# list available Android simulators.
swift bundler simulators

# boot a simulator from the list.
swift bundler simulators boot [id-of-device]

# if you booted a Android device.
SWIFTUSD_ANDROID_SUPPORT_ENABLED=1 swift bundler run --simulator "Pixel_10_Pro" -c release UsdView


Note

Swift is an open source programming language that is fully supported across Android, Linux and Swift on Server, the entire Apple family of devices: macOS, visionOS, iOS, tvOS, watchOS, as well as support for Microsoft Windows. To learn more about Swift, please visit swift.org.



SwiftUSD is licensed under the terms of the Tomorrow Open Source Technology 1.0 License.