-
-
Notifications
You must be signed in to change notification settings - Fork 9
feat(stage): add Stage::up_axis() -> Option<UpAxis> #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #usda 1.0 | ||
| ( | ||
| defaultPrim = "Root" | ||
| ) | ||
|
|
||
| def Xform "Root" | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #usda 1.0 | ||
| ( | ||
| upAxis = "Y" | ||
| defaultPrim = "Root" | ||
| ) | ||
|
|
||
| def Xform "Root" | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #usda 1.0 | ||
| ( | ||
| upAxis = "Z" | ||
| defaultPrim = "Root" | ||
| ) | ||
|
|
||
| def Xform "Root" | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,20 @@ use crate::compose::prim_index::{ArcType, Node, PrimIndex}; | |||||||||||
| use crate::sdf::schema::{ChildrenKey, FieldKey}; | ||||||||||||
| use crate::sdf::{AbstractData, ListOp, Path, Payload, Reference, SpecType, Value}; | ||||||||||||
|
|
||||||||||||
| /// The scene's up-axis, as stored in the root layer's `upAxis` metadata. | ||||||||||||
| /// | ||||||||||||
| /// USD defines two valid values: `"Y"` (Y-up, the default for many DCC tools) | ||||||||||||
| /// and `"Z"` (Z-up, used by e.g. OpenUSD's own reference scenes). | ||||||||||||
| /// | ||||||||||||
| /// See <https://openusd.org/dev/api/group___usd_geom_up_axis__group.html> | ||||||||||||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||||||||||||
| pub enum UpAxis { | ||||||||||||
| /// Y axis points up. | ||||||||||||
| Y, | ||||||||||||
| /// Z axis points up. | ||||||||||||
| Z, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /// A composed USD stage. | ||||||||||||
| /// | ||||||||||||
| /// Owns the loaded layer stack and provides composed access to prims, | ||||||||||||
|
|
@@ -85,6 +99,35 @@ impl Stage { | |||||||||||
| self.field::<String>(&Path::abs_root(), FieldKey::DefaultPrim).ok()? | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /// Returns the `upAxis` metadata from the root layer, if set. | ||||||||||||
| /// | ||||||||||||
| /// USD defines two valid values: `"Y"` and `"Z"`. Any other authored | ||||||||||||
| /// value (malformed data) is treated as `None` rather than an error so | ||||||||||||
| /// that callers can continue inspecting the rest of the stage. | ||||||||||||
| /// | ||||||||||||
| /// # Example | ||||||||||||
| /// | ||||||||||||
| /// ```no_run | ||||||||||||
| /// use openusd::{ar::DefaultResolver, Stage}; | ||||||||||||
| /// use openusd::stage::UpAxis; | ||||||||||||
| /// | ||||||||||||
| /// let resolver = DefaultResolver::new(); | ||||||||||||
| /// let stage = Stage::open(&resolver, "scene.usda").unwrap(); | ||||||||||||
| /// match stage.up_axis() { | ||||||||||||
| /// Some(UpAxis::Y) => println!("Y-up"), | ||||||||||||
| /// Some(UpAxis::Z) => println!("Z-up"), | ||||||||||||
| /// None => println!("upAxis not set"), | ||||||||||||
| /// } | ||||||||||||
| /// ``` | ||||||||||||
| pub fn up_axis(&self) -> Option<UpAxis> { | ||||||||||||
| let raw = self.field::<String>(&Path::abs_root(), FieldKey::UpAxis).ok()??; | ||||||||||||
|
||||||||||||
| let raw = self.field::<String>(&Path::abs_root(), FieldKey::UpAxis).ok()??; | |
| let raw = self | |
| .field::<String>(&Path::abs_root(), FieldKey::UpAxis) | |
| .ok() | |
| .flatten()?; |
Copilot
AI
Apr 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function’s behavior for malformed authored values (anything other than "Y"/"Z" => None) is part of the stated contract, but there isn’t a test covering that case. Adding a small fixture (e.g. upAxis = "X") and a corresponding test would help prevent regressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring says this returns
upAxismetadata "from the root layer", but the implementation usesself.field(...)which resolves the strongest opinion across the entire layer stack (it may come from a sublayer if the strongest/root layer doesn’t author it). Consider clarifying the wording (e.g., “from the pseudo-root (composed across layers)” or “from the root layer stack”) to match actual behavior.