Skip to content

Commit

Permalink
[test] [gui] Add a test of the display of wireframe mode (taichi-dev#…
Browse files Browse the repository at this point in the history
…5967)

* Add a test of drawing mesh instances

* Revert "Add a test of drawing mesh instances"

This reverts commit b443eb0.

* Add a test of display of wireframe mode

* merge

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove unused line

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Morcki and pre-commit-ci[bot] authored Sep 3, 2022
1 parent 40decbc commit c8cf57b
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
Binary file added tests/python/expected/test_wireframe_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions tests/python/test_ggui.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,3 +843,92 @@ def render():
verify_image(window.get_image_buffer_as_numpy(),
'test_draw_part_of_mesh_instances')
window.destroy()


@pytest.mark.skipif(not _ti_core.GGUI_AVAILABLE, reason="GGUI Not Available")
@test_utils.test(arch=supported_archs)
def test_wireframe_mode():
N = 10
NV = (N + 1)**2
NT = 2 * N**2
NE = 2 * N * (N + 1) + N**2
pos = ti.Vector.field(3, ti.f32, shape=NV)
tri = ti.field(ti.i32, shape=3 * NT)
edge = ti.Vector.field(2, ti.i32, shape=NE)

@ti.kernel
def init_pos():
for i, j in ti.ndrange(N + 1, N + 1):
idx = i * (N + 1) + j
pos[idx] = ti.Vector([i / N, 1.0 - j / N, 0.5])

@ti.kernel
def init_tri():
for i, j in ti.ndrange(N, N):
tri_idx = 6 * (i * N + j)
pos_idx = i * (N + 1) + j
if (i + j) % 2 == 0:
tri[tri_idx + 0] = pos_idx
tri[tri_idx + 1] = pos_idx + N + 2
tri[tri_idx + 2] = pos_idx + 1
tri[tri_idx + 3] = pos_idx
tri[tri_idx + 4] = pos_idx + N + 1
tri[tri_idx + 5] = pos_idx + N + 2
else:
tri[tri_idx + 0] = pos_idx
tri[tri_idx + 1] = pos_idx + N + 1
tri[tri_idx + 2] = pos_idx + 1
tri[tri_idx + 3] = pos_idx + 1
tri[tri_idx + 4] = pos_idx + N + 1
tri[tri_idx + 5] = pos_idx + N + 2

@ti.kernel
def init_edge():
for i, j in ti.ndrange(N + 1, N):
edge_idx = i * N + j
pos_idx = i * (N + 1) + j
edge[edge_idx] = ti.Vector([pos_idx, pos_idx + 1])
start = N * (N + 1)
for i, j in ti.ndrange(N, N + 1):
edge_idx = start + j * N + i
pos_idx = i * (N + 1) + j
edge[edge_idx] = ti.Vector([pos_idx, pos_idx + N + 1])
start = 2 * N * (N + 1)
for i, j in ti.ndrange(N, N):
edge_idx = start + i * N + j
pos_idx = i * (N + 1) + j
if (i + j) % 2 == 0:
edge[edge_idx] = ti.Vector([pos_idx, pos_idx + N + 2])
else:
edge[edge_idx] = ti.Vector([pos_idx + 1, pos_idx + N + 1])

init_pos()
init_tri()
init_edge()

window = ti.ui.Window("test", (1024, 1024), vsync=True, show_window=False)
canvas = window.get_canvas()
scene = ti.ui.Scene()
camera = ti.ui.make_camera()
camera.position(1.5, 1, -1)
camera.lookat(1, 0.5, 0)
camera.fov(90)

def render():
scene.set_camera(camera)
scene.point_light(pos=(0.5, 1, 2), color=(1, 1, 1))

scene.mesh(pos,
tri,
color=(39 / 255, 123 / 255, 192 / 255),
two_sided=True,
show_wireframe=True)
canvas.scene(scene)

for _ in range(RENDER_REPEAT):
render()
window.get_image_buffer_as_numpy()

render()
verify_image(window.get_image_buffer_as_numpy(), 'test_wireframe_mode')
window.destroy()

0 comments on commit c8cf57b

Please sign in to comment.