通用场景描述 (USD) 是一个高效、可扩展的系统,用于创作、读取和流式传输时间采样的场景描述,以便在图形应用程序之间进行交换。
有关更多详细信息,请访问网站此处。
dependencies: [
.package(url: "https://github.com/wabiverse/SwiftUSD.git", from: "24.8.13"),
]
// 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: "24.8.13")
],
targets: [
/* 📕 For library products... */
.target(
name: "MyMetaverseLibrary",
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: "MyMetaverseApp",
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.
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()
}
}
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 应用程序完全用 Swift 编写,并且是 Swift/C++ 互操作以及在 Swift 中创建跨平台 UI 应用程序(利用 SwiftCrossUI)的生动示例。
重要提示
bundler 目前正在开发中,以支持在 Linux 上捆绑应用程序,在此之前,请按照这些说明在 Linux 上运行 UsdView
git clone https://github.com/wabiverse/SwiftUSD
cd SwiftUSD
swift run -c release UsdView
提示
通过在终端中运行以下命令,在本地安装 bundler
git clone https://github.com/stackotter/swift-bundler
cd swift-bundler
swift build -c release
sudo cp .build/release/swift-bundler /usr/local/bin/
最后,要使用本地安装的 bundler 运行和捆绑 UsdView 或任何其他应用程序(例如您自己的应用程序!),请运行以下命令
git clone https://github.com/wabiverse/SwiftUSD
cd SwiftUSD
在 macOS 上运行和捆绑 UsdView。
swift bundler run -c release UsdView
在 visionOS 或 iOS 上运行和捆绑 UsdView。
# 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
您甚至可以在一个微小的脚本中运行它,无需任何包,导入语句旁边的注释描述了要从中拉取的 git 源,所有传递链接的内容都将飞速而来 - 查看 swift-sh!
重要提示
您需要使用 Wabi swift-sh 分支才能使其与 Swift 5.9 cxx 互操作一起工作。
注意
Swift 是一种开源编程语言,在 Linux 和 服务器端 Swift、整个 Apple 设备系列:macOS、visionOS、iOS、tvOS、watchOS 以及对 Microsoft Windows 的支持中都得到完全支持。 要了解有关 Swift 的更多信息,请访问 swift.org。