Skip to content

Commit

Permalink
Merge pull request #1844 from Autodesk/t_gamaj/MAYA-114374/no_parenti…
Browse files Browse the repository at this point in the history
…ng_to_instances

MAYA-114374 Prevent parenting under an instance
  • Loading branch information
Krystian Ligenza authored Nov 18, 2021
2 parents 3afdefe + ef73801 commit c114b4b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/mayaUsd/ufe/UsdUndoInsertChildCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ UsdUndoInsertChildCommand::UsdUndoInsertChildCommand(
throw std::runtime_error(err.c_str());
}

// Reparenting directly under an instance prim is disallowed
if (parentPrim.IsInstance()) {
std::string err = TfStringPrintf(
"Parenting geometric prim [%s] under instance prim [%s] is not allowed.",
childPrim.GetName().GetString().c_str(),
parentPrim.GetName().GetString().c_str());
throw std::runtime_error(err.c_str());
}

// Apply restriction rules
ufe::applyCommandRestriction(childPrim, "reparent");
ufe::applyCommandRestriction(parentPrim, "reparent");
Expand Down Expand Up @@ -115,6 +124,7 @@ UsdUndoInsertChildCommand::Ptr UsdUndoInsertChildCommand::create(
if (parent->path().startsWith(child->path())) {
return nullptr;
}

return std::make_shared<MakeSharedEnabler<UsdUndoInsertChildCommand>>(parent, child, pos);
}

Expand Down
9 changes: 9 additions & 0 deletions test/lib/ufe/testParentCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,15 @@ def testAlreadyChild(self):
self.assertIn("pSphere1", childrenNames(children))
self.assertIn("pCylinderShape1", childrenNames(children))

def testIllegalInstance(self):
'''Parenting an object to an instance must report an error.'''

with OpenFileCtx("simpleHierarchy.ma"):
with self.assertRaises(RuntimeError):
cmds.parent(
"|mayaUsdProxy1|mayaUsdProxyShape1,/hierarchy_instance2",
"|mayaUsdProxy1|mayaUsdProxyShape1,/hierarchy_instance1")

def testUnparentUSD(self):
'''Unparent USD node.'''

Expand Down
20 changes: 20 additions & 0 deletions test/testSamples/parentCmd/simpleHierarchy.usda
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,23 @@ def Xform "pCylinder1" (
}
}

def "hierarchy_instance1" (
instanceable = true
kind = "component"
prepend references = </pCylinder1>
)
{
double3 xformOp:translate = (9.056107292292669, -3, 0)
uniform token[] xformOpOrder = ["xformOp:translate"]
}

def "hierarchy_instance2" (
instanceable = true
kind = "component"
prepend references = </pCylinder1>
)
{
double3 xformOp:translate = (9.056107292292669, -6, 0)
uniform token[] xformOpOrder = ["xformOp:translate"]
}

0 comments on commit c114b4b

Please sign in to comment.