generated from taichi-dev/voxel-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main2.py
28 lines (22 loc) · 905 Bytes
/
main2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import cv2
from scene import Scene
import taichi as ti
from taichi.math import *
scene = Scene(voxel_edges=0)
scene.set_floor(-0.77, (1.0, 1.0, 1.0))
scene.set_background_color((0.5, 0.5, 0.4))
scene.set_directional_light((-1, 1, -1), 0.2, (1, 0.8, 0.6))
image = cv2.imread("pic/1.png")
image = cv2.resize(image, (100, 100))
pixel = ti.Vector.field(3, ti.f32, shape=(100, 100))
pixel.from_numpy(image)
@ti.kernel
def initialize_voxels():
for i, j in ti.ndrange(100, 100):
bgr = pixel[i, j]
scene.set_voxel(vec3(j - 50, 50 - i, 50), 1, vec3(bgr[2] / 255, bgr[1] / 255, bgr[0] / 255)) # 前
scene.set_voxel(vec3(50, 50 - i, 50 - j), 1, vec3(bgr[2] / 255, bgr[1] / 255, bgr[0] / 255)) # 右
scene.set_voxel(vec3(j - 50, 50, i - 50), 1, vec3(bgr[2] / 255, bgr[1] / 255, bgr[0] / 255)) # 上
if __name__ == "__main__":
initialize_voxels()
scene.finish()