Skip to content

Commit

Permalink
Add Unit Test for Maya Shading Modes (#77)
Browse files Browse the repository at this point in the history
* Add Unit Test for Maya Shading Modes
  • Loading branch information
roopavr-adsk authored Feb 20, 2024
1 parent 9afcbc4 commit 6fe3600
Show file tree
Hide file tree
Showing 12 changed files with 410 additions and 13 deletions.
1 change: 1 addition & 0 deletions test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(INTERACTIVE_TEST_SCRIPT_FILES
testMaterialXOnNative.py
testNewSceneWithStage.py
testMayaDisplayModes.py
testMayaShadingModes.py
testMayaIsolateSelect.py
testMayaLights.py
testUSDLights.py
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.
21 changes: 8 additions & 13 deletions test/lib/mayaUsd/render/mayaToHydra/testMayaDisplayModes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ def imageDiffFailPercent(self):
return 4
return 0.2

def switchDisplayModes(self):
def test_MayaDisplayModes(self):

# open simple Maya scene
testFile = mayaUtils.openTestScene(
"testMayaDisplayModes",
"testMayaDisplayModes.ma")
cmds.refresh()

panel = mayaUtils.activeModelPanel()

cmds.modelEditor(panel, edit=True, wireframeOnShaded=False)
Expand Down Expand Up @@ -85,18 +92,6 @@ def switchDisplayModes(self):
cmds.modelEditor(panel, edit=True, displayAppearance="smoothShaded")
cmds.refresh()
self.assertSnapshotClose("smoothShaded" + ".png", self.imageDiffFailThreshold, self.imageDiffFailPercent)


def test_MayaDisplayModes(self):
cmds.file(new=True, force=True)

# open simple Maya scene
testFile = mayaUtils.openTestScene(
"testMayaDisplayModes",
"testMayaDisplayModes.ma")
cmds.refresh()

self.switchDisplayModes()

if __name__ == '__main__':
fixturesUtils.runTests(globals())
106 changes: 106 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/testMayaShadingModes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#
# Copyright 2024 Autodesk, Inc. All rights reserved.
#
# 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 maya.cmds as cmds
import fixturesUtils
import mtohUtils
import mayaUtils

import platform

class TestMayaShadingModes(mtohUtils.MtohTestCase): #Subclassing mtohUtils.MtohTestCase to be able to call self.assertSnapshotClose
# MayaHydraBaseTestCase.setUpClass requirement.
_file = __file__

@property
def imageDiffFailThreshold(self):
# HYDRA-837 : Wireframes seem to have a slightly different color on macOS. We'll increase the thresholds
# for that platform specifically for now, so we can still catch issues on other platforms.
if platform.system() == "Darwin":
return 0.05
return 0.01

@property
def imageDiffFailPercent(self):
# HYDRA-837 : Wireframes seem to have a slightly different color on macOS. We'll increase the thresholds
# for that platform specifically for now, so we can still catch issues on other platforms.
if platform.system() == "Darwin":
return 5
return 0.2

def test_MayaShadingModes(self):

testFile = mayaUtils.openTestScene(
"testMayaShadingModes",
"testMayaShadingModes.ma")

cmds.refresh()

panel = mayaUtils.activeModelPanel()

cmds.modelEditor(panel, edit=True, wireframeOnShaded=False)
#Smooth Shading
cmds.modelEditor(panel, edit=True, displayAppearance="smoothShaded")
cmds.refresh()
self.assertSnapshotClose("default" + ".png", self.imageDiffFailThreshold, self.imageDiffFailPercent)

#Flat Shading
cmds.modelEditor(panel, edit=True, displayAppearance="flatShaded")
cmds.refresh()
self.assertSnapshotClose("flatShaded" + ".png", self.imageDiffFailThreshold, self.imageDiffFailPercent)
cmds.modelEditor(panel, edit=True, displayAppearance="smoothShaded")

#Bounding Box
cmds.modelEditor(panel, edit=True, displayAppearance="boundingBox")
cmds.refresh()
self.assertSnapshotClose("boundingBox" + ".png", self.imageDiffFailThreshold, self.imageDiffFailPercent)
cmds.modelEditor(panel, edit=True, displayAppearance="smoothShaded")

#SmoothWirefame
cmds.modelEditor(panel, edit=True, displayAppearance="wireframe")
cmds.modelEditor(panel, edit=True, smoothWireframe=True)
cmds.refresh()
self.assertSnapshotClose("smoothwireframe" + ".png", self.imageDiffFailThreshold, self.imageDiffFailPercent)
cmds.modelEditor(panel, edit=True, smoothWireframe=False)
cmds.modelEditor(panel, edit=True, displayAppearance="smoothShaded")

#SmoothWirefameOnShaded
cmds.modelEditor(panel, edit=True, wireframeOnShaded=True)
cmds.modelEditor(panel, edit=True, smoothWireframe=True)
cmds.refresh()
self.assertSnapshotClose("smoothwireframeonshaded" + ".png", self.imageDiffFailThreshold, self.imageDiffFailPercent)
cmds.modelEditor(panel, edit=True, smoothWireframe=False)
cmds.modelEditor(panel, edit=True, wireframeOnShaded=False)

#X-ray
cmds.modelEditor(panel, edit=True, xray=True)
cmds.refresh()
self.assertSnapshotClose("xray" + ".png", self.imageDiffFailThreshold, self.imageDiffFailPercent)
cmds.modelEditor(panel, edit=True, xray=False)

#joint xray mode
cmds.modelEditor(panel, edit=True, jointXray=True)
cmds.refresh()
self.assertSnapshotClose("jointxray" + ".png", self.imageDiffFailThreshold, self.imageDiffFailPercent)
cmds.modelEditor(panel, edit=True, jointXray=False)

#backfaceCulling
cmds.modelEditor(panel, edit=True, backfaceCulling=True)
cmds.refresh()
self.assertSnapshotClose("backfaceCulling" + ".png", self.imageDiffFailThreshold, self.imageDiffFailPercent)

if __name__ == '__main__':
fixturesUtils.runTests(globals())
Loading

0 comments on commit 6fe3600

Please sign in to comment.