-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mesh.py
34 lines (29 loc) · 1.01 KB
/
Mesh.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
from triangle import Triangle
from vec3d import Vec3d
class Mesh:
tris: list[Triangle]
def __init__(self, tris: list[Triangle] = None):
if tris is not None:
self.tris: list[Triangle] = tris
else:
self.tris = []
def LoadFromObjectFile(self, filename: str):
verts = []
with open(filename, "r") as f:
while True:
line = f.readline()
if not line:
break
if line[0] == "v":
x, y, z = line[2:].split(" ")
verts.append(Vec3d(float(x), float(y), float(z)))
elif line[0] == "f":
p1, p2, p3 = line[2:].split(" ")
self.tris.append(
Triangle(
verts[int(p1) - 1],
verts[int(p2) - 1],
verts[int(p3) - 1],
(0, 0, 0),
)
)