Skip to content

feat(usda): accept instanceable prim metadata#41

Merged
mxpv merged 3 commits intomxpv:mainfrom
yohawing:upstream-review/instanceable-metadata
Apr 7, 2026
Merged

feat(usda): accept instanceable prim metadata#41
mxpv merged 3 commits intomxpv:mainfrom
yohawing:upstream-review/instanceable-metadata

Conversation

@yohawing
Copy link
Copy Markdown
Contributor

@yohawing yohawing commented Apr 7, 2026

Summary

The USDA parser currently rejects instanceable = true/false with Unsupported prim metadata: instanceable, which prevents loading any file that uses USD native instancing (e.g. Kitchen_set_instanced.usd from the usd-wg-assets test set).

This PR adds a match arm in read_prim_metadata_entry that parses the instanceable boolean flag and stores it via the already-defined FieldKey::Instanceable. No changes to the schema or token layers are required; only the parser needed to learn about this entry.

Changes

  • src/usda/parser.rs: handle instanceable in read_prim_metadata_entry (7 lines).
  • fixtures/instanceable_metadata.usda: new fixture with a prim at instanceable = true, one at instanceable = false, and a parent with neither.
  • src/stage.rs: three new unit tests in stage::tests:
    • instanceable_true_parses_and_is_readable
    • instanceable_false_parses_and_is_readable
    • instanceable_absent_returns_none

The tests use the existing stage.field::<bool>(path, FieldKey::Instanceable) API to verify that the flag round-trips correctly.

Test plan

  • cargo test passes (228 tests, 3 new)
  • cargo clippy --all-targets -- -D warnings clean
  • cargo fmt --check clean
  • Manually verified Kitchen_set_instanced.usd from usd-wg-assets now opens

USDA parser rejected `instanceable = true/false` with
"Unsupported prim metadata: instanceable", preventing files
that use USD native instancing from opening.

Add a match arm in `read_prim_metadata_entry` that parses the
`instanceable` boolean flag and stores it via the already-defined
`FieldKey::Instanceable`.  No changes to the schema or token
layers are required.

Add a minimal fixture (`fixtures/instanceable_metadata.usda`)
and three tests in `stage::tests`:
- `instanceable_true_parses_and_is_readable`
- `instanceable_false_parses_and_is_readable`
- `instanceable_absent_returns_none`

Fixes: Kitchen_set_instanced.usd failing on Stage::open()
Copilot AI review requested due to automatic review settings April 7, 2026 07:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the USDA parser to accept the instanceable prim metadata flag (used by native USD instancing), adds a fixture covering instanceable = true/false, and introduces unit tests to verify the authored flag can be read back via Stage::field.

Changes:

  • Parse instanceable in read_prim_metadata_entry and store it under FieldKey::Instanceable.
  • Add a new USDA fixture authoring instanceable true/false on separate prims.
  • Add unit tests asserting instanceable is readable as Some(true), Some(false), or None when absent.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/usda/parser.rs Adds a metadata match arm to parse and store the instanceable flag.
src/stage.rs Adds unit tests verifying instanceable parsing and retrieval behavior.
fixtures/instanceable_metadata.usda Adds a fixture with prims authored with instanceable = true/false plus an un-authored parent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

n if n == FieldKey::Instanceable.as_str() => {
ensure!(list_op.is_none(), "instanceable metadata does not support list ops");
let value = self
.parse_token::<bool>()
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instanceable is parsed via parse_token::<bool>(), which relies on bool::from_str and only accepts true/false. Elsewhere the parser has parse_bool() (used for Type::Bool) that supports USD’s more permissive boolean literal forms (identifier/number/string). For consistency and to avoid rejecting valid boolean encodings here, parse instanceable with parse_bool() (and consider aligning active as well).

Suggested change
.parse_token::<bool>()
.parse_bool()

Copilot uses AI. Check for mistakes.
src/stage.rs Outdated
Ok(())
}

// --- PR #1: instanceable prim metadata ---
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section header // --- PR #1: instanceable prim metadata --- hard-codes a PR number, which won’t stay meaningful over time and isn’t used elsewhere in this test module. Consider replacing it with a descriptive header (e.g., // --- Instanceable prim metadata ---) to keep the tests self-contained.

Suggested change
// --- PR #1: instanceable prim metadata ---
// --- Instanceable prim metadata ---

Copilot uses AI. Check for mistakes.
@yohawing
Copy link
Copy Markdown
Contributor Author

yohawing commented Apr 7, 2026

Hi @mxpv,

Apologies — this PR (and the other four in this batch: #41 #42 #43 #44 #45) was opened by an AI agent on my behalf without enough human review of upstream etiquette. I should have filed an issue first to discuss before dropping a stack of code on you. Sorry for the noise.

For context: I'm building yw-look, a Windows quick-look style asset inspector for CG workflows, and I need a few small accessors on top of openusd to surface stage metadata (upAxis, metersPerUnit) and detect broken references in user assets. These five PRs are the minimal set of additions I needed.

If the API and approach look reasonable to you, I'd be grateful if you could merge them. If not — totally fine to close, I'd just maintain them on my fork instead. Happy to revise based on any feedback.

Thanks for the great crate!

mxpv added 2 commits April 7, 2026 09:02
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
@mxpv
Copy link
Copy Markdown
Owner

mxpv commented Apr 7, 2026

@yohawing no problem! thanks for contributions. Overall the changes make sense, but it'd take some time for me to review each PR.

@mxpv mxpv merged commit c68c566 into mxpv:main Apr 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants