Skip to content

Commit

Permalink
Add minimal usdview ui & app icon.
Browse files Browse the repository at this point in the history
* Bare bones swiftui app, with stub on non-darwin
  platforms as to not introduce a cross platform swiftui
  dependency yet.
  • Loading branch information
furby-tm committed Apr 13, 2024
1 parent e36e2d0 commit 081db71
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 34 deletions.
1 change: 1 addition & 0 deletions Bundler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ identifier = 'foundation.wabi.UsdView'
product = 'UsdView'
version = '1.0.0'
category = 'public.app-category.graphics-design'
icon = 'usdview.png'

[apps.UsdView.plist]
commit = '$(COMMIT_HASH)'
25 changes: 25 additions & 0 deletions Sources/PixarUSD/Usd/Sdf/Layer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,29 @@ public extension SdfLayerHandle
{
pointee.Save(force)
}

/**
* Reloads the layer from its persistent representation.
*
* This restores the layer to a state as if it had just been created
* with ``SdfLayer/findOrOpen()``. This operation is undoable.
*
* The fileName and whether journaling is enabled are not affected
* by this method.
*
* When called with force = false (the default), Reload attempts to
* avoid reloading layers that have not changed on disk. It does so
* by comparing the file's modification time (mtime) to when the
* file was loaded. If the layer has unsaved modifications, this
* mechanism is not used, and the layer is reloaded from disk. If the
* layer has any ``SdfLayer/getExternalAssetDependencies()`` "external
* asset dependencies", their modification state will also be consulted
* when determining if the layer needs to be reloaded.
*
* Passing true to the `force` parameter overrides this behavior, forcing
* the layer to be reloaded from disk regardless of whether it has changed. */
func reload(force: Bool = false)
{
pointee.Reload(force)
}
}
105 changes: 76 additions & 29 deletions Sources/PixarUSD/Usd/Usd/Stage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,6 @@ public extension Usd

public extension Usd.Stage
{
/**
* Traverse the active, loaded, defined, non-abstract prims on this stage depth-first.
*
* Returns a ``Usd.PrimRange`` , which allows low-latency traversal, with the
* ability to prune subtrees from traversal. It is python iterable, so in its simplest form,
* one can do:
* ```swift
* for prim in stage.traverse()
* {
* print(prim.GetPath())
* }
* ```
*
* If either a pre-and-post-order traversal or, a traversal rooted at
* a particular prim is desired, construct a ``Usd.PrimRange``
* directly.
*
* This is equivalent to ``Usd.PrimRange.stage()``. */
func traverse() -> [Usd.Prim]
{
let it = Usd.PrimRange.Stage(getPtr())

return IteratorSequence(it).map { $0 }
}

/**
* ``InitialLoadingSet``
*
Expand Down Expand Up @@ -233,10 +208,7 @@ public extension Usd.Stage
{
Usd.Stage.Open(std.string(filePath), load.rawValue)
}
}

public extension Usd.StageRefPtr
{
/**
* Traverse the active, loaded, defined, non-abstract prims on this stage depth-first.
*
Expand All @@ -257,9 +229,37 @@ public extension Usd.StageRefPtr
* This is equivalent to ``Usd.PrimRange.stage()``. */
func traverse() -> [Usd.Prim]
{
pointee.traverse()
let it = Usd.PrimRange.Stage(getPtr())

return IteratorSequence(it).map { $0 }
}

/**
* Calls Sdf/Layer/reload() on all layers contributing to this stage,
* except session layers and sublayers of session layers.
*
* This includes non-session sublayers, references and payloads.
* Note that reloading anonymous layers clears their content, so
* invoking Reload() on a stage constructed via CreateInMemory()
* will clear its root layer.
*
* \note This method is considered a mutation, which has potentially
* global effect! Unlike the various Load() methods whose actions
* affect only **this stage**, Reload() may cause layers to change their
* contents, and because layers are global resources shared by
* potentially many Stages, calling Reload() on one stage may result in
* a mutation to any number of stages. In general, unless you are
* highly confident your stage is the only consumer of its layers, you
* should only call Reload() when you are assured no other threads may
* be reading from any Stages. */
func reload()
{
Reload()
}
}

public extension Usd.StageRefPtr
{
/**
* Attempt to ensure a ``Usd.Prim`` at path is defined (according to ``Usd.Prim.isDefined()``) on this stage.
*
Expand Down Expand Up @@ -404,4 +404,51 @@ public extension Usd.StageRefPtr
{
pointee.Save()
}

/**
* Calls ``Sdf/Layer/reload()`` on all layers contributing to this
* stage, except session layers and sublayers of session layers.
*
* This includes non-session sublayers, references and payloads.
* Note that reloading anonymous layers clears their content, so
* invoking ``reload()`` on a stage constructed via
* ``__ObjC/Pixar/TfRefPtr<UsdStage>/createInMemory()`` will clear its
* root layer.
*
* > Note: This method is considered a mutation, which has potentially
* global effect! Unlike the various Load() methods whose actions
* affect only **this stage**, Reload() may cause layers to change
* their contents, and because layers are global resources shared by
* potentially many Stages, calling Reload() on one stage may resul
* in a mutation to any number of stages. In general, unless you are
* highly confident your stage is the only consumer of its layers, you
* should only call ``reload()`` when you are assured no other threads
* may be reading from any Stages. */
func reload()
{
pointee.reload()
}

/**
* Traverse the active, loaded, defined, non-abstract prims on this stage depth-first.
*
* Returns a ``Usd.PrimRange`` , which allows low-latency traversal, with the
* ability to prune subtrees from traversal. It is python iterable, so in its simplest form,
* one can do:
* ```swift
* for prim in stage.traverse()
* {
* print(prim.GetPath())
* }
* ```
*
* If either a pre-and-post-order traversal or, a traversal rooted at
* a particular prim is desired, construct a ``Usd.PrimRange``
* directly.
*
* This is equivalent to ``Usd.PrimRange.stage()``. */
func traverse() -> [Usd.Prim]
{
pointee.traverse()
}
}
40 changes: 35 additions & 5 deletions Sources/UsdView/UsdView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ import PixarUSD
#if canImport(Metal)
import Metal
#endif /* canImport(Metal) */
#if canImport(SwiftUI)
import SwiftUI

public protocol PixarApp: App
{}
#else /* canImport(SwiftUI) */
public protocol PixarApp
{}
#endif /* canImport(SwiftUI) */

/**
* ``UsdView``
Expand All @@ -46,7 +55,7 @@ import PixarUSD
* the purposes of demonstrating the usage of USD,
* from the Swift programming language. */
@main
class UsdView
struct UsdView: PixarApp
{
#if canImport(Metal) && !os(visionOS)
let hydra: HDMTLRenderer
Expand All @@ -66,12 +75,33 @@ class UsdView
#if canImport(Metal) && !os(visionOS)
hydra = HDMTLRenderer(device: MTLCreateSystemDefaultDevice()!)!
#endif /* canImport(Metal) && !os(visionOS) */

#if canImport(SwiftUI)
runDemo(with: self)
#endif /* canImport(SwiftUI) */
}

static func main()
{
let app = UsdView()
#if canImport(SwiftUI)
var body: some Scene
{
WindowGroup("UsdView", id: "usdview")
{
Text("UsdView Under Construction...")
.font(.system(size: 24, weight: .black))
.padding()
}
}
#else /* canImport(SwiftUI) */
static func main()
{
let app = UsdView()

app.runDemo(with: app)
}
#endif /* canImport(SwiftUI) */

func runDemo(with app: Self)
{
/* ---------- Hydra Engine. ---------- */

#if canImport(Metal) && !os(visionOS)
Expand Down Expand Up @@ -152,7 +182,7 @@ class UsdView

/* ------------------------------------ */

Msg.logger.log(level: .info, "UsdView is not yet implemented... will exit now.")
Msg.logger.log(level: .info, "UsdView launched.")

/* ------------------------------------ */
}
Expand Down
Binary file added usdview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 081db71

Please sign in to comment.