Better UVs for map
This commit is contained in:
parent
d860f2f53f
commit
5f56d8e84a
@ -80,7 +80,7 @@ namespace Assets.Map
|
|||||||
var center = location.Center;
|
var center = location.Center;
|
||||||
var left = location.BoundaryEdges;
|
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];
|
(int, int) last = location.BoundaryEdges[0];
|
||||||
left.RemoveAt(0);
|
left.RemoveAt(0);
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -14,6 +14,7 @@ namespace Assets
|
|||||||
public float uvScale = 1.0f;
|
public float uvScale = 1.0f;
|
||||||
|
|
||||||
private List<Vector3> _vertices;
|
private List<Vector3> _vertices;
|
||||||
|
private List<Vector2> _uv;
|
||||||
private List<Vector3> _normals;
|
private List<Vector3> _normals;
|
||||||
private List<int> _triangles;
|
private List<int> _triangles;
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ namespace Assets
|
|||||||
|
|
||||||
_vertices = new List<Vector3>();
|
_vertices = new List<Vector3>();
|
||||||
_normals = new List<Vector3>();
|
_normals = new List<Vector3>();
|
||||||
|
_uv = new List<Vector2>();
|
||||||
_triangles = new List<int>();
|
_triangles = new List<int>();
|
||||||
|
|
||||||
foreach (var location in graph.LocationGenerator.Result.Vertices.Skip(1))
|
foreach (var location in graph.LocationGenerator.Result.Vertices.Skip(1))
|
||||||
@ -38,7 +40,7 @@ namespace Assets
|
|||||||
|
|
||||||
Mesh mesh = new Mesh();
|
Mesh mesh = new Mesh();
|
||||||
mesh.vertices = _vertices.ToArray();
|
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.normals = _normals.ToArray();
|
||||||
mesh.triangles = _triangles.ToArray();
|
mesh.triangles = _triangles.ToArray();
|
||||||
|
|
||||||
@ -53,8 +55,11 @@ namespace Assets
|
|||||||
|
|
||||||
foreach (var vertex in vertices)
|
foreach (var vertex in vertices)
|
||||||
{
|
{
|
||||||
_vertices.Add(PointToVector(location, vertex));
|
var v = PointToVector(location, vertex);
|
||||||
|
|
||||||
|
_vertices.Add(v);
|
||||||
_normals.Add(Vector3.up);
|
_normals.Add(Vector3.up);
|
||||||
|
_uv.Add(new Vector2(v.x, v.z) / uvScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
int end = _vertices.Count;
|
int end = _vertices.Count;
|
||||||
@ -73,13 +78,19 @@ namespace Assets
|
|||||||
|
|
||||||
private void GenerateLocationWall(Location location, IList<Point> points)
|
private void GenerateLocationWall(Location location, IList<Point> points)
|
||||||
{
|
{
|
||||||
|
var length = 0.0;
|
||||||
|
|
||||||
foreach (var (a, b) in location.BoundaryEdges.Select(x => (points[x.Item1], points[x.Item2])))
|
foreach (var (a, b) in location.BoundaryEdges.Select(x => (points[x.Item1], points[x.Item2])))
|
||||||
{
|
{
|
||||||
int start = _vertices.Count;
|
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(veca);
|
||||||
_vertices.Add(PointToVector(location, b));
|
|
||||||
_vertices.Add(new Vector3((float)a.x, -10,(float)a.y));
|
_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));
|
_vertices.Add(new Vector3((float)b.x, -10,(float)b.y));
|
||||||
|
|
||||||
_normals.Add(Vector3.up);
|
_normals.Add(Vector3.up);
|
||||||
@ -89,9 +100,19 @@ namespace Assets
|
|||||||
|
|
||||||
_triangles.AddRange(new []
|
_triangles.AddRange(new []
|
||||||
{
|
{
|
||||||
start, start + 1, start + 2,
|
start, start + 2, start + 1,
|
||||||
start + 1, start + 3, start + 2
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user