How to save files in (.usdz)? Is this a wrapper around OpenUSD? #12
Replies: 3 comments
-
I'll answer your second question in this comment, then follow up in a new comment with an answer to your first question.
Effectively yes, the PixarUSD is a single monolithic Swift import, usage like: import PixarUSD
// so that you can utilize a safer, more "swifty" native
// Swift API with USD, alternative to unsafe/weird C++
// types and paradigms, and away from the C world of things
// like `std.string`, in favor of native Swift types like
// `String`.
@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()
}
} That same code would alternatively look like the following, if your preference was to use the "raw c++" interop bindings, instead of the monolithic swift PixarUSD target. import CxxStdlib
import Foundation
import Sdf
import Usd
import UsdGeom
@main
enum Creator
{
static func main()
{
/* Create a new USD stage with a transform and a sphere. */
let stage = Pixar.Usd.Stage.CreateNew(std.string("HelloPixarUSD.usda"), .LoadAll)
Pixar.UsdGeomXform.Define(stage.pointee.getPtr(), Pixar.SdfPath(std.string("/Hello")))
Pixar.UsdGeomSphere.Define(stage.pointee.getPtr(), Pixar.SdfPath(std.string("/Hello/World")))
stage.pointee.GetPseudoRoot().SetDocumentation(std.string("Hello World Example (Swift)!"))
stage.pointee.Save()
}
} |
Beta Was this translation helpful? Give feedback.
-
The entirety of the USD API has not yet been wrapped into Swift, but for now I believe the following should do what you're looking for: import CxxStdlib
import PixarUSD
// open your usda file referencing your other files/textures.
let stage = Usd.Stage.open("Path/To/MyUsdaFile.usda")
// export your usda file as a single usdz file.
// note: tad bit ugly because this function hasn't
// yet been wrapped in swift.
stage.pointee.Export(
/*newFilename=*/std.string("MySingleUSDzFile.usdz"),
/*addSourceFileComment=*/true,
/*args=*/Pixar.SdfLayer.FileFormatArguments()
) |
Beta Was this translation helpful? Give feedback.
-
Note Currently the monolithic PixarUSD swift target is responsible for all the native "swifty" api These improvements -- along with the ability to slim USD down in Swift, along with lots of other improvements like supporting the building of 3rd party plugins to be built/linked with SwiftUSD (without CMake) for use in other DCC applications like Maya or Blender, are happening in the feature/3rd-party-plugin-building branch, led by @gracien-app's efforts. |
Beta Was this translation helpful? Give feedback.
-
I have one usda file which is referencing 3usdz file and it’s related textures. How can i Save all these files under a single usdz file that can be shared across the platforms?
Beta Was this translation helpful? Give feedback.
All reactions