Skip to content

Commit

Permalink
HYDRA-1161 : Add a unit test for selection highlight of usd instancea… (
Browse files Browse the repository at this point in the history
#218)

* HYDRA-1161 : Add a unit test for selection highlight of usd instanceable prims
Disable the testMaterialXOnNative unit test until get get a build of lookdevX.

* fix indentation

* Adding that this test is only for usd 24.11+

* Fixing maya version in the scene
  • Loading branch information
lanierd-adsk authored Dec 6, 2024
1 parent 2c0003c commit 4e1434e
Show file tree
Hide file tree
Showing 12 changed files with 440 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(INTERACTIVE_TEST_SCRIPT_FILES
testStageAddPrim.py
testTransforms.py
testRefinement.py
testMaterialXOnNative.py|depOnPlugins:lookdevx
#testMaterialXOnNative.py|depOnPlugins:lookdevx HYDRA-1320 : disable this test until we get a new build of lookdevX
testNewSceneWithStage.py
# To be reenabled after investigation
#testMayaDisplayModes.py|skipOnPlatform:osx
Expand Down Expand Up @@ -54,6 +54,7 @@ set(INTERACTIVE_TEST_SCRIPT_FILES
testCustomShadersNode.py
testMayaDefaultMaterial.py
testMayaLightingModes.py
testStageInstanceablePrimsSelHighlight.py
cpp/testColorPreferences.py
cpp/testCppFramework.py
cpp/testDataProducerExample.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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#
# 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 ufe

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

IMAGE_DIFF_FAIL_THRESHOLD = 0.1
IMAGE_DIFF_FAIL_PERCENT = 0.3

def SelectAndDoSnapshots( self, cylinderItems, sphereItem, snapshotSuffix):
self.assertIsNotNone(cylinderItems)
self.assertIsNotNone(sphereItem)
#Select the cylinder and do a snapshot
ufe.GlobalSelection.get().clear()
ufe.GlobalSelection.get().append(cylinderItems)
cylinderSnapshotName = "cylSel"+ snapshotSuffix +".png"
self.assertSnapshotClose(cylinderSnapshotName, self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

#Select the sphere and do a snapshot
ufe.GlobalSelection.get().clear()
ufe.GlobalSelection.get().append(sphereItem)
sphereSnapshotName = "spherSel"+ snapshotSuffix +".png"
self.assertSnapshotClose(sphereSnapshotName, self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

def test_UsdStageInstanceablePrimsSelHighlight(self):
import usdUtils # usdUtils imports mayaUsd.ufe
from mayaUsd import lib as mayaUsdLib

if self._usdVersion < (0, 24, 11): #This test is only working with usd 24.11+
return

#Load a scene with a usd stage with 2 prims that have a Hierarchy
#Cylinder1 is the parent of Sphere1
testFile = mayaUtils.openTestScene(
"testStageInstanceablePrimsSelHighlight",
"testInstanceablePrimsSelHighlight.ma")
self.setHdStormRenderer()
cmds.refresh()

#Get the usd prims
mayaUsdProxyShapeNode = "stageShape1"
theStage = mayaUsdLib.GetPrim(mayaUsdProxyShapeNode).GetStage()

cylinderPrim = theStage.GetPrimAtPath('/Root/Cylinder1')
self.assertIsNotNone(cylinderPrim)
spherePrim = theStage.GetPrimAtPath('/Root/Cylinder1/Sphere1')
self.assertIsNotNone(spherePrim)

#Creater the ufe paths to the cylinder and sphere prims
cylinderPath = ufe.Path([
mayaUtils.createUfePathSegment("|stage1|stageShape1"), #|stage1|stageShape1 is the UFE path to the proxy shape node
usdUtils.createUfePathSegment("/Root/Cylinder1")])
cylinderItems = ufe.Hierarchy.createItem(cylinderPath)
self.assertIsNotNone(cylinderItems)

spherePath = ufe.Path([
mayaUtils.createUfePathSegment("|stage1|stageShape1"), #|stage1|stageShape1 is the UFE path to the proxy shape node
usdUtils.createUfePathSegment("/Root/Cylinder1/Sphere1")])
sphereItem = ufe.Hierarchy.createItem(spherePath)
self.assertIsNotNone(sphereItem)

#Select the cylinder and sphere alternativelely and do snapshots
self.SelectAndDoSnapshots(cylinderItems, sphereItem, "")

#Set the cylinder only as instanceable
cylinderPrim.SetInstanceable(True)
self.assertTrue(cylinderPrim.IsInstanceable())
self.assertFalse(spherePrim.IsInstanceable())
self.SelectAndDoSnapshots(cylinderItems, sphereItem, "_Cyl_Inst")

#Set the sphere and cylinder as instanceable
spherePrim.SetInstanceable(True)
self.assertTrue(spherePrim.IsInstanceable())
self.assertTrue(cylinderPrim.IsInstanceable())
self.SelectAndDoSnapshots(cylinderItems, sphereItem, "_Cyl_Spher_Inst")

#Set the sphere only as instanceable
cylinderPrim.SetInstanceable(False)
self.assertFalse(cylinderPrim.IsInstanceable())
self.assertTrue(spherePrim.IsInstanceable())
self.SelectAndDoSnapshots(cylinderItems, sphereItem, "_Spher_Inst")

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

0 comments on commit 4e1434e

Please sign in to comment.