コード例 #1
0
ファイル: banana.py プロジェクト: zhiliwei/taichi_mpm
        base_delta_t=5e-5,
        num_frames=1000,
        penalty=1e3,
        cfl=0.5,
        rpic_damping=1,
    )

    levelset = mpm.create_levelset()
    levelset.add_plane(tc.Vector(0, 1, 0), -0.42)
    levelset.add_plane(tc.Vector(1, 0, 0), -0.16)
    levelset.set_friction(-1)
    mpm.set_levelset(levelset, False)

    tex = tc.Texture('mesh',
                     resolution=(2 * r, 2 * r, 2 * r),
                     translate=(0.4, 0.5, 0.55),
                     scale=(0.05, 0.07, 0.07),
                     adaptive=False,
                     filename='$mpm/banana.obj') * 10

    mpm.add_particles(type='von_mises',
                      pd=True,
                      density_tex=tex.id,
                      initial_velocity=(0, 0, 0),
                      density=400,
                      color=(0.8, 0.7, 1.0),
                      initial_position=(0.5, 0.5, 0.5),
                      youngs_modulus=4e5,
                      poisson_ratio=0.4,
                      yield_stress=5)

    length = 0.20
コード例 #2
0
if __name__ == '__main__':
    mpm = tc.dynamics.MPM(
        gravity=(0, -4.0),
        res=(r + 1, r + 1, r + 1),
        frame_dt=0.01,
        base_delta_t=0.0003,
        num_frames=500,
    )

    levelset = mpm.create_levelset()
    levelset.add_plane(tc.Vector(0.0, 1, 0), -0.2)
    levelset.set_friction(-1)
    mpm.set_levelset(levelset, False)

    tex = tc.Texture('sphere', center=(0.5, 0.45, 0.5), radius=0.04) * 10
    tex = tex.translate(tc.Vector(0.2, 0.45, 0.5))

    tex = tc.Texture('mesh',
                     resolution=(2 * r, 2 * r, 2 * r),
                     translate=(0.5, 0.56, 0.47),
                     scale=(0.4, 0.4, 0.4),
                     adaptive=False,
                     filename='$mpm/bunny_small.obj') * 15

    mpm.add_particles(type='jelly',
                      pd=True,
                      density_tex=tex.id,
                      initial_velocity=(0, 0, 0),
                      density=400,
                      color=(0.8, 0.7, 1.0),
コード例 #3
0
    levelset = mpm.create_levelset()
    levelset.add_plane(tc.Vector(0, 1, 0), -0.4)
    levelset.add_plane(tc.Vector(1, 0, 0), -0.1)
    levelset.add_plane(tc.Vector(-1, 0, 0), 0.9)
    levelset.add_plane(tc.Vector(0, 0, 1), -0.1)
    levelset.add_plane(tc.Vector(0, 0, -1), 0.9)
    levelset.set_friction(0.4)
    mpm.set_levelset(levelset, False)

    #tex = tc.Texture('rect', bounds=(0.6, 0.01, 0.6)) * 10
    #tex = tex.translate((0, -0.1, 0))

    tex = tc.Texture('mesh',
                     translate=(0.5, 0.43, 0.5),
                     scale=(0.7, 0.4, 0.7),
                     adaptive=False,
                     filename='projects/mpm/data/sand_mountain.obj') * 8

    mpm.add_particles(type='sand',
                      pd=True,
                      density_tex=tex.id,
                      initial_position=(0, 0, 0),
                      initial_velocity=(0, 0, 0),
                      friction_angle=35,
                      density=400,
                      color=(0.9, 0.5, 0.6))

    def position_function(t):
        if (t < 0.1):
            return tc.Vector(0.5, 0.45, 0.3)
コード例 #4
0
ファイル: material_balls.py プロジェクト: xj361685640/taichi
def create_scene():
    downsample = 1
    camera = tc.Camera('thinlens',
                       res=(960 // downsample, 540 // downsample),
                       fov=40,
                       origin=(0, 20, 40),
                       look_at=(0, 1, 0),
                       up=(0, 1, 0),
                       aperture=0.3)

    scene = tc.Scene()

    base_mesh = tc.geometry.create_sphere((50, 50), smooth=True)

    materials = [
        tc.SurfaceMaterial('diffuse', color=(1, 0, 0)),
        tc.SurfaceMaterial('diffuse', color=(0, 1, 0)),
        tc.SurfaceMaterial('diffuse', color=(0, 0, 1)),
        tc.SurfaceMaterial('reflective', color=(1, 1, 1)),
        tc.SurfaceMaterial('glossy', color=(1, 1, 1), glossiness=(10, 10, 10)),
        tc.SurfaceMaterial('refractive', color=(1, 1, 1), ior=2.5),
        tc.SurfaceMaterial('pbr',
                           diffuse=(1, 0, 0),
                           specular=(0, 1, 0),
                           glossiness=(100, 0, 0)),
    ]

    with scene:
        scene.set_camera(camera)

        for i, mat in enumerate(materials):
            scene.add_mesh(
                tc.Mesh(base_mesh,
                        mat,
                        translate=((i - (len(materials) - 1) / 2) * 3, 1.3, 0),
                        scale=1))

        # Ground
        tex = (((tc.Texture('perlin') + 1) * 6).zoom(
            (0.6, 0.6, 0.6))).fract() * (1.0, 0.7, 0.4)
        scene.add_mesh(
            tc.Mesh('plane',
                    tc.SurfaceMaterial('pbr', diffuse_map=tex),
                    scale=200,
                    translate=(0, 0, 0),
                    rotation=(0, 0, 0)))

        # Board
        gradient = tc.Texture('uv', coeff_u=1, coeff_v=0)

        scene.add_mesh(
            tc.Mesh('plane',
                    tc.SurfaceMaterial('pbr',
                                       diffuse_map=gradient,
                                       specular_map=1 - gradient),
                    scale=(10, 1, 1),
                    translate=(0, 0.3, 2),
                    rotation=(0, 0, 0)))

        scene.add_mesh(
            tc.Mesh('plane',
                    tc.SurfaceMaterial('glossy',
                                       color=(1, 1, 1),
                                       glossiness_map=gradient * 100),
                    scale=(10, 1, 1),
                    translate=(0, 0.3, 4.5),
                    rotation=(0, 0, 0)))

        scene.add_mesh(
            tc.Mesh('plane',
                    tc.SurfaceMaterial('pbr',
                                       diffuse_map=gradient * (1, 0, 0) +
                                       (1 - gradient) * (0, 1, 1)),
                    scale=(10, 1, 1),
                    translate=(0, 0.3, 7),
                    rotation=(0, 0, 0)))

        scene.add_mesh(
            tc.Mesh('plane',
                    tc.SurfaceMaterial('transparent',
                                       mask=gradient,
                                       nested=tc.SurfaceMaterial('diffuse',
                                                                 color=(1, 1,
                                                                        1))),
                    scale=(10, 1, 1),
                    translate=(0, 0.3, 9.5),
                    rotation=(0, 0, 0)))

        for i in range(10):
            scene.add_mesh(
                tc.Mesh(tc.geometry.create_mesh_from_functions(
                    (50, 50), lambda p: Vector(
                        p.x * 2 - 1,
                        sin(p.x * 10 * pi) + cos(p.y * 5 * pi), p.y * 2 - 1)),
                        material=tc.SurfaceMaterial('reflective',
                                                    color=(1, 1, 1)),
                        translate=(0, 1, -6),
                        scale=(8, 0.2, 2)))

        envmap = tc.EnvironmentMap('base',
                                   filepath=tc.settings.get_asset_path(
                                       'envmaps/schoenbrunn-front_hd.hdr'))
        envmap.set_transform(
            tc.core.Matrix4(1.0).rotate_euler(Vector(0, 30, 0)))
        scene.set_environment_map(envmap)

    return scene
コード例 #5
0
ファイル: sand.py プロジェクト: squarefk/taichi_mpm
        particle_collision=False,
        optimized=True,
        verbose_bgeo=True,
        gravity=(0, -1, 0),
        base_delta_t=1e-6 * 64,
        task_id=task_id,
        num_frames=120)

  levelset = mpm.create_levelset()
  levelset.add_cuboid((0, 0.2, 0.05), (0.95, 0.95, 0.95), True)
  levelset.set_friction(-3)
  mpm.set_levelset(levelset, False)

  tex = tc.Texture(
      'mesh',
      translate=(0.5, 0.5, 0.5),
      scale=(0.012, 0.012, 0.012),
      adaptive=True,
      filename='../../data/cute_dragon.obj') * 8
  tex = tc.Texture(
      'rotate', tex=tex, rotate_axis=1, rotate_times=3).translate((0.1, -0.125,
                                                                   0))

  mpm.add_particles(
      type='sand',
      density_tex=tex.id,
      lambda_0=20000,
      mu_0=1000,
      friction_angle=10)

  tex_sphere = tc.Texture(
      'mesh',
コード例 #6
0
ファイル: paper_cut.py プロジェクト: zgsxwsdxg/taichi
def create_scene():
    downsample = 1
    width, height = 960 / downsample, 540 / downsample
    camera = tc.Camera('pinhole',
                       width=width,
                       height=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
コード例 #7
0
ファイル: vcm.py プロジェクト: zhutaorun/taichi
                           fov=90,
                           origin=(-5, 2, 0),
                           look_at=(0, 1, 2),
                           up=(0, 1, 0),
                           aperture=10)
        scene.set_camera(camera)

        # Box
        scene.add_mesh(
            tc.Mesh('cube',
                    material=tc.SurfaceMaterial('pbr', diffuse=(1, 1, 1)),
                    scale=10))

        tex = tc.Texture('checkerboard',
                         tex1=tc.Texture('const', value=(1, 1, 0.5, 1)),
                         tex2=tc.Texture('const', value=(0.5, 0.5, 0.5)),
                         repeat_u=10,
                         repeat_v=10)

        # Ground
        scene.add_mesh(
            tc.Mesh(tc.geometry.create_plane(),
                    material=tc.SurfaceMaterial(
                        'pbr',
                        diffuse_map=tex,
                    ),
                    scale=10))

        # Mirror
        scene.add_mesh(
            tc.Mesh('plane',
コード例 #8
0
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.'
コード例 #9
0
ファイル: water.py プロジェクト: zhiliwei/taichi_mpm
                              particle_collision=False,
                              optimized=True,
                              verbose_bgeo=True,
                              gravity=(0, -1, 0),
                              base_delta_t=1e-6 * 16,
                              task_id=task_id,
                              num_frames=240)

    levelset = mpm.create_levelset()
    levelset.add_cuboid((0, 0.2, 0.05), (0.95, 0.95, 0.95), True)
    levelset.set_friction(-2.5)
    mpm.set_levelset(levelset, False)

    tex = tc.Texture('mesh',
                     translate=(0.5, 0.5, 0.5),
                     scale=(0.012, 0.012, 0.012),
                     adaptive=True,
                     filename='$mpm/cute_dragon.obj') * 8
    tex = tc.Texture('rotate', tex=tex, rotate_axis=1,
                     rotate_times=3).translate((0.1, -0.125, 0))

    mpm.add_particles(
        type='elastic',
        density_tex=tex.id,
    )

    tex = tc.Texture('ring', outer=0.03) * 8
    tex = tc.Texture('bound',
                     tex=tex,
                     axis=2,
                     bounds=(0.45, 0.55),
コード例 #10
0
ファイル: balls.py プロジェクト: squarefk/taichi_mpm
    def levelset_generator(t):
        during = 1
        if t > during:
            t = during
        d = 0.12 * t / during
        levelset = mpm.create_levelset()
        levelset.add_cuboid((0.1 + d, 0.5, 0.1 + d),
                            (0.9 - d, 0.5 + box, 0.9 - d), True)
        levelset.set_friction(-2)
        return levelset

    mpm.set_levelset(levelset_generator, True)

    tex_sphere = tc.Texture('mesh',
                            translate=((0, 0, 0)),
                            scale=(radius, radius, radius),
                            adaptive=True,
                            filename='../../data/sphere_small.obj') * 8
    for i in range(n):
        for j in range(n):
            center = (first + i * box, 0.5 + box * 0.5, first + j * box)
            tex = tex_sphere.translate(center)
            if i == 1 and j == 4:
                E = 2e5
            elif i == 2 and j == 1:
                E = 8e3
            elif i == 3 and j == 1:
                E = 8e3
            elif i == 4 and j == 2:
                E = 4e4
            else:
コード例 #11
0
ファイル: stork.py プロジェクト: zhiliwei/taichi_mpm
                              verbose_bgeo=True,
                              gravity=(0, 0, 0),
                              base_delta_t=1e-6 * 8,
                              task_id=task_id,
                              print_energy=True,
                              num_frames=480)

    levelset = mpm.create_levelset()
    # levelset.add_plane(tc.Vector(0, 1, 0), -0.3)
    levelset.add_cuboid((0.5, 0.1, 0.3), (0.7, 0.35, 0.7), False)
    levelset.set_friction(-1)
    mpm.set_levelset(levelset, False)

    tex = tc.Texture('mesh',
                     translate=(0.5, 0.5, 0.5),
                     scale=(0.005, 0.005, 0.005),
                     adaptive=True,
                     filename='$mpm/stork.obj') * 12
    tex = tc.Texture('rotate', tex=tex, rotate_axis=1,
                     rotate_times=1).translate((0.1, 0, 0))
    tex_up = tc.Texture('bound',
                        tex=tex,
                        axis=1,
                        bounds=(0.4, 0.9),
                        outside_val=(0, 0, 0))
    tex_down = tc.Texture('bound',
                          tex=tex,
                          axis=1,
                          bounds=(0.1, 0.4),
                          outside_val=(0, 0, 0))
コード例 #12
0
crash_report.enable()

version = 10
narrow_band = True
volume_fraction = 0.2
# Initialize
n = 2000
opt = TopoOpt(res=(n, n, n), version=version, volume_fraction=volume_fraction,
              grid_update_start=2 if narrow_band else 1000000,
              progressive_vol_frac=0, fixed_cell_density=0.21, cg_max_iterations=100)


s = 1
tex = tc.Texture(
    'mesh',
    translate=(0.5, 0.5, 0.5),
    scale=(s, s, s),
    adaptive=False,
    filename='projects/topo_opt/data/wing_2.obj')

s *= 0.95
tex_shell = tc.Texture(
    'mesh',
    translate=(0.5, 0.5, 0.5),
    scale=(s, s, s),
    adaptive=False,
    filename='projects/topo_opt/data/wing_2.obj')

opt.populate_grid(domain_type='texture', tex_id=tex.id)
opt.general_action(action='make_shell', tex_id=tex_shell.id)
opt.general_action(action='voxel_connectivity_filtering')
コード例 #13
0
    end_t = 2.9

    def position_function(t):
        return tc.Vector(0.5, 0.45, 0.5)

    def rotation_function(t):
        if (t < start_t):
            return tc.Vector(0, 0, 0)
        if (start_t <= t < end_t):
            return tc.Vector(0, omega * (t - start_t), 0)
        if (t >= end_t):
            return tc.Vector(0, omega * (end_t - start_t), 0)

    tex0 = tc.Texture('mesh',
                      resolution=(2 * r, 2 * r, 2 * r),
                      translate=(0.5, 0.6, 0.5),
                      scale=(1, 1, 1),
                      filename='projects/mpm/data/bowl_init_sand.obj') * 10

    mpm.add_particles(type='sand',
                      density_tex=tex0.id,
                      initial_velocity=(0, 0, 0),
                      density=400,
                      color=(0.8, 0.7, 1.0),
                      friction_angle=10)

    mpm.add_particles(type='rigid',
                      density=40,
                      scale=(1, 1, 1),
                      friction=0.2,
                      scripted_position=tc.function13(position_function),
コード例 #14
0
ファイル: goo_blocks.py プロジェクト: yuan-feng/taichi_mpm
      base_delta_t=1e-4,
      gravity=(0, -10, 0),
      pushing_force=0,
      penalty=5e4,
      rpic_damping=1,
      cfl=0.5,)

  levelset = mpm.create_levelset()
  levelset.add_plane(tc.Vector(0, 1, 0), -0.445)
  levelset.set_friction(-1)
  mpm.set_levelset(levelset, False)

  ratio = 0.5
  rho = (400, 2000, 5000)

  tex = tc.Texture('rect', bounds=(0.4, 0.1, 0.2)) * 20

  mpm.add_particles(
      type='von_mises',
      density_tex=tex.id,
      density=rho[0],
      youngs_modulus=5e4,
      poisson_ratio=0.4,
      yield_stress=10)

  period = 0.3

  def frame_update(t, frame_dt):
    id = floor(t / period)
    if (id < 3 and 0 < t <= id * period + frame_dt):
      mpm.add_particles(
コード例 #15
0
ファイル: shadows.py プロジェクト: zgsxwsdxg/taichi
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
コード例 #16
0
ファイル: simple_texture.py プロジェクト: taichi-dev/taichi
from taichi.examples.patterns import taichi_logo

import taichi as ti

ti.init(arch=ti.vulkan)

res = (512, 512)
pixels = ti.Vector.field(3, dtype=float, shape=res)

tex_format = ti.u8
texture = ti.Texture(tex_format, 1, (128, 128))
tex_ndarray = ti.ndarray(tex_format, shape=(128, 128))


@ti.kernel
def make_texture(arr: ti.types.ndarray()):
    for i, j in ti.ndrange(128, 128):
        ret = taichi_logo(ti.Vector([i, j]) / 128)
        ret = ti.cast(ret * 255, ti.u8)
        arr[i, j] = ret


make_texture(tex_ndarray)
texture.from_ndarray(tex_ndarray)


@ti.kernel
def paint(t: ti.f32, tex: ti.types.texture(num_dimensions=2)):
    for i, j in pixels:
        uv = ti.Vector([i / res[0], j / res[1]])
        warp_uv = uv + ti.Vector(
コード例 #17
0
      print_rigid_body_state=False)

  ###########################################################################
  # add levelset walls
  ###########################################################################
  levelset = mpm.create_levelset()
  # levelset.add_cuboid((0.5-0.45, 0.4, 0.35), (0.5, 0.9, 0.65), True)
  levelset.add_cuboid((0.5 - 0.45, 0.465, 0.35), (0.5 + 0.45, 0.9, 0.65), True)
  levelset.set_friction(-2)
  mpm.set_levelset(levelset, False)

  ###########################################################################
  # add sand
  ###########################################################################
  # tex = tc.Texture('rect', bounds=(0.45, 0.1, 0.3)).translate((-0.225,0,0)) * 8
  tex = tc.Texture('rect', bounds=(0.9, 0.07, 0.3)) * 8

  mpm.add_particles(
      type='sand',
      pd=True,
      friction_angle=45,
      density_tex=tex.id,
      lambda_0=204057.0 * 5,
      mu_0=136038.0 * 5,
      density=2000)

  def frame_update(t, frame_dt):
    if t < 0.2 - 0.0001 or t > 0.2 + 0.0001:
      return

    ###########################################################################
コード例 #18
0
cdf = False

r = 50

if __name__ == '__main__':
    res = (r, r, r)
    mpm = tc.dynamics.MPM(res=res,
                          base_delta_t=5e-4,
                          num_frames=200,
                          gravity=(0, 0, 0),
                          print_energy=True,
                          optimized=False)

    tex = tc.Texture('mesh',
                     resolution=(2 * r, 2 * r, 2 * r),
                     translate=(0.5, 0.5, 0.5),
                     scale=(0.4, 0.4, 0.4),
                     adaptive=False,
                     filename='$mpm/box.obj') * 8

    mpm.add_particles(type='jelly',
                      density_tex=tex.id,
                      initial_velocity=(0, 0, 0),
                      E=1e3,
                      initial_dg=1.1)

    e = mpm.simulate_with_energy(clear_output_directory=True,
                                 print_profile_info=True)
    print(e)
コード例 #19
0
ファイル: vaze.py プロジェクト: zorrock/taichi
def create_scene():
    downsample = 2
    width, height = 600 / downsample, 800 / downsample
    camera = tc.Camera('pinhole',
                       width=width,
                       height=height,
                       fov=30,
                       origin=(0, 4, 40),
                       look_at=(0, 4, 0),
                       up=(0, 1, 0))

    scene = tc.Scene()

    radius = lambda x: exp(sin(x * 2 * pi + 0.1) + x + sin(150 * x) * 0.02) / 3
    surf = lambda p: tc.geometry.rotate_y(Vector(radius(p.x), p.x * 4, 0), p.y
                                          * 2 * pi)

    tex = ((tc.Texture('perlin') + 1) *
           5).zoom(zoom=(10, 10, 2)).fract() * (1.0, 0.4, 0.2)

    with scene:
        scene.set_camera(camera)

        mesh = tc.Mesh('plane',
                       tc.SurfaceMaterial('diffuse', color=(1, 1, 1)),
                       translate=(0, 0, 0),
                       scale=40,
                       rotation=(0, 0, 0))
        scene.add_mesh(mesh)

        mesh = tc.Mesh('plane',
                       tc.SurfaceMaterial('diffuse', color=(1, 1, 1)),
                       translate=(0, 0, -40),
                       scale=40,
                       rotation=(90, 0, 0))
        scene.add_mesh(mesh)

        mesh = tc.geometry.create_mesh_from_functions((150, 150),
                                                      surf,
                                                      smooth=False)
        scene.add_mesh(
            tc.Mesh(mesh,
                    tc.SurfaceMaterial('pbr', diffuse_map=tex),
                    translate=(0, 0, 0),
                    scale=2))

        # Lights

        mesh = tc.Mesh('plane',
                       tc.SurfaceMaterial('emissive', color=(1, 0.9, 0.6)),
                       translate=(-10, 10, 30),
                       scale=1,
                       rotation=(-110, -45, 0))
        scene.add_mesh(mesh)

        mesh = tc.Mesh('plane',
                       tc.SurfaceMaterial('emissive',
                                          color=(0.01, 0.02, 0.04)),
                       translate=(10, 10, 30),
                       scale=3,
                       rotation=(-110, 45, 0))
        scene.add_mesh(mesh)

        with tc.transform_scope(translate=(9, 10, -10),
                                scale=(0.3, 1.3, 0.3),
                                rotation=(88, -27, 0)):
            mesh = tc.Mesh(
                'plane', tc.SurfaceMaterial('emissive', color=(100, 100, 10)))
            scene.add_mesh(mesh)
            surf = lambda p: tc.geometry.rotate_y(
                Vector(p.x * 3, p.x * p.x * 4 - 2, 0), p.y * 2 * pi)
            bowl = tc.geometry.create_mesh_from_functions((50, 50), surf)
            mesh = tc.Mesh(bowl, tc.SurfaceMaterial('diffuse',
                                                    color=(0, 0, 0)))
            scene.add_mesh(mesh)

    return scene
コード例 #20
0
from taichi.examples.patterns import taichi_logo

import taichi as ti

ti.init(arch=ti.vulkan)

res = (512, 512)
img = ti.Vector.field(4, dtype=float, shape=res)
pixels_arr = ti.Vector.ndarray(4, dtype=float, shape=res)

texture = ti.Texture(ti.f32, 1, (128, 128))


@ti.kernel
def make_texture(tex: ti.types.rw_texture(num_dimensions=2,
                                          num_channels=1,
                                          channel_format=ti.f32,
                                          lod=0)):
    for i, j in ti.ndrange(128, 128):
        ret = ti.cast(taichi_logo(ti.Vector([i, j]) / 128), ti.f32)
        tex.store(ti.Vector([i, j]), ti.Vector([ret, 0.0, 0.0, 0.0]))


@ti.kernel
def paint(t: ti.f32, pixels: ti.types.ndarray(field_dim=2),
          tex: ti.types.texture(num_dimensions=2)):
    for i, j in pixels:
        uv = ti.Vector([i / res[0], j / res[1]])
        warp_uv = uv + ti.Vector(
            [ti.cos(t + uv.x * 5.0),
             ti.sin(t + uv.y * 5.0)]) * 0.1
コード例 #21
0
ファイル: mgpcg_smoke_3d.py プロジェクト: zgsxwsdxg/taichi
                      pressure_tolerance=1e-6,
                      density_scaling=2,
                      initial_speed=(0, 0, 0),
                      tracker_generation=20,
                      perturbation=0,
                      pressure_solver='mgpcg',
                      num_threads=2,
                      open_boundary=True,
                      maximum_pressure_iterations=200,
                      super_sampling=20)

    video_manager = tc.VideoManager(output_dir='new_year')
    images = []
    for i in range(600):
        print('frame', i)
        generation = tc.Texture('sphere', radius=0.08, center=(0.25, 0.1, 0.25)) + \
            tc.Texture('sphere', radius=0.08, center=(0.25, 0.1, 0.75)) + \
            tc.Texture('sphere', radius=0.08, center=(0.75, 0.1, 0.25)) + \
            tc.Texture('sphere', radius=0.08, center=(0.75, 0.1, 0.75))
        smoke.update(generation=generation * 100,
                     color=tc.Texture('const',
                                      value=colorsys.hls_to_rgb(
                                          0.02 * i + 0.0, 0.7, 1.0)),
                     temperature=tc.Texture('const', value=(1, 0, 0, 0)),
                     initial_velocity=tc.Texture('const',
                                                 value=(0, 100, 0, 0)))
        smoke.step(0.03)
        particles = smoke.c.get_render_particles()
        width, height = 512, 1024
        image_buffer = tc.core.Array2DVector3(Vectori(width, height),
                                              Vector(0, 0, 0.0))
コード例 #22
0
import taichi as tc

cdf = False

r = 100

if __name__ == '__main__':
    res = (r, r, r)
    mpm = tc.dynamics.MPM(res=res, base_delta_t=3e-4, num_frames=50)

    levelset = mpm.create_levelset()
    levelset.add_plane(tc.Vector(0.0, 1, 0), -0.2)
    mpm.set_levelset(levelset)

    tex = tc.Texture('sphere', center=(0.7, 0.45, 0.5), radius=0.08) * 3
    mpm.add_particles(
        type='linear',
        density_tex=tex.id,
        initial_velocity=(-1, 0, 0),
        E=1e4,
    )

    mpm.simulate(clear_output_directory=True, print_profile_info=True)