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)
|
// Add indices (triangles)
|
||||||
for (int i = 0; i < g.Indices.Length; i += 3) {
|
for (int i = 0; i < g.Indices.Length; i += 3) {
|
||||||
// VectorUtils yields triangles in clockwise winding
|
int i1 = baseIndex + g.Indices[i];
|
||||||
// Unity is supposed to use clockwise as well, but in practice we find we need to flip the order to get correct facing.
|
int i2 = baseIndex + g.Indices[i + 1];
|
||||||
indices.Add(baseIndex + g.Indices[i + 1]);
|
int i3 = baseIndex + g.Indices[i + 2];
|
||||||
indices.Add(baseIndex + g.Indices[i]);
|
if (!IsClockwise( g.Vertices[i1], g.Vertices[i2], g.Vertices[i3] ))
|
||||||
indices.Add(baseIndex + g.Indices[i + 2]);
|
{
|
||||||
|
// 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;
|
baseIndex += g.Vertices.Length;
|
||||||
@@ -317,6 +329,12 @@ public class SvgToFlatMeshEditor : EditorWindow
|
|||||||
return mesh;
|
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
|
// Build an extruded Mesh from geometries
|
||||||
Mesh BuildExtrudedMeshFromBeziers(List<BezierPathSegment[]> beziers, Vector2 geomsCenter, float globalScale, float height){
|
Mesh BuildExtrudedMeshFromBeziers(List<BezierPathSegment[]> beziers, Vector2 geomsCenter, float globalScale, float height){
|
||||||
// Forget about UVs (unnecessary for our use case)
|
// Forget about UVs (unnecessary for our use case)
|
||||||
|
|||||||
Reference in New Issue
Block a user