Add Maya-style prim editing to SceneHierarchyPanel

- Inline rename: double-click prim label or F2 to edit name in-place;
  Enter commits, click-away or Esc cancels (undo-able)
- Drag-and-drop reparent: drag any prim onto another to make it a child;
  invisible root drop zone below tree to reparent to stage root (undo-able)
- Ctrl+G group: creates Xform group at common parent, reparents selection
  under it; filters descendant duplication; selects new group (undo-able)
- Delete key shortcut: opens existing remove-prim modal when panel focused
- Context menu: Rename (F2) and Group (Ctrl+G) items added
- Three new undo-able commands using UsdNamespaceEditor (USD 25.05):
  RenamePrimCommand, ReparentPrimCommand, GroupPrimsCommand

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-27 19:44:55 +08:00
parent 88ae8ccefa
commit b31ca69d4f
8 changed files with 586 additions and 28 deletions
+59
View File
@@ -0,0 +1,59 @@
#include "RenamePrimCommand.h"
#include "../../utils/Logger.h"
#include <pxr/usd/usd/namespaceEditor.h>
#include <pxr/usd/usd/prim.h>
#include <pxr/base/tf/token.h>
PXR_NAMESPACE_USING_DIRECTIVE
namespace UsdLayerManager {
RenamePrimCommand::RenamePrimCommand(UsdStageRefPtr stage,
const SdfPath& primPath,
const std::string& newName)
: m_stage(stage)
, m_oldPath(primPath)
, m_oldName(primPath.GetName())
, m_newName(newName)
, m_description("Rename " + primPath.GetName() + " \xe2\x86\x92 " + newName)
{
m_newPath = primPath.GetParentPath().AppendChild(TfToken(newName));
}
void RenamePrimCommand::Execute() {
UsdPrim prim = m_stage->GetPrimAtPath(m_oldPath);
if (!prim.IsValid()) {
LOG_ERROR("RenamePrimCommand::Execute: prim not found: " + m_oldPath.GetString());
return;
}
UsdNamespaceEditor editor(m_stage);
editor.RenamePrim(prim, TfToken(m_newName));
std::string whyNot;
if (!editor.CanApplyEdits(&whyNot)) {
LOG_ERROR("RenamePrimCommand::Execute: cannot rename " + m_oldPath.GetString() + ": " + whyNot);
return;
}
if (!editor.ApplyEdits()) {
LOG_ERROR("RenamePrimCommand::Execute: ApplyEdits failed for " + m_oldPath.GetString());
}
}
void RenamePrimCommand::Undo() {
UsdPrim prim = m_stage->GetPrimAtPath(m_newPath);
if (!prim.IsValid()) {
LOG_ERROR("RenamePrimCommand::Undo: prim not found: " + m_newPath.GetString());
return;
}
UsdNamespaceEditor editor(m_stage);
editor.RenamePrim(prim, TfToken(m_oldName));
std::string whyNot;
if (!editor.CanApplyEdits(&whyNot)) {
LOG_ERROR("RenamePrimCommand::Undo: cannot rename back " + m_newPath.GetString() + ": " + whyNot);
return;
}
if (!editor.ApplyEdits()) {
LOG_ERROR("RenamePrimCommand::Undo: ApplyEdits failed for " + m_newPath.GetString());
}
}
} // namespace UsdLayerManager