<s> from meshtool . filters . base_filters import OptimizationFilter <EOL> import collada <EOL> import numpy <EOL> def adjustTexcoords ( mesh ) : <EOL> for geom in mesh . geometries : <EOL> prims_to_delete = [ ] <EOL> prims_to_add = [ ] <EOL> for prim_index , prim in enumerate ( geom . primitives ) : <EOL> if type ( prim ) is not collada . triangleset . TriangleSet or len ( prim . texcoordset ) < <NUM_LIT:1> : <EOL> continue <EOL> texarray = prim . texcoordset [ <NUM_LIT:0> ] [ prim . texcoord_indexset [ <NUM_LIT:0> ] ] <EOL> if numpy . min ( texarray ) >= <NUM_LIT:0.0> and numpy . max ( texarray ) <= <NUM_LIT:1.0> : <EOL> continue <EOL> x1 = texarray [ : , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> x2 = texarray [ : , <NUM_LIT:1> , <NUM_LIT:0> ] <EOL> x3 = texarray [ : , <NUM_LIT:2> , <NUM_LIT:0> ] <EOL> y1 = texarray [ : , <NUM_LIT:0> , <NUM_LIT:1> ] <EOL> y2 = texarray [ : , <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> y3 = texarray [ : , <NUM_LIT:2> , <NUM_LIT:1> ] <EOL> xmin = numpy . minimum ( x1 , numpy . minimum ( x2 , x3 ) ) <EOL> ymin = numpy . minimum ( y1 , numpy . minimum ( y2 , y3 ) ) <EOL> xfloor = numpy . floor ( xmin ) <EOL> yfloor = numpy . floor ( ymin ) <EOL> texarray [ : , : , <NUM_LIT:0> ] -= xfloor [ : , numpy . newaxis ] <EOL> texarray [ : , : , <NUM_LIT:1> ] -= yfloor [ : , numpy . newaxis ] <EOL> texarray = texarray . flatten ( ) <EOL> old_input_list = prim . getInputList ( ) . getList ( ) <EOL> inpl = collada . source . InputList ( ) <EOL> new_index = numpy . copy ( prim . index ) <EOL> for offset , semantic , srcid , setid in old_input_list : <EOL> if semantic == '<STR_LIT>' and ( setid == '<STR_LIT:0>' or len ( prim . texcoordset ) == <NUM_LIT:1> ) : <EOL> base_source_name = srcid [ <NUM_LIT:1> : ] + '<STR_LIT>' <EOL> source_name = base_source_name <EOL> ct = <NUM_LIT:0> <EOL> while source_name in geom . sourceById : <EOL> source_name = '<STR_LIT>' % ( base_source_name , ct ) <EOL> ct += <NUM_LIT:1> <EOL> new_tex_src = collada . source . FloatSource ( source_name , texarray , ( '<STR_LIT:S>' , '<STR_LIT:T>' ) ) <EOL> geom . sourceById [ source_name ] = new_tex_src <EOL> new_tex_index = numpy . arange ( len ( new_index ) * <NUM_LIT:3> ) <EOL> new_tex_index . shape = ( len ( new_index ) , <NUM_LIT:3> ) <EOL> new_index [ : , : , offset ] = new_tex_index <EOL> srcid = '<STR_LIT>' % source_name <EOL> inpl . addInput ( offset , semantic , srcid , setid ) <EOL> newtriset = geom . createTriangleSet ( new_index , inpl , prim . material ) <EOL> prims_to_add . append ( newtriset ) <EOL> prims_to_delete . append ( prim_index ) <EOL> for i in sorted ( prims_to_delete , reverse = True ) : <EOL> del geom . primitives [ i ] <EOL> for prim in prims_to_add : <EOL> geom . primitives . append ( prim ) <EOL> def FilterGenerator ( ) : <EOL> class AdjustTexcoordsFilter ( OptimizationFilter ) : <EOL> def __init__ ( self ) : <EOL> super ( AdjustTexcoordsFilter , self ) . __init__ ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> def apply ( self , mesh ) : <EOL> adjustTexcoords ( mesh ) <EOL> return mesh <EOL> return AdjustTexcoordsFilter ( ) <EOL> from meshtool . filters import factory <EOL> factory . register ( FilterGenerator ( ) . name , FilterGenerator ) </s>
