okay, so I've got something kinda working.  But my math is wrong somewhere in 
figuring out the average normals. I'm having a hard time visualizing it.  
Here's my code in case anybody has experience averaging normals. Maybe I'm 
doing this all wrong - I dunno. I'd really appreciate any help. Thx!

#========================================
import pymel.core as pm
from itertools import chain
import time


def convertToVerts( components ):
    return pm.ls( pm.polyListComponentConversion( components, toVertex=True ),
                                                    flatten=True)

def getAvgVertTfm( components ):
    
    verts = convertToVerts(components)      
    
    positions = []
    normals = []   
    for vert in verts:
        positions.append( vert.getPosition() )
        normals.append( vert.getNormals() )

    avgPos = [ sum(pos)/len(pos) for pos in zip(*positions) ]
    avgNormal = [ sum(normal)/len(normal) for normal in zip(*normals) ]
    
    avgNormalRotation = [ sum(rotation)/len(rotation) for rotation
                          in zip(*pm.datatypes.degrees(avgNormal)) ]

    avgTfm = pm.datatypes.TransformationMatrix()
    avgTfm.setTranslation(avgPos, space="world")    
    avgTfm.setRotation(avgNormalRotation)

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

    '''
    still need to add object matrix multiplications
    '''


startTime = time.time()
getAvgVertTfm( pm.ls(sl=True) )
print time.time()-startTime
#=======================================

-- 
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/5a1fb218-e05a-4517-8d88-7b0cc81f4326%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to