Sdf-tier namespace edits: subtree remove + move#112
Open
bresilla wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
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_subtreeto delete a spec and its authored descendants plus detach from the parent child list. - Add
Layer::move_spec_subtreeto 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 newnamespace_testsmodule.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 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 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 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(); |
Contributor
Author
|
Went ahead and built the actual editor on top of this in #113 - the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First piece of the namespace editing work (#102). This is just the sdf-tier mechanical half - two
Layermethods:remove_spec_subtree(path)- erase a spec and everything under it, and pull the leaf out of its parent'sprimChildren/propertyChildren.move_spec_subtree(old, new)- rename or reparent: re-home the whole subtree (keeping SpecType + fields), scaffold the destination parent as anoverif 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).