Skip to content

Commit

Permalink
Fix tests that rely on the default material.
Browse files Browse the repository at this point in the history
  • Loading branch information
krickw committed Mar 30, 2022
1 parent 3885eb0 commit 68adba8
Show file tree
Hide file tree
Showing 37 changed files with 64 additions and 40 deletions.
1 change: 0 additions & 1 deletion lib/usd/hdMaya/adapters/materialNetworkConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ void HdMayaMaterialNetworkConverter::initialize()
{ HdMayaAdapterTokens->clearcoatRoughness, coatRoughnessConverter },
{ HdMayaAdapterTokens->opacity, transmissionToOpacity },
{ HdMayaAdapterTokens->metallic, fixedZeroFloat },
{ HdMayaAdapterTokens->useSpecularWorkflow, fixedOneInt },
} } },
{ HdMayaAdapterTokens->file,
{ UsdImagingTokens->UsdUVTexture,
Expand Down
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.
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.
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.
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.
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.
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.
11 changes: 8 additions & 3 deletions test/lib/mayaUsd/render/mayaToHydra/testMtohBasicRender.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest

import maya.cmds as cmds
import maya.mel

import fixturesUtils
import mtohUtils
Expand Down Expand Up @@ -47,17 +48,21 @@ def test_flat_orange(self):
# flat_orange_bad.png, and 163200000 is the maximum diff for an 8-bit,
# 40x40, 4-channel image. So this tests that assertSnapshotClose is
# working
self.assertSnapshotClose("flat_orange_bad.png", 17515 / 163200000.0)
self.assertSnapshotClose("flat_orange_bad.png", None, 17515 / 163200000.0)


class TestHdMayaRender(mtohUtils.MtohTestCase):
_file = __file__

def test_cube(self):
imageVersion = None
if maya.mel.eval("defaultShaderName") != "standardSurface1":
imageVersion = 'lambertDefaultMaterial'

self.makeCubeScene(camDist=6)
self.assertSnapshotClose("cube_unselected.png")
self.assertSnapshotClose("cube_unselected.png", imageVersion)
cmds.select(self.cubeTrans)
self.assertSnapshotClose("cube_selected.png")
self.assertSnapshotClose("cube_selected.png", imageVersion)


if __name__ == '__main__':
Expand Down
51 changes: 30 additions & 21 deletions test/lib/mayaUsd/render/mayaToHydra/testMtohDagChanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest

import maya.cmds as cmds
import maya.mel

import fixturesUtils
import mtohUtils
Expand All @@ -18,6 +19,10 @@ def setUp(self):
self.grp2 = cmds.createNode('transform', name='group2')
self.grp2Rprim = self.rprimPath(self.grp2)

self.imageVersion = None
if maya.mel.eval("defaultShaderName") != "standardSurface1":
self.imageVersion = 'lambertDefaultMaterial'

def test_reparent_transform(self):
cmds.parent(self.cubeTrans, self.grp1)
grp1ShapeRprim = self.rprimPath(self.cubeShape)
Expand Down Expand Up @@ -93,22 +98,22 @@ def test_instances(self):

# No instances to start
# (1) |pCube1|pCubeShape1
self.assertSnapshotClose("instances_1.png")
self.assertSnapshotClose("instances_1.png", self.imageVersion)

# Add |group1|pCube1 instance
# (1) |pCube1|pCubeShape1
# (2) |group1|pCube1|pCubeShape1
cmds.parent(self.cubeTrans, self.grp1, add=1, r=1)
cmds.select(clear=1)
self.assertSnapshotClose("instances_12.png")
self.assertSnapshotClose("instances_12.png", self.imageVersion)

# Add |pCube2|pCubeShape1 instance
# (1) |pCube1|pCubeShape1
# (2) |group1|pCube1|pCubeShape1
# (3) |pCube2|pCubeShape1
cmds.parent(self.cubeShape, pCube2, add=1, r=1, shape=1)
cmds.select(clear=1)
self.assertSnapshotClose("instances_123.png")
self.assertSnapshotClose("instances_123.png", self.imageVersion)

# Add |group2|group1|pCube1 instance
# (1) |pCube1|pCubeShape1
Expand All @@ -117,7 +122,7 @@ def test_instances(self):
# (4) |group2||group1|pCube1|pCubeShape1
cmds.parent(self.grp1, self.grp2, add=1, r=1)
cmds.select(clear=1)
self.assertSnapshotClose("instances_1234.png")
self.assertSnapshotClose("instances_1234.png", self.imageVersion)

# Add |group1|pCube2 instance
# (1) |pCube1|pCubeShape1
Expand All @@ -128,7 +133,7 @@ def test_instances(self):
# (6) |group2||group1|pCube2|pCubeShape1
cmds.parent(pCube2, self.grp1, add=1, r=1)
cmds.select(clear=1)
self.assertSnapshotClose("instances_123456.png")
self.assertSnapshotClose("instances_123456.png", self.imageVersion)

# Delete group2
# [no shapes]
Expand All @@ -137,7 +142,7 @@ def test_instances(self):
try:
cmds.delete(self.grp2)
self.assertNotIn(self.cubeRprim, self.getIndex())
self.assertSnapshotClose("instances_0.png")
self.assertSnapshotClose("instances_0.png", self.imageVersion)
finally:
cmds.undoInfo(closeChunk=1)

Expand All @@ -149,7 +154,7 @@ def test_instances(self):
# (5) |group1|pCube2|pCubeShape1
# (6) |group2||group1|pCube2|pCubeShape1
cmds.undo()
self.assertSnapshotClose("instances_123456.png")
self.assertSnapshotClose("instances_123456.png", self.imageVersion)

# Remove |group2|group1 instance
# (1) |pCube1|pCubeShape1
Expand All @@ -158,7 +163,7 @@ def test_instances(self):
# (5) |group1|pCube2|pCubeShape1
cmds.parent('|{self.grp2}|{self.grp1}'.format(self=self),
removeObject=1)
self.assertSnapshotClose("instances_1235.png")
self.assertSnapshotClose("instances_1235.png", self.imageVersion)

# Remove pCube2|pCubeShape1 instance
# (1) |pCube1|pCubeShape1
Expand All @@ -168,7 +173,7 @@ def test_instances(self):
cmds.parent('|{pCube2}|{self.cubeShape}'.format(self=self,
pCube2=pCube2),
removeObject=1, shape=1)
self.assertSnapshotClose("instances_12.png")
self.assertSnapshotClose("instances_12.png", self.imageVersion)
finally:
cmds.undoInfo(closeChunk=1)

Expand All @@ -178,7 +183,7 @@ def test_instances(self):
# (3) |pCube2|pCubeShape1
# (5) |group1|pCube2|pCubeShape1
cmds.undo()
self.assertSnapshotClose("instances_1235.png")
self.assertSnapshotClose("instances_1235.png", self.imageVersion)

# Remove pCube1|pCubeShape1 (the "master" instance)
# (3) |pCube2|pCubeShape1
Expand All @@ -187,7 +192,7 @@ def test_instances(self):
try:
cmds.parent('|{self.cubeTrans}|{self.cubeShape}'.format(self=self),
removeObject=1, shape=1)
self.assertSnapshotClose("instances_35.png")
self.assertSnapshotClose("instances_35.png", self.imageVersion)
finally:
cmds.undoInfo(closeChunk=1)

Expand All @@ -202,29 +207,29 @@ def test_instances(self):
# need to disable without flusing the queue, so we can test redo
cmds.undoInfo(stateWithoutFlush=0)
try:
self.assertSnapshotClose("instances_1235.png")
self.assertSnapshotClose("instances_1235.png", self.imageVersion)
finally:
cmds.undoInfo(stateWithoutFlush=1)

# Redo remove pCube2|pCubeShape1 instance
# (3) |pCube2|pCubeShape1
# (5) |group1|pCube2|pCubeShape1
cmds.redo()
self.assertSnapshotClose("instances_35.png")
self.assertSnapshotClose("instances_35.png", self.imageVersion)

# Remove |group1|pCube2 instance
# (3) |pCube2|pCubeShape1
cmds.parent('{self.grp1}|{pCube2}'.format(self=self,
pCube2=pCube2),
removeObject=1)
self.assertSnapshotClose("instances_3.png")
self.assertSnapshotClose("instances_3.png", self.imageVersion)
finally:
cmds.undoInfo(state=undoWasEnabled)

def test_move(self):
self.assertSnapshotClose("instances_1.png")
self.assertSnapshotClose("instances_1.png", self.imageVersion)
cmds.setAttr('{}.ty'.format(self.cubeTrans), 5)
self.assertSnapshotClose("instances_3.png")
self.assertSnapshotClose("instances_3.png", self.imageVersion)

def test_instance_move(self):
# Add |group1|pCube1 instance
Expand All @@ -235,11 +240,11 @@ def test_instance_move(self):

# because we haven't moved anything, it should initially look like only
# one cube...
self.assertSnapshotClose("instances_1.png")
self.assertSnapshotClose("instances_1.png", self.imageVersion)

cmds.setAttr('{}.tz'.format(self.grp1), 5)
# Now that we moved one, it should look like 2 cubes
self.assertSnapshotClose("instances_12.png")
self.assertSnapshotClose("instances_12.png", self.imageVersion)


class TestUndo(mtohUtils.MtohTestCase):
Expand All @@ -248,6 +253,10 @@ class TestUndo(mtohUtils.MtohTestCase):
def test_node_creation_undo(self):
undoWasEnabled = cmds.undoInfo(q=1, state=1)

self.imageVersion = None
if maya.mel.eval("defaultShaderName") != "standardSurface1":
self.imageVersion = 'lambertDefaultMaterial'

cmds.undoInfo(state=0)
try:
cmds.file(new=1, f=1)
Expand All @@ -264,7 +273,7 @@ def test_node_creation_undo(self):
cmds.select(clear=1)
cmds.refresh()
self.assertEqual([cubeRprim], self.getIndex())
self.assertSnapshotClose("instances_1.png")
self.assertSnapshotClose("instances_1.png", self.imageVersion)
finally:
cmds.undoInfo(closeChunk=1)

Expand All @@ -276,7 +285,7 @@ def test_node_creation_undo(self):
try:
cmds.refresh()
self.assertEqual([], self.getIndex())
self.assertSnapshotClose("instances_0.png")
self.assertSnapshotClose("instances_0.png", self.imageVersion)
finally:
cmds.undoInfo(stateWithoutFlush=1)

Expand All @@ -286,7 +295,7 @@ def test_node_creation_undo(self):
try:
cmds.refresh()
self.assertEqual([cubeRprim], self.getIndex())
self.assertSnapshotClose("instances_1.png")
self.assertSnapshotClose("instances_1.png", self.imageVersion)
finally:
cmds.undoInfo(stateWithoutFlush=1)

Expand Down
8 changes: 6 additions & 2 deletions test/lib/mayaUsd/render/mayaToHydra/testMtohVisibility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import maya.cmds as cmds
import maya.mel

import fixturesUtils
import mtohUtils
Expand All @@ -10,6 +11,9 @@ def setUp(self):
self.makeCubeScene(camDist=6)
self.assertTrue(cmds.getAttr("{}.visibility".format(self.cubeTrans)))
self.assertTrue(cmds.getAttr("{}.visibility".format(self.cubeShape)))
self.imageVersion = None
if maya.mel.eval("defaultShaderName") != "standardSurface1":
self.imageVersion = 'lambertDefaultMaterial'

def test_toggleTransVis(self):
# because snapshotting is slow, we only use it in this test - otherwise
Expand All @@ -23,7 +27,7 @@ def test_toggleTransVis(self):
self.assertIn(
self.cubeRprim,
self.getVisibleIndex())
self.assertSnapshotClose(cubeUnselectedImg)
self.assertSnapshotClose(cubeUnselectedImg, self.imageVersion)

cmds.setAttr("{}.visibility".format(self.cubeTrans), False)
self.assertFalse(cmds.getAttr("{}.visibility".format(self.cubeTrans)))
Expand All @@ -39,7 +43,7 @@ def test_toggleTransVis(self):
self.assertIn(
self.cubeRprim,
self.getVisibleIndex())
self.assertSnapshotClose(cubeUnselectedImg)
self.assertSnapshotClose(cubeUnselectedImg, self.imageVersion)

def test_toggleShapeVis(self):
cmds.setAttr("{}.visibility".format(self.cubeShape), False)
Expand Down
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 @@ -26,6 +26,7 @@
from mayaUsd import ufe as mayaUsdUfe

from maya import cmds
import maya.mel
import maya.api.OpenMayaRender as omr

from pxr import Usd
Expand All @@ -34,7 +35,6 @@

import os


class testVP2RenderDelegatePerInstanceInheritedData(imageUtils.ImageDiffingTestCase):
"""
Tests imaging using the Viewport 2.0 render delegate when using per-instance
Expand All @@ -55,15 +55,19 @@ def setUpClass(cls):

cls._testDir = os.path.abspath('.')

cls._imageVersion = None
if maya.mel.eval("defaultShaderName") != "standardSurface1":
cls._imageVersion = 'lambertDefaultMaterial'

@classmethod
def tearDownClass(cls):
panel = mayaUtils.activeModelPanel()
cmds.modelEditor(panel, edit=True, useDefaultMaterial=False)

def assertSnapshotClose(self, imageName, usdVersion=None):
def assertSnapshotClose(self, imageName, version=None):
paths = []
if (usdVersion):
paths = [usdVersion, imageName]
if (version):
paths = [version, imageName]
else:
paths = [imageName]

Expand All @@ -72,7 +76,7 @@ def assertSnapshotClose(self, imageName, usdVersion=None):
imageUtils.snapshot(snapshotImage, width=960, height=540)
return self.assertImagesClose(baselineImage, snapshotImage)

def _StartTest(self, testName):
def _StartTest(self, testName, version=None):
cmds.file(force=True, new=True)
mayaUtils.loadPlugin("mayaUsdPlugin")
panel = mayaUtils.activeModelPanel()
Expand All @@ -82,7 +86,7 @@ def _StartTest(self, testName):
mayaUtils.createProxyFromFile(testFile)
globalSelection = ufe.GlobalSelection.get()
globalSelection.clear()
self.assertSnapshotClose('%s_unselected.png' % self._testName)
self.assertSnapshotClose('%s_unselected.png' % self._testName, version)

def testPerInstanceInheritedData(self):
self._StartTest('perInstanceInheritedData')
Expand Down Expand Up @@ -138,10 +142,10 @@ def testPerInstanceInheritedDataPartialOverridePxrMtls(self):
def testPerInstanceInheritedDataPartialOverride(self):
self._StartTest('inheritedDisplayColor_pxrSurface')

def testPerInstanceInheriedDataBasisCurves(self):
self._StartTest('basisCurveInstance')
def testPerInstanceInheritedDataBasisCurves(self):
self._StartTest('basisCurveInstance', self._imageVersion)
cmds.select("|stage|stageShape,/instanced_2")
self.assertSnapshotClose('%s_selected.png' % self._testName)
self.assertSnapshotClose('%s_selected.png' % self._testName, self._imageVersion)

@unittest.skipUnless("SkipWhenDefaultMaterialActive" in dir(omr.MRenderItem), "Requires new SDK API")
def testInstanceDefaultMaterial(self):
Expand All @@ -151,10 +155,10 @@ def testInstanceDefaultMaterial(self):
self.assertSnapshotClose('%s_selected.png' % self._testName)
panel = mayaUtils.activeModelPanel()
cmds.modelEditor(panel, edit=True, useDefaultMaterial=True)
self.assertSnapshotClose('%s_default.png' % self._testName)
self.assertSnapshotClose('%s_default.png' % self._testName, self._imageVersion)
cmds.select("|stage|stageShape,/root/group/billboard_04",
"|stage|stageShape,/root/group/flatquad_04")
self.assertSnapshotClose('%s_defaultSelected.png' % self._testName)
self.assertSnapshotClose('%s_defaultSelected.png' % self._testName, self._imageVersion)
cmds.modelEditor(panel, edit=True, useDefaultMaterial=False)
self.assertSnapshotClose('%s_notDefault.png' % self._testName)

Expand Down
7 changes: 5 additions & 2 deletions test/testUtils/mtohUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ def setUpClass(cls):

cls._testDir = os.path.abspath('.')

def assertSnapshotClose(self, refImage,
def assertSnapshotClose(self, refImage, imageVersion=None,
maxAvgChannelDiff=\
ImageDiffingTestCase.AVG_CHANNEL_DIFF):
if not os.path.isabs(refImage):
refImage = os.path.join(self._inputDir, refImage)
if imageVersion:
refImage = os.path.join(self._inputDir, imageVersion, refImage)
else:
refImage = os.path.join(self._inputDir, refImage)
super(MtohTestCase, self).assertSnapshotClose(
refImage, maxAvgChannelDiff=maxAvgChannelDiff)

Expand Down

0 comments on commit 68adba8

Please sign in to comment.