def testSingleAttributeBlocking(self): ''' Authoring attribute(s) in weaker layer(s) are not permitted if there exist opinion(s) in stronger layer(s).''' # create new stage cmds.file(new=True, force=True) import mayaUsd_createStageWithNewLayer mayaUsd_createStageWithNewLayer.createStageWithNewLayer() proxyShapes = cmds.ls(type="mayaUsdProxyShapeBase", long=True) proxyShapePath = proxyShapes[0] proxyShapeItem = ufe.Hierarchy.createItem( ufe.PathString.path(proxyShapePath)) proxyShapeContextOps = ufe.ContextOps.contextOps(proxyShapeItem) stage = mayaUsd.lib.GetPrim(proxyShapePath).GetStage() # create a prim. This creates the primSpec in the root layer. proxyShapeContextOps.doOp(['Add New Prim', 'Capsule']) # create a USD prim capsulePath = ufe.PathString.path('|stage1|stageShape1,/Capsule1') capsuleItem = ufe.Hierarchy.createItem(capsulePath) capsulePrim = mayaUsd.ufe.ufePathToPrim( ufe.PathString.string(capsulePath)) # author a new radius value self.assertTrue(capsulePrim.HasAttribute('radius')) radiusAttrUsd = capsulePrim.GetAttribute('radius') # authoring new attribute edit is expected to be allowed. self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(radiusAttrUsd)) radiusAttrUsd.Set(10) # author a new axis value self.assertTrue(capsulePrim.HasAttribute('axis')) axisAttrUsd = capsulePrim.GetAttribute('axis') # authoring new attribute edit is expected to be allowed. self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(axisAttrUsd)) axisAttrUsd.Set('Y') # create a sub-layer. rootLayer = stage.GetRootLayer() subLayerA = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="LayerA")[0] # check to see the if the sublayers was added addedLayers = [subLayerA] self.assertEqual(rootLayer.subLayerPaths, addedLayers) # set the edit target to LayerA. cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerA) # radiusAttrUsd is not allowed to change since there is an opinion in a stronger layer self.assertFalse(mayaUsdUfe.isAttributeEditAllowed(radiusAttrUsd)) # axisAttrUsd is not allowed to change since there is an opinion in a stronger layer self.assertFalse(mayaUsdUfe.isAttributeEditAllowed(axisAttrUsd))
def testTranslateLockedLayer(self): # create new stage cmds.file(new=True, force=True) # Open usdCylinder.ma scene in testSamples mayaUtils.openCylinderScene() # get the stage proxyShapes = cmds.ls(type="mayaUsdProxyShapeBase", long=True) proxyShapePath = proxyShapes[0] stage = mayaUsd.lib.GetPrim(proxyShapePath).GetStage() # cylinder prim cylinderPrim = stage.GetPrimAtPath('/pCylinder1') self.assertIsNotNone(cylinderPrim) # create a sub-layer. rootLayer = stage.GetRootLayer() subLayerA = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="LayerA")[0] # check to see the if the sublayers was added addedLayers = [subLayerA] self.assertEqual(rootLayer.subLayerPaths, addedLayers) # set the edit target to LayerA. cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerA) # set permission to edit to false layerA = Sdf.Find(subLayerA) layerA.SetPermissionToEdit(False) # Check that our helper function is returning the right thing self.assertFalse(mayaUsdUfe.isEditTargetLayerModifiable(stage)) # Get translate attribute and make sure its empty translateAttr = cylinderPrim.GetAttribute('xformOp:translate') self.assertIsNotNone(translateAttr) tranlateBeforeEdit = translateAttr.Get() # create a transform3d and translate cylinderPath = ufe.Path([ mayaUtils.createUfePathSegment("|mayaUsdTransform|shape"), usdUtils.createUfePathSegment("/pCylinder1") ]) cylinderItem = ufe.Hierarchy.createItem(cylinderPath) cylinderT3d = ufe.Transform3d.transform3d(cylinderItem) if cylinderT3d is not None: cylinderT3d.translate(5.0, 6.0, 7.0) # check that the translate operation didn't change anything tranlateAfterEdit = translateAttr.Get() self.assertEqual(tranlateBeforeEdit, tranlateAfterEdit)
def setAndRemoveEditTargetRecursive(layer, index, editLayer): cmds.mayaUsdEditTarget(shapePath, edit=True, editTarget=editLayer) cmds.mayaUsdLayerEditor(layer.identifier, edit=True, removeSubPath=[index, shapePath]) self.assertEqual(stage.GetEditTarget().GetLayer().identifier, rootLayerID) cmds.undo() self.assertEqual(stage.GetEditTarget().GetLayer().identifier, editLayer) subLayer = Sdf.Layer.FindRelativeToLayer(layer, editLayer) for subLayerOffset, subLayerId in enumerate( subLayer.subLayerPaths): setAndRemoveEditTargetRecursive(subLayer, subLayerOffset, subLayerId)
def testSingleAttributeBlocking(self): ''' Authoring attribute(s) in weaker layer(s) are not permitted if there exist opinion(s) in stronger layer(s).''' # create new stage cmds.file(new=True, force=True) # Open usdCylinder.ma scene in testSamples mayaUtils.openCylinderScene() # get the stage proxyShapes = cmds.ls(type="mayaUsdProxyShapeBase", long=True) proxyShapePath = proxyShapes[0] stage = mayaUsd.lib.GetPrim(proxyShapePath).GetStage() # cylinder prim cylinderPrim = stage.GetPrimAtPath('/pCylinder1') self.assertIsNotNone(cylinderPrim) # author a new radius value self.assertTrue(cylinderPrim.HasAttribute('doubleSided')) doubleSidedAttr = cylinderPrim.GetAttribute('doubleSided') # authoring new attribute edit is expected to be allowed. self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(doubleSidedAttr)) doubleSidedAttr.Set(0) # create a sub-layer. rootLayer = stage.GetRootLayer() subLayerA = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="LayerA")[0] # check to see the if the sublayers was added addedLayers = [subLayerA] self.assertEqual(rootLayer.subLayerPaths, addedLayers) # set the edit target to LayerA. cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerA) # doubleSidedAttr is not allowed to change since there is an opinion in a stronger layer self.assertFalse(mayaUsdUfe.isAttributeEditAllowed(doubleSidedAttr))
def testMayaSelectMuteLayer(self): '''Stale selection items must be removed on mute layer.''' # Create new stage import mayaUsd_createStageWithNewLayer proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer( ) proxyShapePath = ufe.PathString.path(proxyShapePathStr) proxyShapeItem = ufe.Hierarchy.createItem(proxyShapePath) proxyShapeContextOps = ufe.ContextOps.contextOps(proxyShapeItem) # Create a sub-layer. stage = mayaUsd.lib.GetPrim(proxyShapePathStr).GetStage() rootLayer = stage.GetRootLayer() subLayerId = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="Layer1")[0] # Set the edit target to new sub-layer. cmds.mayaUsdEditTarget(proxyShapePathStr, edit=True, editTarget=subLayerId) # Create a prim. This will create the primSpec in the new sub-layer. proxyShapeContextOps.doOp(['Add New Prim', 'Capsule']) capsulePathStr = '%s,/Capsule1' % proxyShapePathStr capsulePath = ufe.PathString.path(capsulePathStr) capsuleItem = ufe.Hierarchy.createItem(capsulePath) # Select the prim. This is the core of the test: on subtree invalidate, # the prim's UFE scene item should be removed from the selection. sn = ufe.GlobalSelection.get() sn.clear() sn.append(capsuleItem) self.assertTrue(sn.contains(capsulePath)) # Mute sub-layer cmds.mayaUsdLayerEditor(subLayerId, edit=True, muteLayer=[1, proxyShapePathStr]) # Should be nothing on the selection list. self.assertTrue(sn.empty()) # Undo: capsule should be back on the selection list. cmds.undo() self.assertTrue(sn.contains(capsulePath)) # Redo: selection list now empty. cmds.redo() self.assertTrue(sn.empty()) cmds.undo() # Change attribute on the capsule, using the item from the selection, # which must be valid. self.assertTrue(len(sn), 1) capsuleItem = sn.front() capsuleAttrs = ufe.Attributes.attributes(capsuleItem) self.assertIsNotNone(capsuleAttrs) capsuleRadius = capsuleAttrs.attribute('radius') capsuleRadius.set(2) self.assertEqual(capsuleRadius.get(), 2) # Now mute the layer outside a Maya command. Stale scene items must be # removed from the selection. self.assertTrue(len(sn), 1) self.assertTrue(sn.contains(capsulePath)) stage.MuteLayer(subLayerId) self.assertTrue(sn.empty())
def testEditTarget(self): """ tests 'mayaUsdEditTarget' command, but also touches on adding anon layers """ shapePath, stage = getCleanMayaStage() # original target is the root anonymous layer originalTargetID = stage.GetEditTarget().GetLayer().identifier rootLayer = stage.GetRootLayer() self.assertEqual(originalTargetID, rootLayer.identifier) currentTargetID = cmds.mayaUsdEditTarget(shapePath, query=True, editTarget=True)[0] self.assertEqual(originalTargetID, currentTargetID) # add two sub layers redLayerId = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="redLayer")[0] greenLayerId = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="greenLayer")[0] self.assertEqual(len(rootLayer.subLayerPaths), 2) cmds.mayaUsdEditTarget(shapePath, edit=True, editTarget=greenLayerId) self.assertEqual(stage.GetEditTarget().GetLayer().identifier, greenLayerId) # do we return that new target? self.assertEqual( stage.GetEditTarget().GetLayer().identifier, cmds.mayaUsdEditTarget(shapePath, query=True, editTarget=True)[0]) undoStepTwo = greenLayerId cmds.mayaUsdEditTarget(shapePath, edit=True, editTarget=redLayerId) self.assertEqual(stage.GetEditTarget().GetLayer().identifier, redLayerId) undoStepOne = redLayerId # can we set the target back to the root? rootLayerID = rootLayer.identifier cmds.mayaUsdEditTarget(shapePath, edit=True, editTarget=rootLayerID) self.assertEqual(stage.GetEditTarget().GetLayer().identifier, rootLayerID) # undo cmds.undo() self.assertEqual(stage.GetEditTarget().GetLayer().identifier, undoStepOne) cmds.undo() self.assertEqual(stage.GetEditTarget().GetLayer().identifier, undoStepTwo) # test bad input with self.assertRaises(RuntimeError): cmds.mayaUsdEditTarget("bogusShape", query=True, editTarget=True) with self.assertRaises(RuntimeError): cmds.mayaUsdEditTarget("bogusShape", edit=True, editTarget=greenLayerId) with self.assertRaises(RuntimeError): cmds.mayaUsdEditTarget(shapePath, edit=True, editTarget="bogusLayer")
def testTransformationAttributeBlocking(self): '''Authoring transformation attribute(s) in weaker layer(s) are not permitted if there exist opinion(s) in stronger layer(s).''' # create new stage cmds.file(new=True, force=True) import mayaUsd_createStageWithNewLayer mayaUsd_createStageWithNewLayer.createStageWithNewLayer() proxyShapes = cmds.ls(type="mayaUsdProxyShapeBase", long=True) proxyShapePath = proxyShapes[0] proxyShapeItem = ufe.Hierarchy.createItem( ufe.PathString.path(proxyShapePath)) proxyShapeContextOps = ufe.ContextOps.contextOps(proxyShapeItem) stage = mayaUsd.lib.GetPrim(proxyShapePath).GetStage() # create 3 sub-layers ( LayerA, LayerB, LayerC ) and set the edit target to LayerB. rootLayer = stage.GetRootLayer() subLayerC = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerC")[0] subLayerB = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerB")[0] subLayerA = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerA")[0] # check to see the sublayers added addedLayers = [subLayerA, subLayerB, subLayerC] self.assertEqual(rootLayer.subLayerPaths, addedLayers) # set the edit target to LayerB cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerB) # create a prim. This creates the primSpec in the SubLayerB. proxyShapeContextOps.doOp(['Add New Prim', 'Sphere']) spherePath = ufe.PathString.path('|stage1|stageShape1,/Sphere1') sphereItem = ufe.Hierarchy.createItem(spherePath) spherePrim = mayaUsd.ufe.ufePathToPrim( ufe.PathString.string(spherePath)) # create a transform3d sphereT3d = ufe.Transform3d.transform3d(sphereItem) # create a xformable sphereXformable = UsdGeom.Xformable(spherePrim) # writing to "transform op order" is expected to be allowed. self.assertTrue( mayaUsdUfe.isAttributeEditAllowed( sphereXformable.GetXformOpOrderAttr())) # do any transform editing. sphereT3d = ufe.Transform3d.transform3d(sphereItem) sphereT3d.scale(2.5, 2.5, 2.5) sphereT3d.translate(4.0, 2.0, 3.0) # check the "transform op order" stack. self.assertEqual(sphereXformable.GetXformOpOrderAttr().Get(), Vt.TokenArray(('xformOp:translate', 'xformOp:scale'))) # check if translate attribute is editable translateAttr = spherePrim.GetAttribute('xformOp:translate') self.assertIsNotNone(translateAttr) # authoring new transformation edit is expected to be allowed. self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(translateAttr)) sphereT3d.translate(5.0, 6.0, 7.0) self.assertEqual(translateAttr.Get(), Gf.Vec3d(5.0, 6.0, 7.0)) # set the edit target to a weaker layer (LayerC) cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerC) # authoring new transformation edit is not allowed. self.assertFalse(mayaUsdUfe.isAttributeEditAllowed(translateAttr)) # set the edit target to a stronger layer (LayerA) cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerA) # authoring new transformation edit is allowed. self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(translateAttr)) sphereT3d.rotate(0.0, 90.0, 0.0) # check the "transform op order" stack. self.assertEqual( sphereXformable.GetXformOpOrderAttr().Get(), Vt.TokenArray( ('xformOp:translate', 'xformOp:rotateXYZ', 'xformOp:scale')))
def testRemoveEditTarget(self): shapePath, stage = getCleanMayaStage() rootLayer = stage.GetRootLayer() rootLayerID = rootLayer.identifier def setAndRemoveEditTargetRecursive(layer, index, editLayer): cmds.mayaUsdEditTarget(shapePath, edit=True, editTarget=editLayer) cmds.mayaUsdLayerEditor(layer.identifier, edit=True, removeSubPath=[index, shapePath]) self.assertEqual(stage.GetEditTarget().GetLayer().identifier, rootLayerID) cmds.undo() self.assertEqual(stage.GetEditTarget().GetLayer().identifier, editLayer) subLayer = Sdf.Layer.FindRelativeToLayer(layer, editLayer) for subLayerOffset, subLayerId in enumerate( subLayer.subLayerPaths): setAndRemoveEditTargetRecursive(subLayer, subLayerOffset, subLayerId) # build a layer hierarchy layerColorId = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="Color")[0] myLayerId = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="MyLayer")[0] layerRedId = cmds.mayaUsdLayerEditor(layerColorId, edit=True, addAnonymous="Red")[0] layerGreen = cmds.mayaUsdLayerEditor(layerColorId, edit=True, addAnonymous="Green")[0] layerBlue = cmds.mayaUsdLayerEditor(layerColorId, edit=True, addAnonymous="Blue")[0] layerDarkRed = cmds.mayaUsdLayerEditor(layerRedId, edit=True, addAnonymous="DarkRed")[0] layerLightRed = cmds.mayaUsdLayerEditor(layerRedId, edit=True, addAnonymous="LightRed")[0] mySubLayerId = cmds.mayaUsdLayerEditor(myLayerId, edit=True, addAnonymous="MySubLayer")[0] # traverse the layer tree # for each layer, set it as the edit target and remove it. for subLayerOffset, subLayerPath in enumerate(rootLayer.subLayerPaths): setAndRemoveEditTargetRecursive(rootLayer, subLayerOffset, subLayerPath) # # Test when the editTarget's parent (direct/ indirect) layer is removed # cmds.mayaUsdEditTarget(shapePath, edit=True, editTarget=layerDarkRed) # remove the Red layer (direct parent of DarkRed layer) cmds.mayaUsdLayerEditor(layerColorId, edit=True, removeSubPath=[2, shapePath]) self.assertEqual(stage.GetEditTarget().GetLayer().identifier, rootLayerID) cmds.undo() self.assertEqual(stage.GetEditTarget().GetLayer().identifier, layerDarkRed) # remove the Color layer (indirect parent of DarkRed layer) cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, removeSubPath=[1, shapePath]) self.assertEqual(stage.GetEditTarget().GetLayer().identifier, rootLayerID) cmds.undo() self.assertEqual(stage.GetEditTarget().GetLayer().identifier, layerDarkRed) # # Test with a layer that is a sublayer multiple times. # sharedLayerFile = tempfile.NamedTemporaryFile(suffix=".usda", prefix="sharedLayer", delete=False, mode="w") sharedLayerFile.write("#usda 1.0") sharedLayerFile.close() sharedLayer = path.normcase(sharedLayerFile.name) cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, insertSubPath=[0, sharedLayer]) cmds.mayaUsdLayerEditor(mySubLayerId, edit=True, insertSubPath=[0, sharedLayer]) cmds.mayaUsdEditTarget(shapePath, edit=True, editTarget=sharedLayer) # remove the sharedLayer under the root layer. # the edit target should still be the shared layer cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, removeSubPath=[0, shapePath]) self.assertEqual( path.normcase(stage.GetEditTarget().GetLayer().identifier), sharedLayer) cmds.undo() self.assertEqual( path.normcase(stage.GetEditTarget().GetLayer().identifier), sharedLayer) # remove the sharedLayer under the MySubLayer. # the edit target should still be the shared layer cmds.mayaUsdLayerEditor(mySubLayerId, edit=True, removeSubPath=[0, shapePath]) self.assertEqual( path.normcase(stage.GetEditTarget().GetLayer().identifier), sharedLayer) cmds.undo() self.assertEqual( path.normcase(stage.GetEditTarget().GetLayer().identifier), sharedLayer) # remove MySubLayer (Direct parent of SharedLayer). # the edit target should still be the shared layer cmds.mayaUsdLayerEditor(myLayerId, edit=True, removeSubPath=[0, shapePath]) self.assertEqual( path.normcase(stage.GetEditTarget().GetLayer().identifier), sharedLayer) cmds.undo() self.assertEqual( path.normcase(stage.GetEditTarget().GetLayer().identifier), sharedLayer) # remove MyLayer (Indirect parent of SharedLayer). # the edit target should still be the shared layer cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, removeSubPath=[0, shapePath]) self.assertEqual( path.normcase(stage.GetEditTarget().GetLayer().identifier), sharedLayer) cmds.undo() self.assertEqual( path.normcase(stage.GetEditTarget().GetLayer().identifier), sharedLayer) # remove SharedLayer everywhere. # the edit target should become the root layer cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, removeSubPath=[0, shapePath]) cmds.mayaUsdLayerEditor(mySubLayerId, edit=True, removeSubPath=[0, shapePath]) self.assertEqual(stage.GetEditTarget().GetLayer().identifier, rootLayerID) cmds.undo() self.assertEqual( path.normcase(stage.GetEditTarget().GetLayer().identifier), sharedLayer)
def testAttributeBlocking3dMatrixOps(self): ''' Verify authoring transformation attribute(s) in weaker layer(s) are not permitted if there exist opinion(s) in stronger layer(s) when using UsdTransform3dMatrixOp. ''' # create new stage cmds.file(new=True, force=True) # Open usdCylinder.ma scene in testSamples mayaUtils.openCylinderScene() # get the stage proxyShapes = cmds.ls(type="mayaUsdProxyShapeBase", long=True) proxyShapePath = proxyShapes[0] stage = mayaUsd.lib.GetPrim(proxyShapePath).GetStage() # cylinder prim cylinderPrim = stage.GetPrimAtPath('/pCylinder1') self.assertIsNotNone(cylinderPrim) # create 3 sub-layers ( LayerA, LayerB, LayerC ) and set the edit target to LayerB. rootLayer = stage.GetRootLayer() subLayerC = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerC")[0] subLayerB = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerB")[0] subLayerA = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerA")[0] # check to see the sublayers added addedLayers = [subLayerA, subLayerB, subLayerC] self.assertEqual(rootLayer.subLayerPaths, addedLayers) # set the edit target to LayerB cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerB) # create a xformable and give it a matrix4d xformOp:transform # This will match the UsdTransform3dMatrixOp, but not the Maya API. cylinderXformable = UsdGeom.Xformable(cylinderPrim) transformOp = cylinderXformable.AddTransformOp() xform = Gf.Matrix4d(1.0).SetTranslate(Gf.Vec3d(10, 20, 30)) transformOp.Set(xform) self.assertTrue( cylinderPrim.GetPrim().HasAttribute("xformOp:transform")) # Now that we have set up the transform stack to be 3dMatrixOp compatible, # create the Transform3d interface. cylinderPath = ufe.Path([ mayaUtils.createUfePathSegment("|mayaUsdTransform|shape"), usdUtils.createUfePathSegment("/pCylinder1") ]) cylinderItem = ufe.Hierarchy.createItem(cylinderPath) cylinderT3d = ufe.Transform3d.transform3d(cylinderItem) # select the cylinderItem sn = ufe.GlobalSelection.get() sn.clear() sn.append(cylinderItem) # move cmds.move(65, 20, 10) self.assertEqual(cylinderXformable.GetXformOpOrderAttr().Get(), Vt.TokenArray(('xformOp:transform', ))) # validate the Matrix4d entires actual = cylinderXformable.GetLocalTransformation() expected = Gf.Matrix4d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 65, 20, 10, 1) self.assertTrue(Gf.IsClose(actual, expected, 1e-5)) # set the edit target to a weaker layer (LayerC) cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerC) # check if transform attribute is editable transformAttr = cylinderPrim.GetAttribute('xformOp:transform') self.assertIsNotNone(transformAttr) # authoring new transformation edit is not allowed. self.assertFalse(mayaUsdUfe.isAttributeEditAllowed(transformAttr)) # set the edit target to a stronger layer (LayerA) cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerA) # authoring new transformation edit is allowed. self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(transformAttr))
def testAttributeBlocking3dCommonApi(self): ''' Verify authoring transformation attribute(s) in weaker layer(s) are not permitted if there exist opinion(s) in stronger layer(s) when using UsdGeomXformCommonAPI. ''' # create new stage cmds.file(new=True, force=True) # Open usdCylinder.ma scene in testSamples mayaUtils.openCylinderScene() # get the stage proxyShapes = cmds.ls(type="mayaUsdProxyShapeBase", long=True) proxyShapePath = proxyShapes[0] stage = mayaUsd.lib.GetPrim(proxyShapePath).GetStage() # cylinder prim cylinderPrim = stage.GetPrimAtPath('/pCylinder1') self.assertIsNotNone(cylinderPrim) # create 3 sub-layers ( LayerA, LayerB, LayerC ) and set the edit target to LayerB. rootLayer = stage.GetRootLayer() subLayerC = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerC")[0] subLayerB = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerB")[0] subLayerA = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerA")[0] # check to see the sublayers added addedLayers = [subLayerA, subLayerB, subLayerC] self.assertEqual(rootLayer.subLayerPaths, addedLayers) # set the edit target to LayerB cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerB) # create a xformable and give it a common API single "pivot". # This will match the common API, but not the Maya API. cylinderXformable = UsdGeom.Xformable(cylinderPrim) cylinderXformable.AddTranslateOp(UsdGeom.XformOp.PrecisionFloat, "pivot") cylinderXformable.AddTranslateOp(UsdGeom.XformOp.PrecisionFloat, "pivot", True) self.assertEqual( cylinderXformable.GetXformOpOrderAttr().Get(), Vt.TokenArray(("xformOp:translate:pivot", "!invert!xformOp:translate:pivot"))) self.assertTrue(UsdGeom.XformCommonAPI(cylinderXformable)) # Now that we have set up the transform stack to be common API-compatible, # create the Transform3d interface. cylinderPath = ufe.Path([ mayaUtils.createUfePathSegment("|mayaUsdTransform|shape"), usdUtils.createUfePathSegment("/pCylinder1") ]) cylinderItem = ufe.Hierarchy.createItem(cylinderPath) cylinderT3d = ufe.Transform3d.transform3d(cylinderItem) # select the cylinderItem sn = ufe.GlobalSelection.get() sn.clear() sn.append(cylinderItem) # rotate the cylinder cmds.rotate(0, 90, 0, relative=True, objectSpace=True, forceOrderXYZ=True) self.assertEqual( cylinderXformable.GetXformOpOrderAttr().Get(), Vt.TokenArray(("xformOp:translate:pivot", "xformOp:rotateXYZ", "!invert!xformOp:translate:pivot"))) self.assertTrue(UsdGeom.XformCommonAPI(cylinderXformable)) # set the edit target to a weaker layer (LayerC) cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerC) # check if rotate attribute is editable rotateAttr = cylinderPrim.GetAttribute('xformOp:rotateXYZ') self.assertIsNotNone(rotateAttr) # authoring new transformation edit is not allowed. self.assertFalse(mayaUsdUfe.isAttributeEditAllowed(rotateAttr)) # set the edit target to a stronger layer (LayerA) cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerA) # authoring new transformation edit is allowed. self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(rotateAttr))
def testTransformationAttributeBlocking(self): '''Authoring transformation attribute(s) in weaker layer(s) are not permitted if there exist opinion(s) in stronger layer(s).''' # create new stage cmds.file(new=True, force=True) # Open usdCylinder.ma scene in testSamples mayaUtils.openCylinderScene() # get the stage proxyShapes = cmds.ls(type="mayaUsdProxyShapeBase", long=True) proxyShapePath = proxyShapes[0] stage = mayaUsd.lib.GetPrim(proxyShapePath).GetStage() # cylinder prim cylinderPrim = stage.GetPrimAtPath('/pCylinder1') self.assertIsNotNone(cylinderPrim) # create 3 sub-layers ( LayerA, LayerB, LayerC ) and set the edit target to LayerB. rootLayer = stage.GetRootLayer() subLayerC = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerC")[0] subLayerB = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerB")[0] subLayerA = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="SubLayerA")[0] # check to see the sublayers added addedLayers = [subLayerA, subLayerB, subLayerC] self.assertEqual(rootLayer.subLayerPaths, addedLayers) # set the edit target to LayerB cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerB) # create a transform3d cylinderPath = ufe.Path([ mayaUtils.createUfePathSegment("|mayaUsdTransform|shape"), usdUtils.createUfePathSegment("/pCylinder1") ]) cylinderItem = ufe.Hierarchy.createItem(cylinderPath) cylinderT3d = ufe.Transform3d.transform3d(cylinderItem) # create a xformable cylinderXformable = UsdGeom.Xformable(cylinderPrim) # writing to "transform op order" is expected to be allowed. self.assertTrue( mayaUsdUfe.isAttributeEditAllowed( cylinderXformable.GetXformOpOrderAttr())) # do any transform editing. cylinderT3d = ufe.Transform3d.transform3d(cylinderItem) cylinderT3d.scale(2.5, 2.5, 2.5) cylinderT3d.translate(4.0, 2.0, 3.0) # check the "transform op order" stack. self.assertEqual(cylinderXformable.GetXformOpOrderAttr().Get(), Vt.TokenArray(('xformOp:translate', 'xformOp:scale'))) # check if translate attribute is editable translateAttr = cylinderPrim.GetAttribute('xformOp:translate') self.assertIsNotNone(translateAttr) # authoring new transformation edit is expected to be allowed. self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(translateAttr)) cylinderT3d.translate(5.0, 6.0, 7.0) self.assertEqual(translateAttr.Get(), Gf.Vec3d(5.0, 6.0, 7.0)) # set the edit target to a weaker layer (LayerC) cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerC) # authoring new transformation edit is not allowed. self.assertFalse(mayaUsdUfe.isAttributeEditAllowed(translateAttr)) # set the edit target to a stronger layer (LayerA) cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerA) # authoring new transformation edit is allowed. self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(translateAttr)) cylinderT3d.rotate(0.0, 90.0, 0.0) # check the "transform op order" stack. self.assertEqual( cylinderXformable.GetXformOpOrderAttr().Get(), Vt.TokenArray( ('xformOp:translate', 'xformOp:rotateXYZ', 'xformOp:scale')))