So this is almost working. Although I'm not really getting the orientation I'd 
like for verts on non-flat meshes.  In some areas, it works great, in others - 
I'm not sure how to get the proper orientation.  Any ideas on how to make this 
better?  if you run it with a really lowpoly sphere selected you can see what I 
mean towards the poles.

#=======================
import pymel.core as pm


def getVtxTfm(vtx):
    pos = vtx.getPosition(space='world')
    xVec = vtx.getNormal()
    
    connectedVertNames = [ vert.name() for vert in vtx.connectedVertices() ]

    nextVertName = "{0}.vtx[{1}]".format( vtx.node().name(), ( vtx.index() + 1) 
)
    nextVert = pm.PyNode( nextVertName )
    prevVertName = "{0}.vtx[{1}]".format( vtx.node().name(), ( vtx.index() - 1) 
)
    prevVert = pm.PyNode( prevVertName )

    if nextVertName in connectedVertNames:
        yVec = ( nextVert.getPosition() - pos ).normal()
    else:
        yVec = -( prevVert.getPosition() - pos ).normal()

    zVec = xVec.cross(yVec).normal()
    yVec = zVec.cross(xVec)

    mat = pm.datatypes.Matrix() 
    mat.a00 = xVec[0]
    mat.a01 = xVec[1]
    mat.a02 = xVec[2]
    
    mat.a10 = yVec[0]
    mat.a11 = yVec[1]
    mat.a12 = yVec[2]
    
    mat.a20 = zVec[0]
    mat.a21 = zVec[1]
    mat.a22 = zVec[2]
    
    mat.a30 = pos[0]
    mat.a31 = pos[1]
    mat.a32 = pos[2]

    tfm = pm.datatypes.TransformationMatrix( mat )

    null = pm.spaceLocator()
    null.setTransformation( tfm )



sel = pm.selected()
nodeName = sel[0].name()
for vtxID in sel[0].getVertices()[1]:
    vertex = "{0}.vtx[{1}]".format( nodeName, vtxID )
    vert = pm.PyNode(vertex)
    getVtxTfm(vert)

#=======================

Thanks!
Kev

-- 
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/cbbc6d55-6a8e-4222-88be-cf162d231680%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to