Add location boundary generation
This commit is contained in:
parent
fb1be67f90
commit
8a9adbd28f
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Random = System.Random;
|
using Random = System.Random;
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ namespace Assets.Map
|
|||||||
|
|
||||||
public bool Done => _queue.Count == 0;
|
public bool Done => _queue.Count == 0;
|
||||||
public Graph<LocationSite> Result => _graph;
|
public Graph<LocationSite> Result => _graph;
|
||||||
|
private Dictionary<Location, List<int>> _blacklist = new Dictionary<Location, List<int>>();
|
||||||
|
|
||||||
public LocationGenerator(Graph<LocationSite> graph, Random random = null)
|
public LocationGenerator(Graph<LocationSite> graph, Random random = null)
|
||||||
{
|
{
|
||||||
@ -57,10 +59,33 @@ namespace Assets.Map
|
|||||||
private void SetLocation(int vertex, Location location)
|
private void SetLocation(int vertex, Location location)
|
||||||
{
|
{
|
||||||
_graph.Vertices[vertex].Location = location;
|
_graph.Vertices[vertex].Location = location;
|
||||||
|
location.Sites.Add(_graph.Vertices[vertex]);
|
||||||
|
|
||||||
|
FixBoundaryPoints(vertex, location);
|
||||||
|
FixBoundaryEdges(vertex, location);
|
||||||
|
|
||||||
foreach (var neighbour in _graph.Neighbours(vertex))
|
foreach (var neighbour in _graph.Neighbours(vertex))
|
||||||
if (_graph.Vertices[neighbour].Location == null)
|
if (_graph.Vertices[neighbour].Location == null)
|
||||||
_queue.Add((neighbour, location));
|
_queue.Add((neighbour, location));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FixBoundaryPoints(int vertex, Location location)
|
||||||
|
{
|
||||||
|
var a = location.BoundaryPoints;
|
||||||
|
var b = _graph.Vertices[vertex].Site.Vertices;
|
||||||
|
|
||||||
|
if (!_blacklist.ContainsKey(location)) _blacklist[location] = new List<int>();
|
||||||
|
_blacklist[location].AddRange(a.Intersect(b));
|
||||||
|
|
||||||
|
location.BoundaryPoints = a.Union(b).Except(_blacklist[location]).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FixBoundaryEdges(int vertex, Location location)
|
||||||
|
{
|
||||||
|
var a = location.BoundaryEdges;
|
||||||
|
var b = _graph.Vertices[vertex].Site.Edges;
|
||||||
|
|
||||||
|
location.BoundaryEdges = a.Union(b).Except(a.Intersect(b)).ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,8 +7,10 @@ namespace Assets.Map
|
|||||||
{
|
{
|
||||||
public class Location
|
public class Location
|
||||||
{
|
{
|
||||||
public List<LocationSite> Sites;
|
public List<LocationSite> Sites = new List<LocationSite>();
|
||||||
public List<Point> BoundaryPoints;
|
public List<int> BoundaryPoints = new List<int>();
|
||||||
|
public List<(int, int)> BoundaryEdges = new List<(int, int)>();
|
||||||
|
|
||||||
public LocationType Type;
|
public LocationType Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,30 +248,34 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 06dfaa94f8713f12fbe207b61b694c90, type: 3}
|
m_Script: {fileID: 11500000, guid: 06dfaa94f8713f12fbe207b61b694c90, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
sections:
|
types:
|
||||||
- name:
|
|
||||||
color: {r: 1, g: 0, b: 0, a: 1}
|
|
||||||
- name:
|
- name:
|
||||||
color: {r: 0.18382645, g: 1, b: 0, a: 1}
|
color: {r: 0.18382645, g: 1, b: 0, a: 1}
|
||||||
- name:
|
- name:
|
||||||
color: {r: 1, g: 0, b: 0.74144936, a: 1}
|
color: {r: 1, g: 0, b: 0.74144936, a: 1}
|
||||||
- name:
|
- name:
|
||||||
color: {r: 0, g: 0.06698942, b: 1, a: 1}
|
color: {r: 0, g: 0.06698942, b: 1, a: 1}
|
||||||
- name:
|
- name: fucks
|
||||||
color: {r: 0, g: 1, b: 0.94361734, a: 1}
|
color: {r: 0, g: 1, b: 0.94361734, a: 1}
|
||||||
seed: 120
|
- name:
|
||||||
size: {x: 200, y: 200}
|
color: {r: 1, g: 0.008301804, b: 0, a: 1}
|
||||||
|
- name:
|
||||||
|
color: {r: 0.96469927, g: 1, b: 0, a: 1}
|
||||||
|
seed: 1090655872
|
||||||
|
size: {x: 300, y: 300}
|
||||||
debug:
|
debug:
|
||||||
enabled: 1
|
enabled: 1
|
||||||
displayPoints: 0
|
displayPoints: 0
|
||||||
displayBeachLine: 0
|
displayBeachLine: 0
|
||||||
displayParabolas: 0
|
displayParabolas: 1
|
||||||
displayVertices: 0
|
displayVertices: 0
|
||||||
displayNeighbours: 0
|
displayNeighbours: 0
|
||||||
displayLabels: 0
|
displayLabels: 1
|
||||||
displayHalfEdges: 0
|
displayHalfEdges: 0
|
||||||
displayEdges: 0
|
displayEdges: 0
|
||||||
displayLocations: 1
|
displayLocations: 0
|
||||||
|
displayLocationEdges: 1
|
||||||
|
displayLocationPoints: 1
|
||||||
radius: 5
|
radius: 5
|
||||||
--- !u!33 &528199734
|
--- !u!33 &528199734
|
||||||
MeshFilter:
|
MeshFilter:
|
||||||
|
@ -24,6 +24,8 @@ namespace Assets
|
|||||||
public bool displayHalfEdges = false;
|
public bool displayHalfEdges = false;
|
||||||
public bool displayEdges = true;
|
public bool displayEdges = true;
|
||||||
public bool displayLocations = true;
|
public bool displayLocations = true;
|
||||||
|
public bool displayLocationEdges = true;
|
||||||
|
public bool displayLocationPoints = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@ -204,7 +206,9 @@ namespace Assets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug.displayLocations && LocationGenerator != null)
|
if (LocationGenerator == null) return;
|
||||||
|
|
||||||
|
if (debug.displayLocations)
|
||||||
{
|
{
|
||||||
foreach (var location in LocationGenerator.Result.Vertices.Where(l => l.Location != null && l.Location != _locations[0]))
|
foreach (var location in LocationGenerator.Result.Vertices.Where(l => l.Location != null && l.Location != _locations[0]))
|
||||||
{
|
{
|
||||||
@ -212,6 +216,30 @@ namespace Assets
|
|||||||
Gizmos.DrawSphere(location.Site.Point.ToVector3(), 2);
|
Gizmos.DrawSphere(location.Site.Point.ToVector3(), 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (debug.displayLocationPoints)
|
||||||
|
{
|
||||||
|
foreach (var location in _locations.Skip(1))
|
||||||
|
{
|
||||||
|
Gizmos.color = location.Type.color;
|
||||||
|
foreach (var point in location.BoundaryPoints)
|
||||||
|
{
|
||||||
|
Gizmos.DrawSphere(VoronoiGenerator.Voronoi.Vertices[point].ToVector3(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (debug.displayLocationEdges)
|
||||||
|
{
|
||||||
|
foreach (var location in _locations.Skip(1))
|
||||||
|
{
|
||||||
|
Gizmos.color = location.Type.color;
|
||||||
|
foreach (var (a, b) in location.BoundaryEdges)
|
||||||
|
{
|
||||||
|
Gizmos.DrawLine(VoronoiGenerator.Voronoi.Vertices[a].ToVector3(), VoronoiGenerator.Voronoi.Vertices[b].ToVector3());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Rewind(float y)
|
public void Rewind(float y)
|
||||||
|
@ -6,7 +6,7 @@ EditorSettings:
|
|||||||
serializedVersion: 8
|
serializedVersion: 8
|
||||||
m_ExternalVersionControlSupport: Visible Meta Files
|
m_ExternalVersionControlSupport: Visible Meta Files
|
||||||
m_SerializationMode: 2
|
m_SerializationMode: 2
|
||||||
m_LineEndingsForNewScripts: 2
|
m_LineEndingsForNewScripts: 1
|
||||||
m_DefaultBehaviorMode: 1
|
m_DefaultBehaviorMode: 1
|
||||||
m_PrefabRegularEnvironment: {fileID: 0}
|
m_PrefabRegularEnvironment: {fileID: 0}
|
||||||
m_PrefabUIEnvironment: {fileID: 0}
|
m_PrefabUIEnvironment: {fileID: 0}
|
||||||
|
Loading…
Reference in New Issue
Block a user