-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.py
More file actions
72 lines (56 loc) · 1.58 KB
/
Utility.py
File metadata and controls
72 lines (56 loc) · 1.58 KB
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
from Vertex import Vertex
from Triangle import Triangle
from UV import UV
import numba.typed
class Utility:
def __init__(self, filename):
self.vertex_data = []
self.uv_data = []
self.face_data = []
self.filename = filename
self.triangle_data = numba.typed.List()
for line in open(filename, "r"):
if line.startswith('#'):
continue
values = line.split()
if not values:
continue
if values[0] == 'v':
self.vertex_data.append(Vertex(
float(values[1]), float(values[2]), float(values[3]), 1
))
elif values[0] == 'vt':
self.uv_data.append(UV(
float(values[1]), float(values[2])
))
elif values[0] == 'f':
faces = []
uv_data = []
for v in values[1:]:
w = v.split('/')
faces.append(int(w[0]))
if len(w) >= 2 and len(w[1]) > 0:
uv_data.append(int(w[1]))
else:
uv_data.append(0)
self.face_data.append((faces, uv_data))
def build_triangle_data(self):
for face in self.face_data:
self.triangle_data.append(Triangle(
self.vertex_data[face[0][0] - 1],
self.vertex_data[face[0][1] - 1],
self.vertex_data[face[0][2] - 1],
self.uv_data[face[1][0] - 1],
self.uv_data[face[1][1] - 1],
self.uv_data[face[1][2] - 1]
))
if len(face[0]) > 3:
self.triangle_data.append(Triangle(
self.vertex_data[face[0][0] - 1],
self.vertex_data[face[0][2] - 1],
self.vertex_data[face[0][3] - 1],
self.uv_data[face[1][0] - 1],
self.uv_data[face[1][2] - 1],
self.uv_data[face[1][3] - 1]
))
print("Successfully Built Triangle Data For:", self.filename)