#NEWLINE# def getMipMaps( mesh ) : #NEWLINE# #INDENT# mipmaps = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for effect in mesh . effects : #NEWLINE# #INDENT# for prop in effect . supported : #NEWLINE# #INDENT# propval = getattr ( effect , prop ) #NEWLINE# if isinstance ( propval , collada . material . Map ) : #NEWLINE# #INDENT# image_name = propval . sampler . surface . image . path #NEWLINE# image_data = propval . sampler . surface . image . data #NEWLINE# try : #NEWLINE# #INDENT# im = Image . open ( StringIO ( image_data ) ) #NEWLINE# im . load ( ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# from panda3d.core import Texture #NEWLINE# from panda3d.core import StringStream #NEWLINE# from panda3d.core import PNMImage #NEWLINE# t = Texture ( image_name ) #NEWLINE# success = t . readDds ( StringStream ( image_data ) ) #NEWLINE# if ( success == 0 ) : #NEWLINE# #INDENT# raise FilterException ( ( 'Failed to read image file %s' % image_name ) ) #NEWLINE# #UNINDENT# outdata = t . getRamImageAs ( 'RGBA' ) . getData ( ) #NEWLINE# try : #NEWLINE# #INDENT# im = Image . fromstring ( 'RGBA' , ( t . getXSize ( ) , t . getYSize ( ) ) , outdata ) #NEWLINE# im . load ( ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# raise FilterException ( ( 'Failed to read image file %s' % image_name ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( im . format == 'JPEG' ) : #NEWLINE# #INDENT# output_format = 'JPEG' #NEWLINE# output_extension = 'jpg' #NEWLINE# output_options = { #NEWLINE# #INDENT# 'quality' : 95 , #NEWLINE# 'optimize' : True , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output_format = 'PNG' #NEWLINE# output_extension = 'png' #NEWLINE# output_options = { #NEWLINE# #INDENT# 'optimize' : True , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# orig_im = im #NEWLINE# ( width , height ) = im . size #NEWLINE# width = int ( math . pow ( 2 , int ( math . log ( width , 2 ) ) ) ) #NEWLINE# height = int ( math . pow ( 2 , int ( math . log ( height , 2 ) ) ) ) #NEWLINE# pil_images = [ ] #NEWLINE# while True : #NEWLINE# #INDENT# im = orig_im . resize ( ( width , height ) , Image . ANTIALIAS ) #NEWLINE# pil_images . insert ( 0 , im ) #NEWLINE# if ( ( width == 1 ) and ( height == 1 ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# width = max ( ( width / 2 ) , 1 ) #NEWLINE# height = max ( ( height / 2 ) , 1 ) #NEWLINE# #UNINDENT# tar_buf = StringIO ( ) #NEWLINE# tar = tarfile . TarFile ( fileobj = tar_buf , mode = 'w' ) #NEWLINE# cur_offset = 0 #NEWLINE# byte_ranges = [ ] #NEWLINE# for ( i , pil_img ) in enumerate ( pil_images ) : #NEWLINE# #INDENT# buf = StringIO ( ) #NEWLINE# pil_img . save ( buf , output_format , ** output_options ) #NEWLINE# file_len = buf . tell ( ) #NEWLINE# cur_name = ( '%dx%d.%s' % ( pil_img . size [ 0 ] , buf . size [ 1 ] , output_extension ) ) #NEWLINE# tar_info = tarfile . TarInfo ( name = cur_name ) #NEWLINE# tar_info . size = file_len #NEWLINE# buf . seek ( 0 ) #NEWLINE# tar . addfile ( tarinfo = tar_info , fileobj = buf ) #NEWLINE# cur_offset += 512 #NEWLINE# file_start = cur_offset #NEWLINE# byte_ranges . append ( { #NEWLINE# #INDENT# 'offset' : file_start , #NEWLINE# 'length' : file_len , #NEWLINE# 'width' : pil_img . size [ 0 ] , #NEWLINE# 'height' : pil_img . size [ 1 ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# file_len = ( 512 * ( ( ( file_len + 512 ) - 1 ) / 512 ) ) #NEWLINE# cur_offset += file_len #NEWLINE# #UNINDENT# tar . close ( ) #NEWLINE# mipmaps [ propval . sampler . surface . image . path ] = ( tar_buf . getvalue ( ) , byte_ranges ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return mipmaps