diff --git a/Assets/Map/LocationGenerator.cs b/Assets/Map/LocationGenerator.cs index 9e99c33..172575a 100644 --- a/Assets/Map/LocationGenerator.cs +++ b/Assets/Map/LocationGenerator.cs @@ -80,7 +80,7 @@ namespace Assets.Map var center = location.Center; var left = location.BoundaryEdges; - location.BoundaryEdges = new List<(int, int)>() { left[0] }; + location.BoundaryEdges = new List<(int, int)>() { EnsureClockwise(center, left[0]) }; (int, int) last = location.BoundaryEdges[0]; left.RemoveAt(0); diff --git a/Assets/SampleScenes/Navmesh/CarAI.asset b/Assets/SampleScenes/Navmesh/CarAI.asset index f38f925..a5a33a7 100644 Binary files a/Assets/SampleScenes/Navmesh/CarAI.asset and b/Assets/SampleScenes/Navmesh/CarAI.asset differ diff --git a/Assets/SampleScenes/Scenes/CharacterThirdPersonAI/NavMesh.asset b/Assets/SampleScenes/Scenes/CharacterThirdPersonAI/NavMesh.asset index 90f4702..88ad909 100644 Binary files a/Assets/SampleScenes/Scenes/CharacterThirdPersonAI/NavMesh.asset and b/Assets/SampleScenes/Scenes/CharacterThirdPersonAI/NavMesh.asset differ diff --git a/Assets/Scripts/MapRenderer.cs b/Assets/Scripts/MapRenderer.cs index 456809d..4cc8db3 100644 --- a/Assets/Scripts/MapRenderer.cs +++ b/Assets/Scripts/MapRenderer.cs @@ -14,6 +14,7 @@ namespace Assets public float uvScale = 1.0f; private List _vertices; + private List _uv; private List _normals; private List _triangles; @@ -28,6 +29,7 @@ namespace Assets _vertices = new List(); _normals = new List(); + _uv = new List(); _triangles = new List(); foreach (var location in graph.LocationGenerator.Result.Vertices.Skip(1)) @@ -38,7 +40,7 @@ namespace Assets Mesh mesh = new Mesh(); mesh.vertices = _vertices.ToArray(); - mesh.uv = _vertices.Select(v => new Vector2(v.x, v.z) / uvScale).ToArray(); + mesh.uv = _uv.ToArray(); mesh.normals = _normals.ToArray(); mesh.triangles = _triangles.ToArray(); @@ -53,8 +55,11 @@ namespace Assets foreach (var vertex in vertices) { - _vertices.Add(PointToVector(location, vertex)); + var v = PointToVector(location, vertex); + + _vertices.Add(v); _normals.Add(Vector3.up); + _uv.Add(new Vector2(v.x, v.z) / uvScale); } int end = _vertices.Count; @@ -73,13 +78,19 @@ namespace Assets private void GenerateLocationWall(Location location, IList points) { + var length = 0.0; + foreach (var (a, b) in location.BoundaryEdges.Select(x => (points[x.Item1], points[x.Item2]))) { int start = _vertices.Count; + var dist = Point.Dist(a, b); + + var veca = PointToVector(location, a); + var vecb = PointToVector(location, b); - _vertices.Add(PointToVector(location, a)); - _vertices.Add(PointToVector(location, b)); + _vertices.Add(veca); _vertices.Add(new Vector3((float)a.x, -10,(float)a.y)); + _vertices.Add(vecb); _vertices.Add(new Vector3((float)b.x, -10,(float)b.y)); _normals.Add(Vector3.up); @@ -89,9 +100,19 @@ namespace Assets _triangles.AddRange(new [] { - start, start + 1, start + 2, - start + 1, start + 3, start + 2 + start, start + 2, start + 1, + start + 1, start + 2, start + 3 }); + + _uv.AddRange(new [] + { + new Vector2((float)length, veca.y) / uvScale, + new Vector2((float)length, -10) / uvScale, + new Vector2((float)(length + dist), vecb.y) / uvScale, + new Vector2((float)(length + dist), -10) / uvScale, + }); + + length += dist; } } }