<s> from meshtool . filters . base_filters import PrintFilter <EOL> from meshtool . filters . print_filters . print_render_info import getRenderInfo <EOL> from meshtool . filters . print_filters . print_bounds import getBoundsInfo <EOL> try : <EOL> import json <EOL> except ImportError : <EOL> import simplejson as json <EOL> def getJSON ( mesh ) : <EOL> cameras = [ ] <EOL> for cam in mesh . cameras : <EOL> cameras . append ( { '<STR_LIT:id>' : cam . id } ) <EOL> lights = [ ] <EOL> for light in mesh . lights : <EOL> lights . append ( { '<STR_LIT:id>' : light . id , '<STR_LIT:type>' : type ( light ) . __name__ } ) <EOL> materials = [ ] <EOL> for material in mesh . materials : <EOL> materials . append ( { '<STR_LIT:id>' : material . id , '<STR_LIT>' : material . effect . id } ) <EOL> effects = [ ] <EOL> for effect in mesh . effects : <EOL> effects . append ( { '<STR_LIT:id>' : effect . id , '<STR_LIT:type>' : effect . shadingtype } ) <EOL> images = [ ] <EOL> for image in mesh . images : <EOL> images . append ( { '<STR_LIT:id>' : image . id , '<STR_LIT:name>' : image . path } ) <EOL> primitives = [ ] <EOL> for geom in mesh . geometries : <EOL> for i , prim in enumerate ( geom . primitives ) : <EOL> primitives . append ( { '<STR_LIT:id>' : "<STR_LIT>" % ( geom . id , i ) , <EOL> '<STR_LIT:type>' : type ( prim ) . __name__ , <EOL> '<STR_LIT>' : len ( prim . vertex_index ) if prim . vertex_index is not None else <NUM_LIT:0> , <EOL> '<STR_LIT>' : prim . normal_index is not None , <EOL> '<STR_LIT>' : len ( prim . texcoord_indexset ) > <NUM_LIT:0> } ) <EOL> json_ret = { '<STR_LIT>' : cameras , <EOL> '<STR_LIT>' : lights , <EOL> '<STR_LIT>' : materials , <EOL> '<STR_LIT>' : effects , <EOL> '<STR_LIT>' : images , <EOL> '<STR_LIT>' : primitives } <EOL> json_ret . update ( getRenderInfo ( mesh ) ) <EOL> boundsInfo = getBoundsInfo ( mesh ) <EOL> boundsInfo = { '<STR_LIT>' : [ boundsInfo [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . tolist ( ) , boundsInfo [ '<STR_LIT>' ] [ <NUM_LIT:1> ] . tolist ( ) ] , <EOL> '<STR_LIT>' : boundsInfo [ '<STR_LIT>' ] . tolist ( ) , <EOL> '<STR_LIT>' : boundsInfo [ '<STR_LIT>' ] . tolist ( ) , <EOL> '<STR_LIT>' : float ( boundsInfo [ '<STR_LIT>' ] ) } <EOL> json_ret [ '<STR_LIT>' ] = boundsInfo <EOL> return json . dumps ( json_ret ) <EOL> def FilterGenerator ( ) : <EOL> class PrintJsonFilter ( PrintFilter ) : <EOL> def __init__ ( self ) : <EOL> super ( PrintJsonFilter , self ) . __init__ ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def apply ( self , mesh ) : <EOL> print getJSON ( mesh ) <EOL> return mesh <EOL> return PrintJsonFilter ( ) <EOL> from meshtool . filters import factory <EOL> factory . register ( FilterGenerator ( ) . name , FilterGenerator ) </s>
