Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing a new prim spec to be written in edit target layers #2390

Merged
merged 3 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mayaUsd/ufe/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ uint32_t findLayerIndex(const UsdPrim& prim, const SdfLayerHandle& layer)
{
uint32_t position { 0 };

const PcpPrimIndex& primIndex = prim.GetPrimIndex();
const PcpPrimIndex& primIndex = prim.ComputeExpandedPrimIndex();

// iterate through the expanded primIndex
for (PcpNodeRef node : primIndex.GetNodeRange()) {
Expand Down
43 changes: 42 additions & 1 deletion test/lib/ufe/testAttributeBlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import mayaUtils
import ufeUtils
import usdUtils
import testUtils

from pxr import UsdGeom, Vt, Gf
from pxr import UsdGeom, Vt, Gf, Usd

from maya import cmds
from maya import standalone
Expand Down Expand Up @@ -348,5 +349,45 @@ def testAttributeBlocking3dMatrixOps(self):
# authoring new transformation edit is allowed.
self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(transformAttr))

def testIsAttributeEditAllowed(self):
'''
Verify a edit target layer from a referenced prim can be allowed to edit if it's a stronger layer.
'''
rootLaerPath = testUtils.getTestScene("attributeBlock", "root.usda")
stage = Usd.Stage.Open(rootLaerPath)

primA = stage.GetPrimAtPath("/root/a")
self.assertTrue(primA.IsValid())
fooattrA = primA.GetAttribute("foo")
self.assertTrue(fooattrA.IsValid())

root = stage.GetPrimAtPath('/root')
targetLayer = None

for layer in stage.GetUsedLayers():
if 'subBRef' in layer.identifier:
targetLayer = layer
break

self.assertIsNotNone(targetLayer)

editTarget = _getEditTarget(targetLayer, root)
self.assertIsNotNone(editTarget)
stage.SetEditTarget(editTarget)

self.assertEqual(fooattrA.Get(), 0.0)
self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(fooattrA))
fooattrA.Set(10.0)
primspecA = targetLayer.GetObjectAtPath('/root/a.foo')
self.assertTrue(bool(primspecA))


def _getEditTarget(layer, prim):
query = Usd.PrimCompositionQuery(prim)
for arc in query.GetCompositionArcs():
if (arc.GetTargetNode().layerStack.identifier.rootLayer == layer
and not arc.GetTargetNode().path.ContainsPrimVariantSelection()):
return Usd.EditTarget(layer, arc.GetTargetNode())

if __name__ == '__main__':
unittest.main(verbosity=2)
12 changes: 12 additions & 0 deletions test/testSamples/attributeBlock/root.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#usda 1.0
(
defaultPrim = "root"
subLayers = [
@subB.usda@,
@subC.usda@,
]
)

def "root"
{
}
15 changes: 15 additions & 0 deletions test/testSamples/attributeBlock/subB.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#usda 1.0
(
defaultPrim = "root"
subLayers = [
@sublayerOfSubB.usda@,
]

)

def "root" (
prepend references = @subBRef.usda@
)
{

}
12 changes: 12 additions & 0 deletions test/testSamples/attributeBlock/subBRef.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#usda 1.0
(
defaultPrim = "root"
)
def "root"
{
over "b"
{
float foo = 10.0
}

}
9 changes: 9 additions & 0 deletions test/testSamples/attributeBlock/subC.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#usda 1.0
(
defaultPrim = "root"
)
def "root" (
prepend references = @subCRef.usda@
)
{
}
16 changes: 16 additions & 0 deletions test/testSamples/attributeBlock/subCRef.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#usda 1.0
(
defaultPrim = "root"
)
def "root"
{
def "a"
{
float foo = 0.0
}

def "b"
{
float foo = 0.0
}
}
9 changes: 9 additions & 0 deletions test/testSamples/attributeBlock/sublayerOfSubB.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#usda 1.0
(
defaultPrim = "root"
)
def "root"
{


}