Esempio n. 1
0
 def extract(self, scene, trans):
     obj = self.to_obj_mesh()
     mesh = tina.MeshModel(obj)
     mesh = tina.MeshTransform(mesh, trans)
     material = None
     if self.material is not None:
         material = self.material.extract()
     scene.add_object(mesh, material)
Esempio n. 2
0
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()
Esempio n. 3
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.gpu)

scene = tina.PTScene(smoothing=True, texturing=True)

scene.add_object(tina.PrimitiveMesh.sphere(), tina.Glass())
scene.add_object(
    tina.MeshTransform(tina.MeshModel('assets/cube.obj'),
                       tina.translate([0, -3, 0]) @ tina.scale(2)),
    tina.Lambert())

scene.add_object(
    tina.MeshTransform(tina.MeshModel('assets/plane.obj'),
                       tina.translate([0, 4, 0]) @ tina.scale(0.2)),
    tina.Lamp(color=tina.Texture("assets/cloth.jpg")) * 64)

gui = ti.GUI('bdpt', scene.res)

scene.update()
while gui.running:
    if scene.input(gui):
        scene.clear()
    scene.render(nsteps=6)
    scene.render_light(nsteps=6)
    gui.set_image(scene.img)
    gui.show()
Esempio n. 4
0
#
# 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()
Esempio n. 5
0
# In this episode, you'll learn how to make use of nodes for transformation
#
# 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()

# load the monkey model with the `tina.MeshModel` node:
model = tina.MeshModel('assets/monkey.obj')
# transform the mesh using the `tina.Transform` node:
tmodel = tina.MeshTransform(model)
# load the desired node to be displayed:
scene.add_object(tmodel)
#scene.add_object(model)

gui = ti.GUI('transform')

while gui.running:
    scene.input(gui)

    # create a matrix representing translation along X-axis
    dx = ti.sin(gui.frame * 0.03)
    matrix = tina.translate([dx, 0, 0])
    # set the model transformation matrix for `tina.Transform` node
    tmodel.set_transform(matrix)

    scene.render()
Esempio n. 6
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.gpu)

scene = tina.PTScene(smoothing=True, texturing=True)
scene.load_gltf('assets/cornell.gltf')
scene.add_object(tina.MeshTransform(tina.MeshModel('assets/plane.obj'),
    tina.translate([0, 3.98, 0]) @ tina.scale(0.1)), tina.Lamp(color=64))

if isinstance(scene, tina.PTScene):
    scene.update()

gui = ti.GUI('cornell_box', scene.res)
scene.init_control(gui, center=(0, 2, 0), radius=5)

while gui.running:
    scene.input(gui)
    if isinstance(scene, tina.PTScene):
        scene.render(nsteps=8)
    else:
        scene.render()
    gui.set_image(scene.img)
    gui.show()

ti.imwrite(scene.img, 'cornell.png')
Esempio n. 7
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.opengl)

scene = tina.PTScene(smoothing=True)

roughness = tina.Param(float, initial=0.2)
metallic = tina.Param(float, initial=1.0)
scene.add_object(tina.MeshModel('assets/sphere.obj'), tina.PBR(metallic=metallic, roughness=roughness))

scene.add_object(tina.MeshTransform(tina.MeshModel('assets/plane.obj'),
        tina.translate([0, 0, 4]) @ tina.eularXYZ([ti.pi / 2, 0, 0])
        #@ tina.scale(0.1)), tina.Lamp(color=32))
        @ tina.scale(0.4)), tina.Lamp(color=1))

gui = ti.GUI('path', scene.res)
roughness.make_slider(gui, 'roughness', 0, 1, 0.01)
metallic.make_slider(gui, 'metallic', 0, 1, 0.01)

scene.update()
while gui.running:
    if scene.input(gui):
        scene.clear()
    scene.render(nsteps=6)
    gui.set_image(scene.img)
    gui.show()

#ti.imwrite(scene.img, 'output.png')
Esempio n. 8
0
            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)

scene.lighting.clear_lights()
scene.lighting.add_light(dir=[0, 1, 1], color=[0.9, 0.9, 0.9])
scene.lighting.set_ambient_light([0.1, 0.1, 0.1])
Esempio n. 9
0
import taichi as ti
import tina

ti.init(ti.gpu)

scene = tina.Scene(smoothing=True, rtx=True)

material = tina.Phong(shineness=256)

model = tina.PrimitiveMesh.sphere()
scene.add_object(model, material)

model2 = tina.MeshTransform(tina.PrimitiveMesh.sphere(),
                            tina.translate([1.4, 0, 0]) @ tina.scale(0.5))
scene.add_object(model2, material)

gui = ti.GUI('matball')

scene.update()
scene.init_control(gui)
while gui.running:
    scene.input(gui)
    scene.render()
    gui.set_image(scene.img)
    gui.show()
Esempio n. 10
0
import taichi as ti
import tina

ti.init(ti.gpu)

scene = tina.PTScene()
#scene.engine.skybox = tina.Atomsphere()

model = tina.MeshTransform(tina.MeshModel('assets/plane.obj'),
        tina.translate([0, 0, 4]) @ tina.eularXYZ([ti.pi / 2, 0, 0]))
material = tina.Emission() * 2
scene.add_object(model, material)

metallic = tina.Param(float, initial=1.0)
roughness = tina.Param(float, initial=0.01)
model = tina.MeshModel('assets/monkey.obj')
material = tina.PBR(metallic=metallic, roughness=roughness)
scene.add_object(model, material)

gui = ti.GUI(res=scene.res)
metallic.make_slider(gui, 'metallic')
roughness.make_slider(gui, 'roughness')

scene.update()
while gui.running:
    scene.input(gui)
    scene.render()
    gui.set_image(scene.img)
    gui.show()
Esempio n. 11
0
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
Esempio n. 12
0
 def extract(self, scene, trans):
     obj = self.to_obj_mesh()
     mesh = tina.MeshModel(obj)
     mesh = tina.MeshTransform(mesh, trans)
     scene.add_object(mesh)
Esempio n. 13
0
import taichi as ti
import numpy as np
import taichi_inject
import tina

ti.init(ti.cpu)

scene = tina.PTScene(smoothing=True, texturing=True)

mesh = tina.MeshTransform(tina.MeshModel('assets/monkey.obj'),
                          tina.translate([0, -0.5, 0]))
material = tina.Lambert()

mesh2 = tina.MeshTransform(tina.MeshModel('assets/sphere.obj'),
                           tina.translate([0, +0.5, 0]))
material2 = tina.Lambert(color=tina.Texture('assets/uv.png'))

scene.add_object(mesh, material)
scene.add_object(mesh2, material2)
scene.build()

scene.lighting.set_lights(
    np.array([
        [0, 1.38457, -1.44325],
    ], dtype=np.float32))
scene.lighting.set_light_radii(np.array([
    0.2,
], dtype=np.float32))

gui = ti.GUI('BVH', scene.res)
while gui.running and not gui.get_event(gui.ESCAPE, gui.SPACE):