Yes I noticed that , flattening is not reversible , fortunately in my case it
doesn’t need to be so I just reverse the translation and the rotation. If I
were to do it tho, I would just register the points prior flattening
Sent from Mail for Windows 10
From: Michael Boon
Sent: Thursday, April 5, 2018 6:31 AM
To: Python Programming for Autodesk Maya
Subject: [Maya-Python] Re: Matrix inverse of several transformations ?
Glad you got it.
One thing I noticed from your first post there, is "matrix to flatten on Y."
You can't actually inverse a matrix that flattens things to a plane.
Mathematically, it requires dividing by 0 as your determinate will be 0.
Physically think about the fact that an infinite number of shapes will result
in the same plane once they've been flattened by that matrix, and you have no
way of knowing which one of them you want to get back.
On Thursday, 5 April 2018 07:06:33 UTC+10, justin hidair wrote:
nvm fixed it, this is confusing tho but when you are done with your
transformations and you find yourself at the origin you just need to add the
previous position to your transformed points , the code speaks for itself,
basically if the plane stay the same, it means it works , and it worked ...
import maya.api.OpenMaya as om
import math
sel = om.MSelectionList()
sel.add('pPlaneShape1')
mesh = sel.getDependNode(0)
fnm = om.MFnMesh( mesh )
normal = fnm.getPolygonNormal( 0 )
o = om.MItMeshPolygon(mesh).center()
def get_orient_mat( a ):
b = om.MVector.kYaxisVector
i = om.MMatrix.kIdentity
v = a ^ b
ang = a.angle(b)
if ang < 1e-6:
res = i
return res
if math.fabs(ang-math.pi) < 1e-6:
res = om.MMatrix( [
(math.cos(math.pi) , math.sin(math.pi), 0, 0),
(-math.sin(math.pi), math.cos(math.pi), 0, 0),
(0, 0, 1, 0),
(0,0,0,1) ] )
return res
c = math.cos( ang)
skew = om.MMatrix( [
(0, v.z, -v.y, 0),
(-v.z, 0, v.x, 0),
(v.y, -v.x, 0, 0),
(0,0,0,1) ] )
res = i + skew + (skew*skew)*( 1 / (1+c) )
return res
# matrix to orient in 2D
rmat = get_orient_mat( normal)
# matrix to position to center
tmat = om.MMatrix( [
(1,0,0,0),
(0,1,0,0),
(0,0,1,0),
(-o.x,-o.y,-o.z,1) ] )
# matrix to flatten on y
smat = om.MMatrix( [
(1,0,0,0),
(0,0,0,0),
(0,0,1,0),
(0,0,0,1)] )
mat = tmat * rmat * smat
for i in xrange( fnm.numVertices ):
cur = fnm.getPoint( i)
# cur*=tmat
# cur*=rmat
# cur*=smat
cur*=mat
fnm.setPoint( i , cur )
#reverse
for i in xrange( fnm.numVertices ):
cur = fnm.getPoint( i)
duh = om.MPoint( om.MVector( cur * rmat.inverse() ) + om.MVector( o) )
fnm.setPoint( i , duh )
--
You received this message because you are subscribed to a topic in the Google
Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/python_inside_maya/DQR6qJLVCKg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
[email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/f61fe086-4a32-4f80-8c5d-a7bbd1d2c82f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/5ac5b5ee.c3a7500a.71b43.6fc4%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.