compensate a shear effect

147 views
Skip to first unread message

vince touache

unread,
Aug 13, 2019, 5:38:36 PM8/13/19
to Python Programming for Autodesk Maya
Hi, 

I noticed a weird behavior when trying to scale a constraint object. 
My setup is made of 3 elements. One parent and its child, and a null, at the same level as parent. parent and null are aimConstraining the child (so the child will follow .5 each)
 parent
 |__ child
 null

The weirdness happens when combining rotation and scale, which introduces some shear effect.. what I can't figure out though, is why this shear is affecting so much the rotation (my vectors are still visible as perpendicular).

To check by yourself, you can run this snippet : 

parent = cmds.createNode('transform', ss=1)
cube = cmds.polyCube()[0]
cmds.parent(cube, parent, r=1)
null = cmds.createNode('transform', ss=1)
cmds.orientConstraint(parent, null, cube, mo=0)
cmds.setAttr(parent + '.rx', 45)
print 'before scale / shear', cmds.getAttr(cube + '.rx')
cmds.setAttr(parent + '.sy', 2)
print 'after scale / shear', cmds.getAttr(cube + '.rx')


Before scaling, the rotateX of my cube is correct, but after, it's like 40-is degrees, which doesn't make much sense to me....
I have a shitty fix (run this code)
# shittyFix
dcm = cmds.createNode('decomposeMatrix', ss=1)
cmds.connectAttr(cube + '.wm', dcm + '.inputMatrix')
cpm = cmds.createNode('composeMatrix', ss=1)
cmds.connectAttr(dcm + '.or', cpm + '.ir')
cmds.connectAttr(dcm + '.os', cpm + '.is')
cmds.connectAttr(dcm + '.ot', cpm + '.it')
outDcm = cmds.createNode('decomposeMatrix', ss=1)
cmds.connectAttr(cpm + '.outputMatrix', outDcm + '.inputMatrix')
outLoc = cmds.spaceLocator()[0]
cmds.connectAttr(outDcm + '.orx', outLoc + '.rx')
print 'after shitty fix', cmds.getAttr(outLoc + '.rx')

but it's still not perfect, and I'm not sur why... could this be due to some round issue ? That looks too much to me...
Does anyone have an idea on how to get my proper pCube.rx = 22.5, with this setup (i.e. compensate the shear) ??

Thanks a lot !


vince touache

unread,
Aug 13, 2019, 10:40:06 PM8/13/19
to Python Programming for Autodesk Maya
Found a workaround, making my own orient constraints with matrices instead, but I wouldn't mind some explanation on this, because I'm still not sure why the scale has so much impact on an orient constraint

Michael Boon

unread,
Aug 21, 2019, 3:36:24 AM8/21/19
to Python Programming for Autodesk Maya
Sorry I can't run your code right now and I'm not exactly sure what results you're seeing.

If you're wondering why the non-uniform scale affects shear, it's because shear is exactly that - non-uniform scale on an axis other than one of the primary axes. Think about rotating a square 45° and then squashing it vertically. It ends up being a rhombus.

If you're wondering why the shear causes the rotation to change, I'm not exactly sure how Maya reports rotation on transforms that have shear. In the imaginary square from my previous paragraph, the top and bottom edges have rotated by some angle, but the other two edges have rotated by a different angle (because the axes are not actually at right angles anymore, even though they look like they are in the Maya viewport).

Does that help at all? If not, I can try to run the code tomorrow and see if I can give a more specific explanation.

vince touache

unread,
Aug 21, 2019, 8:35:50 AM8/21/19
to Python Programming for Autodesk Maya
Thanks for the answer Michael.

Shear is not non-uniform scale, however. Shear is "distording" the space of an object, by making its axes non orthogonal. This is what happens with the snippet I posted. Now what is interesting is precisely how maya will interpret it. In a nutshell, what I have is some shear on the cube (we don't care about that), and an orient constraint, driven by this sheared object. And since maya has to "un-shear" the cube space to apply a proper orientation on the slave of the constraint, it has to guess "how" sheared the master was. And it doesn't do it very well. So to summarize :
Object A drives object B in orientConstraint.
If you shear A, that will affect B's orientation.

Again, I found a workaround, but I was just curious about how maya was handling that. And it seems it'll use A's primary axis to compute B's orthonormal frame (hence B's rotation being affected by A's shear)

Michael Boon

unread,
Aug 22, 2019, 1:13:13 AM8/22/19
to Python Programming for Autodesk Maya
Cool, sounds like your guess is as good as mine would be :)
Reply all
Reply to author
Forward
0 new messages