Cleaned up the engine and added support for CSV file parsing.

This commit is contained in:
2020-12-04 00:15:18 -06:00
parent e39eb39d2c
commit 51c5ac335a
2 changed files with 97 additions and 13 deletions
+26 -4
View File
@@ -36,14 +36,36 @@ class Mesh:
if line[0] == 'f':
tmp = line.split(' ')
x = tmp[1].split('//')[0]
y = tmp[2].split('//')[0]
z = tmp[3].split('//')[0]
# Subtract one because the obj file isn't zero indexed.
row1 = self.vertices[int(tmp[1]) - 1]
row2 = self.vertices[int(tmp[2]) - 1]
row3 = self.vertices[int(tmp[3]) - 1]
row1 = self.vertices[int(x) - 1]
row2 = self.vertices[int(y) - 1]
row3 = self.vertices[int(z) - 1]
self.triangles.append(Triangle(Matrix3x3(row1, row2, row3)))
def load_csv(self, path):
values = []
x = 0
y = -2
with open(path, 'r') as reader:
values = reader.readlines()
for i in range(0, 60, 3):
tmp = values[i].split(',')
row1 = Vector3d(x, y, float(tmp[6]))
tmp = values[i + 1].split(',')
row2 = Vector3d(x + 0.5, y, float(tmp[6]))
tmp = values[i + 2].split(',')
row3 = Vector3d(x, y + 0.5, float(tmp[6]))
self.triangles.append(Triangle(Matrix3x3(row1, row2, row3)))
self.triangles.append(Triangle(Matrix3x3(row2, row3, Vector3d(x + 0.5, y + 0.5, float(tmp[6])))))#, row2, row3)))
x += 0.5
#y -= 0.5
def __getitem__(self, key):
return self.triangles[key]