How to use the taichi.visual.texture.Texture function in taichi

To help you get started, we’ve selected a few taichi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yuanming-hu / taichi / projects / examples / rendering / test_volumetric.py View on Github external
downsample = 1
  width, height = 960 / downsample, 540 / downsample
  camera = Camera(
      'thinlens',
      width=width,
      height=height,
      fov=60,
      origin=(0, 1, 4),
      look_at=(0.0, -0.7, -0.0),
      up=(0, 1, 0),
      aperture=0.05)

  scene = Scene()
  with scene:
    scene.set_camera(camera)
    rep = Texture.create_taichi_wallpaper(
        10, rotation=0, scale=0.95) * Texture(
            'const', value=(0.7, 0.5, 0.5))
    material = SurfaceMaterial('pbr', diffuse_map=rep)
    scene.add_mesh(
        Mesh('holder', material=material, translate=(0, -1, -6), scale=2))

    mesh = Mesh(
        'plane',
        SurfaceMaterial('emissive', color=(1, 1, 1)),
        translate=(1.0, 1.0, -1),
        scale=(0.1, 0.1, 0.1),
        rotation=(180, 0, 0))
    scene.add_mesh(mesh)

    # Change this line to your particle output path pls.
    # fn = r'../snow-sim/particles%05d.bin' % frame
github yuanming-hu / taichi / python / examples / simulation / 3d / mpm_sand_steady_test_3d.py View on Github external
def create_snow_scene(frame, d):
    downsample = output_downsample
    width, height = 540 / downsample, 540 / downsample
    camera = Camera('thinlens', width=width, height=height, fov=90,
                    origin=(0, 1, 4), look_at=(0.0, -0.9, -0.0), up=(0, 1, 0), aperture=0.08)

    scene = Scene()
    with scene:
        scene.set_camera(camera)
        rep = Texture.create_taichi_wallpaper(10, rotation=0, scale=0.95) * Texture('const', value=(0.7, 0.5, 0.5))
        material = SurfaceMaterial('pbr', diffuse_map=rep)
        scene.add_mesh(Mesh('holder', material=material, translate=(0, -1, -6), scale=2))

        mesh = Mesh('plane', SurfaceMaterial('emissive', color=(1, 1, 1)),
                    translate=(1.0, 1.0, -1), scale=(0.1, 0.1, 0.1), rotation=(180, 0, 0))
        scene.add_mesh(mesh)

        # Change this line to your particle output path pls.
        # fn = r'../snow-sim/particles%05d.bin' % frame
        fn = d + r'/particles%05d.bin' % frame
        mesh = create_mpm_snow_block(fn)
        scene.add_mesh(mesh)

    return scene
github yuanming-hu / taichi / python / examples / simulation / 3d / mpm_snow_slop_3d.py View on Github external
def create_mpm_sand_block(fn):
    particles = tc_core.RenderParticles()
    assert particles.read(fn)
    downsample = grid_downsample
    tex = Texture.from_render_particles((255 / downsample, 255 / downsample, 255 / downsample), particles) * 5
    # mesh_transform = tc_core.Matrix4(1.0).scale_s(0.5).translate(Vector(0.5, 0.5, 0.5))
    # transform = tc_core.Matrix4(1.0).scale_s(2).scale(Vector(2.0, 0.5, 1.0)).translate(Vector(-2, -0.99, -1))
    mesh_transform = tc_core.Matrix4(1.0).translate(Vector(0, 0.01, 0))
    transform = tc_core.Matrix4(1.0).scale_s(2).translate(Vector(-1, -1, -1))
    vol = VolumeMaterial('sdf_voxel', scattering=5, absorption=0, tex=tex,
                         resolution=(255 / downsample, 255 / downsample, 255 / downsample),
                         transform_ptr=transform.get_ptr_string())
    material = SurfaceMaterial('plain_interface')
    material.set_internal_material(vol)
    return Mesh('cube', material=material, transform=transform * mesh_transform)
github yuanming-hu / taichi / python / examples / simulation / 3d / ampm / ampm_snow_taichi_3d.py View on Github external
with tc.transform_scope(rotation=(20, 0, 0), translate=(0, 0.75, 0), scale=1):
            mesh = tc.Mesh('plane', tc.SurfaceMaterial('emissive', color=(30000, 40000, 60000)),
                           translate=(-20, 30, 0), scale=3, rotation=(0, 0, 180))
            scene.add_mesh(mesh)
            mesh = tc.Mesh('plane', tc.SurfaceMaterial('emissive', color=(6000, 8000, 12000)),
                           translate=(20, 30, 40), scale=3, rotation=(0, 0, -180))
            scene.add_mesh(mesh)

            material = SurfaceMaterial('diffuse', color=(0.24, 0.18, 0.12), f0=1)
            scene.add_mesh(Mesh('cube', material=material, translate=(0, -1.01, 0), scale=(1, 0.02, 0.6)))

            fn = d + r'/particles%05d.bin' % frame
            mesh = create_mpm_snow_block(fn)
            scene.add_mesh(mesh)

        envmap_texture = Texture('spherical_gradient', inside_val=(10, 10, 10, 10), outside_val=(1, 1, 1, 0),
                                 angle=10, sharpness=20)
        envmap = EnvironmentMap('base', texture=envmap_texture.id, res=(1024, 1024))
        scene.set_environment_map(envmap)

    return scene
github yuanming-hu / taichi / python / examples / simulation / 3d / ampm / ampm_snow_smash_balls_3d.py View on Github external
if __name__ == '__main__':
    downsample = grid_downsample
    resolution = (255 / downsample, 255 / downsample, 255 / downsample)

    mpm = MPM3(resolution=resolution, gravity=(0, -10, 0), async=True, num_threads=8, strength_dt_mul=4,
               affine_damping=1000)

    # real theta_c = 2.5e-2f, theta_s = 7.5e-3f;

    tex_ball1 = Texture('sphere', center=(0.41, 0.23, 0.5), radius=0.08) * 1
    tex_ball1 = tex_ball1 * (Texture('perlin') * 6 + 2)
    mpm.add_particles(density_tex=tex_ball1.id, initial_velocity=(200, 5, 0), compression=1.0,
                      mu_0=3e5, lambda_0=3e5)

    tex_ball2 = Texture('sphere', center=(0.59, 0.2, 0.5), radius=0.08) * 1
    tex_ball2 = tex_ball2 * (Texture('perlin') * 6 + 2)
    mpm.add_particles(density_tex=tex_ball2.id, initial_velocity=(-200, 5, 0), compression=1.0,
                      mu_0=3e5, lambda_0=3e5)

    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:
            d = mpm.get_directory()
            if i % 10 == 0:
github yuanming-hu / taichi / python / examples / simulation / 3d / ampm / ampm_sand_column_collapse_3d.py View on Github external
def create_sand_scene(frame, d):
    downsample = output_downsample
    width, height = 540 / downsample, 540 / downsample
    camera = Camera('thinlens', width=width, height=height, fov=35,
                    origin=(0, 1, 4), look_at=(0.0, -0.9, -0.0), up=(0, 1, 0), aperture=0.08)

    scene = Scene()
    with scene:
        scene.set_camera(camera)
        rep = Texture.create_taichi_wallpaper(10, rotation=0, scale=0.95) * Texture('const', value=(0.7, 0.5, 0.5))
        material = SurfaceMaterial('pbr', diffuse_map=rep)
        scene.add_mesh(Mesh('holder', material=material, translate=(0, -1, -6), scale=2))

        mesh = Mesh('plane', SurfaceMaterial('emissive', color=(1, 1, 1)),
                    translate=(1.0, 1.0, -1), scale=(0.1, 0.1, 0.1), rotation=(180, 0, 0))
        scene.add_mesh(mesh)

        # Change this line to your particle output path pls.
        # fn = r'../sand-sim/particles%05d.bin' % frame
        fn = d + r'/particles%05d.bin' % frame
        mesh = create_mpm_sand_block(fn)
        scene.add_mesh(mesh)

    return scene
github yuanming-hu / taichi / python / examples / simulation / 3d / mpm_sand_column_collapse_3d.py View on Github external
return scene


def render_sand_frame(frame, d):
    renderer = Renderer(output_dir='volumetric', overwrite=True, frame=frame)
    renderer.initialize(preset='pt', scene=create_sand_scene(frame, d), sampler='prand')
    renderer.set_post_processor(LDRDisplay(exposure=0.6, bloom_radius=0.0, bloom_threshold=1.0))
    renderer.render(render_epoch)


if __name__ == '__main__':
    downsample = grid_downsample
    resolution = (432 / downsample, 144 / downsample, 432 / downsample)
    tex = Texture('ring', outer=0.15) * 2
    tex = Texture('bound', tex=tex, axis=2, bounds=(0.0, 0.8), outside_val=(0, 0, 0))
    tex = Texture('rotate', tex=tex, rotate_axis=0, rotate_times=1)
    mpm = MPM3(resolution=resolution, gravity=(0, -100, 0), base_delta_t=0.001, num_threads=8)
    mpm.add_particles(type="dp", density_tex=tex.id, initial_velocity=(0, 0, 0))
    for i in range(step_number):
        print 'process(%d/%d)' % (i, step_number)
        mpm.step(0.01)
        if gi_render:
            d = mpm.get_directory()
            if i % 20 == 0:
                render_sand_frame(i, d)
    mpm.make_video()
github yuanming-hu / taichi / python / examples / simulation / 3d / ampm / ampm_sand_column_collapse_3d.py View on Github external
return scene


def render_sand_frame(frame, d):
    renderer = Renderer(output_dir='volumetric', overwrite=True, frame=frame)
    renderer.initialize(preset='pt', scene=create_sand_scene(frame, d), sampler='prand')
    renderer.set_post_processor(LDRDisplay(exposure=0.6, bloom_radius=0.0, bloom_threshold=1.0))
    renderer.render(render_epoch)


if __name__ == '__main__':
    downsample = grid_downsample
    resolution = (432 / downsample, 144 / downsample, 432 / downsample)
    tex = Texture('ring', outer=0.15) * 2
    tex = Texture('bound', tex=tex, axis=2, bounds=(0.0, 0.8), outside_val=(0, 0, 0))
    tex = Texture('rotate', tex=tex, rotate_axis=0, rotate_times=1)
    mpm = MPM3(resolution=resolution, gravity=(0, -100, 0), base_delta_t=0.000001, num_threads=8, async=True)
    mpm.add_particles(type="dp", density_tex=tex.id, initial_velocity=(0, 0, 0))
    for i in range(step_number):
        print 'process(%d/%d)' % (i, step_number)
        mpm.step(0.01)
        if gi_render:
            d = mpm.get_directory()
            if i % 20 == 0:
                render_sand_frame(i, d)
    mpm.make_video()
github yuanming-hu / taichi / python / examples / simulation / 3d / mpm_sand_column_collapse_3d.py View on Github external
scene.add_mesh(mesh)

    return scene


def render_sand_frame(frame, d):
    renderer = Renderer(output_dir='volumetric', overwrite=True, frame=frame)
    renderer.initialize(preset='pt', scene=create_sand_scene(frame, d), sampler='prand')
    renderer.set_post_processor(LDRDisplay(exposure=0.6, bloom_radius=0.0, bloom_threshold=1.0))
    renderer.render(render_epoch)


if __name__ == '__main__':
    downsample = grid_downsample
    resolution = (432 / downsample, 144 / downsample, 432 / downsample)
    tex = Texture('ring', outer=0.15) * 2
    tex = Texture('bound', tex=tex, axis=2, bounds=(0.0, 0.8), outside_val=(0, 0, 0))
    tex = Texture('rotate', tex=tex, rotate_axis=0, rotate_times=1)
    mpm = MPM3(resolution=resolution, gravity=(0, -100, 0), base_delta_t=0.001, num_threads=8)
    mpm.add_particles(type="dp", density_tex=tex.id, initial_velocity=(0, 0, 0))
    for i in range(step_number):
        print 'process(%d/%d)' % (i, step_number)
        mpm.step(0.01)
        if gi_render:
            d = mpm.get_directory()
            if i % 20 == 0:
                render_sand_frame(i, d)
    mpm.make_video()