#NEWLINE# def setup( self , p1 , p2 , radius , detail , hollow ) : #NEWLINE# #INDENT# ( x1 , y1 , z1 ) = p1 #NEWLINE# ( x2 , y2 , z2 ) = p2 #NEWLINE# ( dx , dy , dz ) = ( ( x2 - x1 ) , ( y2 - y1 ) , ( z2 - z1 ) ) #NEWLINE# ( cx , cy , cz ) = ( ( x1 + ( dx / 2 ) ) , ( y1 + ( dy / 2 ) ) , ( z1 + ( dz / 2 ) ) ) #NEWLINE# a = ( atan2 ( dz , dx ) - ( pi / 2 ) ) #NEWLINE# b = ( atan2 ( dy , hypot ( dx , dz ) ) - ( pi / 2 ) ) #NEWLINE# matrix = Matrix ( ) #NEWLINE# matrix = matrix . rotate ( ( cos ( a ) , 0 , sin ( a ) ) , b ) #NEWLINE# normal_matrix = matrix #NEWLINE# matrix = matrix . translate ( ( cx , cy , cz ) ) #NEWLINE# d = distance ( p1 , p2 ) #NEWLINE# angles = [ ( ( ( i * 2 ) * pi ) / detail ) for i in xrange ( ( detail + 1 ) ) ] #NEWLINE# for ( a1 , a2 ) in zip ( angles , angles [ 1 : ] ) : #NEWLINE# #INDENT# ( x1 , z1 ) = ( ( cos ( a1 ) * radius ) , ( sin ( a1 ) * radius ) ) #NEWLINE# ( x2 , z2 ) = ( ( cos ( a2 ) * radius ) , ( sin ( a2 ) * radius ) ) #NEWLINE# ( y1 , y2 ) = ( ( ( - d ) / 2 ) , ( d / 2 ) ) #NEWLINE# ( n1 , n2 ) = ( normalize ( ( x1 , 0 , z1 ) ) , normalize ( ( x2 , 0 , z2 ) ) ) #NEWLINE# uv1 = ( ( 0.5 + ( cos ( a1 ) * 0.5 ) ) , ( 0.5 + ( sin ( a1 ) * 0.5 ) ) ) #NEWLINE# uv2 = ( ( 0.5 + ( cos ( a2 ) * 0.5 ) ) , ( 0.5 + ( sin ( a2 ) * 0.5 ) ) ) #NEWLINE# u1 = ( a1 % ( 2 * pi ) ) #NEWLINE# u2 = ( a2 % ( 2 * pi ) ) #NEWLINE# if ( u2 < u1 ) : #NEWLINE# #INDENT# u2 += ( 2 * pi ) #NEWLINE# #UNINDENT# positions = [ ( 0 , y1 , 0 ) , ( x1 , y1 , z1 ) , ( x2 , y1 , z2 ) , ( 0 , y2 , 0 ) , ( x2 , y2 , z2 ) , ( x1 , y2 , z1 ) , ( x1 , y1 , z1 ) , ( x1 , y2 , z1 ) , ( x2 , y1 , z2 ) , ( x2 , y1 , z2 ) , ( x1 , y2 , z1 ) , ( x2 , y2 , z2 ) ] #NEWLINE# normals = [ ( 0 , ( - 1 ) , 0 ) , ( 0 , ( - 1 ) , 0 ) , ( 0 , ( - 1 ) , 0 ) , ( 0 , 1 , 0 ) , ( 0 , 1 , 0 ) , ( 0 , 1 , 0 ) , n1 , n1 , n2 , n2 , n1 , n2 ] #NEWLINE# uvs = [ ( 0.5 , 0.5 ) , uv1 , uv2 , ( 0.5 , 0.5 ) , uv2 , uv1 , ( u1 , 0 ) , ( u1 , 1 ) , ( u2 , 0 ) , ( u2 , 0 ) , ( u1 , 1 ) , ( u2 , 1 ) ] #NEWLINE# if hollow : #NEWLINE# #INDENT# positions = positions [ 6 : ] #NEWLINE# normals = normals [ 6 : ] #NEWLINE# uvs = uvs [ 6 : ] #NEWLINE# #UNINDENT# for position in positions : #NEWLINE# #INDENT# self . positions . append ( ( matrix * position ) ) #NEWLINE# #UNINDENT# for normal in normals : #NEWLINE# #INDENT# self . normals . append ( ( normal_matrix * normal ) ) #NEWLINE# #UNINDENT# for uv in uvs : #NEWLINE# #INDENT# self . uvs . append ( uv )