#NEWLINE# def smooth_normals( positions , normals ) : #NEWLINE# #INDENT# 'Assigns an averaged normal to each position based on all of the normals\n    originally used for the position.\n    ' #NEWLINE# lookup = defaultdict ( list ) #NEWLINE# for ( position , normal ) in zip ( positions , normals ) : #NEWLINE# #INDENT# lookup [ position ] . append ( normal ) #NEWLINE# #UNINDENT# result = [ ] #NEWLINE# for position in positions : #NEWLINE# #INDENT# tx = ty = tz = 0 #NEWLINE# for ( x , y , z ) in lookup [ position ] : #NEWLINE# #INDENT# tx += x #NEWLINE# ty += y #NEWLINE# tz += z #NEWLINE# #UNINDENT# d = ( ( ( ( tx * tx ) + ( ty * ty ) ) + ( tz * tz ) ) ** 0.5 ) #NEWLINE# result . append ( ( ( tx / d ) , ( y / d ) , ( tz / d ) ) ) #NEWLINE# #UNINDENT# return result