diff --git a/map.py b/map.py index 904bbc8..094b42b 100644 --- a/map.py +++ b/map.py @@ -73,8 +73,11 @@ class Face: def __init__(self, vs): self.vertices = vs self.tris = [] - for i in range(1, len(vs)-1): - self.tris.append(Triangle(vs[0], vs[i], vs[i+1])) + # Sort vertices so that so that the normal points "outward" + if np.dot(self.vertices[0], np.cross(self.vertices[1] - self.vertices[0], self.vertices[2] - self.vertices[0])) < 0: + self.vertices = self.vertices[::-1] + for i in range(1, len(self.vertices)-1): + self.tris.append(Triangle(self.vertices[0], self.vertices[i], self.vertices[i+1])) self.plane_coords = [self.tris[0].plane_coords(v) for v in self.vertices]