Пример #1
0
import taichi as ti
import taichi_three as t3
import numpy as np

ti.init(ti.cpu)

scene = t3.Scene()
model1 = t3.Model(t3.Mesh.from_obj(t3.readobj('assets/torus.obj')))
model2 = t3.Model(t3.Mesh.from_obj(t3.readobj('assets/cube.obj', scale=0.5)))
model = t3.ModelGroup([model1, model2])
scene.add_model(model)
camera = t3.Camera(res=(600, 400))
scene.add_camera(camera)
light = t3.Light([0.4, -1.5, -1.8])
scene.add_light(light)

gui = ti.GUI('Camera', camera.res)
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    model2.L2W[None] = t3.translate(0, ti.sin(t3.get_time()) * 0.6, 0)
    model.L2W[None] = t3.rotateZ(t3.get_time())
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
    gui.show()
Пример #2
0
model.material = t3.Material(
    t3.IdealRT(
        diffuse=t3.Constant(1.0),
        emission=t3.Constant(0.0),
    ))
scene.add_model(model)
light = t3.Model(t3.Mesh.from_obj(cube))
light.material = t3.Material(
    t3.IdealRT(
        diffuse=t3.Constant(0.0),
        emission=t3.Constant(1.0),
        emission_color=t3.Constant(10.0),
    ))
scene.add_model(light)
camera = t3.RTCamera(res=res)
camera.ctl = t3.CameraCtl(pos=[0, 2, 8], target=[0, 2, 0])
scene.add_camera(camera)
accumator = t3.Accumator(camera.res)

light.L2W[None] = t3.translate(0, 3.9, 0) @ t3.scale(0.25)
gui = ti.GUI('Model', camera.res)
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    if camera.from_mouse(gui):
        accumator.reset()
    accumator.render(camera, 3)
    #gui.set_image(accumator.buf)
    gui.set_image(1 - np.exp(-1.6 * accumator.buf.to_numpy()))
    gui.show()
Пример #3
0
sphere = t3.Model(t3.Mesh.from_obj('assets/sphere.obj'))
scene.add_model(sphere)

light = t3.Light(dir=[0.4, -1.5, 1.8])
scene.add_light(light)
scene.add_camera(light.make_shadow_camera())


@ti.kernel
def update_display():
    for i in ti.grouped(x):
        mesh.pos[i] = x[i]


init()
sphere.L2W[None] = t3.translate(ball_pos) @ t3.scale(ball_radius)
with ti.GUI('Mass Spring', camera.res) as gui:
    while gui.running and not gui.get_event(gui.ESCAPE):
        if not gui.is_pressed(gui.SPACE):
            for i in range(steps):
                substep()
        if gui.is_pressed('r'):
            init()
        update_display()

        camera.from_mouse(gui)

        scene.render()
        gui.set_image(camera.img)
        gui.show()
Пример #4
0
import taichi_three as t3
import numpy as np
import time

ti.init(ti.cpu)

scene = t3.Scene()
model = t3.Model(t3.Mesh.from_obj(t3.readobj('assets/torus.obj', scale=0.8)))
scene.add_model(model)
ball = t3.Model(t3.Mesh.from_obj(t3.readobj('assets/sphere.obj', scale=0.1)))
ball.material = t3.Material(
    t3.BlinnPhong(emission=t3.Constant(t3.RGB(1.0, 1.0, 1.0)), ))
scene.add_model(ball)
camera = t3.Camera()
camera.ctl = t3.CameraCtl(pos=[0, 1.8, 1.8])
scene.add_camera(camera)
light = t3.PointLight(pos=[0, 1, 0])
scene.add_light(light)
ambient = t3.AmbientLight(0.2)
scene.add_light(ambient)

gui = ti.GUI('Model', camera.res)
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    camera.from_mouse(gui)
    light.pos[None].y = ti.cos(time.time())
    ball.L2W[None] = t3.translate(light.pos[None].value)
    scene.render()
    gui.set_image(camera.img)
    gui.show()
Пример #5
0
ti.init(ti.cpu)

scene = t3.Scene()
obj1 = t3.readobj('assets/torus.obj', scale=0.8)
obj2 = t3.readobj('assets/cylinder.obj', scale=0.6)
model1 = t3.Model(t3.Mesh.from_obj(obj1))
model2 = t3.Model(t3.Mesh.from_obj(obj2))
scene.add_model(model1)
scene.add_model(model2)
camera = t3.Camera()
camera.ctl = t3.CameraCtl(pos=[1, 1, -1])
scene.add_camera(camera)
light = t3.Light([0.4, -1.5, 1.8])
scene.add_shadow_camera(light.make_shadow_camera())
scene.add_light(light)

gui = ti.GUI('Model', camera.res)
gui2 = ti.GUI('Depth map', light.shadow.res)
gui2.fps_limit = None
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    camera.from_mouse(gui)
    model2.L2W[None] = t3.translate(0, 0.16 * ti.sin(gui.frame * 0.03), 0)
    scene.render_shadows()
    scene.render()
    gui.set_image(camera.img)
    gui2.set_image(light.shadow.img)
    gui.show()
    gui2.show()
Пример #6
0
scene = t3.Scene()
camera = t3.Camera()
camera.ctl = t3.CameraCtl(pos=[0, 1, 1.8])
scene.add_camera(camera)
model = t3.Model(t3.Mesh.from_obj('assets/torus.obj'))
scene.add_model(model)
orient = t3.Model(t3.Mesh.from_obj(t3.readobj('assets/orient.obj', scale=0.8)))
scene.add_model(orient)
ambient = t3.AmbientLight(0.3)
scene.add_light(ambient)
light = t3.Light([0.4, -1.5, -1.8], 0.7)
scene.add_light(light)
shadow = light.make_shadow_camera()
scene.add_camera(shadow)

gui = ti.GUI('Camera', camera.res)
#gui2 = ti.GUI('Shadow', shadow.res)
#gui2.fps_limit = None
while gui.running:  # and gui2.running:
    gui.get_event(None)
    #gui2.get_event(None)
    orient.L2W[None] = t3.translate(0, t3.sin(t3.get_time()), 0)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    #gui2.running = not gui2.is_pressed(ti.GUI.ESCAPE)
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
    #gui2.set_image(shadow.fb.idepth)
    gui.show()
    #gui2.show()
Пример #7
0
import taichi as ti
import taichi_three as t3
import numpy as np
import math, time

ti.init(ti.cpu)

scene = t3.Scene()
monkey = t3.Model(t3.Mesh.from_obj(t3.readobj('assets/monkey.obj', scale=0.6)))
torus = t3.Model(t3.Mesh.from_obj(t3.readobj('assets/torus.obj')))
scene.add_model(monkey)
scene.add_model(torus)
camera = t3.Camera()
scene.add_camera(camera)
light = t3.Light(dir=[0.4, -1.5, -1.8])
scene.add_light(light)

gui = ti.GUI('Transform', camera.res)
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    camera.from_mouse(gui)
    monkey.L2W[None] = t3.rotateZ(angle=time.time())
    torus.L2W[None] = t3.translate(x=0, y=math.cos(time.time()) * 0.5, z=0)
    scene.render()
    gui.set_image(camera.img)
    gui.show()
Пример #8
0
    color=t3.Constant(t3.RGB(1, 0, 0)),
))
scene.add_model(xplus)
yplus = t3.Model(mesh)
yplus.material = t3.Material(t3.CookTorrance(
    color=t3.Constant(t3.RGB(0, 1, 0)),
))
scene.add_model(yplus)
zplus = t3.Model(mesh)
zplus.material = t3.Material(t3.CookTorrance(
    color=t3.Constant(t3.RGB(0, 0, 1)),
))
scene.add_model(zplus)
center = t3.Model(mesh)
center.material = t3.Material(t3.CookTorrance(
    color=t3.Constant(t3.RGB(1, 1, 1)),
))
scene.add_model(center)

xplus.L2W[None] = t3.translate(1, 0, 0) @ t3.scale(0.1)
yplus.L2W[None] = t3.translate(0, 1, 0) @ t3.scale(0.1)
zplus.L2W[None] = t3.translate(0, 0, 1) @ t3.scale(0.1)
center.L2W[None] = t3.scale(0.1)

gui = t3.GUI('Coordinate system')
while gui.running:
    gui.get_event(None)
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
    gui.show()
Пример #9
0
scene = t3.Scene()
model = t3.Model(t3.Mesh.from_obj('assets/monkey.obj'))
scene.add_model(model)
plane = t3.Model(t3.QuadToTri(t3.MeshGrid(2)))
scene.add_model(plane)
camera = t3.Camera()
scene.add_camera_d(camera)
camerafb = t3.FrameBuffer(camera,
                          buffers=dict(
                              img=[3, float],
                              normal=[3, float],
                          ))
ssaobuf = t3.LaplacianBlur(t3.SSAO(camerafb))
buffer = t3.ImgBinaryOp(camerafb, ssaobuf, lambda x, y: x * y)
#buffer = ssaobuf
scene.add_buffer(buffer)
light = t3.Light([0.4, -1.5, -0.8], 0.9)
scene.add_light(light)
ambient = t3.AmbientLight(0.1)
scene.add_light(ambient)

plane.L2W[None] = t3.translate(0, -1, 0) @ t3.scale(2, 2, 2)
gui = ti.GUI('SSAO', buffer.res)
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(buffer.img)
    gui.show()