<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import time <EOL> import hashlib <EOL> from panda3d . core import PStatCollector , Mat4 , Point4 , Vec3 <EOL> from rpcore . globals import Globals <EOL> def rgb_from_string ( text , min_brightness = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> ohash = hashlib . md5 ( text [ : : - <NUM_LIT:1> ] . encode ( "<STR_LIT:ascii>" ) ) . hexdigest ( ) <EOL> r , g , b = int ( ohash [ <NUM_LIT:0> : <NUM_LIT:2> ] , <NUM_LIT:16> ) , int ( ohash [ <NUM_LIT:2> : <NUM_LIT:4> ] , <NUM_LIT:16> ) , int ( ohash [ <NUM_LIT:4> : <NUM_LIT:6> ] , <NUM_LIT:16> ) <EOL> neg_inf = <NUM_LIT:1.0> - min_brightness <EOL> return ( min_brightness + r / <NUM_LIT> * neg_inf , <EOL> min_brightness + g / <NUM_LIT> * neg_inf , <EOL> min_brightness + b / <NUM_LIT> * neg_inf ) <EOL> def profile ( func ) : <EOL> """<STR_LIT>""" <EOL> collector_name = "<STR_LIT>" % func . __name__ <EOL> global_showbase = Globals . base <EOL> if hasattr ( global_showbase , '<STR_LIT>' ) : <EOL> if collector_name in global_showbase . custom_collectors . keys ( ) : <EOL> pstat = global_showbase . custom_collectors [ collector_name ] <EOL> else : <EOL> global_showbase . custom_collectors [ collector_name ] = PStatCollector ( collector_name ) <EOL> pstat = global_showbase . custom_collectors [ collector_name ] <EOL> else : <EOL> pstat = PStatCollector ( collector_name ) <EOL> global_showbase . custom_collectors = { } <EOL> global_showbase . custom_collectors [ collector_name ] = pstat <EOL> def do_pstat ( * args , ** kargs ) : <EOL> pstat . start ( ) <EOL> returned = func ( * args , ** kargs ) <EOL> pstat . stop ( ) <EOL> return returned <EOL> do_pstat . __name__ = func . __name__ <EOL> do_pstat . __dict__ = func . __dict__ <EOL> do_pstat . __doc__ = func . __doc__ <EOL> return do_pstat <EOL> class profile_cpu ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> def __enter__ ( self ) : <EOL> self . start_time = time . clock ( ) <EOL> def __exit__ ( self , * args ) : <EOL> duration = ( time . clock ( ) - self . start_time ) * <NUM_LIT> <EOL> print ( self . name , "<STR_LIT>" , round ( duration , <NUM_LIT:2> ) , "<STR_LIT>" ) <EOL> def snap_shadow_map ( mvp , cam_node , resolution ) : <EOL> """<STR_LIT>""" <EOL> mvp = Mat4 ( mvp ) <EOL> base_point = mvp . xform ( Point4 ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ) * <NUM_LIT:0.5> + <NUM_LIT:0.5> <EOL> texel_size = <NUM_LIT:1.0> / float ( resolution ) <EOL> offset_x = base_point . x % texel_size <EOL> offset_y = base_point . y % texel_size <EOL> mvp . invert_in_place ( ) <EOL> new_base = mvp . xform ( Point4 ( <EOL> ( base_point . x - offset_x ) * <NUM_LIT> - <NUM_LIT:1.0> , <EOL> ( base_point . y - offset_y ) * <NUM_LIT> - <NUM_LIT:1.0> , <EOL> ( base_point . z ) * <NUM_LIT> - <NUM_LIT:1.0> , <NUM_LIT:1> ) ) <EOL> cam_node . set_pos ( cam_node . get_pos ( ) - Vec3 ( new_base . x , new_base . y , new_base . z ) ) </s>
