def play_replay(resultid, existing, startpos): seconds = None if startpos: try: seconds = int(startpos) except ValueError: minutes, seconds = [int(a) for a in startpos.split(":")] seconds += minutes * 60 if not os.path.exists("local_replays"): os.makedirs("local_replays") filename = os.path.join("local_replays", "replay_%d.bin" % resultid) if not os.path.exists(filename): network.download_replay(resultid, filename) with Simulator(start=not existing, autoquit=False, fixed_time_step=False) as simulator: simulator.set_paused(True) simulator.remove_all_vehicles() simulator.start_playback(filename) if seconds: simulator.seek_and_pause_replay(seconds) simulator.set_replay_paused(False)
def play_replay(resultid, existing, startpos): seconds = None if startpos: try: seconds = int(startpos) except ValueError: minutes, seconds = [int(a) for a in startpos.split(':')] seconds += minutes * 60 if not os.path.exists('local_replays'): os.makedirs('local_replays') filename = os.path.join('local_replays', 'replay_%d.bin' % resultid) if not os.path.exists(filename): network.download_replay(resultid, filename) with Simulator(start=not existing, autoquit=False, fixed_time_step=False) as simulator: simulator.set_paused(True) simulator.remove_all_vehicles() simulator.start_playback(filename) if seconds: simulator.seek_and_pause_replay(seconds) simulator.set_replay_paused(False)
def record_movie( existing, matinee, camera, vehicle, camera_name, follow, resultid, startpos, record, followcam, speed, offset_y, offset_z, look_distance, look_offset_z, look_offset_y, rev, endpos, fov, show_arrows, behaviors, start_dist, fsmooth, ): # Since - looks like a parameter, we replace m by -, this way m can be used instead of # - at the command line. offset_y = offset_y.replace("m", "-") if offset_y else None offset_z = offset_z.replace("m", "-") if offset_z else None look_distance = look_distance.replace("m", "-") if look_distance else None look_offset_z = look_offset_z.replace("m", "-") if look_offset_z else None look_offset_y = look_offset_y.replace("m", "-") if look_offset_y else None behaviors = behaviors.split(",") if behaviors else [] behaviors = [a.strip() for a in behaviors] if not os.path.exists("local_replays"): os.makedirs("local_replays") minutes = 0 try: seconds = float(startpos) except ValueError: minutes, seconds = [float(a) for a in startpos.split(":")] total_seconds = seconds + minutes * 60 end_minutes = 0 try: end_seconds = int(endpos) except ValueError: end_minutes, end_seconds = [int(a) for a in endpos.split(":")] end_total_seconds = end_seconds + end_minutes * 60 try: resultid = int(resultid) filename = os.path.join("local_replays", "replay_%d.bin" % resultid) if not os.path.exists(filename): network.download_replay(resultid, filename) except ValueError: filename = resultid resultid = os.path.split(filename)[-1] print filename moviename = "%s_%02d%02d" % (resultid, minutes, seconds) if matinee: moviename += "_mat_%s" % matinee if camera: moviename += "_cam_%s" % camera if vehicle: moviename += "_veh_%s_%s" % (vehicle, camera_name) if followcam: moviename += "_followcam_%s_%s_%s_%s" % (speed, offset_z, offset_y, fov) if look_distance: moviename += "_%s_%s_%s" % (look_distance, look_offset_z, look_offset_y) if rev: moviename += "_rev" if follow: moviename += "_follow_%s" % follow with Simulator( start=not existing, autoquit=True, fixed_time_step=True, dumpmovie=record, moviename=moviename ) as simulator: if not record: simulator.execute_command("r.setres 1920x1080") # First we remove all existing vehicles simulator.set_paused(True) simulator.remove_all_vehicles() simulator.set_arrows_visible(show_arrows, behaviors) simulator.start_playback(filename) if total_seconds > 0: simulator.seek_and_pause_replay(total_seconds) simulator.set_replay_paused(False) if matinee: simulator.start_matinee("Matinee" + matinee) if camera: simulator.select_camera("Camera" + camera) if vehicle: simulator.select_vehicle_camera(int(vehicle), camera_name) if follow: simulator.camera_look_at_vehicle(int(follow)) if followcam: simulator.followcam( speed=float(speed), offset_z=float(offset_z), offset_y=float(offset_y), look_distance=float(look_distance) if look_distance else 0.0, rev=rev, look_offset_y=float(look_offset_y) if look_offset_y else 0.0, look_offset_z=float(look_offset_z) if look_offset_z else 0.0, fov=float(fov), start_distance=float(start_dist), fsmooth=float(fsmooth), ) print ("") while True: stats = simulator.receive_stats() total_seconds = stats["time"] minutes, seconds = divmod(total_seconds, 60) print (CURSOR_UP_ONE + ERASE_LINE + CURSOR_UP_ONE) print ("%02d:%02d / %02d:%02d" % (minutes, seconds, end_minutes, end_seconds)) if total_seconds >= end_total_seconds: break
def record_movie(existing, matinee, camera, vehicle, camera_name, follow, resultid, startpos, record, followcam, speed, offset_y, offset_z, look_distance, look_offset_z, look_offset_y, rev, endpos, fov, show_arrows, behaviors, start_dist, fsmooth): # Since - looks like a parameter, we replace m by -, this way m can be used instead of # - at the command line. offset_y = offset_y.replace('m', '-') if offset_y else None offset_z = offset_z.replace('m', '-') if offset_z else None look_distance = look_distance.replace('m', '-') if look_distance else None look_offset_z = look_offset_z.replace('m', '-') if look_offset_z else None look_offset_y = look_offset_y.replace('m', '-') if look_offset_y else None behaviors = behaviors.split(',') if behaviors else [] behaviors = [a.strip() for a in behaviors] if not os.path.exists('local_replays'): os.makedirs('local_replays') minutes = 0 try: seconds = float(startpos) except ValueError: minutes, seconds = [float(a) for a in startpos.split(':')] total_seconds = seconds + minutes * 60 end_minutes = 0 try: end_seconds = int(endpos) except ValueError: end_minutes, end_seconds = [int(a) for a in endpos.split(':')] end_total_seconds = end_seconds + end_minutes * 60 try: resultid = int(resultid) filename = os.path.join('local_replays', 'replay_%d.bin' % resultid) if not os.path.exists(filename): network.download_replay(resultid, filename) except ValueError: filename = resultid resultid = os.path.split(filename)[-1] print filename moviename = "%s_%02d%02d" % (resultid, minutes, seconds) if matinee: moviename += "_mat_%s" % matinee if camera: moviename += "_cam_%s" % camera if vehicle: moviename += "_veh_%s_%s" % (vehicle, camera_name) if followcam: moviename += "_followcam_%s_%s_%s_%s" % (speed, offset_z, offset_y, fov) if look_distance: moviename += "_%s_%s_%s" % (look_distance, look_offset_z, look_offset_y) if rev: moviename += "_rev" if follow: moviename += "_follow_%s" % follow with Simulator(start=not existing, autoquit=True, fixed_time_step=True, dumpmovie=record, moviename=moviename) as simulator: if not record: simulator.execute_command('r.setres 1920x1080') # First we remove all existing vehicles simulator.set_paused(True) simulator.remove_all_vehicles() simulator.set_arrows_visible(show_arrows, behaviors) simulator.start_playback(filename) if total_seconds > 0: simulator.seek_and_pause_replay(total_seconds) simulator.set_replay_paused(False) if matinee: simulator.start_matinee('Matinee' + matinee) if camera: simulator.select_camera('Camera' + camera) if vehicle: simulator.select_vehicle_camera(int(vehicle), camera_name) if follow: simulator.camera_look_at_vehicle(int(follow)) if followcam: simulator.followcam( speed=float(speed), offset_z=float(offset_z), offset_y=float(offset_y), look_distance=float(look_distance) if look_distance else 0.0, rev=rev, look_offset_y=float(look_offset_y) if look_offset_y else 0.0, look_offset_z=float(look_offset_z) if look_offset_z else 0.0, fov=float(fov), start_distance=float(start_dist), fsmooth=float(fsmooth)) print('') while True: stats = simulator.receive_stats() total_seconds = stats['time'] minutes, seconds = divmod(total_seconds, 60) print(CURSOR_UP_ONE + ERASE_LINE + CURSOR_UP_ONE) print('%02d:%02d / %02d:%02d' % (minutes, seconds, end_minutes, end_seconds)) if total_seconds >= end_total_seconds: break