-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
28 lines (24 loc) · 827 Bytes
/
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
import numpy as np
import os
vertices = []
polygons = []
def round_number(string_number):
if "\n" in string_number:
string_number = string_number.replace("\n", "")
if "." in string_number:
parts = string_number.split(".")
if len(parts[1]) > 5:
return parts[0] + "." + parts[1][:5]
return string_number
with open('car.obj') as f:
for line in f:
if line.startswith('v '):
vertex = list(map(round_number, line[2:].split()))
vertices.append(vertex)
elif line.startswith('f '):
indices = line[2:].split()
polygon = np.array([int(index.split('/')[0])-1 for index in indices])
polygons.append(polygon)
for polygon in polygons:
with open('data.txt', 'a') as file:
file.write(str(polygon))