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 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/5e66ac31-fbb0-4c46-ae96-374288f90932%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to