-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSceneData.py
214 lines (166 loc) · 6.51 KB
/
SceneData.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import taichi as ti
import numpy as np
########################### Important !!!! ###############################
#struct description
#material : type_f aleboTex_f color_v3 param_v5 10
# 0 disney metallic_f roughness_f
# 1 glass ior extinction
# 2 light
# 10 spectral
#shape : type_f pos_v3 param_v6 10
# 1 sphere radius
# 2 quad v1 v2
# 3 spot x1 x2 scale normal
# 4 laser radius X X normal
#vertex : pos_v3 normal_v3 tex_v3 9
#primitive : type(0:tri 1:shape) vertexIndex(shape_index) matIndex 3
# 32bit | 32bit | 32bit | 32bit | 32bit |96bit |96bit
#bvh_node : is_leaf axis |left_node right_node parent_node prim_index min_v3 max_v3 11
# 1bit 2bit
# 32bit |32bit |32bit |96bit |96bit
#compact_node : is_leaf axis |prim_index offset min_v3 max_v3 9
# 1bit 2bit
########################### Important !!!! ###############################
MAT_VEC_SIZE = 10
VER_VEC_SIZE = 9
PRI_VEC_SIZE = 3
SHA_VEC_SIZE = 10
NOD_VEC_SIZE = 11
CPNOD_VEC_SIZE = 9
SHPAE_NONE = 0
SHPAE_SPHERE = 1
SHPAE_QUAD = 2
SHPAE_SPOT = 3
SHPAE_LASER = 4
PRIMITIVE_NONE = 0
PRIMITIVE_TRI = 1
PRIMITIVE_SHAPE = 2
MAT_DISNEY = 0.0
MAT_GLASS = 1.0
MAT_LIGHT = 2.0
MAT_SPECTRAL = 10.0
IS_LEAF = 1
class Material:
def __init__(self):
self.type = 0
self.alebdoTex = 0
self.color = [0.0, 0.0, 0.0]
self.param = [0.0, 0.0, 0.0, 0.0, 0.0]
def setColor(self, color):
self.color = color
def setMetal(self, metal):
self.param[0] = metal
def setRough(self, rough):
self.param[1] = rough
def setIor(self, ior):
self.param[0] = ior
def setExtinciton(self, extinction):
self.param[1] = extinction
def fillStruct(self, np_data, index):
np_data[index, 0] = float(self.type)
np_data[index, 1] = float(self.alebdoTex)
np_data[index, 2] = self.color[0]
np_data[index, 3] = self.color[1]
np_data[index, 4] = self.color[2]
for i in range(5, MAT_VEC_SIZE):
np_data[index, i] = self.param[i-5]
class Shape:
def __init__(self):
self.type = 0
self.pos = [0.0, 0.0, 0.0]
self.param = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
def setRadius(self, radius):
self.param[0] = radius
def setXita(self, xita1, xita2):
self.param[0] = xita1
self.param[1] = xita2
def setScale(self, scale):
self.param[2] = scale
def setV1(self, V1):
self.param[0] = V1[0]
self.param[1] = V1[1]
self.param[2] = V1[2]
def setV2(self, V2):
self.param[3] = V2[0]
self.param[4] = V2[1]
self.param[5] = V2[2]
def setNormal(self, normal):
self.param[3] = normal[0]
self.param[4] = normal[1]
self.param[5] = normal[2]
def getRadius(self):
return self.param[0]
def fillStruct(self, np_data, index):
np_data[index, 0] = float(self.type)
np_data[index, 1] = self.pos[0]
np_data[index, 2] = self.pos[1]
np_data[index, 3] = self.pos[2]
for i in range(4, VER_VEC_SIZE+1):
np_data[index, i] = self.param[i-4]
class Vertex:
def __init__(self):
self.pos = [0.0, 0.0, 0.0]
self.normal = [0.0, 0.0, 0.0]
self.tex = [0.0, 0.0, 0.0]
def setPos(self, buf, offset):
self.pos[0] = buf[offset +0 ]
self.pos[1] = buf[offset +1 ]
self.pos[2] = buf[offset +2 ]
def setNormal(self, buf, offset):
self.normal[0] = buf[offset +0 ]
self.normal[1] = buf[offset +1 ]
self.normal[2] = buf[offset +2 ]
def setTex(self, buf, offset):
self.tex[0] = buf[offset +0 ]
self.tex[1] = buf[offset +1 ]
self.tex[2] = 0.0
def setTex3(self, buf, offset):
self.tex[0] = buf[offset +0 ]
self.tex[1] = buf[offset +1 ]
self.tex[2] = buf[offset +2 ]
def fillStruct(self, np_data, index):
for i in range(0, 3):
np_data[index, i+0] = self.pos[i]
np_data[index, i+3] = self.normal[i]
np_data[index, i+6] = self.tex[i]
class Primitive:
def __init__(self):
self.type = 0
self.vertex_shape_index = 0
self.mat_index = 0
def fillStruct(self, np_data, index):
np_data[index, 0] = self.type
np_data[index, 1] = self.vertex_shape_index
np_data[index, 2] = self.mat_index
# 32bit | 32bit | 32bit | 32bit | 32bit |96bit |96bit
#bvh_node : is_leaf axis prim_size |left_node right_node parent_node prim_index min_v3 max_v3 11
# 1bit 2bit 29 bit
# 32bit |32bit |96bit |96bit
#compact_node : is_leaf axis prim_size |prim_index /offset min_v3 max_v3 8
# 1bit 2bit 29 bit
class Bounds:
def __init__(self):
self.min_v3 = [np.Infinity,np.Infinity,np.Infinity]
self.max_v3 = [-np.Infinity,-np.Infinity,-np.Infinity]
def Merge(self, v):
for k in range(3):
self.min_v3[k] = min(self.min_v3[k], v[k])
self.max_v3[k] = max(self.max_v3[k], v[k])
def MergeBox(self, b):
self.Merge(b.min_v3)
self.Merge(b.max_v3)
def GetSurfaceArea(self):
e1 = self.max_v3[0] - self.min_v3[0]
e2 = self.max_v3[1] - self.min_v3[1]
e3 = self.max_v3[2] - self.min_v3[2]
return 2.0*(e1*e2+e2*e3+e3*e1)
class BVHNode:
def __init__(self):
self.is_leaf = 0
self.axis = 0
self.left_node = 0
self.right_node = 0
self.parent_node = 0
self.prim_index = 0
self.min_v3 = [np.Infinity,np.Infinity,np.Infinity]
self.max_v3 = [-np.Infinity,-np.Infinity,-np.Infinity]