예제 #1
0
import taichi_three as t3
import taichi as ti

N = 64

scene = t3.Scene()
mesh = t3.DynamicMesh(n_faces=N, n_pos=N + 1)
model = t3.Model(mesh)
scene.add_model(model)
camera = t3.Camera()
scene.add_camera(camera)
light = t3.AmbientLight(1.0)
scene.add_light(light)


@ti.kernel
def init_mesh():
    mesh.pos[N] = [0, 0, 0]
    for i in range(N):
        a = i / N * t3.tau
        mesh.pos[i] = [ti.sin(a), ti.cos(a), 0]
        mesh.faces[i] = [[i, 0, 0], [(i + 1) % N, 0, 0], [N, 0, 0]]


init_mesh()

gui = ti.GUI('Dynamic faces', camera.res)
while gui.running:
    mesh.n_faces[None] = gui.frame % N

    scene.render()
예제 #2
0
import taichi_three as t3
import taichi as ti

N = 512

scene = t3.Scene()
mesh = t3.DynamicMesh(n_faces=N - 1, n_pos=N)
model = t3.WireframeModel(t3.PolyToEdge(mesh))
scene.add_model(model)
camera = t3.Camera()
scene.add_camera(camera)


@ti.kernel
def init_mesh():
    for i in range(N):
        x = i / N * 2 - 1
        mesh.pos[i] = [x, ti.sin(x * 10), ti.cos(x * 10)]

    for i in range(N - 1):
        mesh.faces[i] = [[i, 0, 0], [i, 0, 0], [i + 1, 0, 0]]
    mesh.n_faces[None] = N - 1


init_mesh()

gui = ti.GUI('Helix', camera.res)
while gui.running and not gui.get_event(gui.ESCAPE):
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
예제 #3
0
import taichi as ti
import taichi_three as t3
from taichi_three.mciso import MCISO, Voxelizer
import numpy as np

ti.init(arch=ti.opengl)

vol = np.load('assets/smoke.npy')

mciso = MCISO(vol.shape[0], use_sparse=False)

scene = t3.Scene()
mesh = t3.DynamicMesh(n_faces=mciso.N_res,
                      n_pos=mciso.N_res,
                      n_nrm=mciso.N_res)
model = t3.Model(mesh)
scene.add_model(model)
camera = t3.Camera()
scene.add_camera(camera)
scene.add_light(t3.Light([0.4, -1.5, -1.8], 0.8))
scene.add_light(t3.AmbientLight(0.22))


@ti.kernel
def update_mesh():
    mesh.n_faces[None] = mciso.Js_n[None]
    for i in range(mciso.Js_n[None]):
        for t in ti.static(range(3)):
            mesh.faces[i][t, 0] = mciso.Jts[i][t]
            mesh.faces[i][t, 2] = mciso.Jts[i][t]
        mesh.pos[i] = (mciso.vs[i] + 0.5) / mciso.N * 2 - 1
예제 #4
0
import taichi_three as t3
import taichi as ti

scene = t3.Scene()
mesh = t3.DynamicMesh(n_faces=1, n_pos=3)
model = t3.Model(t3.MeshNoCulling(mesh))
scene.add_model(model)
camera = t3.Camera()
scene.add_camera(camera)
light = t3.AmbientLight(1.0)
scene.add_light(light)


@ti.kernel
def init_mesh():
    mesh.n_faces[None] = 1
    mesh.pos[0] = [0, 1, 0]
    mesh.pos[1] = [1, -1, 0]
    mesh.pos[2] = [-1, -1, 0]
    mesh.faces[0] = [[0, 0, 0], [1, 0, 0], [2, 0, 0]]


init_mesh()

gui = ti.GUI('Triangle', camera.res)
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(gui.ESCAPE)
    camera.from_mouse(gui)

    scene.render()