generated from taichi-dev/voxel-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
97 lines (90 loc) · 5.26 KB
/
main.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from scene import Scene
import taichi as ti
from taichi.math import *
scene = Scene(voxel_edges=0.05, exposure=0.3)
scene.set_floor(-63, (1.0,1.0,1.0))
scene.set_background_color((0.1, 0.1, 0.2)) # 天空颜色
scene.set_directional_light((1, 1, -1), 0.2, (0.8, 0.8, 1))
@ti.func
def create_revolute(pos, length, radii, color, dir):
for i in range(length):
radius = radii[0] + i / length * (radii[1] - radii[0])
for j, k in ti.ndrange((-radius, radius), (-radius, radius)):
if (j * j + k * k < radius * radius):
if dir == 1: scene.set_voxel(pos + vec3(i,j,k), 2, color)
elif dir == 2: scene.set_voxel(pos + vec3(j,i,k), 2, color)
else: scene.set_voxel(pos + vec3(j,k,i), 1, color)
@ti.func
def create_box(pos,size,color):
for i, j, k in ti.ndrange((0,size[0]),(0,size[1]),(0,size[2])):
scene.set_voxel(pos + vec3(i,j,k),2,color)
@ti.kernel
def initialize_voxels():
# mast
create_box(vec3(-55, -62, -18), vec3(1, 124, 1), vec3(0.3, 0.3, 0.3))
create_box(vec3(54, -62, -18), vec3(1, 124, 1), vec3(0.3, 0.3, 0.3))
create_box(vec3(-62, 8, -18), vec3(15, 1, 1), vec3(1,1,0.2))
create_box(vec3(-62, -9, -18), vec3(15, 1, 1), vec3(1,1,0.2))
create_box(vec3(47, 8, -18), vec3(15, 1, 1), vec3(1,1,0.2))
create_box(vec3(47, -9, -18), vec3(15, 1, 1), vec3(1,1,0.2))
create_box(vec3(-62, 61, -18), vec3(15, 1, 1), vec3(1,1,0.2))
create_box(vec3(-62, -62, -18), vec3(15, 1, 1), vec3(1,1,0.2))
create_box(vec3(47, 61, -18), vec3(15, 1, 1), vec3(1,1,0.2))
create_box(vec3(47, -62, -18), vec3(15, 1, 1), vec3(1,1,0.2))
create_box(vec3(-6, -29, -18), vec3(3, 1, 1), vec3(0.3, 0.3, 0.3))
create_box(vec3(4, -29, -18), vec3(3, 1, 1), vec3(0.3, 0.3, 0.3))
create_box(vec3(-30, 0, 0), vec3(60, 1, 1), vec3(0.3,0.3,0.3))
create_box(vec3(-30, 0, -4), vec3(1, 1, 9), vec3(1,1,0.2))
create_box(vec3(30, 0, -4), vec3(1, 1, 9), vec3(1,1,0.2))
create_box(vec3(-10, 0, -4), vec3(1, 1, 9), vec3(1,1,0.2))
create_box(vec3(10, 0, -4), vec3(1, 1, 9), vec3(1,1,0.2))
create_box(vec3(-55, 0, -18), vec3(110, 1, 1), vec3(0.2,0.2,0.2))
# solar array
create_box(vec3(-62, 10, -18), vec3(6, 50, 1), vec3(0.2, 0.2, 1))
create_box(vec3(-53, 10, -18), vec3(6, 50, 1), vec3(0.2, 0.2, 1))
create_box(vec3(-53, 10, -18), vec3(6, 50, 1), vec3(0.2, 0.2, 1))
create_box(vec3(-62, -60, -18), vec3(6, 50, 1), vec3(0.2, 0.2, 1))
create_box(vec3(-53, -60, -18), vec3(6, 50, 1), vec3(0.2, 0.2, 1))
create_box(vec3(56, 10, -18), vec3(6, 50, 1), vec3(0.2, 0.2, 1))
create_box(vec3(47, 10, -18), vec3(6, 50, 1), vec3(0.2, 0.2, 1))
create_box(vec3(56, -60, -18), vec3(6, 50, 1), vec3(0.2, 0.2, 1))
create_box(vec3(47, -60, -18), vec3(6, 50, 1), vec3(0.2, 0.2, 1))
create_box(vec3(-28, 0, -4), vec3(17, 1, 3), vec3(0.2, 0.2, 1))
create_box(vec3(-28, 0, 2), vec3(17, 1, 3), vec3(0.2, 0.2, 1))
create_box(vec3(12, 0, -4), vec3(17, 1, 3), vec3(0.2, 0.2, 1))
create_box(vec3(12, 0, 2), vec3(17, 1, 3), vec3(0.2, 0.2, 1))
create_box(vec3(-23, -32, -18), vec3(17, 7, 1), vec3(0.2, 0.2, 1))
create_box(vec3(7, -32, -18), vec3(17, 7, 1), vec3(0.2, 0.2, 1))
create_box(vec3(-14, 0, 54), vec3(29, 1, 5), vec3(0.2, 0.2, 1))
create_box(vec3(-14, 0, -58), vec3(29, 1, 5), vec3(0.2, 0.2, 1))
# section
create_revolute(vec3(-52, 0, -18),18,vec2(5,8),vec3(0.8,0.8,0.8),1)
create_revolute(vec3(-34, 0, -18),25,vec2(8,8),vec3(0.5, 0.5, 0.5),1)
create_revolute(vec3(-9, 0, -18),5,vec2(8,4),vec3(0.8,0.8,0.8),1)
create_revolute(vec3(-9, 0, -18),5,vec2(8,4),vec3(0.8,0.8,0.8),1)
create_revolute(vec3(-4, 0, -18),4,vec2(2,5),vec3(0.3, 0.3, 0.5),1)
create_revolute(vec3(0, 0, -18),4,vec2(5,2),vec3(0.3, 0.3, 0.5),1)
create_revolute(vec3(4, 0, -18),5,vec2(4,8),vec3(0.8, 0.8, 0.8),1)
create_revolute(vec3(9, 0, -18),13,vec2(8,8),vec3(0.5, 0.5, 0.5),1)
create_box(vec3(22, -6, -24), vec3(12, 12, 12), vec3(0.2, 0.2, 0.3))
create_revolute(vec3(34, 0, -18),18,vec2(8,5),vec3(0.8,0.8,0.8),1)
create_revolute(vec3(0, 0, -55),16,vec2(4,5),vec3(0.8,0.8,0.8),3)
create_revolute(vec3(0, 0, -39),6,vec2(4,2),vec3(0.8,0.8,0.8),3)
create_revolute(vec3(0, 0, -34),6,vec2(2,4),vec3(0.8,0.8,0.8),3)
create_revolute(vec3(0, 0, -29),6,vec2(4,4),vec3(0.5,0.5,0.5),3)
create_revolute(vec3(0, 0, -23),5,vec2(4,2),vec3(0.8,0.8,0.8),3)
create_revolute(vec3(0, 0, -13),5,vec2(2,4),vec3(0.8,0.8,0.8),3)
create_revolute(vec3(0, 0, -8),12,vec2(4,4),vec3(0.8,0.8,0.8),3)
create_revolute(vec3(0, 0, 4),25,vec2(6,6),vec3(0.8,0.8,0.8),3)
create_revolute(vec3(0, 0, 29),5,vec2(6,4),vec3(0.8,0.8,0.8),3)
create_revolute(vec3(0, 0, 34),5,vec2(3,5),vec3(0.5,0.5,0.5),3)
create_revolute(vec3(0, 0, 39),5,vec2(5,5),vec3(0.5,0.5,0.5),3)
create_revolute(vec3(0, 0, 44),5,vec2(5,3),vec3(0.5,0.5,0.5),3)
create_revolute(vec3(0, 0, 49),12,vec2(4,4),vec3(0.8,0.8,0.8),3)
create_revolute(vec3(0, -36, -18),16,vec2(5,5),vec3(0.8,0.8,0.8),2)
create_revolute(vec3(0, -20, -18),4,vec2(5,3),vec3(0.8,0.8,0.8),2)
create_revolute(vec3(0, -16, -18),4,vec2(3,5),vec3(0.8,0.8,0.8),2)
create_revolute(vec3(0, -12, -18),8,vec2(5,5),vec3(0.8,0.8,0.8),2)
create_revolute(vec3(0, -4, -18),4,vec2(5,3),vec3(0.8,0.8,0.8),2)
initialize_voxels()
scene.finish()