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

MAYA-112608: add grouping with absolute, relative, world flags. #1600

Merged
merged 7 commits into from
Jul 29, 2021
Merged
Changes from 1 commit
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
91 changes: 80 additions & 11 deletions test/lib/ufe/testGroupCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

import mayaUsd.ufe

from pxr import Kind
from pxr import Usd
from pxr import Kind, Usd, UsdGeom, Vt

from maya import cmds
from maya import standalone
Expand All @@ -35,6 +34,38 @@
import os
import unittest

def createStage():
''' create a simple stage '''
cmds.file(new=True, force=True)
import mayaUsd_createStageWithNewLayer
proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
proxyShapes = cmds.ls(type="mayaUsdProxyShapeBase", long=True)
proxyShapePath = proxyShapes[0]
proxyShapeItem = ufe.Hierarchy.createItem(ufe.PathString.path(proxyShapePath))
proxyShapeContextOps = ufe.ContextOps.contextOps(proxyShapeItem)
stage = mayaUsd.lib.GetPrim(proxyShapePath).GetStage()
return (stage, proxyShapePathStr, proxyShapeItem, proxyShapeContextOps)

class SphereGenerator():
''' simple sphere generator '''
def __init__(self, num, contextOp, proxyShapePathStr):
self.gen = self.__generate(num)
self.num = num
self.contextOp = contextOp
self.proxyShapePathStr = proxyShapePathStr

def createSphere(self):
return next(self.gen)

def __addPrimSphere(self, increment):
self.contextOp.doOp(['Add New Prim', 'Sphere'])
return ufe.PathString.path('{},/Sphere{}'.format(self.proxyShapePathStr, increment))

def __generate(self, num):
increment = 0
while increment < self.num:
increment += 1
yield self.__addPrimSphere(increment)

class GroupCmdTestCase(unittest.TestCase):
'''Verify the Maya group command, for multiple runtimes.
Expand Down Expand Up @@ -99,7 +130,7 @@ def testUsdGroup(self):
self.assertEqual("ballset.usda", layer.GetDisplayName())
stage.SetEditTarget(layer)

if (ufeUtils.ufeFeatureSetVersion() >= 3):
if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3000'):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Guard against UFEV3.1.

# group
groupName = cmds.group(ufe.PathString.string(ball5Path),
ufe.PathString.string(ball3Path), n="newGroup")
Expand All @@ -124,7 +155,7 @@ def testUsdGroup(self):

# The command will now append a number 1 at the end to match the naming
# convention in Maya.
if (ufeUtils.ufeFeatureSetVersion() >= 3):
if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3000'):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Guard against UFEV3.1.

newGroupPath = parentPath + ufe.PathComponent(groupName)
else:
newGroupPath = parentPath + ufe.PathComponent("newGroup1")
Expand All @@ -141,13 +172,19 @@ def testUsdGroup(self):
self.assertTrue(ball5Path not in childPaths)
self.assertTrue(ball3Path not in childPaths)

if ufeUtils.ufeFeatureSetVersion() >= 3:
if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3000'):
cmds.undo()
else:
groupCmd.undo()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test now uses the cmds::undo() and cmds::redo() instead of groupCmd.


# gloabl selection should not be empty after undo.
self.assertEqual(len(globalSelection), 1)
if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3004'):
pass
# TODO: for some strange reasons the globalSelection returns 0??
# I tried the same steps in interactive Maya and it correctly returns 2
# self.assertEqual(len(globalSelection), 2)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ppt-adsk I am going to investigate this tomorrow morning. For some odd reasons the globalSelection length after undo is reported az 0. This can't be true, since there are 2 items in selection after undo.

I tried the exact same steps in interactive Maya and it all behaves as expected.

else:
self.assertEqual(len(globalSelection), 1)

parentChildrenUndo = parentHierarchy.children()
self.assertEqual(len(parentChildrenUndo), 6)
Expand Down Expand Up @@ -323,22 +360,54 @@ def testGroupRestirction(self):
stage.GetPrimAtPath("/Ball_set/Props/Ball_6"),
stage.GetPrimAtPath("/Sphere1")])

@unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupAbsolute only available in UFE v3 or greater.')
@unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupAbsolute is only available in UFE preview version 0.3.5 and greater')
def testGroupAbsolute(self):
'''Verify -absolute flag.'''
pass

@unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupRelative only available in UFE v3 or greater.')
cmds.file(new=True, force=True)

# create a stage
(stage, proxyShapePathStr, proxyShapeItem, contextOp) = createStage();

# create a sphere generator
sphereGen = SphereGenerator(2, contextOp, proxyShapePathStr)

spherePath = sphereGen.createSphere()
spherePrim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(spherePath))

# no TRS attributes
self.assertFalse(spherePrim.HasAttribute('xformOp:translate'))
self.assertFalse(spherePrim.HasAttribute('xformOp:rotateXYZ'))
self.assertFalse(spherePrim.HasAttribute('xformOp:scale'))

# create a group with absolute flag set to True
cmds.group(ufe.PathString.string(spherePath), absolute= True)

# verify that groupItem has 1 child
groupItem = ufe.GlobalSelection.get().front()
groupHierarchy = ufe.Hierarchy.hierarchy(groupItem)
self.assertEqual(len(groupHierarchy.children()), 1)

# verify XformOpOrderAttr exist after grouping
newspherePrim = stage.GetPrimAtPath("/group1/Sphere1")
sphereXformable = UsdGeom.Xformable(newspherePrim)

self.assertEqual(
sphereXformable.GetXformOpOrderAttr().Get(), Vt.TokenArray((
"xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale")))


@unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupRelative is only available in UFE preview version 0.3.5 and greater')
def testGroupRelative(self):
'''Verify -relative flag.'''
pass

@unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupWorld only available in UFE v3 or greater.')
@unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupWorld is only available in UFE preview version 0.3.5 and greater')
def testGroupWorld(self):
'''Verify -world flag.'''
pass

@unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupHierarchyAfterUndoRedo only available in UFE v3 or greater.')
@unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupHierarchyAfterUndoRedo is only available in UFE preview version 0.3.5 and greater')
def testGroupHierarchyAfterUndoRedo(self):
'''Verify grouping after multiple undo/redo.'''
pass
Expand Down