def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) # Load a file that has the same scene in both the Maya Dag # hierarchy and the USD hierarchy. mayaUtils.openTestScene("parentCmd", "simpleSceneMayaPlusUSD_TRS.ma") # Create multiple scene items. We will alternate between selecting a # Maya item and a USD item, 3 items each data model, one item at a # time, so we select 6 different items, one at a time. shapeSegment = mayaUtils.createUfePathSegment( "|mayaUsdProxy1|mayaUsdProxyShape1") ufeNames = ["cubeXform", "cylinderXform", "sphereXform"] mayaNames = ["pCube1", "pCylinder1", "pSphere1"] usdPaths = [] for n in ["/" + o for o in ufeNames]: usdPaths.append( ufe.Path([shapeSegment, usdUtils.createUfePathSegment(n)])) mayaPaths = [] for n in ["|" + o for o in mayaNames]: mayaPaths.append(ufe.Path(mayaUtils.createUfePathSegment(n))) # Create a list of paths by alternating USD objects and Maya objects # Flatten zipped tuples using list comprehension double loop. zipped = zip(usdPaths, mayaPaths) paths = [j for i in zipped for j in i] # Create items for all paths. self.items = [ufe.Hierarchy.createItem(p) for p in paths] # Clear selection to start off cmds.select(clear=True)
def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) # Load a file that has the same scene in both the Maya Dag # hierarchy and the USD hierarchy. mayaUtils.openTestScene("parentCmd", "simpleSceneMayaPlusUSD_TRS.ma" ) # Clear selection to start off cmds.select(clear=True)
def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) # Load a file that has the same scene in both the Maya Dag # hierarchy and the USD hierarchy. mayaUtils.openTestScene("parentCmd", "simpleSceneMayaPlusUSD_TRS.ma") # Clear selection to start off cmds.select(clear=True) # Save current 'MAYA_USD_MATRIX_XFORM_OP_NAME' env var, if present. self.mayaUsdMatrixXformOpName = os.environ.get( 'MAYA_USD_MATRIX_XFORM_OP_NAME')
def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) # Load a file that has the same scene in both the Maya Dag # hierarchy and the USD hierarchy. mayaUtils.openTestScene("parentCmd", "simpleSceneMayaPlusUSD_TRS.ma") shapeSegment = mayaUtils.createUfePathSegment( "|mayaUsdProxy1|mayaUsdProxyShape1") def makeUsdPath(name): return ufe.Path([shapeSegment, usdUtils.createUfePathSegment(name)]) ufeNames = ["/cubeXform", "/cylinderXform", "/sphereXform"] self.usdPaths = [ufe.PathString.string(makeUsdPath(name)) for name in ufeNames] self.mayaPaths = ["pCube1", "pCylinder1", "pSphere1"] # Clear selection to start off cmds.select(clear=True)
def testFallback(self): '''Transformable not handled by standard Transform3d handlers must be handled by fallback handler.''' mayaUtils.openTestScene("xformOpFallback", "fallbackTest.ma") # We have three objects in the scene, one Maya, one USD with a Maya # transform stack, and one USD which does not match any Transform3d # handler. This last object is the one to which fallback transform ops # will be appended. mayaObj = '|null1|pSphere1' mayaSpherePath = ufe.PathString.path(mayaObj) usdSpherePath = ufe.PathString.path( '|fallbackTest|fallbackTestShape,/parent/sphere1') usdFallbackSpherePath = ufe.PathString.path( '|fallbackTest|fallbackTestShape,/sphere1') mayaSphereItem = ufe.Hierarchy.createItem(mayaSpherePath) usdSphereItem = ufe.Hierarchy.createItem(usdSpherePath) usdFallbackSphereItem = ufe.Hierarchy.createItem(usdFallbackSpherePath) # For scene items with fallback transform ops, the transform3d() # interface considers the complete object (i.e. all transform ops in # the stack), which is undesirable when setting and getting fallback # pivot transform ops. To consider only the fallback transform ops, # use the editTransform3d() interface. For scene items with only a # Maya transform stack, editTransform3d() and transform3d() are # equivalent, so arbitrarily choose editTransform3d(). usdSphere3d = ufe.Transform3d.editTransform3d( usdSphereItem, ufe.EditTransform3dHint()) usdFallbackSphere3d = ufe.Transform3d.editTransform3d( usdFallbackSphereItem, ufe.EditTransform3dHint()) sn = ufe.GlobalSelection.get() sn.clear() sn.append(mayaSphereItem) sn.append(usdSphereItem) sn.append(usdFallbackSphereItem) # All objects should have the same world transform. We use the Maya # world transform as the benchmark. checkWorldSpaceXform(self, [mayaObj, usdSphere3d, usdFallbackSphere3d]) # Count the number of transform ops in the Maya transform stack sphere # and the fallback transform stack sphere. spherePrim = mayaUsd.ufe.ufePathToPrim( ufe.PathString.string(usdSpherePath)) fallbackSpherePrim = mayaUsd.ufe.ufePathToPrim( ufe.PathString.string(usdFallbackSpherePath)) sphereXformable = UsdGeom.Xformable(spherePrim) fallbackSphereXformable = UsdGeom.Xformable(fallbackSpherePrim) sphereOps = sphereXformable.GetOrderedXformOps() fallbackSphereOps = fallbackSphereXformable.GetOrderedXformOps() # Both prims have TRS transform ops. self.assertEqual(len(sphereOps), 3) self.assertEqual(len(fallbackSphereOps), 3) # First, translate all objects. cmds.move(0, 0, 5, r=True, os=True, wd=True) checkWorldSpaceXform(self, [mayaObj, usdSphere3d, usdFallbackSphere3d]) # The sphere with the Maya transform stack has no additional transform # op; the sphere with the fallback stack will have an additional # translate op. sphereOps = sphereXformable.GetOrderedXformOps() fallbackSphereOps = fallbackSphereXformable.GetOrderedXformOps() self.assertEqual(len(sphereOps), 3) self.assertEqual(len(fallbackSphereOps), 4) # Rotate cmds.rotate(40, 0, 0, r=True, os=True, fo=True) checkWorldSpaceXform(self, [mayaObj, usdSphere3d, usdFallbackSphere3d]) # The sphere with the Maya transform stack has no additional transform # op; the sphere with the fallback stack will have an additional # rotate op. sphereOps = sphereXformable.GetOrderedXformOps() fallbackSphereOps = fallbackSphereXformable.GetOrderedXformOps() self.assertEqual(len(sphereOps), 3) self.assertEqual(len(fallbackSphereOps), 5) # Scale cmds.scale(1, 1, 2.0, r=True) checkWorldSpaceXform(self, [mayaObj, usdSphere3d, usdFallbackSphere3d]) # The sphere with the Maya transform stack has no additional transform # op; the sphere with the fallback stack will have an additional # scale op. sphereOps = sphereXformable.GetOrderedXformOps() fallbackSphereOps = fallbackSphereXformable.GetOrderedXformOps() self.assertEqual(len(sphereOps), 3) self.assertEqual(len(fallbackSphereOps), 6) # Command to change the pivots on Maya items and UFE items is # different, so remove Maya item from selection. sn.remove(mayaSphereItem) mayaPivots = [ mayaObj + "." + attrName for attrName in ["scalePivot", "rotatePivot"] ] cmds.move(0, -2.5, 2.5, *mayaPivots, r=True) cmds.move(0, -2.5, 2.5, r=True, urp=True, usp=True) checkPivotsAndCompensations(self, mayaObj, usdSphere3d) checkPivotsAndCompensations(self, mayaObj, usdFallbackSphere3d) # Both spheres have 6 additional transform ops: rotate pivot and its # inverse, scale pivot and its inverse, rotate pivot translate, and # scale pivot translate. sphereOps = sphereXformable.GetOrderedXformOps() fallbackSphereOps = fallbackSphereXformable.GetOrderedXformOps() self.assertEqual(len(sphereOps), 9) self.assertEqual(len(fallbackSphereOps), 12) # Perform an additional pivot move, to ensure that the existing pivot # values are properly considered. cmds.move(0, -1, 1, *mayaPivots, r=True) cmds.move(0, -1, 1, r=True, urp=True, usp=True) checkPivotsAndCompensations(self, mayaObj, usdSphere3d) checkPivotsAndCompensations(self, mayaObj, usdFallbackSphere3d)
def __enter__(self): mayaUtils.openTestScene("parentCmd", self._fileName)