<s> import sys <EOL> import optparse <EOL> import glob <EOL> import os <EOL> import string <EOL> import tempfile <EOL> import shutil <EOL> import zipfile <EOL> import textureconverter <EOL> from pipelinetools import * <EOL> def MakeObjQuad ( origsize , trimsize , scale , depth , plane , outfilename ) : <EOL> p0 = [ ( trimsize [ <NUM_LIT:0> ] - origsize [ <NUM_LIT:0> ] / <NUM_LIT:2> ) * scale , ( - trimsize [ <NUM_LIT:3> ] + origsize [ <NUM_LIT:1> ] / <NUM_LIT:2> ) * scale , depth ] <EOL> p1 = [ ( trimsize [ <NUM_LIT:0> ] - origsize [ <NUM_LIT:0> ] / <NUM_LIT:2> ) * scale , ( - trimsize [ <NUM_LIT:1> ] + origsize [ <NUM_LIT:1> ] / <NUM_LIT:2> ) * scale , depth ] <EOL> p2 = [ ( trimsize [ <NUM_LIT:2> ] - origsize [ <NUM_LIT:0> ] / <NUM_LIT:2> ) * scale , ( - trimsize [ <NUM_LIT:1> ] + origsize [ <NUM_LIT:1> ] / <NUM_LIT:2> ) * scale , depth ] <EOL> p3 = [ ( trimsize [ <NUM_LIT:2> ] - origsize [ <NUM_LIT:0> ] / <NUM_LIT:2> ) * scale , ( - trimsize [ <NUM_LIT:3> ] + origsize [ <NUM_LIT:1> ] / <NUM_LIT:2> ) * scale , depth ] <EOL> if plane == "<STR_LIT>" : <EOL> p0 [ <NUM_LIT:1> ] , p0 [ <NUM_LIT:2> ] = p0 [ <NUM_LIT:2> ] , p0 [ <NUM_LIT:1> ] <EOL> p1 [ <NUM_LIT:1> ] , p1 [ <NUM_LIT:2> ] = p1 [ <NUM_LIT:2> ] , p1 [ <NUM_LIT:1> ] <EOL> p2 [ <NUM_LIT:1> ] , p2 [ <NUM_LIT:2> ] = p2 [ <NUM_LIT:2> ] , p2 [ <NUM_LIT:1> ] <EOL> p3 [ <NUM_LIT:1> ] , p3 [ <NUM_LIT:2> ] = p3 [ <NUM_LIT:2> ] , p3 [ <NUM_LIT:1> ] <EOL> f = open ( outfilename , "<STR_LIT:w>" ) <EOL> f . write ( '<STR_LIT>' % { '<STR_LIT:x>' : p0 [ <NUM_LIT:0> ] , '<STR_LIT:y>' : p0 [ <NUM_LIT:1> ] , '<STR_LIT:z>' : p0 [ <NUM_LIT:2> ] } ) <EOL> f . write ( '<STR_LIT>' % { '<STR_LIT:x>' : p1 [ <NUM_LIT:0> ] , '<STR_LIT:y>' : p1 [ <NUM_LIT:1> ] , '<STR_LIT:z>' : p1 [ <NUM_LIT:2> ] } ) <EOL> f . write ( '<STR_LIT>' % { '<STR_LIT:x>' : p2 [ <NUM_LIT:0> ] , '<STR_LIT:y>' : p2 [ <NUM_LIT:1> ] , '<STR_LIT:z>' : p2 [ <NUM_LIT:2> ] } ) <EOL> f . write ( '<STR_LIT>' % { '<STR_LIT:x>' : p3 [ <NUM_LIT:0> ] , '<STR_LIT:y>' : p3 [ <NUM_LIT:1> ] , '<STR_LIT:z>' : p3 [ <NUM_LIT:2> ] } ) <EOL> if plane == "<STR_LIT>" : <EOL> f . write ( '<STR_LIT>' ) <EOL> elif plane == "<STR_LIT>" : <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> def ProcessFile ( file , options ) : <EOL> basename = os . path . splitext ( os . path . basename ( file ) ) [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" + file <EOL> basedir = GetBaseDirectory ( file , "<STR_LIT>" ) <EOL> tooldir = VerifyDirectory ( basedir , "<STR_LIT>" ) <EOL> outdir = VerifyDirectory ( basedir , "<STR_LIT>" ) <EOL> tempdir = tempfile . mkdtemp ( ) <EOL> origsize , trimsize , trimmed = TrimImage ( file ) <EOL> tempimagename = os . path . join ( tempdir , "<STR_LIT>" ) <EOL> tempobjname = os . path . join ( tempdir , "<STR_LIT>" ) <EOL> trimmed . save ( tempimagename ) <EOL> tex_filename = os . path . join ( os . path . dirname ( tempimagename ) , "<STR_LIT>" ) <EOL> textureconverter . Convert ( tempimagename , tex_filename ) <EOL> MakeObjQuad ( origsize , trimsize , options . scale , options . depth , options . plane , tempobjname ) <EOL> zip_filename = os . path . join ( outdir , basename + "<STR_LIT>" ) <EOL> print zip_filename <EOL> outzip = zipfile . ZipFile ( zip_filename , "<STR_LIT:w>" ) <EOL> for f in [ tex_filename , tempobjname ] : <EOL> archive_name = os . path . relpath ( f , tempdir ) <EOL> outzip . write ( f , archive_name , zipfile . ZIP_DEFLATED ) <EOL> outzip . close ( ) <EOL> shutil . rmtree ( tempdir ) <EOL> def main ( argv ) : <EOL> try : <EOL> import psyco <EOL> psyco . full ( ) <EOL> except ImportError : <EOL> pass <EOL> parser = optparse . OptionParser ( description = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , help = "<STR_LIT>" , default = <NUM_LIT:1> , type = float ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , help = "<STR_LIT>" , default = <NUM_LIT:0> , type = float ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , help = "<STR_LIT>" , default = '<STR_LIT>' , type = '<STR_LIT>' , choices = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> options , arguments = parser . parse_args ( ) <EOL> files = list ( set ( sum ( [ glob . glob ( x ) for x in arguments ] , [ ] ) ) ) <EOL> if len ( files ) == <NUM_LIT:0> : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> for file in files : <EOL> ProcessFile ( file , options ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( sys . argv [ <NUM_LIT:1> : ] ) </s>
