예제 #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)
예제 #2
0
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()
예제 #3
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()
예제 #4
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.cpu)

scene = tina.PTScene(smoothing=True)
scene.engine.skybox = tina.PlainSkybox()

scene.add_object(tina.MeshModel('assets/monkey.obj'), tina.Lambert())

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

scene.update()
while gui.running:
    if scene.input(gui):
        scene.clear()
    scene.render()
    gui.set_image(scene.img)
    gui.show()
예제 #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')
예제 #6
0
import taichi as ti
import tina

ti.init(ti.cpu)

scene = tina.Scene(smoothing=True)

metallic = tina.Param(float)
roughness = tina.Param(float)
material = tina.CookTorrance(metallic=metallic, roughness=roughness)
model = tina.MeshModel('assets/sphere.obj')
scene.add_object(model, material)

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

scene.init_control(gui, blendish=True)
while gui.running:
    scene.input(gui)
    scene.render()
    gui.set_image(scene.img)
    gui.show()
예제 #7
0
#
# 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])
# specifies the ambient color to be dark green
예제 #8
0
import taichi as ti
import tina

ti.init(ti.cpu)

scene = tina.Scene()
model = tina.MeshModel('assets/cube.obj')
material = tina.Emission() * tina.Input('pos')
scene.add_object(model, material)

gui = ti.GUI(res=scene.res)

while gui.running:
    scene.input(gui)
    scene.render()
    gui.set_image(scene.img)
    gui.show()
예제 #9
0
# In this episode, you'll learn some basic options to specify for a Tina scene.
#
# This tutorial is based on docs/monkey.py, make sure you check that first

import taichi as ti
import tina

ti.init(ti.gpu)

# There are some options you may specify to tina.Scene, try turn off some
# of them and see what's the difference
#
# culling: enable face culling for better performance (default: on)
# clipping: enable view space clipping for rid objects out of depth (default: off)
# smoothing: enable smooth shading by interpolating normals (default: off)
# texturing: enable texture coordinates, see docs/texture.py (default: off)
# taa: temporal anti-aliasing, won't work well for dynamic scenes (default: off)
scene = tina.Scene(smoothing=True, taa=True)

# (make sure your OBJ model have normals to make smooth shading work)
model = tina.MeshModel('assets/torus.obj')
scene.add_object(model)

gui = ti.GUI('options')

while gui.running:
    scene.input(gui)
    scene.render()
    gui.set_image(scene.img)
    gui.show()
예제 #10
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')
예제 #11
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()
예제 #12
0
import taichi as ti
import tina

ti.init(ti.gpu)

scene = tina.Scene(smoothing=True)

model = tina.MeshSmoothNormal(tina.MeshModel('assets/monkey.obj'))
scene.add_object(model)

gui = ti.GUI('smooth')

while gui.running:
    scene.input(gui)
    scene.render()
    gui.set_image(scene.img)
    gui.show()
예제 #13
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.gpu)

scene = tina.PTScene(smoothing=True, texturing=True)
scene.engine.skybox = tina.Skybox('assets/skybox.jpg', cubic=True)
scene.add_object(tina.MeshModel('assets/cube.obj'), tina.Glass())

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

scene.update()
while gui.running:
    if scene.input(gui):
        scene.clear()
    scene.render(nsteps=12)
    #scene.render_light(nsteps=6)
    gui.set_image(scene.img)
    gui.show()
예제 #14
0
 def extract(self, scene, trans):
     obj = self.to_obj_mesh()
     mesh = tina.MeshModel(obj)
     mesh = tina.MeshTransform(mesh, trans)
     scene.add_object(mesh)
예제 #15
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):
예제 #16
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.gpu)

scene = tina.PTScene()
scene.add_object(tina.MeshModel('assets/shadow.obj'))
scene.lighting.skybox = tina.Atomsphere()

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

scene.update()
while gui.running:
    scene.input(gui)
    scene.render()
    gui.set_image(scene.img)
    gui.show()
예제 #17
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()
예제 #18
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])
예제 #19
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.gpu)

scene = tina.PTScene(smoothing=True, texturing=True)
#scene.lighting.skybox = tina.Skybox('assets/skybox.jpg', cubic=True)
model = tina.MeshModel('assets/bunny.obj')
#material = tina.PBR(roughness=0.0, metallic=0.0)
material = tina.PBR(roughness=0.2, metallic=0.8)
scene.add_object(model, material)
denoise = tina.Denoise(scene.res)

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

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

while gui.running:
    scene.input(gui)
    if isinstance(scene, tina.PTScene):
        scene.render(nsteps=5)
    else:
        scene.render()
    #gui.set_image(scene.img)
    denoise.src.from_numpy(scene.img)
    denoise.nlm(radius=2, noiseness=0.9)
    gui.set_image(denoise.dst)
    gui.show()
예제 #20
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.gpu)

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

pars = tina.SimpleParticles()
scene.add_object(pars, tina.Lamp(color=32))

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

pars.set_particles(np.array([
    [0, 0, 5],
]))

scene.update()
while gui.running:
    if scene.input(gui):
        scene.clear()
    scene.render(nsteps=6)
    gui.set_image(scene.img)
    gui.show()
예제 #21
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.gpu)

dens = np.load('assets/smoke.npy')[::1, ::1, ::1]
scene = tina.PTScene()
scene.engine.skybox = tina.Atomsphere()
volume = tina.VolumeScale(tina.SimpleVolume(N=dens.shape[0]), scale=5)
scene.add_object(tina.MeshModel('assets/monkey.obj'))
g = tina.Param(float, initial=0.76)
scene.add_object(volume, tina.HenyeyGreenstein(g=g))
#scene.add_object(tina.MeshTransform(tina.MeshModel('assets/plane.obj'),
#    tina.translate([0, 0, 4]) @ tina.eularXYZ([ti.pi / 2, 0, 0])),
#    tina.Emission() * 4)

gui = ti.GUI('volume', scene.res)
g.make_slider(gui, 'g', -1, 1, 0.01)

volume.set_volume_density(dens)
scene.update()
while gui.running:
    scene.input(gui)
    scene.render()  #nsteps=32)
    gui.set_image(scene.img)
    gui.show()
예제 #22
0
파일: test.py 프로젝트: Magic-Xin/Coding
import taichi as ti
import tina

ti.init(ti.gpu)

scene = tina.Scene(fxaa=True)

material = tina.PBR(metallic=0.6, roughness=0.2)
model = tina.MeshModel('./monkey.obj')

scene.add_object(model, material)

gui = ti.GUI('test')

scene.lighting.clear_lights()
scene.lighting.add_light(dir=[0, 0, 1], color=[1, 1, 1])
scene.lighting.add_light(pos=[1, 1.5, 0.3], color=[1, 0, 0])
scene.lighting.set_ambient_light([0, 0.06, 0])

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)