Skip to content

Commit

Permalink
Merge pull request #287 from elrond79/pr/xformStack
Browse files Browse the repository at this point in the history
[maya] factor out matching of xforms into PxrUsdMayaXformStack
  • Loading branch information
pixar-oss committed Nov 17, 2017
2 parents e914d66 + 007e6c0 commit 11d9332
Show file tree
Hide file tree
Showing 9 changed files with 2,654 additions and 309 deletions.
12 changes: 12 additions & 0 deletions third_party/maya/lib/usdMaya/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pxr_shared_library(${PXR_PACKAGE}
util
usdPrimProvider
writeUtil
xformStack

MayaPrimWriter
MayaTransformWriter
Expand Down Expand Up @@ -124,6 +125,7 @@ pxr_shared_library(${PXR_PACKAGE}
wrapRoundTripUtil.cpp
wrapStageCache.cpp
wrapUserTaggedAttribute.cpp
wrapXformStack.cpp

PYMODULE_FILES
__init__.py
Expand Down Expand Up @@ -168,6 +170,7 @@ pxr_test_scripts(
testenv/testUsdMayaProxyShape.py
testenv/testUsdMayaReferenceAssemblyEdits.py
testenv/testUsdMayaUserExportedAttributes.py
testenv/testUsdMayaXformStack.py
testenv/testUsdMetadataAttributeConverters.py
testenv/testUsdReferenceAssemblyChangeRepresentations.py
testenv/testUsdReferenceAssemblySelection.py
Expand Down Expand Up @@ -581,3 +584,12 @@ pxr_register_test(testUsdReferenceAssemblySelection
MAYA_DISABLE_CIP=1
)

pxr_register_test(testUsdMayaXformStack
CUSTOM_PYTHON "${MAYA_BASE_DIR}/bin/mayapy"
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdMayaXformStack"
TESTENV testUsdMayaXformStack
ENV
MAYA_PLUG_IN_PATH=${CMAKE_INSTALL_PREFIX}/third_party/maya/plugin
MAYA_SCRIPT_PATH=${CMAKE_INSTALL_PREFIX}/third_party/maya/share/usd/plugins/usdMaya/resources
MAYA_DISABLE_CIP=1
)
1 change: 1 addition & 0 deletions third_party/maya/lib/usdMaya/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ TF_WRAP_MODULE {
TF_WRAP(RoundTripUtil);
TF_WRAP(StageCache);
TF_WRAP(UserTaggedAttribute);
TF_WRAP(XformStack);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#usda 1.0
(
defaultPrim = "World"
upAxis = "Z"
)

def Xform "World" (
kind = "component"
)
{
def Xform "X"
{
float xformOp:rotateX:rotateAxis = 60
float3 xformOp:scale = (0.5, 0.5, 0.5)
double3 xformOp:translate = (1.0, 2.0, 3.0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateX:rotateAxis", "xformOp:scale"]
}

def Xform "Y"
{
float xformOp:rotateY:rotateAxis = 60
float3 xformOp:scale = (0.5, 0.5, 0.5)
double3 xformOp:translate = (1.0, 2.0, 3.0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateY:rotateAxis", "xformOp:scale"]
}

def Xform "Z"
{
float xformOp:rotateZ:rotateAxis = 60
float3 xformOp:scale = (0.5, 0.5, 0.5)
double3 xformOp:translate = (1.0, 2.0, 3.0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateZ:rotateAxis", "xformOp:scale"]
}

def Xform "XYZ"
{
float3 xformOp:rotateXYZ:rotateAxis = (60, 120, 180)
float3 xformOp:scale = (0.5, 0.5, 0.5)
double3 xformOp:translate = (1.0, 2.0, 3.0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ:rotateAxis", "xformOp:scale"]
}

def Xform "YZX"
{
float3 xformOp:rotateYZX:rotateAxis = (60, 120, 180)
float3 xformOp:scale = (0.5, 0.5, 0.5)
double3 xformOp:translate = (1.0, 2.0, 3.0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateYZX:rotateAxis", "xformOp:scale"]
}

def Xform "ZXY"
{
float3 xformOp:rotateZXY:rotateAxis = (60, 120, 180)
float3 xformOp:scale = (0.5, 0.5, 0.5)
double3 xformOp:translate = (1.0, 2.0, 3.0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateZXY:rotateAxis", "xformOp:scale"]
}

def Xform "XZY"
{
float3 xformOp:rotateXZY:rotateAxis = (60, 120, 180)
float3 xformOp:scale = (0.5, 0.5, 0.5)
double3 xformOp:translate = (1.0, 2.0, 3.0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXZY:rotateAxis", "xformOp:scale"]
}

def Xform "YXZ"
{
float3 xformOp:rotateYXZ:rotateAxis = (60, 120, 180)
float3 xformOp:scale = (0.5, 0.5, 0.5)
double3 xformOp:translate = (1.0, 2.0, 3.0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateYXZ:rotateAxis", "xformOp:scale"]
}

def Xform "ZYX"
{
float3 xformOp:rotateZYX:rotateAxis = (60, 120, 180)
float3 xformOp:scale = (0.5, 0.5, 0.5)
double3 xformOp:translate = (1.0, 2.0, 3.0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateZYX:rotateAxis", "xformOp:scale"]
}
}
42 changes: 42 additions & 0 deletions third_party/maya/lib/usdMaya/testenv/testUsdImportXforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,48 @@ def testImportMayaXformVariations(self):
print "full failed xform:"
pprint.pprint(attrVals)
raise

def testImportXformsRotateAxis(self):
"""
Tests that importing xforms that have a rotateAxis with rotate order other than just XYZ
still imports correctly
"""
usdFile = os.path.abspath('UsdImportXformsTestRotateAxis.usda')
cmds.usdImport(file=usdFile, shadingMode='none')

expectedRotates = {
'X': (60, 0, 0),
'Y': (0, 60, 0),
'Z': (0, 0, 60),
'XYZ': (-120, 60, 0),
'YZX': (-106.1021138, 25.6589063, 56.3099325),
'ZXY': (120, -60, 0),
'XZY': (-120, -60, 0),
'YXZ': (106.1021138, 25.6589063, -56.3099325),
'ZYX': (-106.1021138, -25.6589063, -56.3099325),
}
expectedScale = (.5, .5, .5)
expectedTranslation = (1.0, 2.0, 3.0)

for rotOrderName, expectedRotation in expectedRotates.iteritems():
mayaTransform = self._GetMayaTransform(rotOrderName)
transformationMatrix = mayaTransform.transformation()

actualTranslation = list(
transformationMatrix.translation(OM.MSpace.kTransform))
self.assertTrue(
Gf.IsClose(expectedTranslation, actualTranslation, self.EPSILON))

expectedRotation = [Gf.DegreesToRadians(x) for x in expectedRotation]
actualRotation = transformationMatrix.rotationOrientation().asEulerRotation()
actualRotation = list(actualRotation)
#print rotOrderName, actualRotation
self.assertTrue(
Gf.IsClose(expectedRotation, actualRotation, self.EPSILON))

actualScale = list(transformationMatrix.scale(OM.MSpace.kTransform))
self.assertTrue(
Gf.IsClose(expectedScale, actualScale, self.EPSILON))


def testPivot(self):
Expand Down
Loading

0 comments on commit 11d9332

Please sign in to comment.