Skip to content

Commit

Permalink
HYDRA-1275 : modifs from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
lanierd-adsk committed Nov 22, 2024
1 parent e4c6283 commit f3ef2fb
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 55 deletions.
2 changes: 1 addition & 1 deletion lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ VtValue MayaHydraLightAdapter::GetLightParamValue(const TfToken& paramName)
const auto color = light.color();
return VtValue(GfVec3f(color.r, color.g, color.b));
} else if (paramName == HdLightTokens->intensity) {
float intensity = light.intensity();
auto intensity = light.intensity();
#if defined(HD_API_VERSION) && HD_API_VERSION >= 74 // For USD 24.11+
if( LightType() == HdPrimTypeTokens->simpleLight){
intensity /= M_PI;
Expand Down
5 changes: 2 additions & 3 deletions test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelect.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import maya.mel as mel
import usdUtils
from pxr import UsdGeom
from pxr import Usd
import testUtils

def enableIsolateSelect(modelPanel):
Expand Down Expand Up @@ -58,9 +57,9 @@ class TestIsolateSelect(mtohUtils.MayaHydraBaseTestCase):

@classmethod
def setUpClass(cls):
if Usd.GetVersion() >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'
super(TestIsolateSelect, cls).setUpClass()
if cls._usdVersion >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'

def setupScene(self):
proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def test_UsdKeepSelectionHighlighting(self):
#Switch to bounding box display mode, we should keep the selected items and their color
#For this snapshot and only for it, we need to modify the default lighting and reset it after the snapshot
cmds.modelEditor(panel, edit=True, displayAppearance="boundingBox")
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("Storm_BoundingBox_AllSelected.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.resetDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.resetDefaultLightIntensityByUsdVersion()

#Switch to wireframe on shaded display mode, we should keep the selected items and their color
cmds.modelEditor(panel, edit=True, displayAppearance="smoothShaded")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ def test_Authoring_Locator(self):
# Check that updating a parent's visibility works after creation
cmds.setAttr(locatorGrandParent + ".visibility", True)
#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("authoring_locator_visibility_on.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.resetDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.resetDefaultLightIntensityByUsdVersion()

# Check that changing the visibility on the shape itself works
cmds.setAttr(locatorShape + ".visibility", False)
self.assertSnapshotClose("authoring_locator_visibility_off.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
# Restore visibility
#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()
cmds.setAttr(locatorShape + ".visibility", True)
self.assertSnapshotClose("authoring_locator_visibility_on.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

Expand All @@ -97,15 +97,15 @@ def test_Authoring_Locator(self):
# Change the shape's transform directly
cmds.xform(cmds.listRelatives(locatorShape, parent=True)[0], translation=[-3,2,-1], rotation=[-15,10,-5], scale=[-2.5, 2.0, -1.5])
self.assertSnapshotClose("authoring_locator_shapeTransformChanged.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.resetDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.resetDefaultLightIntensityByUsdVersion()

def test_Authoring_UsdStage(self):
self.setBasicCam(10)

stageParent, stageShape = self.usdStageSetup()

#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()

# Hide/unhide parent
cmds.select(clear=True)
Expand All @@ -132,7 +132,7 @@ def test_Authoring_UsdStage(self):
cmds.xform(cmds.listRelatives(stageShape, parent=True)[0], translation=[-3,2,-1], rotation=[-15,10,-5], scale=[-2.5, 2.0, -1.5])
cmds.select(clear=True)
self.assertSnapshotAndCompareVp2("usdStage_shapeTransformChanged.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.resetDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.resetDefaultLightIntensityByUsdVersion()

def test_Playback_Locator(self):
self.setBasicCam(10)
Expand All @@ -151,14 +151,14 @@ def test_Playback_Locator(self):

cmds.currentTime(0)
#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("locator_playback_initial.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

cmds.currentTime(2)
self.assertSnapshotClose("locator_playback_translated.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

cmds.currentTime(7)
self.resetDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.resetDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("locator_playback_hidden.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

def test_Playback_UsdStage(self):
Expand All @@ -177,7 +177,7 @@ def test_Playback_UsdStage(self):
self.keyframeAttribute(stageParent, "translateX", 15)

#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()

cmds.currentTime(0)
self.assertSnapshotClose("usdStage_playback_initial.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
Expand All @@ -198,14 +198,14 @@ def test_Playback_UsdStage(self):

cmds.currentTime(7)
self.assertSnapshotSilhouetteClose("usdStage_playback_hidden.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.resetDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.resetDefaultLightIntensityByUsdVersion()

def test_UsdStageAnimatedPrim(self):
self.setBasicCam(10)

stageParent, stageTransform = self.usdStageAnimatedPrimSetup()
#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()

cmds.currentTime(0)
self.keyframeAttribute(stageParent, "translateY", 0)
Expand All @@ -223,7 +223,7 @@ def test_UsdStageAnimatedPrim(self):
cmds.select(clear=True)
self.assertSnapshotClose("usdStageAnimatedPrim_t" + str(time) + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

self.resetDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.resetDefaultLightIntensityByUsdVersion()

self.setViewport2Renderer()
for time in checkedTimes:
Expand Down
7 changes: 3 additions & 4 deletions test/lib/mayaUsd/render/mayaToHydra/testFlowViewportAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import mtohUtils
import maya.mel as mel
from testUtils import PluginLoaded
from pxr import Usd

def setRotateY(matrixAsAList, angle):
''' Sets the matrix as a list of values to be a Rotate about Y matrix (deg), and returns it'''
Expand All @@ -42,9 +41,9 @@ class TestFlowViewportAPI(mtohUtils.MayaHydraBaseTestCase): #Subclassing mtohUti

@classmethod
def setUpClass(cls):
if Usd.GetVersion() >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'
super(TestFlowViewportAPI, cls).setUpClass()
if cls._usdVersion >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'

@classmethod
def tearDownClass(cls):
Expand All @@ -56,7 +55,7 @@ def setUp(self):
#call parent function first
super(TestFlowViewportAPI, self).setUp()
#modify light intensity for usd 24.11+
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()

def setupScene(self):
self.setHdStormRenderer()
Expand Down
7 changes: 3 additions & 4 deletions test/lib/mayaUsd/render/mayaToHydra/testFootPrintNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import mayaUtils
import maya.mel as mel
from testUtils import PluginLoaded
from pxr import Usd

HD_STORM = "HdStormRendererPlugin"
HD_STORM_OVERRIDE = "mayaHydraRenderOverride_" + HD_STORM
Expand All @@ -37,16 +36,16 @@ class TestFootPrintNode(mtohUtils.MayaHydraBaseTestCase): #Subclassing mtohUtils

@classmethod
def setUpClass(cls):
if Usd.GetVersion() >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'
super(TestFootPrintNode, cls).setUpClass()
if cls._usdVersion >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'

#This function is called before each test is launched
def setUp(self):
#call parent function first
super(TestFootPrintNode, self).setUp()
#modify light intensity for usd 24.11+
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()

def tearDown(self):
#is called after each test : finish by a File New command to check that it's not crashing when cleaning up everything'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from testUtils import PluginLoaded
import platform
import unittest
from pxr import Usd

class TestMayaDefaultMaterial(mtohUtils.MayaHydraBaseTestCase): #Subclassing mtohUtils.MayaHydraBaseTestCase to be able to call self.assertSnapshotClose
# MayaHydraBaseTestCase.setUpClass requirement.
Expand All @@ -33,9 +32,9 @@ class TestMayaDefaultMaterial(mtohUtils.MayaHydraBaseTestCase): #Subclassing mto

@classmethod
def setUpClass(cls):
if Usd.GetVersion() >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'
super(TestMayaDefaultMaterial, cls).setUpClass()
if cls._usdVersion >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'

def test_MayaDefaultMaterial(self):

Expand Down
2 changes: 1 addition & 1 deletion test/lib/mayaUsd/render/mayaToHydra/testRefinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUp(self):
#call parent function first
super(TestRefinement, self).setUp()
#modify light intensity for usd 24.11+
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()

def verifySnapshot(self, imageName):
cmds.refresh()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_UsdStagePayloadsOnTheFly(self):
def test_UsdStagePayloadsFromScene(self):
from mayaUsd import lib as mayaUsdLib
self.loadUsdPayloadScene()
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("payloadSceneLoadedPotA.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

#Change the variant
Expand All @@ -160,11 +160,11 @@ def test_UsdStagePayloadsFromScene(self):

def test_UsdStageReferences(self):
self.setUpReferenceScene()
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("referencesSceneCreated.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

self.loadUsdReferencesScene()
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("referencesSceneLoaded.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion test/lib/mayaUsd/render/mayaToHydra/testStageVariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_UsdStageVariants(self):
self.assertEqual(modVariant.GetVariantSelection(), 'OneCube')

#modify light intensity for usd 24.11+
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()

#Select the USD Cubes to see the selection highlight
cubesPath = ufe.Path([
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 @@ -75,7 +75,7 @@ def test_usdPrim(self):
childPrimCube = stage.DefinePrim(childCube, 'Cube')

#modify light intensity for usd 24.11+
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()

self.verifySnapshot("usd_cube_untransformed.png")

Expand All @@ -97,6 +97,7 @@ def test_usdPrim(self):
UsdGeom.XformCommonAPI(parentPrimA).SetScale((2, 3, 2))
self.verifySnapshot("usd_cube_parent_moved_rotated_scaled.png")

self.resetDefaultLightIntensityByUsdVersion()

if __name__ == '__main__':
fixturesUtils.runTests(globals())
8 changes: 4 additions & 4 deletions test/lib/mayaUsd/render/mayaToHydra/testViewportFilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ def ikHandleCreator():
self.stackInstances(ikHandleCreator, 50, [0, 0, 0.005])
cmds.select(all=True)
#For this snapshot with usd 24.11+, we need to modify the default lighting and reset it after the snapshot
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()
self.checkFilter("ikHandles", kExcludeIkHandles, 5)
self.resetDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.resetDefaultLightIntensityByUsdVersion()

def test_Joints(self):
def jointCreator():
Expand Down Expand Up @@ -222,9 +222,9 @@ def test_Strokes(self):
mayaUtils.openTestScene("testViewportFilters", "strokes.ma")
self.setHdStormRenderer()
#For this snapshot with usd 24.11+, we need to modify the default lighting and reset it after the snapshot
self.modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.modifyDefaultLightIntensityByUsdVersion()
self.checkFilter("strokes", kExcludeStrokes, 4)
self.resetDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11()
self.resetDefaultLightIntensityByUsdVersion()

# TODO : Texture Placements (not working in Hydra as of 2024-05-03)

Expand Down
41 changes: 25 additions & 16 deletions test/testUtils/mtohUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import platform
import subprocess
import sys
import math

HD_STORM = "HdStormRendererPlugin"
HD_STORM_OVERRIDE = "mayaHydraRenderOverride_" + HD_STORM
Expand All @@ -53,6 +54,9 @@ class MayaHydraBaseTestCase(unittest.TestCase, ImageDiffingTestCase):
_requiredPlugins = []
_pluginsToUnload = []

#The OpenUSD version
_usdVersion = None

# Unloading mayaHydraFlowViewportAPILocator crashes Maya (HYDRA-1304).
# Unloading mtoa succeeds on Linux, but fails on Windows and macOS
# with "cannot be unloaded because it is still in use" error.
Expand Down Expand Up @@ -93,6 +97,9 @@ def setUpClass(cls):
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

#Set the usd version
cls._usdVersion = Usd.GetVersion()

def setUp(self):
# Maya is not closed/reset between each test of a test suite,
Expand Down Expand Up @@ -139,22 +146,24 @@ def setBasicCam(self, dist=DEFAULT_CAM_DIST):
cmds.setAttr('persp.rotate', -30, 45, 0, type='float3')
cmds.setAttr('persp.translate', dist, .75 * dist, dist, type='float3')

def modifyDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11(self):
#For Usd 24.11+ set the default light intensity to PI instead of 1.0 to counter balance the changes in usd 24.11
#This can be called after the original setUp function which sets the default light to 1
if Usd.GetVersion() >= (0, 24, 11):
if maya.mel.eval("optionVar -exists defaultLightIntensity"):
maya.mel.eval("optionVar -fv defaultLightIntensity 3.1415")
if cmds.attributeQuery('defaultLightIntensity', node='hardwareRenderingGlobals', exists=True):
cmds.setAttr('hardwareRenderingGlobals.defaultLightIntensity', 3.1415)

def resetDefaultLightIntensityIfUsdGreaterOrEqualTo_24_11(self):
#For Usd 24.11+ reset the default light intensity to 1 instead of PI to counter balance the changes in usd 24.11
if Usd.GetVersion() >= (0, 24, 11):
if maya.mel.eval("optionVar -exists defaultLightIntensity"):
maya.mel.eval("optionVar -fv defaultLightIntensity 1.0")
if cmds.attributeQuery('defaultLightIntensity', node='hardwareRenderingGlobals', exists=True):
cmds.setAttr('hardwareRenderingGlobals.defaultLightIntensity', 1.0)
def setMayaDefaultLightIntensity(self, intensity):
if maya.mel.eval("optionVar -exists defaultLightIntensity"):
maya.mel.eval("optionVar -fv defaultLightIntensity {}".format(intensity))
if cmds.attributeQuery('defaultLightIntensity', node='hardwareRenderingGlobals', exists=True):
cmds.setAttr('hardwareRenderingGlobals.defaultLightIntensity', intensity)

def modifyDefaultLightIntensityByUsdVersion(self):
#Add any new case here
if self._usdVersion >= (0, 24, 11):
#For Usd 24.11+ set the default light intensity to PI instead of 1.0 to counter balance the changes in usd 24.11
#The original setUp() function sets the default light to 1.0
self.setMayaDefaultLightIntensity(math.pi)

def resetDefaultLightIntensityByUsdVersion(self):
#Add any case for here
if self._usdVersion >= (0, 24, 11):
#For Usd 24.11+ reset the default light intensity to 1 instead of PI to counter balance the changes in usd 24.11
self.setMayaDefaultLightIntensity(1.0)

def makeCubeScene(self, camDist=DEFAULT_CAM_DIST):
mayaUtils.openNewScene()
Expand Down

0 comments on commit f3ef2fb

Please sign in to comment.