Skip to content

Commit

Permalink
Merge pull request #3479 from Autodesk/bailp/EMSUSD-820/more-pixar-tests
Browse files Browse the repository at this point in the history
EMSUSD-820 run more of the Pixar plugin tests
  • Loading branch information
seando-adsk authored Dec 13, 2023
2 parents e2501f1 + 3e88a38 commit 0528a4b
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 16 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)
32 changes: 32 additions & 0 deletions plugin/pxr/maya/lib/pxrUsdMayaGL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Unit test scripts.
set(TEST_SCRIPT_FILES
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,21 +21,39 @@
import unittest

import fixturesUtils
import imageUtils
import mayaUtils


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, baselineSuffix = None):
if baselineSuffix is None:
baselineSuffix = suffix

def _WriteViewportImage(self, outputImageName, suffix):
# Make sure the hardware renderer is available
MAYA_RENDERER_NAME = 'mayaHardware2'
mayaRenderers = cmds.renderer(query=True,
Expand All @@ -59,8 +77,41 @@ 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)

baselineImageName = '%s_%s.png' % (outputImageName, baselineSuffix)
outputImageName = '%s_%s.png' % (outputImageName, suffix)

baselineImagePath = os.path.join(self._inputDir, 'baseline', baselineImageName)
outputImagePath = os.path.join('.', 'tmp', outputImageName)

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 All @@ -70,25 +121,30 @@ def testGenerateImages(self):
cmds.file(os.path.abspath('InstancerDrawTest.ma'),
open=True, force=True)

# The cards rendering colors in older versions of Maya is lighter,
suffix = ''
if mayaUtils.mayaMajorVersion() <= 2024:
suffix = '_v1'

# Draw in VP2 at current frame.
self._SetModelPanelsToViewport2()
self._WriteViewportImage("InstancerTest", "initial")

# Load assembly in "Cards" to use cards drawmode.
cmds.assembly("CubeModel", edit=True, active="Cards")
self._WriteViewportImage("InstancerTest", "cards")
self._WriteViewportImage("InstancerTest", "cards" + suffix)

# Change the time; this will change the instancer positions.
cmds.currentTime(50, edit=True)
self._WriteViewportImage("InstancerTest", "frame50")
self._WriteViewportImage("InstancerTest", "frame50" + suffix)

# Delete the first instance.
# Tickle the second instance so that it draws.
# Note: it's OK that we need to tickle; the instancing support is not
# the greatest and we're just checking that it doesn't break horribly.
cmds.delete("instance1")
cmds.setAttr("instance2.t", 15, 0, 0, type="double3")
self._WriteViewportImage("InstancerTest", "instance2")
self._WriteViewportImage("InstancerTest", "instance2" + suffix)

# Delete the second instance.
cmds.delete("instance2")
Expand All @@ -99,7 +155,7 @@ def testGenerateImages(self):
cmds.file(os.path.abspath('InstancerDrawTest.ma'),
open=True, force=True)
self._SetModelPanelsToViewport2()
self._WriteViewportImage("InstancerTest", "reload")
self._WriteViewportImage("InstancerTest", "reload", "initial")


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,33 @@
import unittest

import fixturesUtils
import imageUtils
import mayaUtils

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,26 +81,64 @@ 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()

for representation in ['Cards', 'Collapsed', 'Expanded', 'Full',
'Playback']:

# The cards rendering colors in older versions of Maya is lighter,
suffix = ''
if mayaUtils.mayaMajorVersion() <= 2024:
if representation == "Cards":
suffix = '_v1'

cmds.assembly("Cube_1", edit=True, active=representation)

cmds.assembly('Cube_1', edit=True, active=representation)
self._WriteViewportImage(self._testName, representation)
self._WriteViewportImage(self._testName, representation + suffix)


if __name__ == '__main__':
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 0528a4b

Please sign in to comment.