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

Test pixelMove UFE support. #2412

Merged
merged 1 commit into from
Jun 17, 2022
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
1 change: 1 addition & 0 deletions test/lib/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if(CMAKE_UFE_V2_FEATURES_AVAILABLE)
)

list(APPEND INTERACTIVE_TEST_SCRIPT_FILES
testPixelMoveCmd.py
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pixelMove requires a view and a camera, so must be an interactive test.

testUIIcons.py
)
endif()
Expand Down
95 changes: 95 additions & 0 deletions test/lib/ufe/testPixelMoveCmd.py
Original file line number Diff line number Diff line change
@@ -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.")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

UFE support for pixelMove is implemented at fix level 1, so don't run if fix level is below that.

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):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Test UFE pixelMove support by comparing with a Maya object. Move for Maya object and move for non-Maya object (i.e. USD) must match.

'''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'
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also test doing pixel move while looking through an ortho camera?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ortho camera pixel move is unaffected by the selection, and therefore did not require UFE-related changes. Testing pixel move with ortho camera is essentially testing Maya behavior, which plugins should simply rely on and expect (hope?) is tested in Maya.

# 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())
10 changes: 10 additions & 0 deletions test/testUtils/mayaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ def mayaMajorMinorVersions():
"""
return (mayaMajorVersion(), mayaMinorVersion())

def ufeSupportFixLevel():
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Return the newly-implemented UFE fix level, to determine if the UFE pixelMove support is present in Maya or not. fixLevel is implemented in Maya, in the ufeSupport.utils module. If the fixLevel function does not exist, returns 0.

'''
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"):
Expand Down