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 )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
--
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 python_inside_m...@googlegroups.com.
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.