def setUp(self): ''' Called initially to set up the maya test environment ''' # Load plugins self.assertTrue(self.pluginsLoaded) # Set up memento, a list of snapshots. self.memento = [] # Callables to get current object translation and rotation using the # run-time and UFE. self.move = 0 self.rotate = 1 self.scale = 2 self.ops = [self.move, self.rotate, self.scale] self.runTimes = [None, None, None] self.ufes = [None, None, None] self.noSpace = None self.spaces = [om.MSpace.kObject, om.MSpace.kWorld] # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes cmds.polySphere() cmds.polyCube() # Clear selection to start off cmds.select(clear=True)
def setUp(self): ''' Called initially to set up the maya test environment ''' # Load plugins self.assertTrue(self.pluginsLoaded) # These tests requires no additional setup. if self._testMethodName in [ 'testAddNewPrim', 'testAddNewPrimWithDelete' ]: return # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Clear selection to start off. ufe.GlobalSelection.get().clear() # Select Ball_35. ball35Path = ufe.Path([ mayaUtils.createUfePathSegment("|transform1|proxyShape1"), usdUtils.createUfePathSegment("/Room_set/Props/Ball_35") ]) self.ball35Item = ufe.Hierarchy.createItem(ball35Path) self.ball35Prim = usdUtils.getPrimFromSceneItem(self.ball35Item) ufe.GlobalSelection.get().append(self.ball35Item) # Create a ContextOps interface for it. self.contextOps = ufe.ContextOps.contextOps(self.ball35Item)
def setUpClass(cls): if not cls.pluginsLoaded: cls.pluginsLoaded = mayaUtils.isMayaUsdPluginLoaded() # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() random.seed()
def testDefaultPrim(self): mayaUtils.openTopLayerScene() shapePath, stage = getMayaStage() # Change default prim -> dirties scene prim = mayaUsd.ufe.ufePathToPrim( '|transform1|proxyShape1,/Room_set/Props/Ball_35') with DirtySceneCheck(self): stage.SetDefaultPrim(prim)
def setUp(self): ''' Called initially to set up the Maya test environment ''' # Load plugins self.assertTrue(self.pluginsLoaded) # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Clear selection to start off cmds.select(clear=True)
def setUpClass(cls): fixturesUtils.readOnlySetUpClass(__file__, loadPlugin=False) if not cls.pluginsLoaded: cls.pluginsLoaded = mayaUtils.isMayaUsdPluginLoaded() # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() random.seed()
def testFlattenLayerStack(self): mayaUtils.openTopLayerScene() shapePath, stage = getMayaStage() # Flatten layer stack -> dirties scene rootLayer = stage.GetRootLayer() self.assertIsNotNone(rootLayer) flattenedLayer = stage.Flatten() self.assertIsNotNone(flattenedLayer) with DirtySceneCheck(self): rootLayer.TransferContent(flattenedLayer)
def testVisibility(self): '''Test the Object3d visibility methods.''' # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Get a scene item for Ball_35. ball35Path = ufe.Path([ mayaUtils.createUfePathSegment("|transform1|proxyShape1"), usdUtils.createUfePathSegment("/Room_set/Props/Ball_35") ]) ball35Item = ufe.Hierarchy.createItem(ball35Path) # Create an Object3d interface for it. object3d = ufe.Object3d.object3d(ball35Item) visObs = TestObserver() # We start off with no visibility observers. self.assertFalse(ufe.Object3d.hasObserver(visObs)) self.assertEqual(ufe.Object3d.nbObservers(), 0) # Set the observer for visibility changes. ufe.Object3d.addObserver(visObs) self.assertTrue(ufe.Object3d.hasObserver(visObs)) self.assertEqual(ufe.Object3d.nbObservers(), 1) # No notifications yet. self.assertEqual(visObs.notifications(), 0) # Initially it should be visible. self.assertTrue(object3d.visibility()) # Make it invisible. object3d.setVisibility(False) self.assertFalse(object3d.visibility()) # We should have got 'one' notification. self.assertEqual(visObs.notifications(), 1) # Make it visible. object3d.setVisibility(True) self.assertTrue(object3d.visibility()) # We should have got one more notification. self.assertEqual(visObs.notifications(), 2) # Remove the observer. ufe.Object3d.removeObserver(visObs) self.assertFalse(ufe.Object3d.hasObserver(visObs)) self.assertEqual(ufe.Object3d.nbObservers(), 0)
def testFileBackedLayers(self): mayaUtils.openTopLayerScene() shapePath, stage = getMayaStage() # Mute/Un-mute named layer -> dirties scene with DirtySceneCheck(self): stage.MuteLayer('Assembly_room_set.usda') with DirtySceneCheck(self): stage.UnmuteLayer('Assembly_room_set.usda') # Remove named layer -> dirties scene rootLayer = stage.GetRootLayer() with DirtySceneCheck(self): cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, removeSubPath=(0, shapePath))
def setUp(self): ''' Called initially to set up the maya test environment ''' # Load plugins self.assertTrue(self.pluginsLoaded) # Set up memento - [[mayaSelection, ufeSelection], ...] self.memento = [] # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes cmds.polySphere() cmds.polyCube() # Clear selection to start off cmds.select(clear=True)
def testContextOps(self): mayaUtils.openTopLayerScene() # Ball_35 has both variants and references. ufePath = ufe.PathString.path( '|transform1|proxyShape1,/Room_set/Props/Ball_35') item = ufe.Hierarchy.createItem(ufePath) contextOps = ufe.ContextOps.contextOps(item) # Change shading variant -> dirties scene with DirtySceneCheck(self): contextOps.doOp(['Variant Sets', 'shadingVariant', 'Cue']) # Unload reference -> dirties scene with DirtySceneCheck(self): contextOps.doOp(['Unload']) # Load reference -> dirties scene with DirtySceneCheck(self): contextOps.doOp(['Load'])
def setUp(self): ''' Called initially to set up the maya test environment ''' # Load plugins self.assertTrue(self.pluginsLoaded) # Set up memento, a list of snapshots. self.memento = [] # Callables to get current object scale using the run-time and # UFE. self.runTimeScale = None self.ufeScale = None # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes cmds.polySphere() cmds.polyCube() # Clear selection to start off cmds.select(clear=True)
def setUp(self): ''' Called initially to set up the maya test environment ''' # Load plugins self.assertTrue(self.pluginsLoaded) # Callables to get current object translation using the run-time and # UFE interfaces. self.getRunTimeTranslation = None self.getUfeTranslation = None # Callable to set current object translation using the run-time # interface. self.setRunTimeTranslation = None # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes cmds.polySphere() cmds.polyCube() # Clear selection to start off cmds.select(clear=True)
def testUnload(self): mayaUtils.openTopLayerScene() propsPath = ufe.PathString.path( '|transform1|proxyShape1,/Room_set/Props') propsItem = ufe.Hierarchy.createItem(propsPath) propsHier = ufe.Hierarchy.hierarchy(propsItem) # Before unloading it should have 35 children (35 balls). self.assertTrue(propsHier.hasChildren()) ball1Children = propsHier.children() self.assertEqual(len(ball1Children), 35) # Unload props contextOps = ufe.ContextOps.contextOps(propsItem) cmd = contextOps.doOpCmd(['Unload']) ufeCmd.execute(cmd) # After unloading, it should still have 35 children because # the children method returns unloaded prims by default. self.assertTrue(propsHier.hasChildren()) ball1Children = propsHier.children() self.assertEqual(len(ball1Children), 35)
def setUp(self): ''' Called initially to set up the maya test environment ''' self.assertTrue(self.pluginsLoaded) # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene()
def testObservation(self): ''' Test Attributes observation interface. Test both global attribute observation and per-node attribute observation. ''' # Start we a clean scene so we can get a consistent number of notifications cmds.file(new=True, force=True) mayaUtils.openTopLayerScene() # Create three observers, one for global attribute observation, and two # on different UFE items. proxyShapePathSegment = mayaUtils.createUfePathSegment( "|transform1|proxyShape1") path = ufe.Path([ proxyShapePathSegment, usdUtils.createUfePathSegment('/Room_set/Props/Ball_34') ]) ball34 = ufe.Hierarchy.createItem(path) path = ufe.Path([ proxyShapePathSegment, usdUtils.createUfePathSegment('/Room_set/Props/Ball_35') ]) ball35 = ufe.Hierarchy.createItem(path) (ball34Obs, ball35Obs, globalObs) = [TestObserver() for i in range(3)] # Maya registers a single global observer on startup. self.assertEqual(ufe.Attributes.nbObservers(), 1) # No item-specific observers. self.assertFalse(ufe.Attributes.hasObservers(ball34.path())) self.assertFalse(ufe.Attributes.hasObservers(ball35.path())) self.assertEqual(ufe.Attributes.nbObservers(ball34), 0) self.assertEqual(ufe.Attributes.nbObservers(ball35), 0) self.assertFalse(ufe.Attributes.hasObserver(ball34, ball34Obs)) self.assertFalse(ufe.Attributes.hasObserver(ball35, ball35Obs)) # No notifications yet. self.assertEqual(ball34Obs.notifications, 0) self.assertEqual(ball35Obs.notifications, 0) self.assertEqual(globalObs.notifications, 0) # Add a global observer. ufe.Attributes.addObserver(globalObs) self.assertEqual(ufe.Attributes.nbObservers(), 2) self.assertFalse(ufe.Attributes.hasObservers(ball34.path())) self.assertFalse(ufe.Attributes.hasObservers(ball35.path())) self.assertEqual(ufe.Attributes.nbObservers(ball34), 0) self.assertEqual(ufe.Attributes.nbObservers(ball35), 0) self.assertFalse(ufe.Attributes.hasObserver(ball34, ball34Obs)) self.assertFalse(ufe.Attributes.hasObserver(ball35, ball35Obs)) # Add item-specific observers. ufe.Attributes.addObserver(ball34, ball34Obs) self.assertEqual(ufe.Attributes.nbObservers(), 2) self.assertTrue(ufe.Attributes.hasObservers(ball34.path())) self.assertFalse(ufe.Attributes.hasObservers(ball35.path())) self.assertEqual(ufe.Attributes.nbObservers(ball34), 1) self.assertEqual(ufe.Attributes.nbObservers(ball35), 0) self.assertTrue(ufe.Attributes.hasObserver(ball34, ball34Obs)) self.assertFalse(ufe.Attributes.hasObserver(ball34, ball35Obs)) self.assertFalse(ufe.Attributes.hasObserver(ball35, ball35Obs)) ufe.Attributes.addObserver(ball35, ball35Obs) self.assertTrue(ufe.Attributes.hasObservers(ball35.path())) self.assertEqual(ufe.Attributes.nbObservers(ball34), 1) self.assertEqual(ufe.Attributes.nbObservers(ball35), 1) self.assertTrue(ufe.Attributes.hasObserver(ball35, ball35Obs)) self.assertFalse(ufe.Attributes.hasObserver(ball35, ball34Obs)) # Make a change to ball34, global and ball34 observers change. ball34Attrs = ufe.Attributes.attributes(ball34) ball34XlateAttr = ball34Attrs.attribute('xformOp:translate') self.assertEqual(ball34Obs.notifications, 0) # The first modification adds a new spec to ball_34 & its ancestors # "Props" and "Room_set". Ufe should be filtering out those notifications # so the global observer should still only see one notification. ufeCmd.execute(ball34XlateAttr.setCmd(ufe.Vector3d(4, 4, 15))) self.assertEqual(ball34Obs.notifications, 1) self.assertEqual(ball35Obs.notifications, 0) self.assertEqual(globalObs.notifications, 1) # The second modification only sends one USD notification for "xformOps:translate" # because all the spec's already exist. Ufe should also see one notification. ufeCmd.execute(ball34XlateAttr.setCmd(ufe.Vector3d(4, 4, 20))) self.assertEqual(ball34Obs.notifications, 2) self.assertEqual(ball35Obs.notifications, 0) self.assertEqual(globalObs.notifications, 2) # Undo, redo cmds.undo() self.assertEqual(ball34Obs.notifications, 3) self.assertEqual(ball35Obs.notifications, 0) self.assertEqual(globalObs.notifications, 3) cmds.redo() self.assertEqual(ball34Obs.notifications, 4) self.assertEqual(ball35Obs.notifications, 0) self.assertEqual(globalObs.notifications, 4) # get ready to undo the first modification cmds.undo() self.assertEqual(ball34Obs.notifications, 5) self.assertEqual(ball35Obs.notifications, 0) self.assertEqual(globalObs.notifications, 5) # Undo-ing the modification which created the USD specs is a little # different in USD, but from Ufe we should just still see one notification. cmds.undo() self.assertEqual(ball34Obs.notifications, 6) self.assertEqual(ball35Obs.notifications, 0) self.assertEqual(globalObs.notifications, 6) cmds.redo() self.assertEqual(ball34Obs.notifications, 7) self.assertEqual(ball35Obs.notifications, 0) self.assertEqual(globalObs.notifications, 7) # Make a change to ball35, global and ball35 observers change. ball35Attrs = ufe.Attributes.attributes(ball35) ball35XlateAttr = ball35Attrs.attribute('xformOp:translate') # "xformOp:translate" ufeCmd.execute(ball35XlateAttr.setCmd(ufe.Vector3d(4, 8, 15))) self.assertEqual(ball34Obs.notifications, 7) self.assertEqual(ball35Obs.notifications, 1) self.assertEqual(globalObs.notifications, 8) # Undo, redo cmds.undo() self.assertEqual(ball34Obs.notifications, 7) self.assertEqual(ball35Obs.notifications, 2) self.assertEqual(globalObs.notifications, 9) cmds.redo() self.assertEqual(ball34Obs.notifications, 7) self.assertEqual(ball35Obs.notifications, 3) self.assertEqual(globalObs.notifications, 10) # Test removeObserver. ufe.Attributes.removeObserver(ball34, ball34Obs) self.assertFalse(ufe.Attributes.hasObservers(ball34.path())) self.assertTrue(ufe.Attributes.hasObservers(ball35.path())) self.assertEqual(ufe.Attributes.nbObservers(ball34), 0) self.assertEqual(ufe.Attributes.nbObservers(ball35), 1) self.assertFalse(ufe.Attributes.hasObserver(ball34, ball34Obs)) ufeCmd.execute(ball34XlateAttr.setCmd(ufe.Vector3d(4, 4, 25))) self.assertEqual(ball34Obs.notifications, 7) self.assertEqual(ball35Obs.notifications, 3) self.assertEqual(globalObs.notifications, 11) ufe.Attributes.removeObserver(globalObs) self.assertEqual(ufe.Attributes.nbObservers(), 1) ufeCmd.execute(ball34XlateAttr.setCmd(ufe.Vector3d(7, 8, 9))) self.assertEqual(ball34Obs.notifications, 7) self.assertEqual(ball35Obs.notifications, 3) self.assertEqual(globalObs.notifications, 11)