Sector Constellations
Generating links between zones within the sector using elimination algorithm with connectedness testing Improved sample elimination API - now accepts simple density function! Ported MIConvexHull library to single precision, Unity.Mathematics math Removed old galaxy generator (new code is much better!)
This commit is contained in:
parent
3f9af29843
commit
0f33e541c0
99 changed files with 668 additions and 6762 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
|
@ -12,6 +13,9 @@ public class SectorMap : MonoBehaviour
|
|||
public MeshRenderer SectorRenderer;
|
||||
public SectorGenerationSettings Settings;
|
||||
public Prototype ZonePrototype;
|
||||
public Prototype LinkPrototype;
|
||||
public int ZoneCount = 64;
|
||||
public float LinkDensity = .5f;
|
||||
|
||||
[Header("Name Generation")]
|
||||
public TextAsset NameFile;
|
||||
|
|
@ -35,11 +39,30 @@ public class SectorMap : MonoBehaviour
|
|||
for (int i = 0; i < 4096; i++) random.NextFloat();
|
||||
var nameGenerator = new MarkovNameGenerator(ref random, names, NameGeneratorOrder, NameGeneratorMinLength, NameGeneratorMaxLength);
|
||||
Settings.NoisePosition = Random.value * 100;
|
||||
var sector = SectorGenerator.GenerateSector(ref random, Settings, nameGenerator);
|
||||
var sector = SectorGenerator.GenerateSector(Settings, nameGenerator, ZoneCount, LinkDensity);
|
||||
var visitedZones = new HashSet<SectorZone>();
|
||||
Debug.Log($"Found {sector.Zones.Count(z=>!z.AdjacentZones.Any())} orphaned zones!");
|
||||
foreach (var zone in sector.Zones)
|
||||
{
|
||||
var zoneInstance = ZonePrototype.Instantiate<Transform>();
|
||||
zoneInstance.position = new Vector3(zone.Position.x - .5f, zone.Position.y - .5f);
|
||||
zoneInstance.localPosition = new Vector3(zone.Position.x, zone.Position.y);
|
||||
foreach (var link in zone.AdjacentZones)
|
||||
{
|
||||
if (!visitedZones.Contains(link))
|
||||
{
|
||||
var linkInstance = LinkPrototype.Instantiate<Transform>();
|
||||
var pos = (zone.Position + link.Position) / 2;
|
||||
linkInstance.localPosition = new Vector3(pos.x, pos.y);
|
||||
|
||||
var localScale = linkInstance.localScale;
|
||||
localScale = new Vector3(length(zone.Position - link.Position), localScale.y, localScale.z);
|
||||
linkInstance.localScale = localScale;
|
||||
|
||||
var dir = normalize(zone.Position - link.Position);
|
||||
linkInstance.rotation = Quaternion.Euler(0,0,atan2(dir.y,dir.x) * Mathf.Rad2Deg);
|
||||
}
|
||||
}
|
||||
visitedZones.Add(zone);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +72,7 @@ public class SectorMap : MonoBehaviour
|
|||
SectorRenderer.material.SetFloat("CloudAmplitude", Settings.CloudAmplitude);
|
||||
SectorRenderer.material.SetFloat("CloudExponent", Settings.CloudExponent);
|
||||
SectorRenderer.material.SetFloat("NoisePosition", Settings.NoisePosition);
|
||||
SectorRenderer.material.SetFloat("Zoom", Settings.Zoom);
|
||||
SectorRenderer.material.SetFloat("NoiseAmplitude", Settings.NoiseAmplitude);
|
||||
SectorRenderer.material.SetFloat("NoiseOffset", Settings.NoiseOffset);
|
||||
SectorRenderer.material.SetFloat("NoiseGain", Settings.NoiseGain);
|
||||
|
|
|
|||
Loading…
Reference in a new issue