mirror of
https://github.com/appen-isen/jeu-sans-image.git
synced 2026-01-18 16:47:37 +01:00
Fix: reversed floor mesh
Fixed the bug where the floor appeared only seen from below sometimes. (To be more precise, it appeared when the SVG geometry was counter-clockwise)
This commit is contained in:
@@ -295,11 +295,23 @@ public class SvgToFlatMeshEditor : EditorWindow
|
||||
|
||||
// Add indices (triangles)
|
||||
for (int i = 0; i < g.Indices.Length; i += 3) {
|
||||
// VectorUtils yields triangles in clockwise winding
|
||||
// Unity is supposed to use clockwise as well, but in practice we find we need to flip the order to get correct facing.
|
||||
indices.Add(baseIndex + g.Indices[i + 1]);
|
||||
indices.Add(baseIndex + g.Indices[i]);
|
||||
indices.Add(baseIndex + g.Indices[i + 2]);
|
||||
int i1 = baseIndex + g.Indices[i];
|
||||
int i2 = baseIndex + g.Indices[i + 1];
|
||||
int i3 = baseIndex + g.Indices[i + 2];
|
||||
if (!IsClockwise( g.Vertices[i1], g.Vertices[i2], g.Vertices[i3] ))
|
||||
{
|
||||
// Add triangle with reversed winding
|
||||
indices.Add(i1);
|
||||
indices.Add(i3);
|
||||
indices.Add(i2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add triangle with correct winding
|
||||
indices.Add(i3);
|
||||
indices.Add(i1);
|
||||
indices.Add(i2);
|
||||
}
|
||||
}
|
||||
|
||||
baseIndex += g.Vertices.Length;
|
||||
@@ -317,6 +329,12 @@ public class SvgToFlatMeshEditor : EditorWindow
|
||||
return mesh;
|
||||
}
|
||||
|
||||
// Helper to determine if 3 points are in clockwise order
|
||||
bool IsClockwise(Vector2 a, Vector2 b, Vector2 c)
|
||||
{
|
||||
return (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
|
||||
}
|
||||
|
||||
// Build an extruded Mesh from geometries
|
||||
Mesh BuildExtrudedMeshFromBeziers(List<BezierPathSegment[]> beziers, Vector2 geomsCenter, float globalScale, float height){
|
||||
// Forget about UVs (unnecessary for our use case)
|
||||
|
||||
Reference in New Issue
Block a user