feat: sort face vertices before tessellation

This commit is contained in:
s3lph 2024-12-19 18:27:31 +01:00
parent 6398b4f987
commit 016e5a2949
Signed by: s3lph
GPG key ID: 0AA29A52FB33CFB5

7
map.py
View file

@ -73,8 +73,11 @@ class Face:
def __init__(self, vs): def __init__(self, vs):
self.vertices = vs self.vertices = vs
self.tris = [] self.tris = []
for i in range(1, len(vs)-1): # Sort vertices so that so that the normal points "outward"
self.tris.append(Triangle(vs[0], vs[i], vs[i+1])) 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] self.plane_coords = [self.tris[0].plane_coords(v) for v in self.vertices]