<s> from pyglet . gl import * <EOL> import pywavefront . material <EOL> import pywavefront . mesh <EOL> import pywavefront . parser <EOL> class PywavefrontException ( Exception ) : <EOL> pass <EOL> class Wavefront ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , file_name ) : <EOL> self . file_name = file_name <EOL> self . materials = { } <EOL> self . meshes = { } <EOL> self . mesh_list = [ ] <EOL> ObjParser ( self , self . file_name ) <EOL> def draw ( self ) : <EOL> for this_mesh in self . mesh_list : <EOL> this_mesh . draw ( ) <EOL> def add_mesh ( self , the_mesh ) : <EOL> self . mesh_list . append ( the_mesh ) <EOL> if not the_mesh . name : return <EOL> self . meshes [ the_mesh . name ] = the_mesh <EOL> class ObjParser ( parser . Parser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , wavefront , file_name ) : <EOL> self . wavefront = wavefront <EOL> self . mesh = None <EOL> self . material = None <EOL> self . vertices = [ [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] ] <EOL> self . normals = [ [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] ] <EOL> self . tex_coords = [ [ <NUM_LIT:0.> , <NUM_LIT:0.> ] ] <EOL> self . read_file ( file_name ) <EOL> def parse_v ( self , args ) : <EOL> self . vertices . append ( list ( map ( float , args [ <NUM_LIT:0> : <NUM_LIT:3> ] ) ) ) <EOL> def parse_vn ( self , args ) : <EOL> self . normals . append ( list ( map ( float , args [ <NUM_LIT:0> : <NUM_LIT:3> ] ) ) ) <EOL> def parse_vt ( self , args ) : <EOL> self . tex_coords . append ( list ( map ( float , args [ <NUM_LIT:0> : <NUM_LIT:2> ] ) ) ) <EOL> def parse_mtllib ( self , args ) : <EOL> [ mtllib ] = args <EOL> materials = material . MaterialParser ( mtllib ) . materials <EOL> for material_name , material_object in materials . items ( ) : <EOL> self . wavefront . materials [ material_name ] = material_object <EOL> def parse_usemtl ( self , args ) : <EOL> [ usemtl ] = args <EOL> self . material = self . wavefront . materials . get ( usemtl , None ) <EOL> if self . material is None : <EOL> raise PywavefrontException ( '<STR_LIT>' % args [ <NUM_LIT:0> ] ) <EOL> if self . mesh is not None : <EOL> self . mesh . add_material ( self . material ) <EOL> def parse_usemat ( self , args ) : <EOL> self . parse_usemtl ( args ) <EOL> def parse_o ( self , args ) : <EOL> [ o ] = args <EOL> self . mesh = mesh . Mesh ( o ) <EOL> self . wavefront . add_mesh ( self . mesh ) <EOL> def parse_f ( self , args ) : <EOL> if ( len ( self . tex_coords ) > <NUM_LIT:1> ) and ( len ( self . normals ) == <NUM_LIT:1> ) : <EOL> raise PywavefrontException ( '<STR_LIT>' ) <EOL> if self . mesh is None : <EOL> self . mesh = mesh . Mesh ( ) <EOL> self . wavefront . add_mesh ( self . mesh ) <EOL> if self . material is None : <EOL> self . material = material . Material ( ) <EOL> self . mesh . add_material ( self . material ) <EOL> v1 = None <EOL> vlast = None <EOL> points = [ ] <EOL> for i , v in enumerate ( args [ <NUM_LIT:0> : ] ) : <EOL> if type ( v ) is bytes : <EOL> v = v . decode ( ) <EOL> v_index , t_index , n_index = ( list ( map ( int , [ j or <NUM_LIT:0> for j in v . split ( '<STR_LIT:/>' ) ] ) ) + [ <NUM_LIT:0> , <NUM_LIT:0> ] ) [ : <NUM_LIT:3> ] <EOL> if v_index < <NUM_LIT:0> : <EOL> v_index += len ( self . vertices ) - <NUM_LIT:1> <EOL> if t_index < <NUM_LIT:0> : <EOL> t_index += len ( self . tex_coords ) - <NUM_LIT:1> <EOL> if n_index < <NUM_LIT:0> : <EOL> n_index += len ( self . normals ) - <NUM_LIT:1> <EOL> vertex = list ( self . tex_coords [ t_index ] ) + list ( self . normals [ n_index ] ) + list ( self . vertices [ v_index ] ) <EOL> if i >= <NUM_LIT:3> : <EOL> self . material . vertices += v1 + vlast <EOL> self . material . vertices += vertex <EOL> if i == <NUM_LIT:0> : <EOL> v1 = vertex <EOL> vlast = vertex <EOL> def parse_s ( self , args ) : <EOL> return </s>
