From 55e89a21bcefe845c96b83f65b1c28b2e0ebb93e Mon Sep 17 00:00:00 2001 From: Pierre Tremblay Date: Fri, 10 Jun 2022 15:11:07 -0400 Subject: [PATCH] Test pixelMove UFE support. --- test/lib/ufe/CMakeLists.txt | 1 + test/lib/ufe/testPixelMoveCmd.py | 95 ++++++++++++++++++++++++++++++++ test/testUtils/mayaUtils.py | 10 ++++ 3 files changed, 106 insertions(+) create mode 100644 test/lib/ufe/testPixelMoveCmd.py diff --git a/test/lib/ufe/CMakeLists.txt b/test/lib/ufe/CMakeLists.txt index 4a19300f31..e27dbdaf2c 100644 --- a/test/lib/ufe/CMakeLists.txt +++ b/test/lib/ufe/CMakeLists.txt @@ -43,6 +43,7 @@ if(CMAKE_UFE_V2_FEATURES_AVAILABLE) ) list(APPEND INTERACTIVE_TEST_SCRIPT_FILES + testPixelMoveCmd.py testUIIcons.py ) endif() diff --git a/test/lib/ufe/testPixelMoveCmd.py b/test/lib/ufe/testPixelMoveCmd.py new file mode 100644 index 0000000000..09b251ddc1 --- /dev/null +++ b/test/lib/ufe/testPixelMoveCmd.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +# +# Copyright 2022 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 unittest +import mayaUtils +import ufeUtils +import fixturesUtils +from testUtils import assertVectorAlmostEqual, assertVectorNotAlmostEqual + +import mayaUsd.lib + +from maya import cmds +from maya import standalone + +import ufe + +@unittest.skipUnless(mayaUtils.ufeSupportFixLevel() > 0, "Requires pixelMove UFE support.") +class PixelMoveCmdTestCase(unittest.TestCase): + + @classmethod + def setUpClass(cls): + fixturesUtils.readOnlySetUpClass(__file__, initializeStandalone=False) + + def setUp(self): + cmds.file(new=True, force=True) + cmds.select(clear=True) + + def testPixelMove(self): + '''Pixel move command must move non-Maya UFE objects.''' + + # pixelMove has different behavior for orthographic and perspective + # views. Only perspective views are affected by the selected objects' + # bounding boxes. pixelMove sets the view plane origin to be the + # centroid of the bounding box of the selected objects. + + # Save the current camera. + currentCamera = cmds.lookThru(q=True) + + # Use default perspective camera + cmds.lookThru('persp') + + # Create a simple USD scene. Also create a Maya object: this will be + # our reference. + import mayaUsd_createStageWithNewLayer + + psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer() + stage = mayaUsd.lib.GetPrim(psPathStr).GetStage() + stage.DefinePrim('/A', 'Xform') + xformItem = ufeUtils.createItem('|stage1|stageShape1,/A') + + mayaGroup = cmds.group(empty=True) + mayaGroupXlate = cmds.getAttr(mayaGroup+'.translate')[0] + assertVectorAlmostEqual(self, mayaGroupXlate, [0, 0, 0]) + + # Run pixelMove on the Maya object. This will be our reference. + cmds.pixelMove(0, 1) + mayaGroupXlate = cmds.getAttr(mayaGroup+'.translate')[0] + assertVectorNotAlmostEqual(self, mayaGroupXlate, [0, 0, 0]) + + # pixelMove operates only on the selection, not on a commmand line + # argument. + sn = ufe.GlobalSelection.get() + sn.clear() + sn.append(xformItem) + + # Initially the object translation is the identity. + t3d = ufe.Transform3d.transform3d(xformItem) + + self.assertEqual(t3d.translation().vector, [0, 0, 0]) + + # Run pixelMove on the USD object. It must match the Maya values. + cmds.pixelMove(0, 1) + + assertVectorAlmostEqual(self, t3d.translation().vector, mayaGroupXlate) + + # Restore previous camera. + cmds.lookThru(currentCamera) + +if __name__ == '__main__': + fixturesUtils.runTests(globals()) diff --git a/test/testUtils/mayaUtils.py b/test/testUtils/mayaUtils.py index 3be98faba4..2f7828af05 100644 --- a/test/testUtils/mayaUtils.py +++ b/test/testUtils/mayaUtils.py @@ -298,6 +298,16 @@ def mayaMajorMinorVersions(): """ return (mayaMajorVersion(), mayaMinorVersion()) +def ufeSupportFixLevel(): + ''' + Return the fix level defined in the UFE support package. This is used + to determine the presence of a UFE-related feature or bug fix in Maya that + does not depend on a version of UFE itself. + ''' + import maya.internal.ufeSupport.utils as ufeSupportUtils + return ufeSupportUtils.fixLevel() if hasattr(ufeSupportUtils, 'fixLevel') \ + else 0 + def activeModelPanel(): """Return the model panel that will be used for playblasting etc...""" for panel in cmds.getPanel(type="modelPanel"):