Пример #1
0
import taichi as ti
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)
Пример #2
0
import taichi as ti
import taichi_three as t3
import numpy as np

res = 512, 512
ti.init(ti.cpu)

scene = t3.Scene()
cornell = t3.readobj('assets/cornell.obj', orient='-xyz')
cube = t3.readobj('assets/plane.obj')
model = t3.Model(t3.Mesh.from_obj(cornell))
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)
Пример #3
0
import taichi as ti
import taichi_three as t3
import numpy as np

ti.init(ti.cpu)

scene = t3.Scene()
skybox = t3.Skybox('assets/skybox.jpg')
scene.add_model(skybox)
scene.add_light(skybox)
model = t3.Model(t3.Mesh.from_obj('assets/sphere.obj'))
model.material = t3.Material(t3.IdealRT(specular=t3.Constant(1.0), ))
scene.add_model(model)
camera = t3.Camera(res=(600, 400))
camera.ctl = t3.CameraCtl(pos=[0, 0, 3])
scene.add_camera(camera)

gui = ti.GUI('Skybox', camera.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(camera.img)
    gui.show()
import taichi as ti
import taichi_three as t3
import numpy as np

ti.init(ti.cpu)

scene = t3.Scene()
model = t3.Model(t3.Mesh.from_obj(t3.readobj('assets/torus.obj', scale=0.8)))
model.material = t3.Material(
    t3.CookTorrance(
        color=t3.Texture(ti.imread('assets/cloth.jpg')),
        roughness=t3.Texture(ti.imread('assets/pattern.jpg')),
        metallic=t3.Constant(0.5),
    ))
scene.add_model(model)
camera = t3.Camera()
camera.ctl = t3.CameraCtl(pos=[0.8, 0, 2.5])
scene.add_camera(camera)
light = t3.Light([0, -0.5, -1])
scene.add_light(light)
ambient = t3.AmbientLight(0.3)
scene.add_light(ambient)

gui = ti.GUI('PBR demo', camera.res)
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    camera.from_mouse(gui)
    model.L2W[None] = t3.rotateX(angle=t3.get_time())
    scene.render()
    gui.set_image(camera.img)
Пример #5
0
import taichi as ti
import taichi_three as t3
import numpy as np

ti.init(ti.cpu)

scene = t3.Scene()
parts = t3.objunpackmtls(t3.readobj('assets/multimtl.obj', scale=0.8))
model1 = t3.Model(t3.Mesh.from_obj(parts[b'Material1']))
model2 = t3.Model(t3.Mesh.from_obj(parts[b'Material2']))
model1.material = t3.Material(
    t3.CookTorrance(  # Up: gold
        color=t3.Constant(t3.RGB(1.0, 0.96, 0.88)),
        roughness=t3.Constant(0.2),
        metallic=t3.Constant(0.75),
    ))
model2.material = t3.Material(
    t3.CookTorrance(  # Down: cloth
        color=t3.Texture(ti.imread('assets/cloth.jpg')),
        roughness=t3.Constant(0.3),
        metallic=t3.Constant(0.0),
    ))
scene.add_model(model1)
scene.add_model(model2)
camera = t3.Camera()
camera.ctl = t3.CameraCtl(pos=[0.8, 0, 2.5])
scene.add_camera(camera)
light = t3.Light([0, -0.5, -1], 0.9)
scene.add_light(light)
ambient = t3.AmbientLight(0.1)
scene.add_light(ambient)
Пример #6
0
import taichi as ti
import taichi_three as t3
import numpy as np

res = 512, 512
ti.init(ti.cpu)

scene = t3.Scene()
cornell = t3.objunpackmtls(t3.readobj('assets/cornell.obj'))
plane = t3.readobj('assets/plane.obj')
model1 = t3.Model(t3.Mesh.from_obj(cornell[b'Material']))
model1.material = t3.Material(
    t3.IdealRT(
        specular=t3.Constant(0.0),
        diffuse=t3.Constant(1.0),
        emission=t3.Constant(0.0),
        diffuse_color=t3.Texture('assets/smallptwall.png'),
    ))
scene.add_model(model1)
model2 = t3.Model(t3.Mesh.from_obj(cornell[b'Material.001']))
model2.material = t3.Material(
    t3.IdealRT(
        specular=t3.Constant(0.7),
        diffuse=t3.Constant(1.0),
        emission=t3.Constant(0.0),
    ))
scene.add_model(model2)
light = t3.Model(t3.Mesh.from_obj(plane))
light.material = t3.Material(
    t3.IdealRT(
        specular=t3.Constant(0.0),
Пример #7
0
import taichi_three as t3

scene = t3.Scene()
camera = t3.Camera()
scene.add_camera(camera)

light = t3.Light(dir=[-0.2, -0.6, -1.0])
scene.add_light(light)

mesh = t3.Mesh.from_obj(t3.Geometry.cube())
xplus = t3.Model(mesh)
xplus.material = t3.Material(t3.CookTorrance(
    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)