|
19 | 19 | import fixturesUtils |
20 | 20 | import mayaUtils |
21 | 21 | import testUtils |
| 22 | +from testUtils import assertVectorAlmostEqual |
22 | 23 | import ufeUtils |
23 | 24 | import usdUtils |
24 | 25 |
|
25 | 26 | import mayaUsd.ufe |
26 | 27 |
|
27 | 28 | from pxr import Kind, Usd, UsdGeom, Vt |
28 | 29 |
|
29 | | -from maya import cmds |
| 30 | +from maya import cmds, mel |
30 | 31 | from maya import standalone |
31 | 32 |
|
32 | 33 | import ufe |
33 | 34 |
|
34 | | -import os |
35 | 35 | import unittest |
36 | 36 |
|
37 | 37 | def createStage(): |
@@ -867,5 +867,71 @@ def checkAfter(): |
867 | 867 | cmds.redo() |
868 | 868 | checkAfter() |
869 | 869 |
|
| 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 | + |
870 | 936 | if __name__ == '__main__': |
871 | 937 | unittest.main(verbosity=2) |
0 commit comments