From 016e5a29492cfc48cc081976be1669ddb944b5fa Mon Sep 17 00:00:00 2001 From: s3lph Date: Thu, 19 Dec 2024 18:27:31 +0100 Subject: [PATCH] feat: sort face vertices before tessellation --- map.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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]