taichi-dev/taichi_three

How to render some straight or curve line in taichi_three

Opened this issue · 5 comments

I want to draw some curve in 3D space by using taichi_three to render, but some functions which I don't understand

Doc here: t3.142857.red, mainly detailed in rendering meshes, though.
But don't worry, I will write an example here on drawing straight line and curves for you soon :)

Thanks for your reply, I hope the document would include the example how to draw traight or curve line , it could be friendly to new Taichi users like me.

Here's the example that draws a helix-alike curve in 3d space:

import taichi_three as t3
import taichi as ti

N = 512

scene = t3.Scene()
mesh = t3.DynamicMesh(n_faces=N - 1, n_pos=N)
model = t3.WireframeModel(t3.PolyToEdge(mesh))
scene.add_model(model)
camera = t3.Camera()
scene.add_camera(camera)


@ti.kernel
def init_mesh():
    for i in range(N):
        x = i / N * 2 - 1
        mesh.pos[i] = [x, ti.sin(x * 10), ti.cos(x * 10)]

    for i in range(N - 1):
        mesh.faces[i] = [[i, 0, 0], [i, 0, 0], [i + 1, 0, 0]]
    mesh.n_faces[None] = N - 1


init_mesh()

gui = ti.GUI('Helix', camera.res)
while gui.running and not gui.get_event(gui.ESCAPE):
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
    gui.show()

Thanks for your reply, it was a great help to me

Glad to help! Also note that mesh.faces is the indices into corresponding vertices stored in mesh.pos.
Yeah, this face indirect index is really anti-intuitive and hard to learn, it was aimed to be fit with the OBJ format... sorry!
I'm currently on my progress to rewrite the core of Taichi THREE, thank for your support!