Ejemplo n.º 1
0
def objshow(obj,
            visual='color',
            res=(512, 512),
            ortho=False,
            showball=False,
            lightdir=[0.4, -1.5, 0.8]):
    import taichi_three as t3

    t3.reset()
    scene = t3.Scene()
    model = t3.Model.from_obj(obj)
    scene.add_model(model)
    if showball:
        ball = t3.Model.from_obj(t3.readobj('assets/sphere.obj', scale=0.6))
        scene.add_model(ball)
    camera = t3.Camera(res=res)
    if visual != 'color':
        dim = 3
        if visual == 'idepth':
            dim = 0
        if visual == 'texcoor':
            dim = 2
        camera.fb.add_buffer('normal', dim)
    if ortho:
        camera.type = camera.ORTHO
    scene.add_camera(camera)
    light = t3.Light(dir=lightdir)
    scene.add_light(light)

    gui = t3.GUI('Model', camera.res)
    while gui.running:
        gui.get_event(None)
        gui.running = not gui.is_pressed(gui.ESCAPE)
        camera.from_mouse(gui)
        if showball:
            ball.L2W.offset[None] = t3.Vector([1.75, -1.75, 0.0])
        scene.render()
        if visual == 'normal':
            gui.set_image(camera.fb['normal'].to_numpy() * 0.5 + 0.5)
        elif visual == 'color':
            gui.set_image(camera.img)
        else:
            gui.set_image(camera.fb[visual].to_numpy())
        gui.show()
Ejemplo n.º 2
0
import taichi_three as t3

scene = t3.Scene()
camera = t3.Camera()
scene.add_camera(camera)

light = t3.Light(dir=[-0.2, -0.6, -1.0])
scene.add_light(light)

obj = t3.Geometry.cube()
model = t3.Model(t3.Mesh.from_obj(obj))
model.material = t3.Material(t3.BlinnPhong(
    color=t3.Texture('container2.png'),
    specular=t3.Texture('container2_specular.png'),
))
scene.add_model(model)

gui = t3.GUI('Binding Textures')
while gui.running:
    scene.render()
    gui.get_event(None)
    camera.from_mouse(gui)
    gui.set_image(camera.img)
    gui.show()
Ejemplo n.º 3
0
import taichi_three as t3

scene = t3.Scene()
camera = t3.Camera()
scene.add_camera(camera)

model = t3.SimpleModel()
scene.add_model(model)

model.gl.Begin('GL_TRIANGLES')
model.gl.Color(1.0, 0.0, 0.0)
model.gl.Vertex(+0.0, +0.5, 0.0)
model.gl.Color(0.0, 1.0, 0.0)
model.gl.Vertex(+0.5, -0.5, 0.0)
model.gl.Color(0.0, 0.0, 1.0)
model.gl.Vertex(-0.5, -0.5, 0.0)
model.gl.End()

gui = t3.GUI('Hello Triangle')
while gui.running:
    gui.get_event(None)
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
    gui.show()
Ejemplo n.º 4
0
import taichi_three as t3

scene = t3.Scene()
camera = t3.Camera()
scene.add_camera(camera)

light = t3.Light(dir=[-0.2, -0.6, -1.0])
scene.add_light(light)

obj = t3.Geometry.cylinder(semiheight=1, radius=0.2)
model = t3.Model(t3.Mesh.from_obj(obj))
scene.add_model(model)

gui = t3.GUI('Cylinder')
while gui.running:
    gui.get_event(None)
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
    gui.show()
Ejemplo n.º 5
0
import taichi_three as t3

scene = t3.Scene()
camera = t3.Camera()
scene.add_camera(camera)

light = t3.Light(dir=[-0.2, -0.6, -1.0])
scene.add_light(light)

obj = t3.Geometry.cube()
model = t3.Model(t3.Mesh.from_obj(obj))
scene.add_model(model)

gui = t3.GUI('Rotating Cube')
while gui.running:
    gui.get_event(None)
    camera.from_mouse(gui)
    model.L2W[None] = t3.rotateY(t3.get_time())
    scene.render()
    gui.set_image(camera.img)
    gui.show()
Ejemplo n.º 6
0
import taichi_three as t3

scene = t3.Scene()
camera = t3.Camera()
scene.add_camera(camera)

light = t3.Light(dir=[-0.2, -0.6, 1.0])
scene.add_light(light)

obj = t3.readobj('cube.obj', scale=0.6)
model = t3.Model.from_obj(obj)
scene.add_model(model)

gui = t3.GUI('Shading Models')
while gui.running:
    gui.get_event(None)
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
    gui.show()
Ejemplo n.º 7
0
import taichi_three as t3

scene = t3.Scene()
camera = t3.Camera()
scene.add_camera(camera)

light = t3.Light(dir=[-0.2, -0.6, -1.0])
scene.add_light(light)

obj = t3.Geometry.cube()
model = t3.Model(t3.Mesh.from_obj(obj))
scene.add_model(model)

gui = t3.GUI('Hello Cube')
while gui.running:
    gui.get_event(None)
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
    gui.show()
Ejemplo n.º 8
0
    color=t3.Constant(t3.RGB(1, 0, 0)),
))
scene.add_model(xplus)
yplus = t3.Model(mesh)
yplus.material = t3.Material(t3.CookTorrance(
    color=t3.Constant(t3.RGB(0, 1, 0)),
))
scene.add_model(yplus)
zplus = t3.Model(mesh)
zplus.material = t3.Material(t3.CookTorrance(
    color=t3.Constant(t3.RGB(0, 0, 1)),
))
scene.add_model(zplus)
center = t3.Model(mesh)
center.material = t3.Material(t3.CookTorrance(
    color=t3.Constant(t3.RGB(1, 1, 1)),
))
scene.add_model(center)

xplus.L2W[None] = t3.translate(1, 0, 0) @ t3.scale(0.1)
yplus.L2W[None] = t3.translate(0, 1, 0) @ t3.scale(0.1)
zplus.L2W[None] = t3.translate(0, 0, 1) @ t3.scale(0.1)
center.L2W[None] = t3.scale(0.1)

gui = t3.GUI('Coordinate system')
while gui.running:
    gui.get_event(None)
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
    gui.show()