예제 #1
0
파일: util.py 프로젝트: sahirbutt/taichi
def load_module(name, verbose=True):
    if verbose:
        print('Loading module', name)
    try:
        if get_os_name() == 'osx':
            mode = ctypes.RTLD_LOCAL
        else:
            mode = ctypes.RTLD_GLOBAL
        if '.so' in name:
            ctypes.PyDLL(name, mode=mode)
        else:
            ctypes.PyDLL(os.path.join(get_repo_directory(), 'build',
                                      get_dll_name(name)),
                         mode=mode)
    except Exception as e:
        print(Fore.YELLOW +
              "Warning: module [{}] loading failed: {}".format(name, e) +
              Style.RESET_ALL)
예제 #2
0
def build():
    tmp_cwd = os.getcwd()
    bin_dir = get_build_directory()

    try:
        os.mkdir(bin_dir)
    except:
        pass
    os.chdir(bin_dir)

    import multiprocessing
    print('Building taichi...')
    num_make_threads = min(20, multiprocessing.cpu_count())
    if get_os_name() == 'win':
        make_ret = os.system(
            "msbuild /p:Configuration=Release /p:Platform=x64 /m taichi.sln")
    else:
        make_ret = os.system('make -j {}'.format(num_make_threads))
    if make_ret != 0:
        print('  Error: Build failed.')
        exit(-1)

    os.chdir(tmp_cwd)
예제 #3
0
def get_dll_name(name):
    if get_os_name() == 'linux':
        return 'libtaichi_%s.so' % name
    else:
        assert False
예제 #4
0
    import multiprocessing
    print('Building taichi...')
    num_make_threads = min(20, multiprocessing.cpu_count())
    if get_os_name() == 'win':
        make_ret = os.system(
            "msbuild /p:Configuration=Release /p:Platform=x64 /m taichi.sln")
    else:
        make_ret = os.system('make -j {}'.format(num_make_threads))
    if make_ret != 0:
        print('  Error: Build failed.')
        exit(-1)

    os.chdir(tmp_cwd)


if get_os_name() == 'osx':
    bin_dir = get_bin_directory()
    os.environ['DYLD_FALLBACK_LIBRARY_PATH'] = get_runtime_directory()
    if not os.path.exists(os.path.join(bin_dir, 'libtaichi_core.dylib')):
        build()
    tmp_cwd = os.getcwd()
    os.chdir(bin_dir)
    shutil.copy('libtaichi_core.dylib', 'taichi_core.so')
    sys.path.append(bin_dir)
    import taichi_core as tc_core
    os.chdir(tmp_cwd)
elif get_os_name() == 'linux':
    bin_dir = get_bin_directory()
    os.environ['LD_LIBRARY_PATH'] = '/usr/lib64/'
    if not os.path.exists(os.path.join(bin_dir, 'libtaichi_core.so')):
        build()
예제 #5
0
import glob
import os

import pyglet
from pyglet.gl import *

from taichi.misc.util import get_os_name

if get_os_name() == 'osx':
    VIDEO_OUTPUT_ROOT = '/Users/Iterator/simulation_results'
else:
    VIDEO_OUTPUT_ROOT = 'C:/tmp/simulation'


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:
            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))
        uuid = get_uuid()