Skip to content

Commit

Permalink
Merge pull request #765 from Autodesk/kxl-adsk/fix_matrix_conversion_…
Browse files Browse the repository at this point in the history
…for_data_blocks

Use MFnMatrixData when storing/retriving MMatrix from data block
  • Loading branch information
Krystian Ligenza authored Sep 8, 2020
2 parents fc2ccce + f5c26ab commit 5abd7c0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/mayaUsd/utils/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,21 @@ MAYAUSD_NS_DEF

static void set(FnType& data, const Type& value) { data.set(value); }

static void get(const MDataHandle& handle, Type& value) { value = handle.asMatrix(); }
static void get(const MDataHandle& handle, Type& value)
{
MObject dataObj = const_cast<MDataHandle&>(handle).data();
FnType dataFn(dataObj);
get(dataFn, value);
}

static void set(MDataHandle& handle, const Type& value)
{
FnType dataFn;
MObject dataObj = create(dataFn);
set(dataFn, value);

static void set(MDataHandle& handle, const Type& value) { handle.set(value); }
handle.setMObject(dataObj);
}
};

//! \brief Type trait for Maya's float3 type providing get and set methods for data handle and
Expand Down
73 changes: 73 additions & 0 deletions test/lib/testMayaUsdProxyAccessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,59 @@ def validateDisconnect(self, cachingScope):

dumpSessionLayer = stage.GetSessionLayer().ExportToString()
self.assertNotIn("double3 xformOp:translate.timeSamples = {\n",dumpSessionLayer)

def validateMatrixOps(self, cachingScope):
"""
Validate that accessor works correctly with matrix ops
"""
nodeDagPath, stage = createProxyFromFile(self.testAnimatedHierarchyUsdFile)
stage.GetRootLayer().ImportFromString('''#usda 1.0
(
defaultPrim = "pCube1"
upAxis = "Y"
)
def Cube "pCube1" (
kind = "component"
)
{
matrix4d xformOp:transform:offset = ((1,0,0,0),(0,1,0,0),(0,0,1,0),(0, 5, 10,1))
uniform token[] xformOpOrder = ["xformOp:transform:offset"]
}
''')

# Get UFE items
ufeItem = makeUfePath(nodeDagPath,'/pCube1')

# Create accessor plugs
matrixPlug = pa.getOrCreateAccessPlug(ufeItem, usdAttrName='xformOp:transform:offset')

cachingScope.waitForCache()
cachingScope.checkValidFrames(self.cache_allFrames)

# Validate output accessor plugs
cmds.currentTime(1)
v0 = cmds.getAttr('{}.{}'.format(nodeDagPath,matrixPlug))
self.assertEqual(v0, [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 5.0, 10.0, 1.0])

# Create a locator to drive matrix op
# and apply offset on its translateY
cmds.spaceLocator()
srcNodeDagPath = cmds.ls(sl=True,l=True)[0]
cmds.setAttr('{}.ty'.format(srcNodeDagPath), 3)

# Connect src to drive matrix op
cmds.connectAttr('{}.worldMatrix[0]'.format(srcNodeDagPath), '{}.{}'.format(nodeDagPath,matrixPlug))

# Validate
cachingScope.checkValidFrames(self.cache_empty)
cachingScope.waitForCache()
cachingScope.checkValidFrames(self.cache_allFrames)

cmds.currentTime(1)
v0 = cmds.getAttr('{}.{}'.format(nodeDagPath,matrixPlug))
self.assertEqual(v0, [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 3.0, 0.0, 1.0])

###################################################################################
def testOutput_NoCaching(self):
"""
Expand Down Expand Up @@ -1269,3 +1321,24 @@ def testDisconnect_Caching(self):
with CachingScope(self) as thisScope:
thisScope.verifyScopeSetup()
self.validateDisconnect(thisScope)

def testMatrixOp_NoCaching(self):
"""
Validate that accessor works correctly with matrix ops
Cached playback is disabled in this test.
"""
cmds.file(new=True, force=True)
with NonCachingScope(self) as thisScope:
thisScope.verifyScopeSetup()
self.validateMatrixOps(thisScope)

def testMatrixOp_Caching(self):
"""
Validate that accessor works correctly with matrix ops
Cached playback is ENABLED in this test.
"""
cmds.file(new=True, force=True)
with CachingScope(self) as thisScope:
thisScope.verifyScopeSetup()
self.validateMatrixOps(thisScope)

0 comments on commit 5abd7c0

Please sign in to comment.