Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
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')
Ejemplo n.º 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')
Ejemplo n.º 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()
Ejemplo n.º 8
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
Ejemplo n.º 9
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):
Ejemplo n.º 10
0
#scene.lighting.skybox = tina.Atomsphere()

#material = tina.Phong(color=[0.25, 0.5, 0.5])
#scene.add_object(tina.PrimitiveMesh.sphere(), tina.Glass())
roughness = tina.Param(float, initial=0.332)
metallic = tina.Param(float, initial=0.0)
scene.add_object(tina.MeshModel('assets/sphere.obj'), tina.PBR(metallic=metallic, roughness=roughness))
#scene.add_object(tina.PrimitiveMesh.sphere(), tina.Mirror())
#scene.add_object(tina.MeshModel('assets/bunny.obj'), tina.Glass())
#scene.add_object(tina.MeshModel('assets/monkey.obj'), tina.Mirror())
#scene.add_object(tina.MeshModel('assets/cube.obj'), tina.Classic())
#scene.add_object(tina.MeshTransform(tina.MeshModel('assets/cube.obj'), tina.translate([0, -1.2, 0]) @ tina.scale([2, 0.05, 2])), tina.Lambert())

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=128))

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')