renderer do map
This commit is contained in:
parent
4361d2b3cd
commit
367f433639
@ -13,9 +13,9 @@ namespace Editor
|
|||||||
|
|
||||||
DrawDefaultInspector();
|
DrawDefaultInspector();
|
||||||
|
|
||||||
if (GUILayout.Button("Generate"))
|
if (GUILayout.Button("Render"))
|
||||||
{
|
{
|
||||||
// target.Generate();
|
target.Render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ MonoBehaviour:
|
|||||||
displayEdges: 0
|
displayEdges: 0
|
||||||
displayLocations: 0
|
displayLocations: 0
|
||||||
displayLocationCells: 0
|
displayLocationCells: 0
|
||||||
displayLocationEdges: 0
|
displayLocationEdges: 1
|
||||||
displayCities: 1
|
displayCities: 1
|
||||||
displayLocationPoints: 0
|
displayLocationPoints: 0
|
||||||
displayFieldBoundaries: 1
|
displayFieldBoundaries: 1
|
||||||
@ -183,7 +183,7 @@ MonoBehaviour:
|
|||||||
minimumNudgeDistance: 0.25
|
minimumNudgeDistance: 0.25
|
||||||
maximumNudgeDistance: 0.75
|
maximumNudgeDistance: 0.75
|
||||||
radius: 5
|
radius: 5
|
||||||
seed: 1686660096
|
seed: 1770256640
|
||||||
--- !u!4 &319467308
|
--- !u!4 &319467308
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -274,13 +274,13 @@ Transform:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 519420028}
|
m_GameObject: {fileID: 519420028}
|
||||||
m_LocalRotation: {x: 0.35355338, y: -0.35355338, z: 0.1464466, w: 0.8535535}
|
m_LocalRotation: {x: 0.5187663, y: -0.3166594, z: 0.21488002, w: 0.7644835}
|
||||||
m_LocalPosition: {x: 290.29, y: 43.7, z: 190.7}
|
m_LocalPosition: {x: 250, y: 98.4, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 45.000004, y: -45, z: 0}
|
m_LocalEulerAnglesHint: {x: 68.32, y: -45.000004, z: 0}
|
||||||
--- !u!1 &1831814988
|
--- !u!1 &1831814988
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -30,4 +30,13 @@ namespace Assets.Common
|
|||||||
return tail.Concat(head);
|
return tail.Concat(head);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class HasMetadataExtensions
|
||||||
|
{
|
||||||
|
|
||||||
|
public static bool HasProperty(this IHasMetadata subject, string name) => subject.Metadata.HasProperty(name);
|
||||||
|
public static bool HasProperty<T>(this IHasMetadata subject, string name) => subject.Metadata.HasProperty<T>(name);
|
||||||
|
public static void SetProperty<T>(this IHasMetadata subject, string name, T property) => subject.Metadata.SetProperty(name, property);
|
||||||
|
public static T GetProperty<T>(this IHasMetadata subject, string name) => subject.Metadata.GetProperty<T>(name);
|
||||||
|
}
|
||||||
}
|
}
|
7
Assets/Scripts/Common/IHasMetadata.cs
Normal file
7
Assets/Scripts/Common/IHasMetadata.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace Assets.Common
|
||||||
|
{
|
||||||
|
public interface IHasMetadata
|
||||||
|
{
|
||||||
|
Metadata Metadata { get; }
|
||||||
|
}
|
||||||
|
}
|
3
Assets/Scripts/Common/IHasMetadata.cs.meta
Normal file
3
Assets/Scripts/Common/IHasMetadata.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b1254b30c38e4b03ab2d571e411522f6
|
||||||
|
timeCreated: 1573931268
|
@ -4,7 +4,7 @@ using Assets.Voronoi;
|
|||||||
|
|
||||||
namespace Assets.Common
|
namespace Assets.Common
|
||||||
{
|
{
|
||||||
public class Location
|
public class Location : IHasMetadata
|
||||||
{
|
{
|
||||||
public List<MapSite> Sites = new List<MapSite>();
|
public List<MapSite> Sites = new List<MapSite>();
|
||||||
|
|
||||||
@ -34,5 +34,7 @@ namespace Assets.Common
|
|||||||
|
|
||||||
BoundaryEdges = a.Union(b).Except(a.Intersect(b)).ToList();
|
BoundaryEdges = a.Union(b).Except(a.Intersect(b)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Metadata Metadata { get; } = new Metadata();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ using UnityEngine;
|
|||||||
namespace Assets.Common
|
namespace Assets.Common
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class Map
|
public class Map : IHasMetadata
|
||||||
{
|
{
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Graph<MapSite> _sites = new Graph<MapSite>();
|
private Graph<MapSite> _sites = new Graph<MapSite>();
|
||||||
@ -28,7 +28,7 @@ namespace Assets.Common
|
|||||||
|
|
||||||
public Graph<Point> Boundaries { get; set; }
|
public Graph<Point> Boundaries { get; set; }
|
||||||
|
|
||||||
public readonly Metadata Metadata = new Metadata();
|
public Metadata Metadata { get; } = new Metadata();
|
||||||
|
|
||||||
public Map(int seed)
|
public Map(int seed)
|
||||||
{
|
{
|
||||||
|
@ -6,9 +6,9 @@ using System.Linq;
|
|||||||
namespace Assets.Common
|
namespace Assets.Common
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class MapSite
|
public class MapSite : IHasMetadata
|
||||||
{
|
{
|
||||||
public readonly Metadata Metadata = new Metadata();
|
public Metadata Metadata { get; } = new Metadata();
|
||||||
|
|
||||||
public MapSite(Point center, IEnumerable<int> boundary)
|
public MapSite(Point center, IEnumerable<int> boundary)
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,7 @@ namespace Assets
|
|||||||
public Graph<Point> BoundariesGraph => Map?.Boundaries;
|
public Graph<Point> BoundariesGraph => Map?.Boundaries;
|
||||||
public Graph<Location> LocationGraph => Map?.Metadata.GetProperty<Graph<Location>>(LandmassPass.MapLocationsProperty);
|
public Graph<Location> LocationGraph => Map?.Metadata.GetProperty<Graph<Location>>(LandmassPass.MapLocationsProperty);
|
||||||
|
|
||||||
public void Generate()
|
public void Generate(Action<Map> onDone)
|
||||||
{
|
{
|
||||||
GenerationThread?.Abort();
|
GenerationThread?.Abort();
|
||||||
GenerationThread = new Thread(() =>
|
GenerationThread = new Thread(() =>
|
||||||
@ -85,12 +85,18 @@ namespace Assets
|
|||||||
lock (GetType())
|
lock (GetType())
|
||||||
{
|
{
|
||||||
Map = result;
|
Map = result;
|
||||||
|
onDone(result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
GenerationThread.Start();
|
GenerationThread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Generate()
|
||||||
|
{
|
||||||
|
Generate(_ => { });
|
||||||
|
}
|
||||||
|
|
||||||
public void OnDisable()
|
public void OnDisable()
|
||||||
{
|
{
|
||||||
GenerationThread?.Abort();
|
GenerationThread?.Abort();
|
||||||
|
@ -1,197 +1,66 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Assets.Common;
|
using Assets.Common;
|
||||||
|
using Assets.RenderPass;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
using Random = UnityEngine.Random;
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
namespace Assets
|
namespace Assets
|
||||||
{
|
{
|
||||||
// [RequireComponent(typeof(MeshFilter))]
|
[RequireComponent(typeof(MeshFilter))]
|
||||||
// [RequireComponent(typeof(MeshRenderer))]
|
[RequireComponent(typeof(MeshRenderer))]
|
||||||
// [RequireComponent(typeof(LandmassGenerator))]
|
[RequireComponent(typeof(LandmassGenerator))]
|
||||||
public class MapRenderer : MonoBehaviour
|
public class MapRenderer : MonoBehaviour
|
||||||
{
|
{
|
||||||
// public float UVScale = 1.0f;
|
private bool _rerender = false;
|
||||||
//
|
|
||||||
// private List<Vector3> _vertices;
|
private IList<IRenderer> _renderers = new List<IRenderer>
|
||||||
// private List<Vector2> _uv;
|
{
|
||||||
// private List<Vector3> _normals;
|
new LandmassRenderer()
|
||||||
// private List<Color> _colors;
|
};
|
||||||
// private List<int> _triangles;
|
|
||||||
//
|
public void GenerateRandom()
|
||||||
// private List<List<Point>> _edges;
|
{
|
||||||
//
|
var generator = GetComponent<LandmassGenerator>();
|
||||||
// public void Generate()
|
|
||||||
// {
|
generator.seed = Environment.TickCount;
|
||||||
// var graph = GetComponent<LandmassGenerator>();
|
generator.Generate(map => _rerender = true);
|
||||||
//
|
}
|
||||||
// graph.Reset();
|
|
||||||
// graph.Generate();
|
private void Update()
|
||||||
//
|
{
|
||||||
// var points = graph.VoronoiGenerator.Voronoi.Vertices;
|
if (Input.GetMouseButtonDown(0))
|
||||||
//
|
GenerateRandom();
|
||||||
// _vertices = new List<Vector3>();
|
|
||||||
// _normals = new List<Vector3>();
|
if (_rerender)
|
||||||
// _uv = new List<Vector2>();
|
{
|
||||||
// _colors = new List<Color>();
|
Render();
|
||||||
// _triangles = new List<int>();
|
_rerender = false;
|
||||||
//
|
}
|
||||||
// foreach (var location in graph.LocationGenerator.Result.Vertices.Skip(1))
|
}
|
||||||
// {
|
|
||||||
// GenerateLocationEdges(location, points);
|
public void Render()
|
||||||
// GenerateLocationMeshAlt(location, points);
|
{
|
||||||
// GenerateLocationWall(location, points);
|
var map = GetComponent<LandmassGenerator>().Map;
|
||||||
// }
|
|
||||||
//
|
if (map == null)
|
||||||
// Mesh mesh = new Mesh();
|
return;
|
||||||
// mesh.vertices = _vertices.ToArray();
|
|
||||||
// mesh.uv = _uv.ToArray();
|
foreach (var current in _renderers)
|
||||||
// mesh.normals = _normals.ToArray();
|
current.Render(map, this);
|
||||||
// mesh.triangles = _triangles.ToArray();
|
}
|
||||||
// mesh.colors = _colors.ToArray();
|
|
||||||
//
|
public void OnDrawGizmos()
|
||||||
// GetComponent<MeshFilter>().sharedMesh = mesh;
|
{
|
||||||
//
|
var map = GetComponent<LandmassGenerator>().Map;
|
||||||
// }
|
|
||||||
//
|
if (map == null)
|
||||||
// private void GenerateLocationEdges(Location location, List<Point> points)
|
return;
|
||||||
// {
|
|
||||||
// foreach (var (a, b) in location.BoundaryEdges.Select(x => (points[x.Item1], points[x.Item2])))
|
foreach (var current in _renderers)
|
||||||
// location.DetailedEdge.AddRange(this.SplitEdge(a, b, 3));
|
current.DrawGizmos(map, this);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// private IEnumerable<Point> SplitEdge(Point a, Point b, int count)
|
|
||||||
// {
|
|
||||||
//// var direction = ;
|
|
||||||
// var magnitude = Point.Dist(a, b);
|
|
||||||
// var d = new Point(-(b.y - a.y) / magnitude, (b.x - a.x) / magnitude);
|
|
||||||
//
|
|
||||||
// magnitude *= Random.value * 0.4 - 0.2;
|
|
||||||
//
|
|
||||||
// Point c = new Point((a.x + b.x) / 2.0 + d.x * magnitude, (a.y + b.y) / 2.0 + d.y * magnitude);
|
|
||||||
//
|
|
||||||
// if (count > 0)
|
|
||||||
// {
|
|
||||||
// foreach (var p in SplitEdge(a, c, count - 1))
|
|
||||||
// yield return p;
|
|
||||||
//
|
|
||||||
// yield return c;
|
|
||||||
//
|
|
||||||
// foreach (var p in SplitEdge(c, b, count - 1))
|
|
||||||
// yield return p;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// yield return c;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void GenerateLocationMeshAlt(Location location, IList<Point> points)
|
|
||||||
// {
|
|
||||||
// var start = _vertices.Count;
|
|
||||||
// var count = location.DetailedEdge.Count;
|
|
||||||
//
|
|
||||||
// _vertices.AddRange(location.DetailedEdge.Select(p => new Vector3((float)p.x, location.Type.height, (float)p.y)));
|
|
||||||
// _normals.AddRange(Enumerable.Repeat(Vector3.up, count));
|
|
||||||
// _colors.AddRange(Enumerable.Repeat(Color.blue, count));
|
|
||||||
// _uv.AddRange(location.DetailedEdge.Select(p => new Vector2((float)p.x, (float)p.y) / UVScale));
|
|
||||||
//
|
|
||||||
// var triangulator = new Triangulator(location.DetailedEdge.Select(v => new Vector2((float)v.x, (float)v.y)).ToArray());
|
|
||||||
// _triangles.AddRange(triangulator.Triangulate().Select(x => x + start));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void GenerateLocationMesh(Location location, IList<Point> points)
|
|
||||||
// {
|
|
||||||
// foreach (var vertices in location.Sites.Select(site => site.Edges.Select(x => x.Item1).Reverse()))
|
|
||||||
// {
|
|
||||||
// int start = _vertices.Count;
|
|
||||||
//
|
|
||||||
// foreach (var i in vertices)
|
|
||||||
// {
|
|
||||||
// var isEdge = location.BoundaryPoints.Contains(i);
|
|
||||||
//
|
|
||||||
// var vertex = points[i];
|
|
||||||
// var v = PointToVector(location, vertex);
|
|
||||||
//
|
|
||||||
// _vertices.Add(v);
|
|
||||||
// _normals.Add(Vector3.up);
|
|
||||||
// _uv.Add(new Vector2(v.x, v.z) / UVScale);
|
|
||||||
// _colors.Add(isEdge ? Color.red : Color.blue);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// int end = _vertices.Count;
|
|
||||||
//
|
|
||||||
// var triangulator = new Triangulator(_vertices.Skip(start).Take(end - start).Select(v => new Vector2(v.x, v.z)).ToArray());
|
|
||||||
// _triangles.AddRange(triangulator.Triangulate().Select(x => x + start));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static Vector3 PointToVector(Location location, Point vertex)
|
|
||||||
// {
|
|
||||||
// return new Vector3((float)vertex.x, location.Type.height + Mathf.PerlinNoise((float)vertex.x, (float)vertex.y) / 4, (float)vertex.y);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void GenerateLocationWall(Location location, IList<Point> points)
|
|
||||||
// {
|
|
||||||
// var length = 0.0;
|
|
||||||
//
|
|
||||||
// var collection = location.DetailedEdge.Append(location.DetailedEdge.First());
|
|
||||||
// var edges = collection.Zip(collection.Skip(1), (a, b) => (a, b)).Zip(collection.Skip(2), (tuple, c) => (tuple.a, tuple.b, c));
|
|
||||||
//
|
|
||||||
// foreach (var (p, c, n) in edges)
|
|
||||||
// {
|
|
||||||
// int start = _vertices.Count;
|
|
||||||
// var dist = Point.Dist(p, c);
|
|
||||||
//
|
|
||||||
// var veca = PointToVector(location, p);
|
|
||||||
// var vecb = PointToVector(location, c);
|
|
||||||
//
|
|
||||||
// _vertices.Add(veca);
|
|
||||||
// _vertices.Add(new Vector3((float)p.x, -10,(float)p.y));
|
|
||||||
// _vertices.Add(vecb);
|
|
||||||
// _vertices.Add(new Vector3((float)c.x, -10,(float)c.y));
|
|
||||||
//
|
|
||||||
// var normal = new Vector3((float)(p.x + n.x - c.x) / 2.0f, 0, (float)(p.y + n.y - c.y) / 2.0f).normalized;
|
|
||||||
//
|
|
||||||
// _normals.AddRange(Enumerable.Repeat(normal, 4));
|
|
||||||
// _colors.AddRange(Enumerable.Repeat(Color.red, 4));
|
|
||||||
//
|
|
||||||
// _triangles.AddRange(new []
|
|
||||||
// {
|
|
||||||
// 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;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void OnDrawGizmos()
|
|
||||||
// {
|
|
||||||
// var graph = GetComponent<LandmassGenerator>();
|
|
||||||
//
|
|
||||||
// if (graph?.LocationGenerator?.Result == null) return;
|
|
||||||
//
|
|
||||||
// foreach (var location in graph.LocationGenerator.Result.Vertices.Skip(1))
|
|
||||||
// {
|
|
||||||
// var boundary = location.DetailedEdge;
|
|
||||||
// foreach (var (a, b) in boundary.Zip(boundary.Skip(1).Append(boundary.First()), (a, b) => (a, b)))
|
|
||||||
// {
|
|
||||||
// var va = new Vector3((float) a.x, location.Type.height, (float) a.y);
|
|
||||||
// var vb = new Vector3((float) b.x, location.Type.height, (float) b.y);
|
|
||||||
//
|
|
||||||
// Gizmos.DrawLine(va, vb);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,8 +3,10 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace Assets.RenderPass
|
namespace Assets.RenderPass
|
||||||
{
|
{
|
||||||
public interface IRenderPass
|
public interface IRenderer
|
||||||
{
|
{
|
||||||
void Render(Map map, Component component);
|
void Render(Map map, Component component);
|
||||||
|
|
||||||
|
void DrawGizmos(Map map, Component component);
|
||||||
}
|
}
|
||||||
}
|
}
|
174
Assets/Scripts/RenderPass/LandmassRenderer.cs
Normal file
174
Assets/Scripts/RenderPass/LandmassRenderer.cs
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Assets.AnnotationPass;
|
||||||
|
using Assets.Common;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Assets.RenderPass
|
||||||
|
{
|
||||||
|
public class LandmassRenderer : IRenderer
|
||||||
|
{
|
||||||
|
public float UVScale { get; set; } = 1.0f;
|
||||||
|
|
||||||
|
private List<Vector3> _vertices;
|
||||||
|
private List<Vector2> _uv;
|
||||||
|
private List<Vector3> _normals;
|
||||||
|
private List<Color> _colors;
|
||||||
|
private List<int> _triangles;
|
||||||
|
private List<List<Point>> _edges;
|
||||||
|
|
||||||
|
public void Render(Map map, Component component)
|
||||||
|
{
|
||||||
|
var points = map.Boundaries.Vertices;
|
||||||
|
var locations = map.GetProperty<Graph<Location>>(LandmassPass.MapLocationsProperty);
|
||||||
|
|
||||||
|
_vertices = new List<Vector3>();
|
||||||
|
_normals = new List<Vector3>();
|
||||||
|
_uv = new List<Vector2>();
|
||||||
|
_colors = new List<Color>();
|
||||||
|
_triangles = new List<int>();
|
||||||
|
|
||||||
|
foreach (var location in locations.Vertices.Skip(1))
|
||||||
|
{
|
||||||
|
GenerateLocationEdges(location, points);
|
||||||
|
GenerateLocationMesh(location, points);
|
||||||
|
GenerateLocationWall(location, points);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mesh mesh = new Mesh();
|
||||||
|
mesh.vertices = _vertices.ToArray();
|
||||||
|
mesh.uv = _uv.ToArray();
|
||||||
|
mesh.normals = _normals.ToArray();
|
||||||
|
mesh.triangles = _triangles.ToArray();
|
||||||
|
mesh.colors = _colors.ToArray();
|
||||||
|
|
||||||
|
var mf = component.GetComponent<MeshFilter>();
|
||||||
|
mf.sharedMesh = mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateLocationEdges(Location location, List<Point> points)
|
||||||
|
{
|
||||||
|
foreach (var (a, b) in location.BoundaryEdges.Select(x => (points[x.Item1], points[x.Item2])))
|
||||||
|
location.DetailedEdge.AddRange(this.SplitEdge(a, b, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<Point> SplitEdge(Point a, Point b, int count)
|
||||||
|
{
|
||||||
|
var magnitude = Point.Dist(a, b);
|
||||||
|
var d = new Point(-(b.y - a.y) / magnitude, (b.x - a.x) / magnitude);
|
||||||
|
|
||||||
|
magnitude *= Random.value * 0.4 - 0.2;
|
||||||
|
|
||||||
|
Point c = new Point((a.x + b.x) / 2.0 + d.x * magnitude, (a.y + b.y) / 2.0 + d.y * magnitude);
|
||||||
|
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
foreach (var p in SplitEdge(a, c, count - 1))
|
||||||
|
yield return p;
|
||||||
|
|
||||||
|
yield return c;
|
||||||
|
|
||||||
|
foreach (var p in SplitEdge(c, b, count - 1))
|
||||||
|
yield return p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateLocationMeshAlt(Location location, IList<Point> points)
|
||||||
|
{
|
||||||
|
var start = _vertices.Count;
|
||||||
|
var count = location.DetailedEdge.Count;
|
||||||
|
|
||||||
|
_vertices.AddRange(location.DetailedEdge.Select(p => new Vector3((float)p.x, location.Type.height, (float)p.y)));
|
||||||
|
_normals.AddRange(Enumerable.Repeat(Vector3.up, count));
|
||||||
|
_colors.AddRange(Enumerable.Repeat(Color.blue, count));
|
||||||
|
_uv.AddRange(location.DetailedEdge.Select(p => new Vector2((float)p.x, (float)p.y) / UVScale));
|
||||||
|
|
||||||
|
var triangulator = new Triangulator(location.DetailedEdge.Select(v => new Vector2((float)v.x, (float)v.y)).ToArray());
|
||||||
|
_triangles.AddRange(triangulator.Triangulate().Select(x => x + start));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateLocationMesh(Location location, IList<Point> points)
|
||||||
|
{
|
||||||
|
foreach (var vertices in location.Sites.Select(site => site.Edges.Select(x => x.Item1).Reverse()))
|
||||||
|
{
|
||||||
|
int start = _vertices.Count;
|
||||||
|
|
||||||
|
foreach (var i in vertices)
|
||||||
|
{
|
||||||
|
var isEdge = location.BoundaryPoints.Contains(i);
|
||||||
|
|
||||||
|
var vertex = points[i];
|
||||||
|
var v = PointToVector(location, vertex);
|
||||||
|
|
||||||
|
_vertices.Add(v);
|
||||||
|
_normals.Add(Vector3.up);
|
||||||
|
_uv.Add(new Vector2(v.x, v.z) / UVScale);
|
||||||
|
_colors.Add(isEdge ? Color.red : Color.blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
int end = _vertices.Count;
|
||||||
|
|
||||||
|
var triangulator = new Triangulator(_vertices.Skip(start).Take(end - start).Select(v => new Vector2(v.x, v.z)).ToArray());
|
||||||
|
_triangles.AddRange(triangulator.Triangulate().Select(x => x + start));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vector3 PointToVector(Location location, Point vertex)
|
||||||
|
{
|
||||||
|
return new Vector3((float)vertex.x, location.Type.height + Mathf.PerlinNoise((float)vertex.x, (float)vertex.y) / 4, (float)vertex.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateLocationWall(Location location, IList<Point> points)
|
||||||
|
{
|
||||||
|
var length = 0.0;
|
||||||
|
|
||||||
|
var collection = location.DetailedEdge.Append(location.DetailedEdge.First());
|
||||||
|
var edges = collection.Zip(collection.Skip(1), (a, b) => (a, b)).Zip(collection.Skip(2), (tuple, c) => (tuple.a, tuple.b, c));
|
||||||
|
|
||||||
|
foreach (var (p, c, n) in edges)
|
||||||
|
{
|
||||||
|
int start = _vertices.Count;
|
||||||
|
var dist = Point.Dist(p, c);
|
||||||
|
|
||||||
|
var veca = PointToVector(location, p);
|
||||||
|
var vecb = PointToVector(location, c);
|
||||||
|
|
||||||
|
_vertices.Add(veca);
|
||||||
|
_vertices.Add(new Vector3((float)p.x, -10,(float)p.y));
|
||||||
|
_vertices.Add(vecb);
|
||||||
|
_vertices.Add(new Vector3((float)c.x, -10,(float)c.y));
|
||||||
|
|
||||||
|
var normal = new Vector3((float)(p.x + n.x - c.x) / 2.0f, 0, (float)(p.y + n.y - c.y) / 2.0f).normalized;
|
||||||
|
|
||||||
|
_normals.AddRange(Enumerable.Repeat(normal, 4));
|
||||||
|
_colors.AddRange(Enumerable.Repeat(Color.red, 4));
|
||||||
|
|
||||||
|
_triangles.AddRange(new []
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawGizmos(Map map, Component component)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
Assets/Scripts/RenderPass/LandmassRenderer.cs.meta
Normal file
3
Assets/Scripts/RenderPass/LandmassRenderer.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0ca9f42ceab24d34ad59014726adf348
|
||||||
|
timeCreated: 1573931440
|
Loading…
Reference in New Issue
Block a user