Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to render some straight or curve line in taichi_three #30

Open
chongxian opened this issue Nov 30, 2020 · 5 comments
Open

How to render some straight or curve line in taichi_three #30

chongxian opened this issue Nov 30, 2020 · 5 comments

Comments

@chongxian
Copy link

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

@chongxian chongxian changed the title will you provide a document about taichi_three? How to render some straight or curve line in taichi_three Nov 30, 2020
@chongxian chongxian reopened this Nov 30, 2020
@archibate
Copy link
Collaborator

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

@chongxian
Copy link
Author

chongxian commented Nov 30, 2020

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.

@archibate
Copy link
Collaborator

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

@chongxian
Copy link
Author

chongxian commented Dec 1, 2020

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

@archibate
Copy link
Collaborator

archibate commented Dec 8, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants