def main(filename): ti.init(ti.gpu) obj = tina.readobj(filename, scale='auto') scene = tina.Scene((1024, 768), maxfaces=len(obj['f']), smoothing=True) model = tina.MeshModel(obj) scene.add_object(model) gui = ti.GUI('mesh', scene.res, fast_gui=True) while gui.running: scene.input(gui) scene.render() gui.set_image(scene.img) gui.show()
def main(filename, density=16): ti.init(ti.gpu) dens = np.load(filename).astype(np.float32) scene = tina.Scene((1024, 768), N=dens.shape[0], taa=True, density=density) volume = tina.SimpleVolume(N=dens.shape[0]) scene.add_object(volume) gui = ti.GUI('volume', scene.res, fast_gui=True) volume.set_volume_density(dens) while gui.running: scene.input(gui) scene.render() gui.set_image(scene.img) gui.show()
def main(filename, radius=0.05): ti.init(ti.gpu) pos = np.load(filename).astype(np.float32) scene = tina.Scene((1024, 768)) pars = tina.SimpleParticles(maxpars=len(pos)) scene.add_object(pars) gui = ti.GUI('particles', scene.res, fast_gui=True) pars.set_particles(pos) pars.set_particle_radii(np.ones(len(pos), dtype=np.float32) * radius) while gui.running: scene.input(gui) scene.render() gui.set_image(scene.img) gui.show()
def main(): ti.init() scene = tina.Scene(TAA=True) model = tina.MeshModel('./model/QBZ-95.obj') t_model = tina.MeshTransform(model) scene.add_object(t_model) gui = ti.GUI("TEST") while gui.running: scene.input(gui) t_matrix = tina.quaternion(rotate) t_model.set_transform(t_matrix) scene.render() gui.set_image(scene.img) gui.show()
import taichi as ti import numpy as np import tina ti.init(ti.gpu) dens = np.load('assets/smoke.npy') scene = tina.Scene(N=dens.shape[0], taa=True, density=16) volume = tina.SimpleVolume(N=dens.shape[0]) #model = tina.MeshModel('assets/monkey.obj') #scene.add_object(model, tina.CookTorrance(metallic=0.8)) scene.add_object(volume) gui = ti.GUI('volume', scene.res) volume.set_volume_density(dens) while gui.running: scene.input(gui) scene.render() gui.set_image(scene.img) gui.show()
import taichi as ti import tina ti.init(ti.gpu) scene = tina.Scene(smoothing=True, blooming=True) material = tina.Diffuse() model = tina.MeshModel('assets/monkey.obj') scene.add_object(model, material) gui = ti.GUI(res=scene.res) light = gui.slider('light', 0, 32, 0.1) light.value = 6 scene.lighting.clear_lights() while gui.running: scene.lighting.set_ambient_light([light.value] * 3) scene.input(gui) scene.render() gui.set_image(scene.img) gui.show()
J[p] *= 1 + dt * new_C.trace() C[p] = new_C @ti.kernel def init(): for i in range(n_particles): x[i] = ti.Vector([ti.random() for i in range(dim)]) * 0.4 + 0.15 v[i] *= 0 J[i] = 1 mciso = MCISO(int(n_grid * 1)) voxel = Voxelizer(mciso.N, radius=1, weight=18) scene = tina.Scene(smoothing=True, maxfaces=2**18) scene.add_object(mciso) gui = ti.GUI('mciso_mpm3d', scene.res) scene.init_control(gui, center=[0.5, 0.5, 0.5], radius=1.5) scene.lighting.clear_lights() scene.lighting.add_light([-0.4, 1.5, 1.8], color=[0.8, 0.8, 0.8]) scene.lighting.set_ambient_light([0.22, 0.22, 0.22]) init() while gui.running: scene.input(gui) if gui.is_pressed('r'): init()
# In this episode, you'll learn how to render a wireframe model in Tina # # This tutorial is based on docs/monkey.py, make sure you check that first import taichi as ti import tina ti.init(ti.cpu) # you may specify the line width for rendering wireframes: scene = tina.Scene(linewidth=2) # load the monkey using `tina.MeshModel` node (`tina.SimpleMesh` works too): model = tina.MeshModel('assets/monkey.obj') # convert the mesh to its wireframe using the `tina.MeshToWire` node: wiremodel = tina.MeshToWire(model) # add the wireframe model into scene: scene.add_object(wiremodel) # add the original model, with a tiny scale: model = tina.MeshTransform(model, tina.scale(0.9)) scene.add_object(model) gui = ti.GUI('wireframe') while gui.running: scene.input(gui) scene.render() gui.set_image(scene.img) gui.show()
print( f"Res [{RES_X}x{RES_Y}] GPU {args.cuda} RVIZ {disp_in_rviz} size of map {args.map_size} grid {args.voxel_size} " ) if args.record: ti.core.start_recording('./export/TaichiSLAM.yml') ti.init(arch=ti.cc) else: if args.cuda: ti.init(arch=ti.cuda) else: ti.init(arch=ti.cpu, debug=True) gui = ti.GUI('TaichiSLAM', (RES_X, RES_Y)) level = 1 scene = tina.Scene(RES_X, RES_Y, bgcolor=(0.1, 0.1, 0.1)) pars1 = tina.SimpleParticles(maxpars=args.max_disp_particles) pars2 = tina.SimpleParticles(maxpars=args.max_disp_particles) material1 = tina.Lamp() material2 = tina.Lamp() scene.add_object(pars1, material1) scene.add_object(pars2, material2) if args.method == "octo": mapping = Octomap(texture_enabled=args.texture_enabled, max_disp_particles=args.max_disp_particles, min_occupy_thres=args.occupy_thres, map_scale=args.map_size, voxel_size=args.voxel_size, K=args.K) elif args.method == "esdf": mapping = DenseESDF(texture_enabled=args.texture_enabled,
new_C += 4 * weight * g_v.outer_product(dpos) / dx**2 v[p] = new_v x[p] += dt * v[p] J[p] *= 1 + dt * new_C.trace() C[p] = new_C @ti.kernel def init(): for i in range(n_particles): x[i] = ti.Vector([ti.random() for i in range(dim)]) * 0.4 + 0.15 v[i] *= 0 J[i] = 1 scene = tina.Scene(maxpars=n_particles, bgcolor=ti.hex_to_rgb(0xaaaaff)) pars = tina.SimpleParticles(n_particles, radius=0.01) color = tina.Diffuse(color=ti.hex_to_rgb(0xffaaaa)) scene.add_object(pars, color) gui = ti.GUI('pars_mpm3d', scene.res) scene.init_control(gui, center=[0.5, 0.5, 0.5], radius=1.5) scene.lighting.clear_lights() scene.lighting.add_light([-0.4, 1.5, 1.8], color=[0.8, 0.8, 0.8]) scene.lighting.set_ambient_light([0.22, 0.22, 0.22]) init() while gui.running: scene.input(gui) if gui.is_pressed('r'):
new_C += 4 * weight * g_v.outer_product(dpos) / dx**2 v[p] = new_v x[p] += dt * v[p] J[p] *= 1 + dt * new_C.trace() C[p] = new_C @ti.kernel def init(): for i in range(n_particles): x[i] = ti.Vector([ti.random() for i in range(dim)]) * 0.4 + 0.15 v[i] *= 0 J[i] = 1 scene = tina.Scene(maxpars=n_particles) pars = tina.SimpleParticles(n_particles, radius=0.01) scene.add_object(pars) gui = ti.GUI('pars_mpm3d', scene.res) scene.init_control(gui, center=[0.5, 0.5, 0.5], radius=1.5) scene.lighting.clear_lights() scene.lighting.add_light([-0.4, 1.5, 1.8], color=[0.8, 0.8, 0.8]) scene.lighting.set_ambient_light([0.22, 0.22, 0.22]) init() while gui.running: scene.input(gui) if gui.is_pressed('r'): init()
import taichi as ti import tina ti.init(ti.opengl) scene = tina.Scene(fxaa=True) model = tina.MeshModel('assets/monkey.obj') scene.add_object(model, tina.PBR(metallic=0.5, roughness=0.3)) gui = ti.GUI(res=scene.res) abs_thresh = gui.slider('abs_thresh', 0, 0.1, 0.002) rel_thresh = gui.slider('rel_thresh', 0, 0.5, 0.01) factor = gui.slider('factor', 0, 1, 0.01) abs_thresh.value = 0.0625 rel_thresh.value = 0.063 factor.value = 1 while gui.running: scene.fxaa.rel_thresh[None] = rel_thresh.value scene.fxaa.abs_thresh[None] = abs_thresh.value scene.fxaa.factor[None] = factor.value scene.input(gui) scene.render() gui.set_image(scene.img) gui.show()
import taichi as ti import tina ti.init(ti.cuda) scene = tina.Scene(smoothing=True, ssao=True) #, ibl=True) #model = tina.MeshModel('assets/bunny.obj') model = tina.MeshModel('assets/monkey.obj') #model = tina.MeshModel('/home/bate/Documents/testssao.obj') scene.add_object(model) if not scene.ibl: scene.lighting.clear_lights() scene.lighting.set_ambient_light([1, 1, 1]) gui = ti.GUI(res=scene.res) radius = gui.slider('radius', 0, 2, 0.01) thresh = gui.slider('thresh', 0, 1, 0.01) factor = gui.slider('factor', 0, 2, 0.01) radius.value = 0.2 thresh.value = 0.0 factor.value = 1.0 while gui.running: scene.ssao.radius[None] = radius.value scene.ssao.thresh[None] = thresh.value scene.ssao.factor[None] = factor.value scene.input(gui) scene.render()
for d in ti.static(links): disp = x[tl.clamp(i + d, 0, tl.vec(*NN) - 1)] - x[i] length = L * float(d).norm() acc += disp * (disp.norm() - length) / length**2 v[i] += stiffness * acc * dt for i in ti.grouped(x): v[i].y -= gravity * dt v[i] = tl.ballBoundReflect(x[i], v[i], ball_pos, ball_radius, 6) for i in ti.grouped(x): v[i] *= ti.exp(-damping * dt) x[i] += dt * v[i] ### Rendering GUI scene = tina.Scene((1024, 768), smoothing=True, texturing=True) mesh = tina.MeshNoCulling(tina.MeshGrid((N, N))) ball = tina.MeshTransform(tina.MeshModel('assets/sphere.obj')) cloth = tina.CookTorrance(basecolor=tina.Texture('assets/cloth.jpg')) scene.add_object(mesh, cloth) scene.add_object(ball) gui = ti.GUI('Mass Spring', scene.res, fast_gui=True) scene.init_control(gui, center=ball_pos, theta=np.pi / 2 - np.radians(30), radius=1.5)
x[p] += dt * v[p] J[p] *= 1 + dt * new_C.trace() C[p] = new_C @ti.kernel def init(): for i in range(n_particles): x[i] = ti.Vector([ti.random() for i in range(dim)]) * 0.4 + 0.15 v[i] *= 0 J[i] = 1 mciso = tina.MCISO((n_grid, n_grid, n_grid)) scene = tina.Scene(smoothing=True, maxfaces=2**18, ibl=True, ssao=True) material = tina.PBR(metallic=0.15, roughness=0.0) scene.add_object(mciso, material) #boundbox = tina.MeshToWire(tina.MeshTransform(tina.MeshModel('assets/cube.obj'), tina.scale(0.5) @ tina.translate(1))) #scene.add_object(boundbox) gui = ti.GUI('mciso_mpm3d', scene.res) scene.init_control(gui, center=[0.5, 0.5, 0.5], radius=1.5) if not scene.ibl: scene.lighting.clear_lights() scene.lighting.add_light([-0.4, 1.5, 1.8], color=[0.8, 0.8, 0.8]) scene.lighting.set_ambient_light([0.22, 0.22, 0.22]) init()
import taichi as ti import tina ti.init(ti.cpu) scene = tina.Scene(smoothing=True) metallic = tina.Param(float, initial=0.0) specular = tina.Param(float, initial=0.5) roughness = tina.Param(float, initial=0.4) material = tina.PBR(metallic=metallic, roughness=roughness, specular=specular) #shineness = tina.Param(float, initial=32) #specular = tina.Param(float, initial=0.5) #material = tina.Classic(shineness=shineness, specular=specular) model = tina.PrimitiveMesh.sphere() scene.add_object(model, material) gui = ti.GUI('matball') if 'roughness' in globals(): roughness.make_slider(gui, 'roughness') if 'metallic' in globals(): metallic.make_slider(gui, 'metallic') if 'shineness' in globals(): shineness.make_slider(gui, 'shineness', 1, 500, 1) if 'specular' in globals(): specular.make_slider(gui, 'specular') while gui.running: scene.input(gui)
import taichi as ti import tina ti.init(ti.gpu) scene = tina.Scene((640, 480), smoothing=True, ssr=True, taa=True) monkey_material = tina.PBR(metallic=0.0, roughness=0.4) monkey = tina.MeshModel('assets/monkey.obj') scene.add_object(monkey, monkey_material) param_metallic = tina.Param() param_roughness = tina.Param() plane_material = tina.PBR(metallic=param_metallic, roughness=param_roughness) plane = tina.MeshTransform(tina.MeshGrid(32), tina.scale(2) @ tina.eularXYZ([-ti.pi / 2, 0, 0])) scene.add_object(plane, plane_material) gui = ti.GUI(res=scene.res) nsteps = gui.slider('nsteps', 1, 128, 1) nsamples = gui.slider('nsamples', 1, 128, 1) stepsize = gui.slider('stepsize', 0, 32, 0.1) tolerance = gui.slider('tolerance', 0, 64, 0.1) blurring = gui.slider('blurring', 1, 8, 1) metallic = gui.slider('metallic', 0, 1, 0.01) roughness = gui.slider('roughness', 0, 1, 0.01) nsteps.value = 64 nsamples.value = 12 blurring.value = 4 stepsize.value = 2 tolerance.value = 15 metallic.value = 1.0
import taichi as ti import numpy as np import taichi_inject import tina ti.init(ti.gpu) scene = tina.Scene(smoothing=True, texturing=True, rtx=True, taa=True) material = tina.Phong(shineness=64) mesh = tina.PrimitiveMesh.sphere() #mesh = tina.MeshModel('assets/monkey.obj') scene.add_object(mesh, material) gui = ti.GUI('raytrace', scene.res) scene.update() while gui.running: scene.input(gui) scene.render() gui.set_image(scene.img) gui.show()
# In this episode, you'll learn how to render a wireframe model in Tina # # This tutorial is based on docs/monkey.py, make sure you check that first import taichi as ti import tina ti.init(ti.cpu) # you may specify the line width for rendering wireframes: # taa=True turns on Temporal Anti-Aliasing to make lines smoother scene = tina.Scene(linewidth=2, taa=True) # load the monkey using `tina.MeshModel` node (`tina.SimpleMesh` works too): model = tina.MeshModel('assets/monkey.obj') # convert the mesh to its wireframe using the `tina.MeshToWire` node: wiremodel = tina.MeshToWire(model) # add the wireframe model into scene: scene.add_object(wiremodel) # add the original model, with a tiny scale: model = tina.MeshTransform(model, tina.scale(0.9)) scene.add_object(model) gui = ti.GUI('wireframe') while gui.running: scene.input(gui) scene.render() gui.set_image(scene.img)
# In this episode, you'll learn how to use lights and materials in Tina # # This tutorial is based on docs/monkey.py, make sure you check that first import taichi as ti import tina ti.init(ti.gpu) scene = tina.Scene() # 5. Material - for describing the material of an object material = tina.CookTorrance(metallic=0.6, roughness=0.2) # parameters may also be specified by textures (add texturing=True to Scene) #material = tina.CookTorrance(basecolor=tina.Texture('assets/cloth.jpg')) model = tina.MeshModel('assets/monkey.obj') # load our model into the scene with material specified: scene.add_object(model, material) gui = ti.GUI('lighting') # now, let's add some custom light sources into the scene for test # # first of all, remove the 'default light' from scene: scene.lighting.clear_lights() # adds a directional light with direction (0, 0, 1), with white color # the direction will be automatically normalized to obtain desired result scene.lighting.add_light(dir=[0, 0, 1], color=[1, 1, 1]) # adds a point light at position (1, 1.5, 0.3), with red color scene.lighting.add_light(pos=[1, 1.5, 0.3], color=[1, 0, 0])
import tina import taichi as ti scene = tina.Scene(texturing=True, prob=True) verts, faces = tina.readobj('assets/monkey.obj', simple=True) mesh = tina.SimpleMesh() texture = tina.LerpTexture(x0=[1.0, 1.0, 1.0], x1=[0.0, 0.0, 1.0]) material = tina.Diffuse(color=texture) scene.add_object(mesh, material) probe = tina.ProbeShader(scene.res) scene.post_shaders.append(probe) mesh.set_face_verts(verts[faces]) @ti.func def ontouch(probe, I, r): e = probe.elmid[I] for i in ti.static(range(3)): mesh.coors[e, i].x = 1.0 gui = ti.GUI() while gui.running: scene.input(gui) if gui.is_pressed(gui.LMB): mx, my = gui.get_cursor_pos() probe.touch(ontouch, mx, my, 0) scene.render()