diff --git a/plugin/pxr/maya/lib/CMakeLists.txt b/plugin/pxr/maya/lib/CMakeLists.txt index 5d0bc21387..d6df760367 100644 --- a/plugin/pxr/maya/lib/CMakeLists.txt +++ b/plugin/pxr/maya/lib/CMakeLists.txt @@ -1,2 +1,2 @@ add_subdirectory(usdMaya) - +add_subdirectory(pxrUsdMayaGL) diff --git a/plugin/pxr/maya/lib/pxrUsdMayaGL/CMakeLists.txt b/plugin/pxr/maya/lib/pxrUsdMayaGL/CMakeLists.txt new file mode 100644 index 0000000000..70e48d8c0b --- /dev/null +++ b/plugin/pxr/maya/lib/pxrUsdMayaGL/CMakeLists.txt @@ -0,0 +1,35 @@ +# Unit test scripts. +set(TEST_SCRIPT_FILES + # Note: the following test fails when switching to the "Expanded" + # assembly mode, so disabled it until Pixar figures + # what is going wrong. + # testenv/testRefAssemblyDrawRepresentations.py + testenv/testBatchRendererIsolateSelection.py + testenv/testPxrUsdMayaGLInstancerDraw.py +) + +foreach(script ${TEST_SCRIPT_FILES}) + mayaUsd_get_unittest_target(target ${script}) + mayaUsd_add_test(${target} + INTERACTIVE + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + PYTHON_SCRIPT ${script} + ENV + "LD_LIBRARY_PATH=${ADDITIONAL_LD_LIBRARY_PATH}" + + # Maya uses a very old version of GLEW, so we need support for + # pre-loading a newer version from elsewhere. + "LD_PRELOAD=${ADDITIONAL_LD_PRELOAD}" + + # All of the pxrUsdMayaGL tests exercise Pixar's batch renderer, so + # we turn the Viewport 2.0 render delegate off. + "MAYAUSD_DISABLE_VP2_RENDER_DELEGATE=1" + + # Fallback to old color management. We will have to investigate + # and introduce OCIOv2 compatible version of these tests. + "MAYA_COLOR_MANAGEMENT_SYNCOLOR=1" + ) + + # Assign a CTest label to these tests for easy filtering. + set_property(TEST ${target} APPEND PROPERTY LABELS pxrUsdMayaGL) +endforeach() diff --git a/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/InstancerDrawTest/baseline/InstancerTest_reload.png b/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/InstancerDrawTest/baseline/InstancerTest_reload.png new file mode 100644 index 0000000000..2c557f967f Binary files /dev/null and b/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/InstancerDrawTest/baseline/InstancerTest_reload.png differ diff --git a/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testBatchRendererIsolateSelection.py b/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testBatchRendererIsolateSelection.py index fb9cec8fbf..3c86efc8b0 100644 --- a/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testBatchRendererIsolateSelection.py +++ b/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testBatchRendererIsolateSelection.py @@ -34,10 +34,23 @@ def setUpClass(cls): # that way too. cmds.upAxis(axis='z') + cls._testName = 'BatchRendererIsolateSelectionTest' + inputPath = fixturesUtils.setUpClass( + __file__, initializeStandalone=False, loadPlugin=False) + + cmds.loadPlugin('pxrUsd') + + cls._testDir = os.path.abspath('.') + cls._inputDir = os.path.join(inputPath, cls._testName) + # To control where the rendered images are written, we force Maya to # use the test directory as the workspace. cmds.workspace(os.path.abspath('.'), o=True) + # Make sure the relative-path to the USD file works by setting the current + # directory to where that file is. + os.chdir(cls._inputDir) + def _MakeModelPanel(self): window = cmds.window(widthHeight=(400, 400)) cmds.paneLayout() @@ -75,8 +88,8 @@ def _HitTest(self, panel, cube1, cube2, cube3): self.assertEqual(test3, cube3) def testIsolateSelection(self): - cmds.file(os.path.abspath('IsolateSelectionTest.ma'), - open=True, force=True) + mayaSceneFullPath = os.path.join(self._inputDir, 'IsolateSelectionTest.ma') + cmds.file(mayaSceneFullPath,open=True, force=True) # Isolate selection seems to only apply to the interactive viewports, # and not to ogsRenders. However, it's difficult for us to render diff --git a/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testPxrUsdMayaGLInstancerDraw.py b/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testPxrUsdMayaGLInstancerDraw.py index a0ebbae767..6297b2d72c 100644 --- a/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testPxrUsdMayaGLInstancerDraw.py +++ b/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testPxrUsdMayaGLInstancerDraw.py @@ -21,9 +21,10 @@ import unittest import fixturesUtils +import imageUtils -class testPxrUsdMayaGLInstancerDraw(unittest.TestCase): +class testPxrUsdMayaGLInstancerDraw(imageUtils.ImageDiffingTestCase): @classmethod def setUpClass(cls): @@ -31,9 +32,22 @@ def setUpClass(cls): # that way too. cmds.upAxis(axis='z') + cls._testName = 'InstancerDrawTest' + inputPath = fixturesUtils.setUpClass( + __file__, initializeStandalone=False, loadPlugin=False) + + cmds.loadPlugin('pxrUsd') + + cls._testDir = os.path.abspath('.') + cls._inputDir = os.path.join(inputPath, cls._testName) + # To control where the rendered images are written, we force Maya to # use the test directory as the workspace. - cmds.workspace(os.path.abspath('.'), o=True) + cmds.workspace(cls._testDir, o=True) + + # Make sure the relative-path to the USD file works by setting the current + # directory to where that file is. + os.chdir(cls._inputDir) def _WriteViewportImage(self, outputImageName, suffix): # Make sure the hardware renderer is available @@ -59,8 +73,39 @@ def _WriteViewportImage(self, outputImageName, suffix): cmds.setAttr("defaultColorMgtGlobals.outputTransformEnabled", 1) # Do the render. + # + # We need to render twice, once in the input directory where the input + # test file resides and once in the test output directory. + # + # The first render is needed because: + # 1. The USD file used in the assembly lives in the input directory + # 2. It uses a relative path + # 3. It is only resolved when the Maya node gets computed + # 4. The Maya node gets computed only when we try to render it + # + # So we need to do a first compute in the input directory so that the + # input USD file is found. + # + # The second render is needed so that the output file is found in + # the directory the test expects. + + # Make sure the relative-path input assembly USD file is found. + cmds.ogsRender(camera="persp", currentFrame=True, width=960, height=540) + + # Make sure the image is written in the test output folder. + os.chdir(self._testDir) cmds.ogsRender(camera="persp", currentFrame=True, width=960, height=540) + imageName = '%s_%s.png' % (outputImageName, suffix) + baselineImagePath = os.path.join(self._inputDir, 'baseline', imageName) + outputImagePath = os.path.join('.', 'tmp', imageName) + + self.assertImagesClose(baselineImagePath, outputImagePath) + + # Make sure the relative-path to the USD file works by setting the current + # directory to where that file is. + os.chdir(self._inputDir) + def _SetModelPanelsToViewport2(self): modelPanels = cmds.getPanel(type='modelPanel') for modelPanel in modelPanels: diff --git a/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testRefAssemblyDrawRepresentations.py b/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testRefAssemblyDrawRepresentations.py index ed4608adee..473d451ef7 100644 --- a/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testRefAssemblyDrawRepresentations.py +++ b/plugin/pxr/maya/lib/pxrUsdMayaGL/testenv/testRefAssemblyDrawRepresentations.py @@ -24,8 +24,9 @@ import unittest import fixturesUtils +import imageUtils -class testRefAssemblyDrawRepresentations(unittest.TestCase): +class testRefAssemblyDrawRepresentations(imageUtils.ImageDiffingTestCase): @classmethod def setUpClass(cls): @@ -33,12 +34,21 @@ def setUpClass(cls): # that way too. cmds.upAxis(axis='z') + cls._testName = 'RefAssemblyDrawRepresentationsTest' + inputPath = fixturesUtils.setUpClass( + __file__, initializeStandalone=False, loadPlugin=False) + cmds.loadPlugin('pxrUsd') cls._testDir = os.path.abspath('.') + cls._inputDir = os.path.join(inputPath, cls._testName) cls._cameraName = 'MainCamera' + # Make sure the relative-path to the USD file works by setting the current + # directory to where that file is. + os.chdir(cls._inputDir) + def setUp(self): cmds.file(new=True, force=True) @@ -69,18 +79,47 @@ def _WriteViewportImage(self, outputImageName, suffix): cmds.setAttr("defaultColorMgtGlobals.outputTransformEnabled", 1) # Do the render. + # + # We need to render twice, once in the input directory where the input + # test file resides and once in the test output directory. + # + # The first render is needed because: + # 1. The USD file used in the assembly lives in the input directory + # 2. It uses a relative path + # 3. It is only resolved when the Maya node gets computed + # 4. The Maya node gets computed only when we try to render it + # + # So we need to do a first compute in the input directory so that the + # input USD file is found. + # + # The second render is needed so that the output file is found in + # the directory the test expects. + + # Make sure the relative-path input assembly USD file is found. + cmds.ogsRender(camera="persp", currentFrame=True, width=960, height=540) + + # Make sure the image is written in the test output folder. + os.chdir(self._testDir) cmds.ogsRender(camera=self._cameraName, currentFrame=True, width=960, height=540) + imageName = '%s_%s.png' % (outputImageName, suffix) + baselineImagePath = os.path.join(self._inputDir, 'baseline', imageName) + outputImagePath = os.path.join('.', 'tmp', imageName) + + self.assertImagesClose(baselineImagePath, outputImagePath) + + # Make sure the relative-path to the USD file works by setting the current + # directory to where that file is. + os.chdir(self._inputDir) + def testDrawCubeRepresentations(self): """ Tests drawing USD proxy shapes while changing the assembly representation. """ - self._testName = 'RefAssemblyDrawRepresentationsTest' - mayaSceneFile = '%s.ma' % self._testName - mayaSceneFullPath = os.path.abspath(mayaSceneFile) + mayaSceneFullPath = os.path.join(self._inputDir, mayaSceneFile) cmds.file(mayaSceneFullPath, open=True, force=True) UsdMaya.LoadReferenceAssemblies() diff --git a/test/lib/mayaUsd/render/pxrUsdMayaGL/testProxyShapeDrawColors.py b/test/lib/mayaUsd/render/pxrUsdMayaGL/testProxyShapeDrawColors.py index fdb950388b..ecb9fef832 100644 --- a/test/lib/mayaUsd/render/pxrUsdMayaGL/testProxyShapeDrawColors.py +++ b/test/lib/mayaUsd/render/pxrUsdMayaGL/testProxyShapeDrawColors.py @@ -22,9 +22,10 @@ import unittest import fixturesUtils +import imageUtils -class testProxyShapeDrawColors(unittest.TestCase): +class testProxyShapeDrawColors(imageUtils.ImageDiffingTestCase): @classmethod def setUpClass(cls): @@ -117,6 +118,12 @@ def _Snapshot(self, outName): # Do the render. cmds.ogsRender(camera='top', currentFrame=True, width=400, height=400) + imageName = '%s.png' % outName + baselineImagePath = os.path.join(self._inputDir, 'baseline', imageName) + outputImagePath = os.path.join('.', 'tmp', imageName) + + self.assertImagesClose(baselineImagePath, outputImagePath) + if __name__ == '__main__': fixturesUtils.runTests(globals())