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 testMetallicResponse(self): cmds.file(force=True, new=True) mayaUtils.loadPlugin("mayaUsdPlugin") cmds.xform("persp", t=(0, 0, 50)) cmds.xform("persp", ro=[0, 0, 0], ws=True) # Create Test Spheres for i in range(5): for j in range(5): sphere_xform = cmds.polySphere()[0] cmds.move(2.5 * (i - 2), 2.5 * (j - 2), 0, sphere_xform, absolute=True) material_node = cmds.shadingNode("usdPreviewSurface", asShader=True) material_sg = cmds.sets( renderable=True, noSurfaceShader=True, empty=True, name=material_node + "SG", ) cmds.connectAttr( material_node + ".outColor", material_sg + ".surfaceShader", force=True, ) cmds.sets(sphere_xform, e=True, forceElement=material_sg) cmds.setAttr( material_node + ".diffuseColor", 0.944, 0.776, 0.373, type="double3" ) cmds.setAttr(material_node + ".useSpecularWorkflow", False) cmds.setAttr(material_node + ".metallic", i * 0.25) roughness = j * 0.25 if j == 0: roughness = 0.001 cmds.setAttr(material_node + ".roughness", roughness) blue_light = cmds.directionalLight(rgb=(0, 0.6069, 1)) blue_transform = cmds.listRelatives(blue_light, parent=True)[0] cmds.xform(blue_transform, ro=(-45, -45, 0), ws=True) orange_light = cmds.directionalLight(rgb=(1, 0.2703, 0)) orange_transform = cmds.listRelatives(orange_light, parent=True)[0] cmds.xform(orange_transform, ro=(-45, 45, 0), ws=True) panel = mayaUtils.activeModelPanel() cmds.modelEditor(panel, edit=True, lights=False, displayLights="all") if int(os.getenv("MAYA_LIGHTAPI_VERSION")) == 2: self.assertSnapshotClose("testMetallicResponseLightAPI2.png") else: self.assertSnapshotClose("testMetallicResponseLightAPI1.png")
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 _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 testUndoRedo(self): self._StartTest('capsule') mayaUtils.loadPlugin("ufeSupport") cmds.move(3, -3, 3, 'persp') cmds.rotate(60, 0, 45, 'persp') # modify the capsule's height, then undo and redo that operation and # make sure the viewport updates as expected. mayaPathSegment = mayaUtils.createUfePathSegment('|stage|stageShape') capsuleUsdPathSegment = usdUtils.createUfePathSegment('/Capsule1') capsulePath = ufe.Path([mayaPathSegment, capsuleUsdPathSegment]) capsuleItem = ufe.Hierarchy.createItem(capsulePath) capsuleAttrs = ufe.Attributes.attributes(capsuleItem) heightAttr = capsuleAttrs.attribute('height') # get the undo queue into a clean state with nothing on the queue # and no open chunks # disable and flush the undo queue cmds.undoInfo(state=False) # the undo queue could still have some open chunks which were in the # process of being created when I turned the undo queue off. For example, # this test gets run from the mel "python" command (see test.cmake), and # that chunk is currently open. # If I try to query the current chunk string to see if something IS open, # it is always the command I used to try to query the current chunk name! # Experimentally, I found have that there are typically two open chunks. # So just close two chunks. cmds.undoInfo(closeChunk=True) cmds.undoInfo(closeChunk=True) # flush those truncated chunks if they are on the undo queue. They shouldn't # be, because I already disabled the undo queue, but I am paranoid. cmds.flushUndo() # Now run the actual test I want to run. Enable the undo queue for each command # that I want on the queue, and disable the undo queue again, without flushing, # immediately after. cmds.undoInfo(stateWithoutFlush=True) ufeCmd.execute(heightAttr.setCmd(3)) cmds.undoInfo(stateWithoutFlush=False) self.assertSnapshotClose('%s_set_height.png' % self._testName) cmds.undoInfo(stateWithoutFlush=True) cmds.undo() cmds.undoInfo(stateWithoutFlush=False) self.assertSnapshotClose('%s_undo_set_height.png' % self._testName) cmds.undoInfo(stateWithoutFlush=True) cmds.redo() cmds.undoInfo(stateWithoutFlush=False) self.assertSnapshotClose('%s_redo_set_height.png' % self._testName) # Now the test is over, turn the undo queue back on incase this Maya session # gets re-used for more tests. cmds.undoInfo(stateWithoutFlush=True)
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)