SwiftUSD

23.11.35

Pixar's universal scene description for swift and the open source metaverse.
wabiverse/SwiftUSD

What's New

v23.11.35 | OpenSubdiv

2024-04-12T18:29:47Z

What's New

🎧swift on.

SwiftUSD v23.11.35

Addition of Hio, Glf, GeomUtil, and OpenSubdiv Shaders.

Important

Linux users: This release now links against Python 3.10 which differs with that of prior releases (pre v23.11.34) which used to link to Python 3.11, the intention is for a more out-of-the-box experience across the widest range of existing Linux users, if this has the opposite effect - please submit a new issue ticket and provide a more suitable Python version that works best for your use case, in addition to this if you are currently using Swift 5.9 - please upgrade to Swift 5.10 instead.

Changelog

  • Linux now links against Python 3.10 which differs with that of prior releases (pre v23.11.34) which used to link to Python 3.11.
  • Updated to the Swift 5.10 toolchain, in preparation for some changes to be added into Swift 5.10, where it will likely remain as the version minimum for the long haul.
  • Fix missing plugins on Linux when running the Bundler auto installer, you should no longer see any coding errors related to missing USD plugins upon this corresponding call in your own application:
    Pixar.Bundler.shared.setup(.resources)
  • Addition of the following USD (pxr.Imaging) libraries:
    • Hio
    • Glf
    • GeomUtil

Note

We now have CI workflows in order for Linux Ubuntu (x86/64) and macOS (arm64),
you can always check their build status from the root of this project repo's README.

Usage

To use this release of Pixar's USD in your swift project, add the following to the dependencies section in your Package.swift file:

// swift-tools-version: 5.10

dependencies: [
  .package(url: "https://github.com/wabiverse/SwiftUSD.git", from: "23.11.35")
]

The Wabi Foundation uses SwiftUSD to build the Kraken metaversal creation suite, you can always find an up to date configuration to use for your own Swift project here.



Linux

For Linux, these are the only dependencies required, as MetaverseKit provides everything else.

Tip

If you are on a distro like Ubuntu there is a good chance you already have most of these installed.

Dependency CentOS Ubuntu
Boost boost-devel libboost-all-dev
Python python3-devel python3-dev
BZ2 bzip2-devel libbz2-dev
ZLib zlib-devel zlib1g-dev
FreeGLUT freeglut-devel freeglut3-dev
DEFLATE libdeflate-devel libdeflate-dev
Expat libexpat-devel libexpat1-dev
Xcursor libXcursor-devel libxcursor-dev
Xt libXt-devel libxt-dev
Xi libXi-devel libxi-dev
Xinerama libXinerama-devel libxinerama-dev
Xrandr libXrandr-devel libxrandr-dev

Pixar's universal scene description for swift and the open source metaverse.

Important

Supporting SwiftUSD ❤️

If you find SwiftUSD useful, please consider supporting me by becoming a sponsor. I spend a tremendous amount of time dedicating my life to open source projects, and each sponsorship helps me focus more time on making quality tools and software for the community.


Swifting the Metaverse

Universal Scene Description (USD) is an efficient, scalable system for authoring, reading, and streaming time-sampled scene description for interchange between graphics applications.

For more details, please visit the web site here.

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: "23.11.35"),
]
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: "MyMetaversePackage",
  platforms: [
    .macOS(.v14),
    .visionOS(.v1),
    .iOS(.v17),
    .tvOS(.v17),
    .watchOS(.v10)
  ],
  // --- 📦 Package Products. ---
  products: [
    .library(
      name: "MyMetaverseLibrary",
      targets: ["MyMetaverseLibrary"]
    ),
    .executable(
      name: "MyMetaverseApp",
      targets: ["MyMetaverseApp"]
    ),
  ],
  dependencies: [
    .package(url: "https://github.com/wabiverse/SwiftUSD.git", from: "23.11.35")
  ],
  targets: [
    /* 📕 For library products... */
    .target(
      name: "MyMetaverseLibrary",
      dependencies: [
        /* add pixar usd as a library dependency. */
        .product(name: "PixarUSD", package: "SwiftUSD"),
      ],
      swiftSettings: [
        /* needed for SwiftUSD. */
        .interoperabilityMode(.Cxx)
      ]
    ),

    /* 📗 Or executable products... */
    .executableTarget(
      name: "MyMetaverseApp",
      dependencies: [
        /* add pixar usd as an executable dependency. */
        .product(name: "PixarUSD", package: "SwiftUSD"),
      ],
      swiftSettings: [
        /* needed for SwiftUSD. */
        .interoperabilityMode(.Cxx)
      ],
      plugins: [
        /* 📙 And, plugins are added like so. */
        .plugin(name: "UsdGenSchemaPlugin", package: "SwiftUSD")
      ]
    ),
  ],
  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()
  }
}

OH SH!

You can even run it in a tiny script, no package necessary, the comments next to the import statements describe the git sources to pull from, and everything transitively linked will come flying on in - checkout swift-sh!

Important

You will need to use the Wabi fork of swift-sh in order for this to work with Swift 5.9 cxx interop.

image


Note

Swift is an open source programming language that is fully supported across 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.


Description

  • Swift Tools 5.10.0
View More Packages from this Author

Dependencies

Last updated: Thu May 02 2024 11:49:41 GMT-0900 (Hawaii-Aleutian Daylight Time)