def at_startup(): assert os.path.exists(get_root_directory( )), 'Please make sure $TAICHI_ROOT_DIR [' + get_root_directory( ) + '] exists.' output_dir = get_output_directory() if not os.path.exists(output_dir): print('Making output directory') os.mkdir(output_dir) # Load modules f = open(os.path.join(get_root_directory(), 'taichi', 'modules.txt'), 'r') modules = f.readline().strip().split(';') for module in modules: if module != '': print('Loading module', module) try: ctypes.PyDLL( os.path.join(get_root_directory(), 'taichi', 'build', get_dll_name(module))) except Exception as e: print(e) print("Warning: module", module, "loading failed!") tc_core.set_core_state_python_imported(True) f.close()
def __init__(self, max_side, simulator, color_scheme, levelset_supersampling=2, show_grid=False, show_images=True, rescale=True, video_framerate=24, video_output=True, substep=False, need_press=False, show_stat=True): if rescale: scale = min(1.0 * max_side / simulator.res[0], 1.0 * max_side / simulator.res[1]) width = int(round(scale * simulator.res[0])) height = int(round(scale * simulator.res[1])) else: width = max_side height = max_side super(SimulationWindow, self).__init__(width=width, height=height, fullscreen=False, caption='Taichi', config=pyglet.gl.Config(sample_buffers=0, samples=0, depth_size=16, double_buffer=True)) self.width = width self.height = height self.video_framerate = video_framerate self.task_id = get_unique_task_id() self.simulator = simulator self.frame_count = 0 self.color_scheme = color_scheme self.show_images = show_images self.levelset_supersampling = levelset_supersampling self.show_grid = show_grid self.quit_pressed = False self.output_directory = os.path.join(get_output_directory(), self.task_id) self.cpu_time = 0 self.show_stat = show_stat os.mkdir(self.output_directory) self.substep = substep self.video_output = video_output self.video_manager = VideoManager(self.output_directory, automatic_build=self.video_output) self.need_press = need_press self.pressed = False pyglet.clock.schedule_interval(self.update, 1 / 120.0) pyglet.app.run()
def at_startup(): if not is_release(): output_dir = get_output_directory() if not os.path.exists(output_dir): print('Making output directory') os.mkdir(output_dir) tc_core.set_core_state_python_imported(True)
def at_startup(): assert os.path.exists(get_root_directory( )), 'Please make sure $TAICHI_ROOT_DIR [' + get_root_directory( ) + '] exists.' output_dir = get_output_directory() if not os.path.exists(output_dir): print 'Making output directory' os.mkdir(output_dir)
def browse_outputs(): output_dir = get_output_directory() dirs = os.listdir(output_dir) dirs = sorted(dirs) entries = [] for d in dirs: entries.append({ 'title': d, 'text': '', }) return render_template('browser.html', entries=entries)
def at_startup(): assert os.path.exists(get_repo_directory( )), 'Please make sure $TAICHI_REPO_DIR [' + get_repo_directory( ) + '] exists.' output_dir = get_output_directory() if not os.path.exists(output_dir): print('Making output directory') os.mkdir(output_dir) # Load modules load_module('lang_core') tc_core.set_core_state_python_imported(True)
def at_startup(): assert os.path.exists(get_repo_directory( )), 'Please make sure $TAICHI_REPO_DIR [' + get_repo_directory() + '] exists.' output_dir = get_output_directory() if not os.path.exists(output_dir): print('Making output directory') os.mkdir(output_dir) # Load modules f = open(os.path.join(get_repo_directory(), 'modules.txt'), 'r') modules = f.readline().strip().split(';') for module in modules: if module != '': load_module(module) tc_core.set_core_state_python_imported(True) f.close()
def next_frame(): content = request.get_json(silent=True) print(content) directory = os.path.join(get_output_directory(), content['path']) files = sorted(os.listdir(directory)) files = list(filter(lambda x: x.endswith('.json'), files)) frame_fn = '%04d.json' % content['frame_id'] next_frame = files[(files.index(frame_fn) + content['inc']) % len(files)].split('.')[0] next_frame = int(next_frame) json_path = os.path.join(directory, frame_fn) response = {'next_frame': next_frame} if content['need_geometry']: with open(json_path) as f: response['data'] = json.loads(f.read()) return json.dumps(response)
os.chdir(tmp_cwd) elif get_os_name() == 'win': bin_dir = get_bin_directory() dll_path = os.path.join(bin_dir, 'Release', 'taichi_core.dll') if not os.path.exists(dll_path): build() # The problem here is, on windows, when an dll/pyd is loaded, we can not write to it any more old_wd = os.getcwd() os.chdir(bin_dir) if CREATE_SAND_BOX_ON_WINDOWS: # Create a sandbox for separated core lib development and loading dir = os.path.join(get_output_directory(), 'tmp', get_unique_task_id()) os.environ['PATH'] += ';' + (os.path.join(get_repo_directory(), 'external', 'lib')) os.makedirs(dir) shutil.copy(dll_path, os.path.join(dir, 'taichi_core.pyd')) sys.path.append(dir) else: shutil.copy(dll_path, os.path.join(bin_dir, 'taichi_core.pyd')) sys.path.append(bin_dir) import taichi_core as tc_core os.chdir(old_wd) def get_dll_name(name):
exit(-1) os.chdir(tmp_cwd) elif get_os_name() == 'win': bin_dir = get_bin_directory() dll_path1 = os.path.join(bin_dir, 'RelWithDebInfo', 'taichi_core.dll') dll_path2 = os.path.join(bin_dir, 'libtaichi_core.dll') assert os.path.exists(dll_path1) and not os.path.exists(dll_path2) # On windows when an dll/pyd is loaded, we can not write to it any more old_wd = os.getcwd() os.chdir(bin_dir) if create_sand_box_on_windows: # Create a sandbox for separated core lib development and loading dir = os.path.join(get_output_directory(), 'tmp', get_unique_task_id()) lib_dir = os.path.join(get_repo_directory(), 'external', 'lib') os.environ['PATH'] += ';' + lib_dir os.makedirs(dir) if os.path.exists(dll_path1): shutil.copy(dll_path1, os.path.join(dir, 'taichi_core.pyd')) else: shutil.copy(dll_path2, os.path.join(dir, 'taichi_core.pyd')) os.environ['PATH'] += ';' + dir sys.path.append(dir) else: shutil.copy(dll_path, os.path.join(bin_dir, 'taichi_core.pyd')) sys.path.append(bin_dir)
bin_dir = get_bin_directory() + '/' dll_path = bin_dir + '/Release/taichi_core.dll' if not os.path.exists(dll_path): dll_path = bin_dir + '/taichi_core.dll' if not os.path.exists(dll_path): assert False, "Library taichi_core doesn't exist." # The problem here is, on windows, when an dll/pyd is loaded, we can not write to it any more... # Ridiculous... old_wd = os.getcwd() os.chdir(bin_dir) if CREATE_SAND_BOX_ON_WINDOWS: # So let's just create a sandbox for separated core lib development and loading dir = get_output_directory() + '/tmp/' + get_unique_task_id() + '/' os.makedirs(dir) ''' for fn in os.listdir(bin_dir): if fn.endswith('.dll') and fn != 'taichi_core.dll': print dir + fn, bin_dir + fn # Why can we create symbolic links.... # if not ctypes.windll.kernel32.CreateSymbolicLinkW(bin_dir + fn, dir + fn, 0): # raise OSError shutil.copy(bin_dir + fn, dir + fn) ''' shutil.copy(dll_path, dir + 'taichi_core.pyd') sys.path.append(dir) else: shutil.copy(dll_path, bin_dir + 'taichi_core.pyd') sys.path.append(bin_dir)
import glob import os import pyglet from pyglet.gl import * from taichi.misc.util import get_os_name, get_unique_task_id from taichi.misc.settings import get_output_directory VIDEO_OUTPUT_ROOT = get_output_directory() def normalized_color_255(*args): return tuple(map(lambda x: x / 255.0, args)) class SimulationWindow(pyglet.window.Window): def __init__(self, max_side, simulator, color_scheme, levelset_supersampling=2, show_grid=False, show_images=True, rescale=True): if rescale: scale = min(1.0 * max_side / simulator.simulation_width, 1.0 * max_side / simulator.simulation_height) width = int(round(scale * simulator.simulation_width)) height = int(round(scale * simulator.simulation_height)) else:
output_dir = get_output_directory() dirs = os.listdir(output_dir) dirs = sorted(dirs) entries = [] for d in dirs: entries.append({ 'title': d, 'text': '', }) return render_template('browser.html', entries=entries) @app.route('/view/<folder>') def view(folder): return render_template('view.html', folder=folder) frame_buffer = os.path.join(get_output_directory(), 'frame_buffer') video_buffer = os.path.join(get_output_directory(), 'videos') @app.route('/clear_frame_buffer', methods=['POST']) def clear_frame_buffer(): try: os.mkdir(frame_buffer) except Exception as e: print(e) clear_directory_with_suffix(frame_buffer, 'png') return '' @app.route('/make_video/<task_id>', methods=['POST']) def make_video(task_id): try: os.mkdir(video_buffer)