Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HYDRA-536 & HYDRA-537 : Background color and grid tests #112

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
2 changes: 2 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ set(INTERACTIVE_TEST_SCRIPT_FILES
testCurveTools.py
testPolygonPrimitives.py
testFootPrintNode.py
testBackgroundColor.py
testGrid.py
cpp/testColorPreferences.py
cpp/testCppFramework.py
cpp/testMayaSceneFlattening.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.
1 change: 1 addition & 0 deletions test/lib/mayaUsd/render/mayaToHydra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ To add a new Python-only test suite :

Some important notes :
- Before each test, a new file will be opened and the renderer will be switched to Hydra. If you need to switch between renderers, you can use the `self.setHdStormRenderer()` and `self.setViewport2Renderer()` methods.
- Some test settings (such as turning color management off, disabling the grid, etc.) are applied by default when opening a scene using `mayaUtils.openNewScene` or `mayaUtils.openTestScene`. The new scene opened before each test is opened using `mayaUtils.openNewScene`, meaning those test settings will automatically be applied before each test. These methods provide the option not to apply those settings if desired, by passing in `useTestSettings=False`. If you want to test a setting that is modified as part of those test settings, you can either re-set it explicitly in the test, and/or load a scene with the desired settings by calling `mayaUtils.openTestScene(<path arguments>, useTestSettings=False)`. In case you want to avoid ever changing the test settings entirely, you can also override the `setUp` method.

# Best practices
- Don't skip tests unless necessary. If a test requires a certain plugin to be loaded, don't skip the test if the plugin fails to load, as this will falsely be reported as a pass. For such cases, prefer setting the `_requiredPlugins` variable in your test class.
Expand Down
2 changes: 0 additions & 2 deletions test/lib/mayaUsd/render/mayaToHydra/testArnoldLights.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ def verifyLightingModes(self, shadowOn):

#Test arnold lights (e.g., aiSkyDomeLight,etc.) with a maya native sphere and usd sphere.
def test_ArnoldLights(self):
cmds.file(new=True, force=True)

# Load a maya scene with a maya native sphere, usd sphere and some lights, with HdStorm already being the viewport renderer.
# The sphere is not at the origin on purpose
testFile = mayaUtils.openTestScene(
Expand Down
49 changes: 49 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/testBackgroundColor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2024 Autodesk
#
# 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

class TestBackgroundColor(mtohUtils.MayaHydraBaseTestCase):
# MayaHydraBaseTestCase.setUpClass requirement.
_file = __file__

IMAGE_DIFF_FAIL_THRESHOLD = 0.05
IMAGE_DIFF_FAIL_PERCENT = 1

def compareBackgroundColor(self, imageName):
self.setViewport2Renderer()
self.assertSnapshotClose(imageName, self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.setHdStormRenderer()
self.assertSnapshotClose(imageName, self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

def test_BackgroundColor(self):
cmds.displayRGBColor('background', 0.5, 0, 0)
self.compareBackgroundColor("background_red.jpg")
cmds.displayRGBColor('background', 0, 0.5, 0)
self.compareBackgroundColor("background_green.jpg")
cmds.displayRGBColor('background', 0, 0, 0.5)
self.compareBackgroundColor("background_blue.jpg")

cmds.displayRGBColor('background', 0, 0, 0)
self.compareBackgroundColor("background_black.jpg")
cmds.displayRGBColor('background', 0.5, 0.5, 0.5)
self.compareBackgroundColor("background_gray.jpg")
cmds.displayRGBColor('background', 1, 1, 1)
self.compareBackgroundColor("background_white.jpg")
Comment on lines +34 to +46
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we must use .jpg for playblasts to render the background color, using .png always rendered the background as transparent.


if __name__ == '__main__':
fixturesUtils.runTests(globals())
1 change: 0 additions & 1 deletion test/lib/mayaUsd/render/mayaToHydra/testFootPrintNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ def test_MultipleViewports(self):
#Test loading a scene
def test_Load(self):
with PluginLoaded('mayaHydraFootPrintNode'):
cmds.file(new=True, force=True)
testFile = mayaUtils.openTestScene(
"testFootPrintNode",
"testFootPrintNodeSaved.ma")
Expand Down
34 changes: 34 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/testGrid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2024 Autodesk
#
# 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

class TestGrid(mtohUtils.MayaHydraBaseTestCase):
# MayaHydraBaseTestCase.setUpClass requirement.
_file = __file__

IMAGE_DIFF_FAIL_THRESHOLD = 0.15
IMAGE_DIFF_FAIL_PERCENT = 2

def test_Grid(self):
cmds.grid(toggle=True)
self.assertSnapshotClose("grid_enabled.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
cmds.grid(toggle=False)
self.assertSnapshotClose("grid_disabled.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

if __name__ == '__main__':
fixturesUtils.runTests(globals())
2 changes: 0 additions & 2 deletions test/lib/mayaUsd/render/mayaToHydra/testMayaLights.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ def verifyLightingModes(self, shadowOn):

#Test maya lights (e.g., default,directional,point,spot,etc.) with a maya native sphere and usd sphere.
def test_MayaLights(self):
cmds.file(new=True, force=True)

# Load a maya scene with a maya native sphere, usd sphere and some lights, with HdStorm already being the viewport renderer.
# The sphere is not at the origin on purpose
testFile = mayaUtils.openTestScene(
Expand Down
2 changes: 0 additions & 2 deletions test/lib/mayaUsd/render/mayaToHydra/testMtohBasicRender.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class TestSnapshot(mtohUtils.MayaHydraBaseTestCase):
_file = __file__

def test_flat_orange(self):
cmds.file(new=1, f=1)

Comment on lines -29 to -30
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test hasn't been enabled in over a year; see the test CMakeLists. I updated it on principle in case we bring it back and based on how I think it should be updated, but I haven't actually run it.

activeEditor = cmds.playblast(activeEditor=1)

# Note that we use the default viewport2 renderer, because we're not testing
Expand Down
3 changes: 2 additions & 1 deletion test/lib/mayaUsd/render/mayaToHydra/testMtohDagChanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import maya.mel

import fixturesUtils
import mayaUtils
import mtohUtils

class TestDagChanges(mtohUtils.MayaHydraBaseTestCase):
Expand Down Expand Up @@ -271,7 +272,7 @@ def test_node_creation_undo(self):

cmds.undoInfo(state=0)
try:
cmds.file(new=1, f=1)
mayaUtils.openNewScene()
Comment on lines -274 to +275
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test hasn't been enabled in over a year; see the test CMakeLists. I updated it on principle in case we bring it back and based on how I think it should be updated, but I haven't actually run it.

self.setBasicCam()

self.setHdStormRenderer()
Expand Down
2 changes: 0 additions & 2 deletions test/lib/mayaUsd/render/mayaToHydra/testObjectTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class TestObjectTemplate(mtohUtils.MayaHydraBaseTestCase): #Subclassing mtohUtil

#Test object display & selection when template attribute is on.
def test_ObjectTemplate(self):
cmds.file(new=True, force=True)

# Load a maya scene with a maya native sphere
testFile = mayaUtils.openTestScene(
"testObjectTemplate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ class TestUsdStagePayloadsAndReferences(mtohUtils.MayaHydraBaseTestCase): #Subcl
IMAGE_DIFF_FAIL_PERCENT = 2

def loadUsdPayloadScene(self):
cmds.file(new=True, force=True)
mayaUtils.openTestScene(
"testStagePayloadsReferences",
"FlowerPot.ma")
self.setHdStormRenderer()
cmds.refresh()

def loadUsdReferencesScene(self):
cmds.file(new=True, force=True)
mayaUtils.openTestScene(
"testStagePayloadsReferences",
"References.ma")
Expand All @@ -49,7 +47,7 @@ def setUpReferenceScene(self):
from mayaUsd import lib as mayaUsdLib
import mayaUsd_createStageWithNewLayer

cmds.file(new=True, force=True)
mayaUtils.openNewScene()

# Create a simple scene with a Def prim with a USD reference.
psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
Expand All @@ -66,7 +64,7 @@ def setUpReferenceScene(self):
self.setHdStormRenderer()

def setUpPayloadScene(self):
cmds.file(new=True, force=True)
mayaUtils.openNewScene()
import mayaUsd_createStageWithNewLayer
from mayaUsd import lib as mayaUsdLib
import usdUtils
Expand Down
1 change: 0 additions & 1 deletion test/lib/mayaUsd/render/mayaToHydra/testStageVariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def test_UsdStageVariants(self):
from mayaUsd import lib as mayaUsdLib
# usdUtils imports mayaUsd.ufe
import usdUtils
cmds.file(new=True, force=True)

testFile = mayaUtils.openTestScene(
"testStageVariants",
Expand Down
2 changes: 0 additions & 2 deletions test/lib/mayaUsd/render/mayaToHydra/testStandardSurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class TestStandardSurface(mtohUtils.MayaHydraBaseTestCase): #Subclassing mtohUti

#Test the translation from maya standard surface with a maya native plane to usd preview surface.
def test_StandardSurface(self):
cmds.file(new=True, force=True)

# Load a maya scene with a maya native plane, which has autodesk standard surface as material
testFile = mayaUtils.openTestScene(
"testStandardSurface",
Expand Down
3 changes: 2 additions & 1 deletion test/lib/mayaUsd/render/mayaToHydra/testTransforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import maya.cmds as cmds

import fixturesUtils
import mayaUtils
import mtohUtils

class TestTransforms(mtohUtils.MayaHydraBaseTestCase):
Expand Down Expand Up @@ -59,7 +60,7 @@ def test_usdPrim(self):
import mayaUsd_createStageWithNewLayer
from pxr import UsdGeom, Gf

cmds.file(new=True, force=True)
mayaUtils.openNewScene()
self.setBasicCam(10)
self.setHdStormRenderer()

Expand Down
2 changes: 0 additions & 2 deletions test/lib/mayaUsd/render/mayaToHydra/testUSDLights.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def verifyLightingModes(self, shadowOn):

#Test usd lights (e.g., disk,distant,dome,etc.) with a maya native sphere and usd sphere.
def test_USDLights(self):
cmds.file(new=True, force=True)

# Load a maya scene with a maya native sphere, usd sphere and some lights, with HdStorm already being the viewport renderer.
# The sphere is not at the origin on purpose
testFile = mayaUtils.openTestScene(
Expand Down
37 changes: 1 addition & 36 deletions test/testUtils/imageUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed a bunch of settings changes that were happening under the hood and moved them to an optional step when opening scenes (except camera as that one was never used). I kept defaultRenderGlobals.imageFormat because this is set based on the extension of the file name being passed in.

import os
import maya.cmds as cmds
import maya.mel
import mayaUtils
import subprocess

KNOWN_FORMATS = {
Expand All @@ -31,19 +29,8 @@
'bmp': 20,
'png': 32,
}
def resetDefaultLightIntensity():
"""If the current Maya version supports setting the default light intensity,
then restore it to 1 so snapshots look equal across versions."""
if maya.mel.eval("optionVar -exists defaultLightIntensity"):
maya.mel.eval("optionVar -fv defaultLightIntensity 1")
if cmds.attributeQuery('defaultLightIntensity', node='hardwareRenderingGlobals', exists=True):
cmds.setAttr('hardwareRenderingGlobals.defaultLightIntensity', 1.0)
resetDefaultLightIntensity()

def snapshot(outputPath, width=400, height=None, hud=False, grid=False, colorManagementEnabled=False, camera=None):
resetDefaultLightIntensity()
cmds.displayRGBColor('background', 0.36, 0.36, 0.36)

def snapshot(outputPath, width=400, height=None):
if height is None:
height = width

Expand All @@ -60,37 +47,15 @@ def snapshot(outputPath, width=400, height=None, hud=False, grid=False, colorMan

# save the old output image format
oldFormat = cmds.getAttr("defaultRenderGlobals.imageFormat")
# save the hud setting
oldHud = cmds.headsUpDisplay(q=1, layoutVisibility=1)
# save the grid setting
oldGrid = cmds.grid(q=1, toggle=1)
# save the old color management status
oldColorManagementEnabled = cmds.colorManagementPrefs(q=1, cmEnabled=1)

# Find the current model panel for playblasting
# to make sure the desired camera is set, if any
panel = mayaUtils.activeModelPanel()
oldCamera = cmds.modelPanel(panel, q=True, cam=True)
if camera:
cmds.modelEditor(panel, edit=True, camera=camera)

cmds.setAttr("defaultRenderGlobals.imageFormat", formatNum)
cmds.headsUpDisplay(layoutVisibility=hud)
cmds.grid(toggle=grid)
cmds.colorManagementPrefs(edit=True, cmEnabled=colorManagementEnabled)
try:
cmds.refresh()
cmds.playblast(cf=outputPath, viewer=False, format="image",
frame=cmds.currentTime(q=1), offScreen=1,
widthHeight=(width, height), percent=100)
finally:
cmds.setAttr("defaultRenderGlobals.imageFormat", oldFormat)
cmds.headsUpDisplay(layoutVisibility=oldHud)
cmds.grid(toggle=oldGrid)
cmds.colorManagementPrefs(edit=True, cmEnabled=oldColorManagementEnabled)

if camera:
cmds.lookThru(panel, oldCamera)

def imageDiff(imagePath1, imagePath2, verbose, fail, failpercent, hardfail,
warn, warnpercent, hardwarn, perceptual):
Expand Down
Loading
Loading