-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HYDRA-803 : add a test for USd stage references and payloads
- Loading branch information
1 parent
def1947
commit 8412215
Showing
23 changed files
with
845 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+2.05 KB
...aUsd/render/mayaToHydra/StagePayloadsReferencesTest/cubeLoadWithDescendants.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.05 KB
test/lib/mayaUsd/render/mayaToHydra/StagePayloadsReferencesTest/cubeLoaded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.53 KB
test/lib/mayaUsd/render/mayaToHydra/StagePayloadsReferencesTest/cubeUnloaded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.53 KB
...lib/mayaUsd/render/mayaToHydra/StagePayloadsReferencesTest/cubeUnloadedRedo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.05 KB
...lib/mayaUsd/render/mayaToHydra/StagePayloadsReferencesTest/cubeUnloadedUndo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.53 KB
test/lib/mayaUsd/render/mayaToHydra/StagePayloadsReferencesTest/initialState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23 KB
...yaUsd/render/mayaToHydra/StagePayloadsReferencesTest/payloadSceneLoadedPotA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23.6 KB
...yaUsd/render/mayaToHydra/StagePayloadsReferencesTest/payloadSceneLoadedPotB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.05 KB
...yaUsd/render/mayaToHydra/StagePayloadsReferencesTest/referencesSceneCreated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.4 KB
...ayaUsd/render/mayaToHydra/StagePayloadsReferencesTest/referencesSceneLoaded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
174 changes: 174 additions & 0 deletions
174
test/lib/mayaUsd/render/mayaToHydra/testStagePayloadsReferences.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
# | ||
# 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 unittest | ||
import testUtils | ||
import mayaUtils | ||
import usdUtils | ||
import ufe | ||
import usdUfe | ||
from pxr import Usd, Sdf | ||
|
||
class TestUsdStagePayloadsAndReferences(mtohUtils.MtohTestCase): #Subclassing mtohUtils.MtohTestCase to be able to call self.assertSnapshotClose | ||
# MayaHydraBaseTestCase.setUpClass requirement. | ||
_file = __file__ | ||
|
||
IMAGE_DIFF_FAIL_THRESHOLD = 0.1 | ||
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") | ||
self.setHdStormRenderer() | ||
cmds.refresh() | ||
|
||
def setUpReferenceScene(self): | ||
from mayaUsd import lib as mayaUsdLib | ||
import mayaUsd_createStageWithNewLayer | ||
|
||
cmds.file(new=True, force=True) | ||
|
||
# Create a simple scene with a Def prim with a USD reference. | ||
psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer() | ||
psPath = ufe.PathString.path(psPathStr) | ||
ps = ufe.Hierarchy.createItem(psPath) | ||
stage = mayaUsdLib.GetPrim(psPathStr).GetStage() | ||
aPrim = stage.DefinePrim('/A', 'Xform') | ||
|
||
sphereFile = testUtils.getTestScene("testStagePayloadsReferences", "cube.usda") | ||
sdfRef = Sdf.Reference(sphereFile) | ||
primRefs = aPrim.GetReferences() | ||
primRefs.AddReference(sdfRef) | ||
self.assertTrue(aPrim.HasAuthoredReferences()) | ||
self.setHdStormRenderer() | ||
|
||
def setUpPayloadScene(self): | ||
cmds.file(new=True, force=True) | ||
import mayaUsd_createStageWithNewLayer | ||
from mayaUsd import lib as mayaUsdLib | ||
|
||
self.setHdStormRenderer() | ||
|
||
# Create the following hierarchy: | ||
# | ||
# proxy shape | ||
# |_ A | ||
# |_ B | ||
# | ||
|
||
psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer() | ||
self.stage = mayaUsdLib.GetPrim(psPathStr).GetStage() | ||
self.stage.DefinePrim('/A', 'Xform') | ||
self.stage.DefinePrim('/B', 'Xform') | ||
|
||
psPath = ufe.PathString.path(psPathStr) | ||
psPathSegment = psPath.segments[0] | ||
aPath = ufe.Path([psPathSegment, usdUtils.createUfePathSegment('/A')]) | ||
bPath = ufe.Path([psPathSegment, usdUtils.createUfePathSegment('/B')]) | ||
self.a = ufe.Hierarchy.createItem(aPath) | ||
self.b = ufe.Hierarchy.createItem(bPath) | ||
|
||
cmds.select(clear=True) | ||
|
||
@unittest.skipUnless(mtohUtils.checkForMayaUsdPlugin(), "Requires Maya USD Plugin.") | ||
def test_UsdStagePayloadsOnTheFly(self): | ||
import mayaUsd.ufe | ||
|
||
self.setUpPayloadScene() | ||
|
||
primUfePath = "|stage1|stageShape1,/A" | ||
prim = mayaUsd.ufe.ufePathToPrim(primUfePath) | ||
|
||
# Verify initial state | ||
self.assertFalse(prim.HasPayload()) | ||
self.assertSnapshotClose("initialState.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
payloadFile = testUtils.getTestScene('testStagePayloadsReferences', 'cube.usda') | ||
cmd = usdUfe.AddPayloadCommand(prim, payloadFile, True) | ||
self.assertIsNotNone(cmd) | ||
|
||
# Verify state after add payload | ||
cmd.execute() | ||
self.assertTrue(prim.HasPayload()) | ||
self.assertTrue(prim.IsLoaded()) | ||
self.assertSnapshotClose("cubeLoaded.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
# Verify unload payload | ||
cmd = usdUfe.UnloadPayloadCommand(prim) | ||
self.assertIsNotNone(cmd) | ||
|
||
cmd.execute() | ||
self.assertFalse(prim.IsLoaded()) | ||
self.assertSnapshotClose("cubeUnloaded.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
cmd.undo() | ||
self.assertTrue(prim.IsLoaded()) | ||
self.assertSnapshotClose("cubeUnloadedUndo.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
cmd.redo() | ||
self.assertFalse(prim.IsLoaded()) | ||
self.assertSnapshotClose("cubeUnloadedRedo.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
# Verify load payload | ||
cmd = usdUfe.LoadPayloadCommand(prim, Usd.LoadWithDescendants) | ||
self.assertIsNotNone(cmd) | ||
|
||
cmd.execute() | ||
self.assertTrue(prim.IsLoaded()) | ||
self.assertSnapshotClose("cubeLoadWithDescendants.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
@unittest.skipUnless(mtohUtils.checkForMayaUsdPlugin(), "Requires Maya USD Plugin.") | ||
def test_UsdStagePayloadsFromScene(self): | ||
from mayaUsd import lib as mayaUsdLib | ||
self.loadUsdPayloadScene() | ||
self.assertSnapshotClose("payloadSceneLoadedPotA.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
#Change the variant | ||
shapeNode = "FlowerPotShape" | ||
shapeStage = mayaUsdLib.GetPrim(shapeNode).GetStage() | ||
rootPrim = shapeStage.GetPrimAtPath('/FlowerPot') | ||
self.assertFalse(rootPrim== None) | ||
modVariant = rootPrim.GetVariantSet('modelingVariant') | ||
self.assertFalse(modVariant== None) | ||
self.assertEqual(modVariant.GetVariantSelection(), 'FlowerPotA') | ||
|
||
modVariant.SetVariantSelection('FlowerPotB') | ||
self.assertEqual(modVariant.GetVariantSelection(), 'FlowerPotB') | ||
self.assertSnapshotClose("payloadSceneLoadedPotB.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
@unittest.skipUnless(mtohUtils.checkForMayaUsdPlugin(), "Requires Maya USD Plugin.") | ||
def test_UsdStageReferences(self): | ||
self.setUpReferenceScene() | ||
self.assertSnapshotClose("referencesSceneCreated.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
self.loadUsdReferencesScene() | ||
self.assertSnapshotClose("referencesSceneLoaded.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
if __name__ == '__main__': | ||
fixturesUtils.runTests(globals()) |
Binary file not shown.
Oops, something went wrong.