Skip to content

Commit 387a1fa

Browse files
authored
Merge pull request #2525 from Autodesk/tremblp/MAYA-122119/test_groupcmd
Added test for group pivot options Maya fix.
2 parents 47bcad8 + f33b582 commit 387a1fa

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

test/lib/ufe/testGroupCmd.py

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
import fixturesUtils
2020
import mayaUtils
2121
import testUtils
22+
from testUtils import assertVectorAlmostEqual
2223
import ufeUtils
2324
import usdUtils
2425

2526
import mayaUsd.ufe
2627

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

29-
from maya import cmds
30+
from maya import cmds, mel
3031
from maya import standalone
3132

3233
import ufe
3334

34-
import os
3535
import unittest
3636

3737
def createStage():
@@ -867,5 +867,71 @@ def checkAfter():
867867
cmds.redo()
868868
checkAfter()
869869

870+
def runTestGroupPivotOptions(self, doGroupCmd, expectPivot):
871+
'''Test group under parent with preserve position.'''
872+
873+
# Maya menu invokes doGroup MEL script, we'll do the same.
874+
#
875+
# doGroup 0 1 0: group under parent, preserve position, group pivot
876+
# center.
877+
# doGroup 0 1 1: group under parent, preserve position, group pivot
878+
# origin.
879+
#
880+
# Compare against Maya object behavior.
881+
882+
cmds.file(new=True, force=True)
883+
884+
sphere, _ = cmds.polySphere()
885+
v = [5, 0, 0]
886+
cmds.move(*v)
887+
# doGroup has no return value. It creates group1 and selects it.
888+
mel.eval(doGroupCmd)
889+
890+
# group transform is the identity.
891+
groupMayaXform = cmds.xform(q=True, matrix=True)
892+
rpMaya = cmds.xform(q=True, rotatePivot=True)
893+
spMaya = cmds.xform(q=True, scalePivot=True)
894+
identity = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0,
895+
0.0, 0.0, 0.0, 1.0]
896+
897+
assertVectorAlmostEqual(self, groupMayaXform, identity)
898+
assertVectorAlmostEqual(self, expectPivot, rpMaya, 6)
899+
assertVectorAlmostEqual(self, expectPivot, spMaya, 6)
900+
901+
# Do the same with USD.
902+
import mayaUsd_createStageWithNewLayer
903+
mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
904+
905+
psPathStr = '|stage1|stageShape1'
906+
stage = mayaUsd.lib.GetPrim(psPathStr).GetStage()
907+
xform = stage.DefinePrim('/Xform1', 'Xform')
908+
909+
cmds.select(psPathStr + ',/Xform1', r=True)
910+
cmds.move(*v)
911+
912+
mel.eval(doGroupCmd)
913+
groupPath = psPathStr + ',/group1'
914+
groupItem = ufeUtils.createItem(groupPath)
915+
t3d = ufe.Transform3d.transform3d(groupItem)
916+
917+
rpUsd = t3d.rotatePivot()
918+
spUsd = t3d.scalePivot()
919+
# Flatten out UFE matrices for comparison.
920+
groupUsdXform = [y for x in t3d.matrix().matrix for y in x]
921+
922+
assertVectorAlmostEqual(self, groupUsdXform, identity)
923+
assertVectorAlmostEqual(self, expectPivot, rpUsd.vector, 6)
924+
assertVectorAlmostEqual(self, expectPivot, spUsd.vector, 6)
925+
926+
@unittest.skipUnless(mayaUtils.ufeSupportFixLevel() >= 5, 'Requires Maya xform command fix.')
927+
def testGroupPivotCenter(self):
928+
# With group pivot center the group pivot is on the grouped object.
929+
self.runTestGroupPivotOptions("doGroup 0 1 0", [5, 0, 0])
930+
931+
@unittest.skipUnless(mayaUtils.ufeSupportFixLevel() >= 5, 'Requires Maya xform command fix.')
932+
def testGroupPivotOrigin(self):
933+
# With group pivot origin the group pivot is at the origin.
934+
self.runTestGroupPivotOptions("doGroup 0 1 1", [0, 0, 0])
935+
870936
if __name__ == '__main__':
871937
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)