Skip to content

Sdf-tier namespace edits: subtree remove + move#112

Open
bresilla wants to merge 4 commits into
mxpv:mainfrom
bresilla:feat/namespace-sdf
Open

Sdf-tier namespace edits: subtree remove + move#112
bresilla wants to merge 4 commits into
mxpv:mainfrom
bresilla:feat/namespace-sdf

Conversation

@bresilla
Copy link
Copy Markdown
Contributor

@bresilla bresilla commented Jun 7, 2026

First piece of the namespace editing work (#102). This is just the sdf-tier mechanical half - two Layer methods:

  • remove_spec_subtree(path) - erase a spec and everything under it, and pull the leaf out of its parent's primChildren/propertyChildren.
  • move_spec_subtree(old, new) - rename or reparent: re-home the whole subtree (keeping SpecType + fields), scaffold the destination parent as an over if it's missing, and update both parents' child lists.

It's basically the inverse of the bookkeeping create_* already does. Single-layer only, and on purpose it does NOT touch relationship targets or connections that point at the moved paths - that fixup belongs in the stage-level editor, same as C++ where Sdf doesn't track backpointers.

The actual UsdNamespaceEditor (validation, multi-layer apply, target fixup) sits on top of these and comes next - wanted to land the foundation on its own since it's self-contained and easy to review.

6 tests cover remove (prim subtree + property), rename, reparent to an existing and to a missing parent, and the rejections (collision / move-under-self / kind mismatch).

Copilot AI review requested due to automatic review settings June 7, 2026 15:09
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

Note

Copilot was unable to run its full agentic suite in this review.

Adds namespace-edit helpers to mechanically remove or move authored Sdf specs within a single layer, including required child-list bookkeeping and basic safety checks.

Changes:

  • Add Layer::remove_spec_subtree to delete a spec and its authored descendants plus detach from the parent child list.
  • Add Layer::move_spec_subtree to rename/reparent a spec subtree, scaffold missing destination prim chain, and update child lists.
  • Add helper utilities (child_registration, remove_from_token_vec, subtree_paths) and a new namespace_tests module.

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

Comment thread src/sdf/layer.rs
Comment on lines +575 to +579
if new_parent.is_abs_root() {
if data.spec_type(&new_parent).is_none() {
data.create_spec(new_parent.clone(), SpecType::PseudoRoot);
}
} else {
Comment thread src/sdf/layer.rs
Comment on lines +584 to +592
for old_path in subtree_paths(data, old) {
let new_path = old_path
.replace_prefix(old, new)
.expect("subtree_paths only yields `old` and its descendants");
if let Some(spec) = data.erase_spec(&old_path) {
let ty = spec.ty;
*data.create_spec(new_path, ty) = spec;
}
}
Comment thread src/sdf/layer.rs
Comment on lines +896 to +898
fn subtree_paths(data: &Data, prefix: &Path) -> Vec<Path> {
data.paths().into_iter().filter(|p| p.has_prefix(prefix)).collect()
}
Comment thread src/sdf/layer.rs
Comment on lines +1047 to +1053
#[test]
fn reparent_prim_to_existing_parent() {
let mut layer = scene();
layer.create_prim("/X", Specifier::Def, "Xform").unwrap();
layer
.move_spec_subtree(&path("/A/B").unwrap(), &path("/X/B").unwrap())
.unwrap();
@bresilla
Copy link
Copy Markdown
Contributor Author

bresilla commented Jun 7, 2026

Went ahead and built the actual editor on top of this in #113 - the NamespaceEditor that does rename/reparent/delete with the target + connection fixup. It's stacked on this branch, so its diff shows these commits too until this merges, then I'll rebase it clean. Didn't want to sit waiting, so just kept going.

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.

2 participants