diff --git a/crates/usd/src/scene/usda.rs b/crates/usd/src/scene/usda.rs index 40637ea04..be0ef9d0d 100644 --- a/crates/usd/src/scene/usda.rs +++ b/crates/usd/src/scene/usda.rs @@ -346,8 +346,19 @@ impl Parser<'_, '_> { if !self.lx.eat(b'=')? { continue; } + let scalar_external = matches!(key.as_str(), "references" | "payload") && matches!(self.lx.peek()?, Tok::Asset(_)); let mut acc = Acc::default(); self.value(&mut acc, 0)?; + if scalar_external { + // The target and layer offset belong to this external arc, not the next metadata + // entry. External targets must not become references to same-named local prims. + if matches!(self.lx.peek()?, Tok::Path(_)) { + self.value(&mut acc, 0)?; + } + if self.lx.eat(b'(')? { + self.skip_block(b'(', b')')?; + } + } if keep && KEPT_METADATA.contains(&key.as_str()) { out.push((key, acc)); } diff --git a/crates/usd/tests/scene.rs b/crates/usd/tests/scene.rs index d8fa22c7f..0d944b322 100644 --- a/crates/usd/tests/scene.rs +++ b/crates/usd/tests/scene.rs @@ -73,6 +73,41 @@ def Xform "World" } "#; +#[test] +fn scalar_external_arcs_keep_following_metadata_and_prims() { + // Original generated layers: external targets must never resolve to the local class. + for key in ["references", "payload"] { + for arc in [ + "@external.usda@", + "@external.usda@", + "@external.usda@ (offset = 10; scale = 2)", + "@external.usda@ (offset = 10; scale = 2)", + ] { + let source = format!( + r#"#usda 1.0 +class Xform "LocalTemplate" {{}} +def Xform "External" ( + prepend {key} = {arc} + active = false +) {{}} +def Xform "Mixed" ( + prepend {key} = [@external.usda@, ] +) {{}} +def Xform "Later" {{}} +"# + ); + let layer = read_layer(source.as_bytes()).unwrap_or_else(|error| panic!("{key} = {arc}: {error}")); + let external = layer.prims.iter().find(|p| p.path == "/External").unwrap(); + assert!(external.references.is_empty(), "{key} = {arc}"); + assert_eq!(external.active, Some(false), "{key} = {arc}"); + let mixed = layer.prims.iter().find(|p| p.path == "/Mixed").unwrap(); + assert_eq!(mixed.references, ["/LocalTemplate"], "{key} = {arc}"); + assert!(layer.prims.iter().any(|p| p.path == "/Later"), "{key} = {arc}"); + assert!(layer.warnings.iter().any(|w| w.contains("external references and payloads")), "{key} = {arc}"); + } + } +} + #[test] fn usda_corpus_overlays_references_coordinates_transforms_and_meshes() { let layer = read_layer(CORPUS_USDA.as_bytes()).unwrap();