from vectors import Vector2d, Vector3d, Vector4d from matrix import Matrix3x3 from triangle import Triangle class Engine: def __init__(self, width, height): self._width = width self._height = height @property def width(self): return self._width @width.setter def width(self, width): raise ValueError("Not allowed") class Mesh: def __init__(self): self.triangles = [] self.vertices = [] def load_obj_file(self, path): lines = [] with open(path, 'r') as reader: lines = reader.readlines() for line in lines: if line[0] == 'v': tmp = line.split(' ') x = float(tmp[1]) y = float(tmp[2]) z = float(tmp[3]) self.vertices.append(Vector3d(x, y, z)) if line[0] == 'f': tmp = line.split(' ') # 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] self.triangles.append(Triangle(Matrix3x3(row1, row2, row3))) def __getitem__(self, key): return self.triangles[key] def __len__(self): return len(self.triangles)