Taichi field整体赋值


之前用过几次GGUI,刚想整个多米诺骨牌的模拟,在前瞻探路时想给vertices和indices整体赋值,但尝试方圆括号后好像都不行,在scene.mesh函数各种报错。网上走了一圈都是像我之前那样逐个赋值,python的传统赋值方式好像也不行,想问问是该怎么写来着?
(个人主C++,对python的了解与实操仅限taichi,望轻喷)

import taichi as ti
ti.init(ti.gpu)

vertices = ti.Vector.field(3, dtype = float, shape = 8)
vertices_offset = ti.Vector.field(3, dtype = float, shape = 8)
indices = ti.field(ti.i32, shape = 36)

vertices = ((-0.1,-0.1,-0.1),(-0.1,-0.1,0.1),(0.1,-0.1,0.1),(0.1,-0.1,-0.1),(-0.1,0.1,-0.1),(-0.1,0.1,0.1),(0.1,0.1,0.1),(0.1,0.1,-0.1))
#vertices[0] = (-0.1,-0.1,-0.1)
#vertices[1] = (-0.1,-0.1,0.1)
#vertices[2] = (0.1,-0.1,0.1)
#vertices[3] = (0.1,-0.1,-0.1)
#vertices[4] = (-0.1,0.1,-0.1)
#vertices[5] = (-0.1,0.1,0.1)
#vertices[6] = (0.1,0.1,0.1)
#vertices[7] = (0.1,0.1,-0.1)

indices = (0, 1, 2, 0, 2, 3, 0, 1, 4, 1, 4, 5, 1, 2, 5, 2, 5, 6, 2, 3, 6, 3, 6, 7, 0, 3, 4, 3, 4, 7, 4, 5, 7, 5, 6, 7)
#indices[0] = 0
#indices[1] = 1
#indices[2] = 2
#indices[3] = 0
#indices[4] = 2
#indices[5] = 3
#indices[6] = 0
#indices[7] = 1
#indices[8] = 4
#indices[9] = 1
#indices[10] = 4
#indices[11] = 5
#indices[12] = 1
#indices[13] = 2
#indices[14] = 5
#indices[15] = 2
#indices[16] = 5
#indices[17] = 6
#indices[18] = 2
#indices[19] = 3
#indices[20] = 6
#indices[21] = 3
#indices[22] = 6
#indices[23] = 7
#indices[24] = 0
#indices[25] = 3
#indices[26] = 4
#indices[27] = 3
#indices[28] = 4
#indices[29] = 7
#indices[30] = 4
#indices[31] = 5
#indices[32] = 7
#indices[33] = 5
#indices[34] = 6
#indices[35] = 7

window = ti.ui.Window("", (1024, 1024), vsync = True)
canvas = window.get_canvas()
canvas.set_background_color((0, 0, 0))
scene = ti.ui.Scene()
camera = ti.ui.make_camera()
camera.position(0, 3, -3)
camera.lookat(0, 0, 0)
scene.set_camera(camera)

while window.running:
    scene.point_light(pos = (0, 1, 2), color = (1, 1, 1))
    scene.mesh(vertices, indices = indices, color = (0.46, 0.84, 0.92), two_sided = True)
    canvas.scene(scene)
    window.show()

可以考虑用 .fill() 函数给整个slice填充数值。

fill函数之前了解到的是给一定区域赋上一个定值,刚刚在py上试了下只接受两个输入,查手册也没查到。我贴了下代码,能再麻烦写下那两个field的自定义赋值吗?

vertices_np = np.array(((-0.1,-0.1,-0.1),(-0.1,-0.1,0.1),(0.1,-0.1,0.1),(0.1,-0.1,-0.1),(-0.1,0.1,-0.1),(-0.1,0.1,0.1),)(0.1,0.1,0.1),(0.1,0.1,-0.1))
vertices.from_numpy(vertices_np)