-
Notifications
You must be signed in to change notification settings - Fork 24
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
Simple triangle example doesn't work (Mesh culling func misses) #33
Comments
Thank for asking, you may use the newly added
python3 -m pip uninstall -y taichi_three # remove the old version
python3 -m pip uninstall -y taichi_three # double uninstall for sure
git clone https://github.com/taichi-dev/taichi_three.git --depth=1
cd taichi_three
python3 -m pip install wheel # required for building wheel
python3 setup.py bdist_wheel # create the wheel file
python3 -m pip install dist/*.whl # install the latest version
import taichi_three as t3
import taichi as ti
@ti.data_oriented
class MeshNoCulling: # the same one as taichi_three/model.py have in latest master branch
def __init__(self, mesh):
self.mesh = mesh
@property
def shape(self):
return self.mesh.shape
@property
def static_shape(self):
return [2, *self.mesh.static_shape]
def before_rendering(self):
self.mesh.before_rendering()
@ti.func
def get_face(self, i, j: ti.template()):
face = self.mesh.get_face(i, t3.ts.vec(*[j[_] for _ in range(1, j.n)]))
ret = t3.DataOriented()
if ti.static(j.x == 0):
ret.__dict__.update(
pos = [face.pos[i] for i in [0, 1, 2]],
tex = [face.tex[i] for i in [0, 1, 2]],
nrm = [face.nrm[i] for i in [0, 1, 2]],
)
else:
ret.__dict__.update(
pos = [face.pos[i] for i in [0, 2, 1]],
tex = [face.tex[i] for i in [0, 2, 1]],
nrm = [face.nrm[i] for i in [0, 2, 1]],
)
return ret
N = 64
scene = t3.Scene()
mesh = t3.DynamicMesh(n_faces=N, n_pos=N + 1)
model = t3.Model(MeshNoCulling(mesh)) # here
scene.add_model(model)
camera = t3.Camera()
scene.add_camera(camera)
light = t3.AmbientLight(1.0)
scene.add_light(light)
@ti.materialize_callback
@ti.kernel
def init_mesh():
mesh.nrm[0] = [0, 0, 1]
mesh.pos[N] = [0, 0, 0]
for i in range(N):
a = i / N * t3.tau
mesh.pos[i] = [ti.sin(a), ti.cos(a), 0]
mesh.faces[i] = [[i, 0, 0], [(i + 1) % N, 0, 0], [N, 0, 0]]
gui = ti.GUI('Dynamic', camera.res)
while gui.running:
gui.get_event(None)
camera.from_mouse(gui)
mesh.n_faces[None] = gui.frame % N
scene.render()
gui.set_image(camera.img)
gui.show()
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello!
What should I do if I also want to keep the back face of a dynamic triangle?
https://github.com/taichi-dev/taichi_three/blob/master/examples/simple_triangle.py
The text was updated successfully, but these errors were encountered: