import taichi as tc from taichi.dynamics.mpm import MPM3 from taichi.visual.texture import Texture if __name__ == '__main__': downsample = 2 resolution = (511 / downsample, 127 / downsample, 255 / downsample) tex = Texture('image', filename=tc.get_asset_path('/textures/taichi_words.png')) * 8 tex = Texture('bound', tex=tex, axis=2, bounds=(0.475, 0.525), outside_val=(0, 0, 0)) mpm = MPM3(resolution=resolution, gravity=(0, -10, 0), initial_velocity=(0, 0, 0), delta_t=0.001, num_threads=8, density_tex=tex.id) for i in range(1000): mpm.step(0.05) mpm.make_video()
from taichi.misc.util import * from taichi.two_d import * from taichi import get_asset_path if __name__ == '__main__': scale = 8 res = (80 * scale, 40 * scale) simulator = MPMSimulator(res=res, simulation_time=30, frame_dt=6e-2, base_delta_t=1e-3) simulator.add_event(-1, lambda s: s.add_particles_texture(Vector(1, 0.60), 1.8, get_asset_path('textures/hybrid.png'), 'ep', theta_c=1, theta_s=1)) levelset = simulator.create_levelset() levelset.add_polygon([(0.05, 0.05), (1, 0.4), (1.95, 0.05), (1.95, 0.95), (0.05, 0.95)], True) levelset.set_friction(0) simulator.set_levelset(levelset) window = SimulationWindow(1280, simulator, color_schemes['bw'], levelset_supersampling=2, show_images=True)
def create_scene(): downsample = 1 width, height = 960 // downsample, 540 // downsample camera = tc.Camera('pinhole', res=(width, height), fov=90, origin=(0, 0, 10), look_at=(0, 0, 0), up=(0, 1, 0)) scene = tc.Scene() with scene: scene.set_camera(camera) taichi_tex = tc.Texture('taichi', scale=0.96) mesh = tc.Mesh('plane', tc.SurfaceMaterial('pbr', diffuse=(.1, .1, .1)), translate=(0, 0, -0.05), scale=10, rotation=(90.3, 0, 0)) scene.add_mesh(mesh) # Taichi Text text = 1 - tc.Texture( 'text', content='Taichi', width=200, height=200, font_file=tc.get_asset_path('fonts/go/Go-Bold.ttf'), size=50, dx=0, dy=0) mesh = tc.Mesh('plane', tc.SurfaceMaterial('transparent', nested=tc.SurfaceMaterial('diffuse', color=(1, 1, 1)), mask=text), translate=(5.0, 2, 0.05), scale=2, rotation=(90, 0, 0)) scene.add_mesh(mesh) mesh = tc.Mesh('plane', tc.SurfaceMaterial('pbr', diffuse=(0.2, 0.5, 0.2)), translate=(0, 0, 0), scale=(8.3, 1, 4.5), rotation=(90, 0, 0)) scene.add_mesh(mesh) ''' text = 1 - tc.Texture('text', content='Physically based Computer Graphics', width=400, height=400, size=30, font_file=tc.get_asset_path('fonts/go/Go-Bold.ttf'), dx=0, dy=0) mesh = tc.Mesh('plane', tc.SurfaceMaterial('transparent', nested=tc.SurfaceMaterial('diffuse', color=(1, 0.1, 0.5)), mask=text), translate=(3.0, -6, 0.03), scale=(2, 2, 2), rotation=(90, 0, 0)) scene.add_mesh(mesh) ''' mesh = tc.Mesh('plane', tc.SurfaceMaterial('pbr', diffuse=(0.2, 0.5, 0.2)), translate=(0, 0, 0), scale=(8.3, 1, 4.5), rotation=(90, 0, 0)) scene.add_mesh(mesh) ring_tex = 1 - tc.Texture('ring', inner=0.0, outer=1.0) grid_tex = (1 - tc.Texture('rect', bounds=(0.9, 0.9, 1.0))).repeat( 6, 6, 1) # Taichi circle mesh = tc.Mesh('plane', tc.SurfaceMaterial('transparent', nested=tc.SurfaceMaterial('diffuse', color=(1, 1, 1)), mask=taichi_tex), translate=(-3.7, 0, 0.05), scale=2, rotation=(90, 0, 0)) scene.add_mesh(mesh) for i in range(1, 5): inv_ring_tex = tc.Texture('ring', inner=0.0, outer=0.5 + i * 0.1) color = colorsys.hls_to_rgb(i * 0.1, 0.5, 1.0) scene.add_mesh( tc.Mesh('plane', tc.SurfaceMaterial('transparent', nested=tc.SurfaceMaterial( 'diffuse', color=color), mask=inv_ring_tex), translate=(-3.7, 0, i * 0.03), scale=4, rotation=(90, 0, 0))) scene.add_mesh( tc.Mesh('plane', tc.SurfaceMaterial('transparent', nested=tc.SurfaceMaterial('diffuse', color=(0, 0.2, 0.5)), mask=grid_tex), translate=(4.3, 0, 0.17), scale=1, rotation=(90, 0, 0))) scene.add_mesh( tc.Mesh('plane', tc.SurfaceMaterial('transparent', nested=tc.SurfaceMaterial('diffuse', color=(1, 1, 0)), mask=grid_tex), translate=(4.3, 0, 0.07), scale=2, rotation=(90, 0, 0))) scene.add_mesh( tc.Mesh('plane', tc.SurfaceMaterial('transparent', nested=tc.SurfaceMaterial('diffuse', color=(0, 1, 1)), mask=grid_tex), translate=(4.3, 0, 0.02), scale=3, rotation=(90, 0, 0))) mesh = tc.Mesh('plane', tc.SurfaceMaterial('emissive', color=(1, 1, 1)), translate=(-30, 30, 10), scale=6, rotation=(0, 0, -90)) scene.add_mesh(mesh) mesh = tc.Mesh('plane', tc.SurfaceMaterial('emissive', color=(1, 1, 1)), translate=(30, 0, 10), scale=2, rotation=(0, 0, 90)) scene.add_mesh(mesh) return scene
def create_scene(): downsample = 2 width, height = 1500 / downsample, 600 / downsample camera = tc.Camera('pinhole', width=width, height=height, fov=30, origin=(0, 1, 20), look_at=(0, 2, 0), up=(0, 1, 0)) scene = tc.Scene() with scene: scene.set_camera(camera) ground_tex = tc.Texture( 'image', filename=tc.get_asset_path('textures/paper.jpg')) mesh = tc.Mesh('plane', tc.SurfaceMaterial('pbr', diffuse_map=ground_tex), translate=(0, 0, -5), scale=10, rotation=(90, 0, 0)) scene.add_mesh(mesh) mesh = tc.Mesh('plane', tc.SurfaceMaterial('pbr', diffuse_map=ground_tex), translate=(0, 0, 0), scale=10, rotation=(0, 0, 0)) scene.add_mesh(mesh) mesh = tc.Mesh('plane', tc.SurfaceMaterial('emissive_spot', color=(1, 1, 1), exponential=3), translate=(0, 0, -1.5), scale=0.1, rotation=(-101, 0, 0)) scene.add_mesh(mesh) fill_light = 0.03 mesh = tc.Mesh('plane', tc.SurfaceMaterial('emissive', color=(fill_light, fill_light, 3 * fill_light)), translate=(0, 10, 30), scale=1, rotation=(-90, 0, 0)) scene.add_mesh(mesh) emission = 3 with tc.transform_scope(rotation=(0, 10, 0)): mesh = tc.Mesh('plane', tc.SurfaceMaterial('emissive_spot', color=(emission, emission, emission), exponential=100), translate=(10, 2, 1), scale=0.1, rotation=(0, 0, 100)) scene.add_mesh(mesh) for j in range(3): for i in range(14): with tc.transform_scope(translate=(i - 7, (random.random() - 0.5) * 0.4, j)): with tc.transform_scope(rotation=(0, 0, 10 - j * 10), translate=(0, -j * 0.3 + i * 0.04 - 0.4, 0)): s = random.random() * 0.5 + 0.8 r = random.random() if r < 0.5: shape = 'cube' else: shape = tc.geometry.create_cylinder((100, 2), smooth=False) mesh = tc.Mesh(shape, tc.SurfaceMaterial('diffuse', color=(0.3, 0.2, 0.1)), scale=(0.4 * s, 1 * s, 0.4 * s), rotation=(-4, -12, 0)) scene.add_mesh(mesh) return scene
async = True if async: simulator = MPMSimulator(res=res, simulation_time=30, frame_dt=1e-1, base_delta_t=1e-6, async=True, strength_dt_mul=6) else: simulator = MPMSimulator(res=res, simulation_time=30, frame_dt=1e-1, base_delta_t=1e-3) simulator.add_event( -1, lambda s: s.add_particles_texture( Vector(1, 0.60), 1.8, get_asset_path('textures/asyncmpm.png'), 'ep' )) levelset = simulator.create_levelset() levelset.add_polygon([(0.05, 0.05), (1, 0.4), (1.95, 0.05), (1.95, 0.95), (0.05, 0.95)], True) levelset.set_friction(0) simulator.set_levelset(levelset) window = SimulationWindow(1280, simulator, color_schemes['bw'], levelset_supersampling=2, show_images=True, show_stat=False)
if __name__ == '__main__': downsample = grid_downsample resolution = (255 / downsample, 255 / downsample, 255 / downsample) mpm = MPM3(resolution=resolution, gravity=(0, -50, 0), async=True, num_threads=8, strength_dt_mul=4, affine_damping=1000) tex = Texture('mesh', resolution=resolution, filename=tc.get_asset_path('meshes/armadillo.obj')) tex = Texture('rotate', tex=tex, rotate_axis=1, rotate_times=2) tex = tex.zoom((0.4, 0.4, 0.4), (0.5, 0, 0.5), False) tex = tex * (Texture('perlin').zoom((10, 10, 10)) * 6 + 2) # tex = Texture('rotate', tex=tex, rotate_axis=0, rotate_times=1) # tex = Texture('rotate', tex=tex, rotate_axis=2, rotate_times=1) mpm.add_particles(density_tex=tex.id, initial_velocity=(0, 0, 0), theta_c=1, theta_s=1) # Dynamic Levelset def levelset_generator(t): levelset = mpm.create_levelset() levelset.add_cuboid((0.01, 0.01, 0.01), (0.99, 0.99, 0.99), True) for i in range(0, 24, 3):
import taichi as tc from taichi.dynamics.mpm import MPM3 from taichi.visual.texture import Texture if __name__ == '__main__': downsample = 3 resolution = (511 / downsample, 127 / downsample, 255 / downsample) tex = Texture('image', filename=tc.get_asset_path('/textures/taichi_words.png')) * 8 tex = Texture('bound', tex=tex, axis=2, bounds=(0.475, 0.525), outside_val=(0, 0, 0)) mpm = MPM3(resolution=resolution, gravity=(0, -10, 0), initial_velocity=(0, 0, 0), delta_t=0.001, num_threads=8, density_tex=tex.id) for i in range(1000): mpm.step(0.05) mpm.make_video()
import time import taichi as tc from taichi.gui.image_viewer import show_image tc.core.print_all_units() tc.core.test() tex = tc.Texture('const', value=(0.1, 0.1, 0.1, 0.1)) tex = tex.flip(0) try: tc.core.test_raise_error() except Exception as e: print 'Exception:', e img = tc.util.imread(tc.get_asset_path('textures/vegas.jpg')) show_image('img', img) time.sleep(1) print 'Testing passed.'
def render_frame(frame, d, t): renderer = Renderer(output_dir='volumetric', overwrite=True, frame=frame) renderer.initialize(preset='pt', scene=create_scene(frame, d, t), sampler='prand', max_path_length=3) renderer.set_post_processor(LDRDisplay(exposure=1, bloom_radius=0.00, bloom_threshold=1.0)) renderer.render(render_epoch) if __name__ == '__main__': downsample = grid_downsample resolution = (255 / downsample, 255 / downsample, 255 / downsample) mpm = MPM3(resolution=resolution, gravity=(0, -50, 0), async=False, base_delta_t=0.0002, num_threads=8, strength_dt_mul=4) tex = Texture('mesh', resolution=resolution, filename=tc.get_asset_path('meshes/bunny.obj')) tex = tex.zoom((0.4, 0.4, 0.4), (0.5, 0.5, 0.5), False) tex = Texture('rotate', tex=tex, rotate_axis=0, rotate_times=1) tex = tex * (Texture('perlin').zoom((10, 10, 10)) * 6 + 2) mpm.add_particles(density_tex=tex.id, initial_velocity=(0, 0, -50)) levelset = mpm.create_levelset() levelset.add_cuboid((0.01, 0.01, 0.01), (0.99, 0.99, 0.99), True) mpm.set_levelset(levelset) t = 0 for i in range(step_number): print 'process(%d/%d)' % (i, step_number) mpm.step(0.01) t += 0.01 if gi_render: