Skip to content

Commit

Permalink
EMSUSD-820 run more of the Pxiar plugin tests
Browse files Browse the repository at this point in the history
There were tests in the "pxrUsdMayaGL" folder in the pxr (Pixar) plugin that
were not run. As a first step, make these test be run when testing the plugin.

- Add a CMakeLists.txt to setup the test to be run when built using cmake.
- Make sure the folder paths are correct while running the test.
- Make sure the relative USD files used in assembly are found.
- Add one missing baseline image file.
- Disable the testRefAssemblyDrawRepresentations unit test since it fails in the "Expanded" mode.
  • Loading branch information
pierrebai-adsk committed Nov 22, 2023
1 parent e32ff36 commit 66f2462
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plugin/pxr/maya/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_subdirectory(usdMaya)

add_subdirectory(pxrUsdMayaGL)
35 changes: 35 additions & 0 deletions plugin/pxr/maya/lib/pxrUsdMayaGL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,33 @@
import unittest

import fixturesUtils
import imageUtils


class testPxrUsdMayaGLInstancerDraw(unittest.TestCase):
class testPxrUsdMayaGLInstancerDraw(imageUtils.ImageDiffingTestCase):

@classmethod
def setUpClass(cls):
# The test USD data is authored Z-up, so make sure Maya is configured
# 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
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,31 @@
import unittest

import fixturesUtils
import imageUtils

class testRefAssemblyDrawRepresentations(unittest.TestCase):
class testRefAssemblyDrawRepresentations(imageUtils.ImageDiffingTestCase):

@classmethod
def setUpClass(cls):
# The test USD data is authored Z-up, so make sure Maya is configured
# 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)

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import unittest

import fixturesUtils
import imageUtils


class testProxyShapeDrawColors(unittest.TestCase):
class testProxyShapeDrawColors(imageUtils.ImageDiffingTestCase):

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -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())

0 comments on commit 66f2462

Please sign in to comment.