-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjects3d.py
56 lines (43 loc) · 1.72 KB
/
objects3d.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
'''
Universidad del Valle de Guatemala
Gráficas por computadora
Christopher García 20541
2do. ciclo 2022
'''
import re
class Obj(object):
def __init__(self, filename):
with open(filename) as f:
self.lines = f.read().splitlines()
self.vertices = []
self.tvertices = []
self.nvertices = []
self.caras = []
for line in self.lines:
if (not line):
continue
if (line.find("object") != -1 or line.find("#") != -1):
continue
prefix, value = line.split(' ', 1)
if (prefix == 'v'):
temp = []
list(map(lambda x: temp.append(float(x))
if (x != '') else False, value.split(' ')))
self.vertices.append(temp)
if (prefix == 'vt'):
temp = []
list(map(lambda x: temp.append(float(x))
if (x != '') else False, value.split(' ')))
if (len(temp) == 2):
temp.append(0.0000)
self.tvertices.append(temp)
if (prefix == 'vn'):
temp = []
list(map(lambda x: temp.append(float(x))
if (x != '') else False, value.split(' ')))
self.nvertices.append(temp)
if (prefix == 'f'):
self.caras.append([
list(map(lambda x: int(x) if (x != '')
else False, re.split('/+',face))) for face in value.split(' ')
])