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')
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 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)
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 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) 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 testInstanceDefaultMaterial(self): self._StartTest('defaultMaterialBillboards') cmds.select("|stage|stageShape,/root/group/billboard_03", "|stage|stageShape,/root/group/flatquad_03") self.assertSnapshotClose('%s_selected.png' % self._testName) panel = mayaUtils.activeModelPanel() cmds.modelEditor(panel, edit=True, useDefaultMaterial=True) self.assertSnapshotClose('%s_default.png' % self._testName) cmds.select("|stage|stageShape,/root/group/billboard_04", "|stage|stageShape,/root/group/flatquad_04") self.assertSnapshotClose('%s_defaultSelected.png' % self._testName) cmds.modelEditor(panel, edit=True, useDefaultMaterial=False) self.assertSnapshotClose('%s_notDefault.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 tearDownClass(cls): panel = mayaUtils.activeModelPanel() cmds.modelEditor(panel, edit=True, useDefaultMaterial=False)
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)
def snapshot(outputPath, width=400, height=None, hud=False, grid=False, camera=None): if height is None: height = width outputExt = os.path.splitext(outputPath)[1].lower().lstrip('.') formatNum = KNOWN_FORMATS.get(outputExt) if formatNum is None: raise ValueError( "input image had unrecognized extension: {}".format(outputExt)) # if given relative path, make it relative to current dir (the test # temp base), rather than the workspace dir outputPath = os.path.abspath(outputPath) # save the old output image format oldFormat = cmds.getAttr("defaultRenderGlobals.imageFormat") # save the hud setting oldHud = cmds.headsUpDisplay(q=1, layoutVisibility=1) # save the grid setting oldGrid = cmds.grid(q=1, toggle=1) # save the old view transform oldColorTransform = cmds.colorManagementPrefs(q=1, outputTarget="playblast", outputTransformName=1) # Some environments use legacy synColor transforms with 2022 and above. # Find whether the color config should be Raw or Raw legacy # However depending on the MAYA_COLOR_MANAGEMENT_SYNCOLOR env var or the loaded # configs, this may be under a different names. So procedurally find it. colorTransforms = cmds.colorManagementPrefs(q=1, outputTransformNames=True) if "Raw" in colorTransforms: newColorTransform = "Raw" elif "Raw (legacy)" in colorTransforms: newColorTransform = "Raw (legacy)" else: # RAW should be reliably raw-like in most configs, so find the first ending in RAW newColorTransform = [ c for c in colorTransforms if c.startswith("Raw ") ] if newColorTransform: newColorTransform = newColorTransform[0] else: raise RuntimeError( "Could not find Raw color space in available color transforms") # Some environments have locked color policies that prevent changing color policies # so we must disable and restore this accordingly. lockedColorTransforms = os.environ.get( "MAYA_COLOR_MANAGEMENT_POLICY_LOCK") == '1' if lockedColorTransforms: os.environ['MAYA_COLOR_MANAGEMENT_POLICY_LOCK'] = '0' # Find the current model panel for playblasting # to make sure the desired camera is set, if any panel = mayaUtils.activeModelPanel() oldCamera = cmds.modelPanel(panel, q=True, cam=True) if camera: cmds.modelEditor(panel, edit=True, camera=camera) # do these in a separate try/finally from color management, because # color management seems a bit more finicky cmds.setAttr("defaultRenderGlobals.imageFormat", formatNum) cmds.headsUpDisplay(layoutVisibility=hud) cmds.grid(toggle=grid) try: cmds.colorManagementPrefs(e=1, outputTarget="playblast", outputTransformName=newColorTransform) try: cmds.playblast(cf=outputPath, viewer=False, format="image", frame=cmds.currentTime(q=1), offScreen=1, widthHeight=(width, height), percent=100) finally: cmds.colorManagementPrefs(e=1, outputTarget="playblast", outputTransformName=oldColorTransform) finally: cmds.setAttr("defaultRenderGlobals.imageFormat", oldFormat) cmds.headsUpDisplay(layoutVisibility=oldHud) cmds.grid(toggle=oldGrid) if lockedColorTransforms: os.environ['MAYA_COLOR_MANAGEMENT_POLICY_LOCK'] = '1' if camera: cmds.lookThru(panel, oldCamera)