Example #1
0
    def testGroupAcrossProxies(self):
        sphereFile = testUtils.getTestScene("groupCmd", "sphere.usda")
        sphereDagPath, sphereStage = mayaUtils.createProxyFromFile(sphereFile)
        usdSphere = sphereDagPath + ",/pSphere1"

        torusFile = testUtils.getTestScene("groupCmd", "torus.usda")
        torusDagPath, torusStage = mayaUtils.createProxyFromFile(torusFile)
        usdTorus = torusDagPath + ",/pTorus1"

        try:
            cmds.group(usdSphere, usdTorus)
        except Exception as e:
            self.assertTrue('cannot group across usd proxies')
Example #2
0
    def testMergeToUnchangedCylinder(self):
        '''Merge edits on unchanged data.'''

        # Create a stage from a file.
        testFile = getTestScene("cylinderSubset", "cylinder.usda")
        testDagPath, stage = mayaUtils.createProxyFromFile(testFile)
        usdCylPathString = testDagPath + ",/sphere_butNot_pCylinder1"

        cylBottomPrim = stage.GetPrimAtPath("/sphere_butNot_pCylinder1/bottom")
        bottomIndices = cylBottomPrim.GetAttribute("indices")
        self.assertEqual("int[]", bottomIndices.GetTypeName())

        # Edit as maya and do nothing.
        with mayaUsd.lib.OpUndoItemList():
            self.assertTrue(
                mayaUsd.lib.PrimUpdaterManager.editAsMaya(usdCylPathString))

        cylMayaItem = ufe.GlobalSelection.get().front()

        # Merge edits back to USD.
        with mayaUsd.lib.OpUndoItemList():
            cylMayaPath = cylMayaItem.path()
            cylMayaPathStr = ufe.PathString.string(cylMayaPath)
            self.assertTrue(
                mayaUsd.lib.PrimUpdaterManager.mergeToUsd(cylMayaPathStr))

        # Check that the indices are still valid.
        cylBottomPrim = stage.GetPrimAtPath("/sphere_butNot_pCylinder1/bottom")
        bottomIndices = cylBottomPrim.GetAttribute("indices")
        self.assertEqual("int[]", bottomIndices.GetTypeName())
Example #3
0
    def testShadowsAndSSAO(self):
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")

        cmds.xform("persp", t=(10, 10, 10))
        cmds.xform("persp", ro=[-30, 45, 0], ws=True)

        testFile = testUtils.getTestScene("UsdPreviewSurface",
                                          "LightAPI_Test.usda")
        mayaUtils.createProxyFromFile(testFile)

        white_light = cmds.directionalLight(rgb=(1, 1, 1))
        white_transform = cmds.listRelatives(white_light, parent=True)[0]
        cmds.xform(white_transform, ro=(-35, 0, 0), ws=True)

        if int(os.getenv("MAYA_LIGHTAPI_VERSION")) == 2:
            light_api = "V2"
        else:
            light_api = "V1"

        panel = mayaUtils.activeModelPanel()
        cmds.modelEditor(panel, edit=True, lights=False, displayLights="all")
        cmds.setAttr("hardwareRenderingGlobals.ssaoEnable", False)
        cmds.modelEditor(panel, edit=True, shadows=False)

        self.assertSnapshotClose('LightAPI_{}.png'.format(light_api))

        cmds.setAttr("hardwareRenderingGlobals.ssaoEnable", True)
        self.assertSnapshotClose('SSAO_LightAPI_{}.png'.format(light_api))

        cmds.modelEditor(panel, edit=True, shadows=True)
        self.assertSnapshotClose('Shadow_LightAPI_{}.png'.format(light_api))

        cmds.setAttr("hardwareRenderingGlobals.ssaoEnable", False)
        cmds.modelEditor(panel, edit=True, shadows=False)
Example #4
0
    def testMergeWithoutMaterials(self):
        '''Merge edits on data and not merging the materials.'''

        # Create a stage from a file.
        testFile = getTestScene("cylinder", "cylinder.usda")
        testDagPath, stage = mayaUtils.createProxyFromFile(testFile)
        usdCylPathString = testDagPath + ",/pCylinder1"

        # Verify that the original scene does not have a look (material) prim.
        cylLooksPrim = stage.GetPrimAtPath("/pCylinder1/Looks")
        self.assertFalse(cylLooksPrim.IsValid())

        # Edit as maya and do nothing.
        cmds.mayaUsdEditAsMaya(usdCylPathString)

        # Merge back to USD.
        cylMayaItem = ufe.GlobalSelection.get().front()
        cylMayaPath = cylMayaItem.path()
        cylMayaPathStr = ufe.PathString.string(cylMayaPath)
        cmds.mayaUsdMergeToUsd(cylMayaPathStr)

        # Verify that the merged scene added a look (material) prim.
        cylLooksPrim = stage.GetPrimAtPath("/pCylinder1/Looks")
        self.assertTrue(cylLooksPrim.IsValid())

        # Undo merge to USD.
        cmds.undo()

        # Merge back to USD with export options that disable materials.
        cmds.mayaUsdMergeToUsd(cylMayaPathStr,
                               exportOptions='shadingMode=none')

        # Verify that the merged scene still does not have a look (material) prim.
        cylLooksPrim = stage.GetPrimAtPath("/pCylinder1/Looks")
        self.assertFalse(cylLooksPrim.IsValid())
Example #5
0
    def testImportDisplayColor(self):
        """Tests that the import of the USD preview surface containing a connected displayColor
        primvar reader shader node is imported with vertex colours for textured display"""
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")

        # Turn on textured display and focus in on the subject
        panel = mayaUtils.activeModelPanel()
        cmds.modelEditor(panel, e=1, displayTextures=1)
        cmds.dolly("persp", abs=True, d=3.2)

        # Import the USD file
        testFile = testUtils.getTestScene("UsdPreviewSurface",
                                          "DisplayColorCube.usda")
        options = [
            "shadingMode=[[useRegistry,UsdPreviewSurface]]", "primPath=/",
            "preferredMaterial=none"
        ]
        cmds.file(testFile,
                  i=True,
                  type="USD Import",
                  ignoreVersion=True,
                  ra=True,
                  mergeNamespacesOnClash=False,
                  namespace="Test",
                  pr=True,
                  importTimeRange="combine",
                  options=";".join(options))

        # Snapshot and assert similarity
        self.assertSnapshotClose('DisplayColorCube.png')
Example #6
0
    def testMetallicF0(self):
        """Tests that the specular F0 of a metallic surface is equal to its base color
        See Pixar USD commit https://github.com/PixarAnimationStudios/USD/commit/f11ab360"""
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")

        cmds.xform("persp", t=(24, 16, 0), ws=True)
        cmds.xform("persp", ro=[-35, 90, 0], ws=True)

        testFile = testUtils.getTestScene("UsdPreviewSurface",
                                          "F0_is_base.usda")
        mayaUtils.createProxyFromFile(testFile)

        # Need a point light at (0.36, 7.625, 8.111)
        white_light = cmds.pointLight(rgb=(1, 1, 1))
        white_transform = cmds.listRelatives(white_light, parent=True)[0]
        cmds.xform(white_transform, t=(0.36, 7.625, 8.111), ws=True)

        panel = mayaUtils.activeModelPanel()
        cmds.modelEditor(panel, edit=True, lights=False, displayLights="all")

        if int(os.getenv("MAYA_LIGHTAPI_VERSION")) == 2:
            light_api = "V2"
        else:
            light_api = "V1"

        self.assertSnapshotClose('F0_is_base_{}.png'.format(light_api))
 def _StartTest(self, testName):
     cmds.file(force=True, new=True)
     mayaUtils.loadPlugin("mayaUsdPlugin")
     self._testName = testName
     testFile = testUtils.getTestScene("camera", self._testName + ".usda")
     mayaUtils.createProxyFromFile(testFile)
     globalSelection = ufe.GlobalSelection.get()
     globalSelection.clear()
Example #8
0
 def _StartTest(self, testName):
     cmds.file(force=True, new=True)
     mayaUtils.loadPlugin("mayaUsdPlugin")
     self._testName = testName
     # Re-using the test scene from the consolidation test
     testFile = testUtils.getTestScene("consolidation", self._testName + ".usda")
     mayaUtils.createProxyFromFile(testFile)
     globalSelection = ufe.GlobalSelection.get()
     globalSelection.clear()
Example #9
0
 def _StartTest(self, testName):
     cmds.file(force=True, new=True)
     mayaUtils.loadPlugin("mayaUsdPlugin")
     self._testName = testName
     testFile = testUtils.getTestScene("consolidation", self._testName + ".usda")
     mayaUtils.createProxyFromFile(testFile)
     globalSelection = ufe.GlobalSelection.get()
     globalSelection.clear()
     self.assertSnapshotClose('%s_unselected.png' % self._testName)
Example #10
0
    def testUnparentMultiStage(self):
        '''Unparent USD nodes in more than one stage.'''

        with OpenFileCtx("simpleHierarchy.ma"):
            # An early version of this test imported the same file into the
            # opened file.  Layers are then shared between the stages, because
            # they come from the same USD file, causing changes done below one
            # proxy shape to be seen in the other.  Import from another file.
            filePath = testUtils.getTestScene("parentCmd", "simpleSceneUSD_TRS.ma")
            cmds.file(filePath, i=True)

            # Unparent a USD node in each stage.  Unparenting Lambert node is
            # nonsensical, but demonstrates the functionality.
            cubePathStr1 = '|mayaUsdProxy1|mayaUsdProxyShape1,/pCylinder1/pCube1'
            lambertPathStr2 = '|simpleSceneUSD_TRS_mayaUsdProxy1|simpleSceneUSD_TRS_mayaUsdProxyShape1,/initialShadingGroup/initialShadingGroup_lambert'

            cylinderItem1 = ufe.Hierarchy.createItem(ufe.PathString.path(
                '|mayaUsdProxy1|mayaUsdProxyShape1,/pCylinder1'))
            shadingGroupItem2 = ufe.Hierarchy.createItem(
                ufe.PathString.path('|simpleSceneUSD_TRS_mayaUsdProxy1|simpleSceneUSD_TRS_mayaUsdProxyShape1,/initialShadingGroup'))
            proxyShapeItem1 = ufe.Hierarchy.createItem(ufe.PathString.path(
                '|mayaUsdProxy1|mayaUsdProxyShape1'))
            proxyShapeItem2 = ufe.Hierarchy.createItem(ufe.PathString.path(
                '|simpleSceneUSD_TRS_mayaUsdProxy1|simpleSceneUSD_TRS_mayaUsdProxyShape1'))
            cylinder1 = ufe.Hierarchy.hierarchy(cylinderItem1)
            shadingGroup2 = ufe.Hierarchy.hierarchy(shadingGroupItem2)
            proxyShape1 = ufe.Hierarchy.hierarchy(proxyShapeItem1)
            proxyShape2 = ufe.Hierarchy.hierarchy(proxyShapeItem2)

            def checkUnparent(done):
                proxyShape1Children   = proxyShape1.children()
                proxyShape2Children   = proxyShape2.children()
                cylinder1Children     = cylinder1.children()
                shadingGroup2Children = shadingGroup2.children()
                self.assertEqual(
                    'pCube1' in childrenNames(proxyShape1Children), done)
                self.assertEqual(
                    'pCube1' in childrenNames(cylinder1Children), not done)
                self.assertEqual(
                    'initialShadingGroup_lambert' in childrenNames(proxyShape2Children), done)
                self.assertEqual(
                    'initialShadingGroup_lambert' in childrenNames(shadingGroup2Children), not done)

            checkUnparent(done=False)

            # Use relative parenting, else trying to keep absolute world
            # position of Lambert node fails (of course).
            cmds.parent(cubePathStr1, lambertPathStr2, w=True, r=True)
            checkUnparent(done=True)
            
            cmds.undo()
            checkUnparent(done=False)

            cmds.redo()
            checkUnparent(done=True)
Example #11
0
    def testInstancedIsolateSelect(self):
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")
        panel = mayaUtils.activeModelPanel()
        usdaFile = testUtils.getTestScene("instances",
                                          "perInstanceInheritedData.usda")
        proxyDagPath, sphereStage = mayaUtils.createProxyFromFile(usdaFile)
        usdball01 = proxyDagPath + ",/root/group/ball_01"
        usdball02 = proxyDagPath + ",/root/group/ball_02"
        usdball03 = proxyDagPath + ",/root/group/ball_03"
        usdball04 = proxyDagPath + ",/root/group/ball_04"
        usdball05 = proxyDagPath + ",/root/group/ball_05"

        cmds.move(8.5, -20, 0, "persp")
        cmds.rotate(90, 0, 0, "persp")

        globalSelection = ufe.GlobalSelection.get()
        globalSelection.clear()

        # Turn on isolate select for cube
        cmds.select(usdball01)
        cmds.isolateSelect(panel, state=1)
        self.assertSnapshotClose('ball01.png')

        # Add the hidden ball and another ball
        cmds.select(usdball02)
        cmds.select(usdball03, add=True)
        cmds.isolateSelect(panel, addSelectedObjects=True)
        self.assertSnapshotClose('ball01_ball02_ball03.png')

        # Remove the hidden ball
        cmds.select(usdball02)
        cmds.isolateSelect(panel, removeSelected=True)
        self.assertSnapshotClose('ball01_ball03.png')

        # Remove the first ball
        cmds.select(usdball01)
        cmds.isolateSelect(panel, removeSelected=True)
        self.assertSnapshotClose('ball03.png')

        #Auto load selected objects
        cmds.editor(panel, edit=True, unlockMainConnection=True)
        cmds.select(usdball02)
        self.assertSnapshotClose('autoLoadSelected_ball02.png')
        cmds.select(usdball01)
        cmds.select(usdball04, add=True)
        self.assertSnapshotClose('autoLoadSelected_ball01_ball04.png')
        cmds.select('|stage')
        self.assertSnapshotClose('autoLoadSelected_instance_stage.png')
        cmds.select(usdball05)
        cmds.select(usdball04, add=True)
        self.assertSnapshotClose('autoLoadSelected_ball04_ball05.png')
        cmds.editor(panel, edit=True, unlockMainConnection=False)
    def _StartTest(self, testName):
        cmds.file(force=True, new=True)
        cmds.move(2, -2, 1.5, 'persp')
        mayaUtils.loadPlugin("mayaUsdPlugin")

        self._testName = testName
        testFile = testUtils.getTestScene("MaterialX",
                                          self._testName + ".usda")
        mayaUtils.createProxyFromFile(testFile)
        globalSelection = ufe.GlobalSelection.get()
        globalSelection.clear()
        self.assertSnapshotClose('%s_render.png' % self._testName)
Example #13
0
    def testFallbackColor(self):
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")

        cmds.xform("persp", t=(0, 0, 5))
        cmds.xform("persp", ro=[0, 0, 0], ws=True)

        testFile = testUtils.getTestScene("UsdPreviewSurface",
                                          "TestFallbackColor.usda")
        mayaUtils.createProxyFromFile(testFile)

        self.assertSnapshotClose('TestFallbackColor.png')
Example #14
0
    def testUseSpecularWorkflow(self):
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")

        cmds.xform("persp", t=(0, 0, 10))
        cmds.xform("persp", ro=[0, 0, 0], ws=True)

        testFile = testUtils.getTestScene("UsdPreviewSurface",
                                          "UseSpecularWorkflowTest.usda")
        mayaUtils.createProxyFromFile(testFile)

        self.assertSnapshotClose('UseSpecularWorkflowTest.png')
Example #15
0
 def _StartTest(self, testName):
     self._testName = testName
     testFile = testUtils.getTestScene("UsdSkel", self._testName + ".usda")
     mayaUtils.createProxyFromFile(testFile)
     globalSelection = ufe.GlobalSelection.get()
     globalSelection.clear()
     cmds.currentTime(0)
     self.assertSnapshotClose('%s_0.png' % self._testName)
     cmds.currentTime(50)
     self.assertSnapshotClose('%s_50.png' % self._testName)
     cmds.currentTime(100)
     self.assertSnapshotClose('%s_100.png' % self._testName)
Example #16
0
 def _StartTest(self, testName):
     cmds.file(force=True, new=True)
     mayaUtils.loadPlugin("mayaUsdPlugin")
     panel = mayaUtils.activeModelPanel()
     cmds.modelEditor(panel, edit=True, useDefaultMaterial=False)
     self._testName = testName
     testFile = testUtils.getTestScene("instances",
                                       self._testName + ".usda")
     mayaUtils.createProxyFromFile(testFile)
     globalSelection = ufe.GlobalSelection.get()
     globalSelection.clear()
     self.assertSnapshotClose('%s_unselected.png' % self._testName)
    def testInstancedSelection(self):
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")
        panel = mayaUtils.activeModelPanel()
        usdaFile = testUtils.getTestScene("instances",
                                          "perInstanceInheritedData.usda")
        proxyDagPath, sphereStage = mayaUtils.createProxyFromFile(usdaFile)
        usdball01 = proxyDagPath + ",/root/group/ball_01"
        usdball03 = proxyDagPath + ",/root/group/ball_03"

        cmds.move(8.5, -20, 0, "persp")
        cmds.rotate(90, 0, 0, "persp")

        # Test smooth shaded
        cmds.modelEditor('modelPanel4',
                         e=True,
                         displayAppearance='smoothShaded',
                         displayLights='default')
        cmds.modelEditor('modelPanel4',
                         e=True,
                         wireframeOnShaded=False,
                         displayLights='default')
        self._selectionTest('instance_', usdball01, usdball03, proxyDagPath,
                            'smoothShaded')

        # Test smooth shaded
        cmds.modelEditor('modelPanel4',
                         e=True,
                         displayAppearance='smoothShaded',
                         displayLights='default')
        cmds.modelEditor('modelPanel4',
                         e=True,
                         wireframeOnShaded=True,
                         displayLights='default')
        self._selectionTest('instance_', usdball01, usdball03, proxyDagPath,
                            'wireframeOnShaded')

        # Test smooth shaded
        cmds.modelEditor('modelPanel4',
                         e=True,
                         displayAppearance='wireframe',
                         displayLights='default')
        cmds.modelEditor('modelPanel4',
                         e=True,
                         wireframeOnShaded=False,
                         displayLights='default')
        self._selectionTest('instance_', usdball01, usdball03, proxyDagPath,
                            'wireframe')
    def testSelection(self):
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")
        panel = mayaUtils.activeModelPanel()
        usdaFile = testUtils.getTestScene("setsCmd", "5prims.usda")
        proxyDagPath, sphereStage = mayaUtils.createProxyFromFile(usdaFile)

        cmds.move(-4, -24, 0, "persp")
        cmds.rotate(90, 0, 0, "persp")

        usdCube = proxyDagPath + ",/Cube1"
        usdCylinder = proxyDagPath + ",/Cylinder1"

        # Test smooth shaded
        cmds.modelEditor('modelPanel4',
                         e=True,
                         displayAppearance='smoothShaded',
                         displayLights='default')
        cmds.modelEditor('modelPanel4',
                         e=True,
                         wireframeOnShaded=False,
                         displayLights='default')
        self._selectionTest('', usdCube, usdCylinder, proxyDagPath,
                            'smoothShaded')

        # Test smooth shaded
        cmds.modelEditor('modelPanel4',
                         e=True,
                         displayAppearance='smoothShaded',
                         displayLights='default')
        cmds.modelEditor('modelPanel4',
                         e=True,
                         wireframeOnShaded=True,
                         displayLights='default')
        self._selectionTest('', usdCube, usdCylinder, proxyDagPath,
                            'wireframeOnShaded')

        # Test smooth shaded
        cmds.modelEditor('modelPanel4',
                         e=True,
                         displayAppearance='wireframe',
                         displayLights='default')
        cmds.modelEditor('modelPanel4',
                         e=True,
                         wireframeOnShaded=False,
                         displayLights='default')
        self._selectionTest('', usdCube, usdCylinder, proxyDagPath,
                            'wireframe')
    def testLayerUnselectable(self):
        '''
        Verify that a higher priority layer can make an selectable prim unselectable.
        '''
        cmds.file(new=True, force=True)

        testFile = testUtils.getTestScene("selectability",
                                          "cone-layer-unselectable-3.usda")
        mayaUtils.createProxyFromFile(testFile)
        globalSelection = ufe.GlobalSelection.get()
        globalSelection.clear()

        self._dragSelectActiveView()

        # verify there is the cone in the selection
        sel = ufe.GlobalSelection.get()
        self.assertTrue(sel.empty())
Example #20
0
    def testSmartTransformDuplicate(self):
        '''Test smart transform option of duplicate command.'''
        torusFile = testUtils.getTestScene("groupCmd", "torus.usda")
        torusDagPath, torusStage = mayaUtils.createProxyFromFile(torusFile)
        usdTorusPathString = torusDagPath + ",/pTorus1"

        cmds.duplicate(usdTorusPathString)
        cmds.move(10, 0, 0, r=True)
        smartDup = cmds.duplicate(smartTransform=True)

        usdTorusItem = ufeUtils.createUfeSceneItem(torusDagPath, '/pTorus3')
        torusT3d = ufe.Transform3d.transform3d(usdTorusItem)
        transVector = torusT3d.inclusiveMatrix().matrix[-1]

        correctResult = [20, 0, 0, 1]

        self.assertEqual(correctResult, transVector)
    def testLayerSelectable(self):
        '''
        Verify that a higher priority layer can make an unselectable prim selectable.
        '''
        cmds.file(new=True, force=True)

        testFile = testUtils.getTestScene("selectability",
                                          "cone-layer-selectable-3.usda")
        mayaUtils.createProxyFromFile(testFile)
        globalSelection = ufe.GlobalSelection.get()
        globalSelection.clear()

        self._dragSelectActiveView()

        # verify there is the cone in the selection
        sel = ufe.GlobalSelection.get()
        self.assertEqual(1, len(sel))
        coneItem = sel.front()
        self.assertEqual(str(coneItem.nodeName()), "Cone1")
Example #22
0
    def testTransform3dMatrixOpAccessors(self):
        '''Matrix transform op TRS must match separate transform op TRS.'''

        testFile = testUtils.getTestScene("transform3d", "TranslateRotate_vs_xform.usda")
        (psPath, stage) = mayaUtils.createProxyFromFile(testFile)

        # cam1 has the "transform" transform op (i.e. a matrix), and cam2 has
        # translate + rotateXYZ transform ops.
        cam1 = ufe.Hierarchy.createItem(
            ufe.PathString.path(psPath + ",/cameras/cam1"))
        cam2 = ufe.Hierarchy.createItem(
            ufe.PathString.path(psPath + ",/cameras/cam2"))
        cam1t3d = ufe.Transform3d.transform3d(cam1)
        cam2t3d = ufe.Transform3d.transform3d(cam2)
        cam1T = cam1t3d.translation()
        cam2T = cam2t3d.translation()
        testUtils.assertVectorAlmostEqual(self, cam1T.vector, cam2T.vector)
        cam1R = cam1t3d.rotation()
        cam2R = cam2t3d.rotation()
        testUtils.assertVectorAlmostEqual(self, cam1R.vector, cam2R.vector)
    def _StartTest(self, testName):
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")

        self._testName = testName
        testFile = testUtils.getTestScene("displayColors",
                                          self._testName + ".ma")

        cmds.file(testFile, o=True)

        exportedFile = os.path.join(self._testDir, "ColorTest.usda")
        cmds.mayaUSDExport(mergeTransformAndShape=True,
                           file=exportedFile,
                           shadingMode='none',
                           exportDisplayColor=True)

        shapeNode = mayaUtils.createProxyFromFile(exportedFile)[0]
        cmds.move(0, 0, -1, shapeNode)

        globalSelection = ufe.GlobalSelection.get()
        globalSelection.clear()
        self.assertSnapshotClose('%s_unselected.png' % self._testName)
    def testCreateStageFromFileWithInvalidUsd(self):
        # We cannot directly call the 'mayaUsdCreateStageFromFile'
        # as it opens a file dialog to choose the scene. So instead
        # we can call what it does once the file is choose.
        # Note: on ballFilePath we replace \ with / to stop the \ as
        #       being interpreted.
        ballFilePath = os.path.normpath(
            testUtils.getTestScene('ballset', 'StandaloneScene',
                                   'invalid_layer.usda')).replace('\\', '/')
        mel.eval('source \"mayaUsd_createStageFromFile.mel\"')
        shapeNode = mel.eval('mayaUsd_createStageFromFilePath(\"' +
                             ballFilePath + '\")')
        mayaSel = cmds.ls(sl=True)
        self.assertEqual(1, len(mayaSel))
        nt = cmds.nodeType(shapeNode)
        self.assertEqual('mayaUsdProxyShape', nt)

        # Verify that the shape node has the correct file path.
        filePathAttr = cmds.getAttr(shapeNode + '.filePath')
        self.assertTrue(self.samefile(filePathAttr, ballFilePath))

        # Verify that the shape node is connected to time.
        self.assertTrue(cmds.isConnected('time1.outTime', shapeNode + '.time'))
Example #25
0
    def testMergeToUsdReferencedPrim(self):
        '''Merge edits on a USD reference back to USD.'''

        # Create a simple scene with a Def prim with a USD reference.
        psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
        psPath = ufe.PathString.path(psPathStr)
        ps = ufe.Hierarchy.createItem(psPath)
        stage = mayaUsd.lib.GetPrim(psPathStr).GetStage()
        aPrim = stage.DefinePrim('/A', 'Xform')

        sphereFile = getTestScene("groupCmd", "sphere.usda")
        sdfRef = Sdf.Reference(sphereFile)
        primRefs = aPrim.GetReferences()
        primRefs.AddReference(sdfRef)
        self.assertTrue(aPrim.HasAuthoredReferences())

        aUsdUfePathStr = psPathStr + ',/A'
        aUsdUfePath = ufe.PathString.path(aUsdUfePathStr)
        aUsdItem = ufe.Hierarchy.createItem(aUsdUfePath)

        # Edit as maya and do nothing.
        with mayaUsd.lib.OpUndoItemList():
            self.assertTrue(
                mayaUsd.lib.PrimUpdaterManager.editAsMaya(aUsdUfePathStr))

        aMayaItem = ufe.GlobalSelection.get().front()

        # Merge edits back to USD.
        with mayaUsd.lib.OpUndoItemList():
            aMayaPath = aMayaItem.path()
            aMayaPathStr = ufe.PathString.string(aMayaPath)
            self.assertTrue(
                mayaUsd.lib.PrimUpdaterManager.mergeToUsd(aMayaPathStr))

        # Check that the reference is still there.
        self.assertTrue(aPrim.HasAuthoredReferences())
Example #26
0
def openTestScene(*args):
    filePath = testUtils.getTestScene(*args)
    cmds.file(filePath, force=True, open=True)
Example #27
0
    def testIsolateSelect(self):
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")
        panel = mayaUtils.activeModelPanel()
        usdaFile = testUtils.getTestScene("setsCmd", "5prims.usda")
        proxyDagPath, sphereStage = mayaUtils.createProxyFromFile(usdaFile)
        usdCube = proxyDagPath + ",/Cube1"
        usdCylinder = proxyDagPath + ",/Cylinder1"
        usdCapsule = proxyDagPath + ",/Capsule1"
        usdCone = proxyDagPath + ",/Cone1"
        usdXform = proxyDagPath + ",/Xform1"

        cmds.move(-4, -24, 0, "persp")
        cmds.rotate(90, 0, 0, "persp")

        globalSelection = ufe.GlobalSelection.get()
        globalSelection.clear()
        self.assertSnapshotClose('unselected.png')

        # Turn on isolate select for cube
        cmds.select(usdCube)
        cmds.isolateSelect(panel, state=1)
        self.assertSnapshotClose('cube.png')

        # Replace isolate select cube with cylinder
        cmds.select(usdCylinder)
        cmds.isolateSelect(panel, loadSelected=True)
        self.assertSnapshotClose('cylinder.png')

        # Add capsule to isolate select
        cmds.select(usdCapsule)
        cmds.isolateSelect(panel, addSelected=True)
        self.assertSnapshotClose('cylinderAndCapsule.png')

        # Remove capsule from isolate select
        cmds.isolateSelect(panel, removeSelected=True)
        self.assertSnapshotClose('cylinderAfterCapsuleRemove.png')

        # Undo, Redo
        cmds.undo()  # Undo remove capsule from isolate select
        self.assertSnapshotClose('undoCapsuleRemove.png')
        cmds.redo()  # Redo remove capsule from isolate select
        self.assertSnapshotClose('redoCapsuleRemove.png')
        cmds.undo()  # Undo remove capsule from isolate select
        cmds.undo()  # Undo add capsule to isolate select
        self.assertSnapshotClose('undoCapsuleAdd.png')

        # Turn off isolate select
        cmds.isolateSelect(panel, state=0)
        self.assertSnapshotClose('isolateSelectOff.png')

        # Create an isolate select set, then add something directly to it
        cmds.isolateSelect(panel, state=1)
        isolateSelectSet = "modelPanel4ViewSelectedSet"
        cmds.sets(usdCube, add=isolateSelectSet)
        cmds.isolateSelect(panel, update=True)
        self.assertSnapshotClose('capsuleAndCube.png')

        # The flags addDagObject and removeDagObject don't
        # work with USD items.

        # Add the cone to the isolate select
        # different from addSelected because it filters out components
        cmds.select(usdCone)
        cmds.isolateSelect(panel, addSelectedObjects=True)
        self.assertSnapshotClose('capsuleAndCubeAndCone.png')

        # Translate Xform1 and reparent Cube1 under Xform1
        cmds.select(usdXform)
        cmds.move(0, 0, 1, relative=True)
        cmds.select(clear=True)
        cmds.parent(usdCube, usdXform, relative=True)
        cmds.isolateSelect(panel, update=True)
        usdCube = usdXform + "/Cube1"
        self.assertSnapshotClose('reparentedCube.png')

        # Reparent Cube1 back
        cmds.parent(usdCube, proxyDagPath, relative=True)
        cmds.isolateSelect(panel, update=True)
        usdCube = proxyDagPath + ",/Cube1"
        self.assertSnapshotClose('reparentedCubeBack.png')

        #reparent the proxy shape
        locatorShape = cmds.createNode("locator")
        locator = "|" + cmds.listRelatives(locatorShape, parent=True)[0]
        cmds.move(0, 0, 5, locator)
        cmds.parent("|stage", locator, relative=True)
        usdCube = locator + usdCube
        self.assertSnapshotClose('reparentedProxyShape.png')

        cmds.undo()  #undo reparent so that _createPrim works
        usdCube = proxyDagPath + ",/Cube1"

        #Auto load new objects
        usdXformItem = self._stringToUfeItem(usdXform)
        usdXformCone = self._createPrim(usdXformItem, 'Cone', '/Xform1/Cone1')
        cmds.select(usdXformCone)
        cmds.move(-8.725, 0, 2)
        self.assertSnapshotClose('autoLoadNewObjects.png')

        #Auto load selected objects
        cmds.editor(panel, edit=True, unlockMainConnection=True)
        self.assertSnapshotClose('autoLoadSelected_xformCone.png')
        cmds.select(usdCube)
        self.assertSnapshotClose('autoLoadSelected_cube.png')
        cmds.select("|stage")
        self.assertSnapshotClose('autoLoadSelected_stage.png')
        cmds.select(usdCone)
        cmds.select(usdCapsule, add=True)
        cmds.select(usdCylinder, add=True)
        self.assertSnapshotClose('autoLoadSelected_coneCapsuleCyliner.png')
        cmds.editor(panel, edit=True, unlockMainConnection=False)
Example #28
0
    def testSetsCmd(self):
        usdaFile = testUtils.getTestScene("setsCmd", "5prims.usda")
        proxyDagPath, sphereStage = mayaUtils.createProxyFromFile(usdaFile)
        usdCube = proxyDagPath + ",/Cube1"
        usdCylinder = proxyDagPath + ",/Cylinder1"
        usdXform = proxyDagPath + ",/Xform1"

        cmds.select(usdCube)
        set1 = cmds.sets()
        cmds.select(usdCylinder)
        set2 = cmds.sets()

        # set contents
        self.assertEqual(usdCube, *cmds.sets(set1, q=True))

        # select set
        cmds.select(set1)
        self.assertEqual(usdCube, *cmds.ls(selection=True, ufe=True))

        # set of sets
        setOfSets = cmds.sets(set1, set2, n="setOfSets")
        cmds.select(setOfSets)
        self.assertEqual([usdCube, usdCylinder],
                         sorted(cmds.ls(selection=True, ufe=True)))

        # union of the sets
        self.assertEqual([usdCube, usdCylinder],
                         sorted(cmds.sets(set2, un=set1)))
        self.assertFalse(cmds.sets(set2,
                                   ii=set1))  # do the sets have common members

        # query set contents, remove from set, add to set
        self.assertTrue(cmds.sets(usdCube,
                                  im=set1))  # Test if Cube1 is in set1
        self.assertFalse(cmds.sets(usdCube,
                                   im=set2))  # Test if Cube1 is in set2
        cmds.sets(usdCube, rm=set1)  # Remove Cube1 from set1
        self.assertFalse(cmds.sets(usdCube,
                                   im=set1))  # Test if Cube1 is in set1
        cmds.sets(usdCube, add=set1)  # Add Cube1 to set1
        self.assertTrue(cmds.sets(usdCube,
                                  im=set1))  # Test if Cube1 is in set1

        # Undo, Redo
        cmds.undo()  # Undo Add Cube1 to set1
        self.assertFalse(cmds.sets(usdCube, im=set1))
        cmds.redo()  # Redo Add Cube1 to set1
        self.assertTrue(cmds.sets(usdCube, im=set1))
        cmds.undo()  # Undo Add Cube1 to set1
        self.assertFalse(cmds.sets(usdCube, im=set1))
        cmds.undo()  # Undo Remove Cube1 from set1
        self.assertTrue(cmds.sets(usdCube, im=set1))

        #reparent Cube1 under Xform1
        cmds.parent(usdCube, usdXform, relative=True)
        usdCube = usdXform + "/Cube1"
        self.assertTrue(cmds.sets(usdCube,
                                  im=set1))  # Test if Cube1 is in set1
        cmds.parent(usdCube, proxyDagPath, relative=True)
        usdCube = proxyDagPath + ",/Cube1"
        self.assertTrue(cmds.sets(usdCube,
                                  im=set1))  # Test if Cube1 is in set1

        #reparent the proxy shape
        locatorShape = cmds.createNode("locator")
        locator = "|" + cmds.listRelatives(locatorShape, parent=True)[0]
        cmds.parent("|stage", locator, relative=True)
        usdCube = locator + usdCube
        self.assertTrue(cmds.sets(usdCube,
                                  im=set1))  # Test if Cube1 is in set1