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()
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) gui.show()
mesh = t3.MeshGrid((128, 128)) model = t3.Model(t3.QuadToTri(mesh)) scene.add_model(model) camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[1.1, 1.6, 1.6]) scene.add_camera(camera) light = t3.Light([0.4, -1.5, -0.8], 0.9) scene.add_light(light) ambient = t3.AmbientLight(0.1) scene.add_light(ambient) @ti.func def Z(xy, t): return 0.1 * ti.sin(10 * xy.norm() - t3.tau * t) @ti.kernel def deform_mesh(t: float): for i, j in mesh.pos: mesh.pos[i, j].y = Z(mesh.pos[i, j].xZ, t) gui = ti.GUI('Meshgrid', camera.res) while gui.running: gui.get_event(None) gui.running = not gui.is_pressed(ti.GUI.ESCAPE) camera.from_mouse(gui) deform_mesh(t3.get_time()) scene.render() gui.set_image(camera.img) gui.show()
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()
import taichi as ti import taichi_three as t3 import numpy as np ti.init(ti.cpu) scene = t3.Scene() obj = t3.readobj('assets/logo.obj', scale=0.8) t3.objbothface(obj) logo1 = t3.Model(t3.Mesh.from_obj(obj)) logo2 = t3.Model(t3.Mesh.from_obj(obj)) scene.add_model(logo1) scene.add_model(logo2) camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[-1, 1, 1]) scene.add_camera(camera) light = t3.Light([0.4, -1.5, 0.8]) scene.add_light(light) gui = ti.GUI('Taichi THREE', camera.res) while gui.running: gui.get_event(None) gui.running = not gui.is_pressed(ti.GUI.ESCAPE) camera.from_mouse(gui) t = t3.get_time() logo1.L2W[None] = t3.rotateY(t) logo2.L2W[None] = t3.rotateX(t3.pi - t) @ t3.rotateZ(t3.pi / 2) scene.render() gui.set_image(camera.img) gui.show()
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) obj = t3.Geometry.cube() model = t3.Model(t3.Mesh.from_obj(obj)) scene.add_model(model) gui = t3.GUI('Rotating Cube') while gui.running: gui.get_event(None) camera.from_mouse(gui) model.L2W[None] = t3.rotateY(t3.get_time()) scene.render() gui.set_image(camera.img) gui.show()