Beispiel #1
0
        def extract(self, scene):
            trans = tina.identity()
            if self.trans is not None:
                offset, rotation, scale = self.trans
                if scale is not None:
                    trans = tina.scale(scale) @ trans
                if rotation is not None:
                    trans = tina.quaternion(rotation) @ trans
                if offset is not None:
                    trans = tina.translate(offset) @ trans

            if self.primitives is not None:
                for primitive in self.primitives:
                    primitive.extract(scene, trans)
Beispiel #2
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()
Beispiel #3
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')
Beispiel #4
0
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()
    gui.set_image(scene.img)
    gui.show()
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])

ball.set_transform(tina.translate(ball_pos) @ tina.scale(ball_radius))

init()

while gui.running:
    scene.input(gui)

    if not gui.is_pressed(gui.SPACE):
        for i in range(steps):
            substep()

    if gui.is_pressed('r'):
        init()

    mesh.pos.copy_from(x)
Beispiel #6
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')
Beispiel #7
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()
Beispiel #8
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.gpu)

scene = tina.PTScene(smoothing=True)
#scene.lighting.skybox = tina.Atomsphere()
#scene.lighting.skybox = tina.Skybox('assets/grass.jpg')

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.lighting.set_lights(np.array([
    [0, 5, 0],
]))
scene.lighting.set_light_colors(np.array([
    [16, 16, 16],
]))
scene.lighting.set_light_radii(np.array([
    0.01,
]))

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

scene.update()
while gui.running:
    if scene.input(gui):
Beispiel #9
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):