diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/CMakeLists.txt b/test/lib/mayaUsd/render/vp2RenderDelegate/CMakeLists.txt index 48df45c1ce..5656a343ae 100644 --- a/test/lib/mayaUsd/render/vp2RenderDelegate/CMakeLists.txt +++ b/test/lib/mayaUsd/render/vp2RenderDelegate/CMakeLists.txt @@ -55,6 +55,12 @@ if (CMAKE_WANT_MATERIALX_BUILD) ) endif() +if(MAYA_MRENDERITEM_UFE_IDENTIFIER_SUPPORT) + list(APPEND TEST_SCRIPT_FILES + testVP2RenderDelegateIsolateSelect.py + ) +endif() + add_custom_target(${TARGET_NAME} ALL) # Copy all the resources and Python scripts to build directory diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/capsuleAndCube.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/capsuleAndCube.png new file mode 100644 index 0000000000..67e384914c Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/capsuleAndCube.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/capsuleAndCubeAndCone.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/capsuleAndCubeAndCone.png new file mode 100644 index 0000000000..8cbe04bad5 Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/capsuleAndCubeAndCone.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cube.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cube.png new file mode 100644 index 0000000000..00f803fd43 Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cube.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cylinder.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cylinder.png new file mode 100644 index 0000000000..8d6a5c1837 Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cylinder.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cylinderAfterCapsuleRemove.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cylinderAfterCapsuleRemove.png new file mode 100644 index 0000000000..004bf2eefb Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cylinderAfterCapsuleRemove.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cylinderAndCapsule.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cylinderAndCapsule.png new file mode 100644 index 0000000000..7653bb6d49 Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/cylinderAndCapsule.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/isolateSelectOff.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/isolateSelectOff.png new file mode 100644 index 0000000000..17e1939b70 Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/isolateSelectOff.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/redoCapsuleRemove.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/redoCapsuleRemove.png new file mode 100644 index 0000000000..004bf2eefb Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/redoCapsuleRemove.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/reparentedCube.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/reparentedCube.png new file mode 100644 index 0000000000..a9bb1a4164 Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/reparentedCube.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/reparentedCubeBack.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/reparentedCubeBack.png new file mode 100644 index 0000000000..4ef23d1104 Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/reparentedCubeBack.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/reparentedProxyShape.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/reparentedProxyShape.png new file mode 100644 index 0000000000..09c56d1092 Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/reparentedProxyShape.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/undoCapsuleAdd.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/undoCapsuleAdd.png new file mode 100644 index 0000000000..004bf2eefb Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/undoCapsuleAdd.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/undoCapsuleRemove.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/undoCapsuleRemove.png new file mode 100644 index 0000000000..7653bb6d49 Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/undoCapsuleRemove.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/unselected.png b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/unselected.png new file mode 100644 index 0000000000..f1c8135a59 Binary files /dev/null and b/test/lib/mayaUsd/render/vp2RenderDelegate/VP2RenderDelegateIsolateSelectTest/baseline/unselected.png differ diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/testVP2RenderDelegateIsolateSelect.py b/test/lib/mayaUsd/render/vp2RenderDelegate/testVP2RenderDelegateIsolateSelect.py new file mode 100644 index 0000000000..dc407fbd81 --- /dev/null +++ b/test/lib/mayaUsd/render/vp2RenderDelegate/testVP2RenderDelegateIsolateSelect.py @@ -0,0 +1,160 @@ +#!/usr/bin/env mayapy +# +# Copyright 2021 Autodesk +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import fixturesUtils +import imageUtils +import mayaUtils +import unittest +import usdUtils +import testUtils + +from mayaUsd import lib as mayaUsdLib +from mayaUsd import ufe as mayaUsdUfe + +from maya import cmds +import maya.api.OpenMayaRender as omr + +from pxr import Usd + +import ufe + +import os + + +class testVP2RenderDelegateIsolateSelect(imageUtils.ImageDiffingTestCase): + """ + Tests imaging using the Viewport 2.0 render delegate when using per-instance + inherited data on instances. + """ + + @classmethod + def setUpClass(cls): + inputPath = fixturesUtils.setUpClass(__file__, + initializeStandalone=False, loadPlugin=False) + + cls._baselineDir = os.path.join(inputPath, + 'VP2RenderDelegateIsolateSelectTest', 'baseline') + + cls._testDir = os.path.abspath('.') + + @classmethod + def tearDownClass(cls): + panel = mayaUtils.activeModelPanel() + cmds.modelEditor(panel, edit=True, useDefaultMaterial=False) + + def assertSnapshotClose(self, imageName): + cmds.undoInfo(stateWithoutFlush=False) # disable the undo queue during the snapshot + baselineImage = os.path.join(self._baselineDir, imageName) + snapshotImage = os.path.join(self._testDir, imageName) + imageUtils.snapshot(snapshotImage, width=960, height=540) + retVal = self.assertImagesClose(baselineImage, snapshotImage) + cmds.undoInfo(stateWithoutFlush=True) + return retVal + + 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("modelPanel4", state=1) + self.assertSnapshotClose('cube.png') + + # Replace isolate select cube with cylinder + cmds.select(usdCylinder) + cmds.isolateSelect("modelPanel4", loadSelected=True) + self.assertSnapshotClose('cylinder.png') + + # Add capsule to isolate select + cmds.select(usdCapsule) + cmds.isolateSelect("modelPanel4", addSelected=True) + self.assertSnapshotClose('cylinderAndCapsule.png') + + # Remove capsule from isolate select + cmds.isolateSelect("modelPanel4", 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("modelPanel4", state=0) + self.assertSnapshotClose('isolateSelectOff.png') + + # Create an isolate select set, then add something directly to it + cmds.isolateSelect("modelPanel4", state=1) + isolateSelectSet = "modelPanel4ViewSelectedSet" + cmds.sets(usdCube, add=isolateSelectSet) + cmds.isolateSelect("modelPanel4", 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("modelPanel4", 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("modelPanel4", update=True) + usdCube = usdXform + "/Cube1" + self.assertSnapshotClose('reparentedCube.png') + + # Reparent Cube1 back + cmds.parent(usdCube, proxyDagPath, relative=True) + cmds.isolateSelect("modelPanel4", 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') + + +if __name__ == '__main__': + fixturesUtils.runTests(globals()) diff --git a/test/lib/ufe/CMakeLists.txt b/test/lib/ufe/CMakeLists.txt index 18da12e888..ad705fb02b 100644 --- a/test/lib/ufe/CMakeLists.txt +++ b/test/lib/ufe/CMakeLists.txt @@ -55,6 +55,11 @@ if (MAYA_API_VERSION VERSION_GREATER_EQUAL 20220100) ) endif() +if(MAYA_MRENDERITEM_UFE_IDENTIFIER_SUPPORT) + list(APPEND TEST_SCRIPT_FILES + testSetsCmd.py + ) +endif() # copy ufe tests to ${CMAKE_CURRENT_BINARY_DIR} and run them from there add_custom_target(${TARGET_NAME} ALL) diff --git a/test/lib/ufe/testSetsCmd.py b/test/lib/ufe/testSetsCmd.py new file mode 100644 index 0000000000..a61cd4c11c --- /dev/null +++ b/test/lib/ufe/testSetsCmd.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python + +# +# Copyright 2021 Autodesk +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import fixturesUtils +import mayaUtils +import testUtils + +from maya import cmds +from maya import standalone + +import unittest + + +class SetsCmdTestCase(unittest.TestCase): + '''Verify the Maya sets command + ''' + + pluginsLoaded = False + + @classmethod + def setUpClass(cls): + fixturesUtils.readOnlySetUpClass(__file__, loadPlugin=False) + + if not cls.pluginsLoaded: + cls.pluginsLoaded = mayaUtils.isMayaUsdPluginLoaded() + + @classmethod + def tearDownClass(cls): + standalone.uninitialize() + + def setUp(self): + ''' Called initially to set up the Maya test environment ''' + # Load plugins + self.assertTrue(self.pluginsLoaded) + + # Clear selection to start off + cmds.select(clear=True) + + 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 + +if __name__ == '__main__': + unittest.main(verbosity=2) diff --git a/test/testSamples/setsCmd/5prims.usda b/test/testSamples/setsCmd/5prims.usda new file mode 100644 index 0000000000..a3c87d1383 --- /dev/null +++ b/test/testSamples/setsCmd/5prims.usda @@ -0,0 +1,40 @@ +#usda 1.0 + +reorder rootPrims = ["Capsule1", "Cone1", "Cube1", "Cylinder1", "Sphere1", "Xform1"] + +def Capsule "Capsule1" +{ + double3 xformOp:translate = (-13.855604588157764, 0, 0) + uniform token[] xformOpOrder = ["xformOp:translate"] +} + +def Cone "Cone1" +{ + double3 xformOp:translate = (-8.725335979971176, 0, 0) + uniform token[] xformOpOrder = ["xformOp:translate"] +} + +def Cylinder "Cylinder1" +{ + double3 xformOp:translate = (1.7859601980783193, 0, 0) + uniform token[] xformOpOrder = ["xformOp:translate"] +} + +def Sphere "Sphere1" +{ + double3 xformOp:translate = (6.180355031854263, 0, 0) + uniform token[] xformOpOrder = ["xformOp:translate"] +} + +def Xform "Xform1" +{ +} + +def Cube "Cube1" +{ + float3 xformOp:rotateXYZ = (0, -0, 0) + float3 xformOp:scale = (1, 1, 1) + double3 xformOp:translate = (-2.1084769730574147, 0, 0) + uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"] +} +