rozmieszczanie drzew
This commit is contained in:
parent
d0f6e8239a
commit
e5613f6af9
@ -1,22 +0,0 @@
|
||||
using Assets;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Editor
|
||||
{
|
||||
[CustomEditor(typeof (ForestGenerator))]
|
||||
public class ForestGeneratorUI : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var target = this.target as ForestGenerator;
|
||||
|
||||
DrawDefaultInspector();
|
||||
|
||||
if (GUILayout.Button("Generate"))
|
||||
{
|
||||
// target.Generate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d169cf324704c908e59fcebe537a011
|
||||
timeCreated: 1567618094
|
@ -35,12 +35,12 @@ namespace Assets.AnnotationPass
|
||||
{
|
||||
var site = _sites[neighbour];
|
||||
|
||||
if (!site.Metadata.HasProperty(SiteLocationProperty))
|
||||
if (!site.HasProperty(SiteLocationProperty))
|
||||
{
|
||||
if (location == _locations[0] || !site.Tags.Contains(CommonTags.Edge))
|
||||
_queue.Add((neighbour, location));
|
||||
}
|
||||
else if (location != site.Metadata.GetProperty<Location>(SiteLocationProperty))
|
||||
else if (location != site.GetProperty<Location>(SiteLocationProperty))
|
||||
_locations.AddEdge(
|
||||
_locations.Vertices.IndexOf(location),
|
||||
_locations.Vertices.IndexOf(site.Metadata.GetProperty<Location>(SiteLocationProperty))
|
||||
@ -55,7 +55,8 @@ namespace Assets.AnnotationPass
|
||||
if (location != _locations[0])
|
||||
site.Tags.Add(CommonTags.Land);
|
||||
|
||||
site.Metadata.SetProperty(SiteLocationProperty, location);
|
||||
site.SetProperty(SiteLocationProperty, location);
|
||||
site.SetProperty(CommonSiteProperties.Height, (double)location.Type.height);
|
||||
}
|
||||
|
||||
private (int, Location) Dequeue()
|
||||
@ -67,7 +68,7 @@ namespace Assets.AnnotationPass
|
||||
|
||||
_queue.RemoveAt(index);
|
||||
|
||||
if (!_sites[pair.Item1].Metadata.HasProperty(SiteLocationProperty)) return pair;
|
||||
if (!_sites[pair.Item1].HasProperty(SiteLocationProperty)) return pair;
|
||||
}
|
||||
|
||||
throw new Exception("No more elements.");
|
||||
@ -125,7 +126,7 @@ namespace Assets.AnnotationPass
|
||||
_sites = map.Sites;
|
||||
_points = map.Boundaries.Vertices;
|
||||
|
||||
map.Metadata.SetProperty(MapLocationsProperty, _locations);
|
||||
map.SetProperty(MapLocationsProperty, _locations);
|
||||
|
||||
var ocean = _locations[0];
|
||||
var possible = new Queue<int>(map.Sites
|
||||
|
7
Assets/Scripts/Common/CommonSiteProperties.cs
Normal file
7
Assets/Scripts/Common/CommonSiteProperties.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Assets.Common
|
||||
{
|
||||
public class CommonSiteProperties
|
||||
{
|
||||
public const string Height = "Common.Height";
|
||||
}
|
||||
}
|
3
Assets/Scripts/Common/CommonSiteProperties.cs.meta
Normal file
3
Assets/Scripts/Common/CommonSiteProperties.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6890627434244b08a4602c46789ad43b
|
||||
timeCreated: 1574019493
|
@ -1,94 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Assets.Common;
|
||||
using Assets.PointDistribution;
|
||||
using Assets.Voronoi;
|
||||
using UnityEngine;
|
||||
using Random = System.Random;
|
||||
|
||||
//namespace Assets
|
||||
//{
|
||||
// [RequireComponent(typeof(MeshFilter))]
|
||||
// [RequireComponent(typeof(MeshRenderer))]
|
||||
// [RequireComponent(typeof(LandmassGenerator))]
|
||||
public class ForestGenerator : MonoBehaviour
|
||||
{
|
||||
// public GameObject[] trees;
|
||||
// [Range(1, 15)]
|
||||
// public float radius = 3.0f;
|
||||
// public GameObject forest;
|
||||
//
|
||||
// private Random _random = new Random();
|
||||
// private List<Site> _sites;
|
||||
//
|
||||
// private LandmassGenerator Generator => GetComponent<LandmassGenerator>();
|
||||
//
|
||||
// public void Generate()
|
||||
// {
|
||||
// Cleanup();
|
||||
//
|
||||
// Generator.EnsureGenerated();
|
||||
//
|
||||
// FindForestSites();
|
||||
// PlaceTrees();
|
||||
//
|
||||
// _random = new Random(Generator.seed);
|
||||
// }
|
||||
//
|
||||
// private void PlaceTrees()
|
||||
// {
|
||||
// foreach (Site site in _sites)
|
||||
// {
|
||||
// var sampler = new PoissonDiskSampler(radius) { Generator = _random };
|
||||
//
|
||||
// Bounding bounding =
|
||||
// BoundingTools.GetBounding(site.Vertices.Select(i => Generator.BoundariesGraph.Vertices[i]));
|
||||
//
|
||||
// var offset = Vector3.up * site.Location.Type.height;
|
||||
// var points = sampler.Generate((float)bounding.Width, (float)bounding.Height);
|
||||
//
|
||||
// foreach (var point in points.Select(point => point + bounding.Min).Where(point => IsPointInSite(site, point)))
|
||||
// PlaceRandomTree(point.ToVector3() + offset);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void Cleanup()
|
||||
// {
|
||||
// var destroy = new List<GameObject>();
|
||||
//
|
||||
// foreach (var child in forest.transform)
|
||||
// if (child is Transform t)
|
||||
// destroy.Add(t.gameObject);
|
||||
//
|
||||
// foreach (var @object in destroy)
|
||||
// DestroyImmediate(@object);
|
||||
// }
|
||||
//
|
||||
// private void FindForestSites()
|
||||
// {
|
||||
// _sites = new List<Site>();
|
||||
//
|
||||
// foreach (var location in Generator.LocationGraph.Vertices.Skip(1))
|
||||
// {
|
||||
// var count = _random.Next(10);
|
||||
//
|
||||
// for (int i = 0; i < count; i++)
|
||||
// _sites.Add(location.Sites[_random.Next(location.Sites.Count)]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void PlaceRandomTree(Vector3 pos)
|
||||
// {
|
||||
// GameObject tree = Instantiate(trees[_random.Next(trees.Length)], forest.transform);
|
||||
//
|
||||
// tree.transform.position = pos - Vector3.down * 0.2f;
|
||||
// }
|
||||
//
|
||||
// private bool IsPointInSite(Site site, Point point)
|
||||
// {
|
||||
// var polygon = site.Vertices.Select(i => Generator.BoundariesGraph[i]).ToArray();
|
||||
//
|
||||
// return PointUtils.IsPointInside(point, polygon);
|
||||
// }
|
||||
}
|
||||
//}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36d65e29139a4864b1c3a6beb0db0cf1
|
||||
timeCreated: 1567614336
|
@ -17,11 +17,18 @@ namespace Assets
|
||||
private bool _rerender = false;
|
||||
|
||||
public GameObject citiesGameObject;
|
||||
public GameObject forestGameObject;
|
||||
public GameObject[] trees;
|
||||
|
||||
private IList<IRenderer> Renderers => new List<IRenderer>
|
||||
{
|
||||
new LandmassRenderer(),
|
||||
new CityRenderer(citiesGameObject),
|
||||
new ForestRender
|
||||
{
|
||||
ForestObject = forestGameObject,
|
||||
Trees = trees,
|
||||
}
|
||||
};
|
||||
|
||||
public void GenerateRandom()
|
||||
|
45
Assets/Scripts/RenderPass/ForestRender.cs
Normal file
45
Assets/Scripts/RenderPass/ForestRender.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets.AnnotationPass;
|
||||
using Assets.Common;
|
||||
using UnityEngine;
|
||||
using Random = System.Random;
|
||||
using Tree = Assets.Common.Tree;
|
||||
|
||||
namespace Assets.RenderPass
|
||||
{
|
||||
public class ForestRender : IRenderer
|
||||
{
|
||||
public ICollection<GameObject> Trees { get; set; }
|
||||
public GameObject ForestObject { get; set; }
|
||||
|
||||
public void Render(Map map, Component component)
|
||||
{
|
||||
var rng = new Random(map.Seed);
|
||||
var trees = map.GetProperty<IEnumerable<Tree>>(ForestPass.TreesProperty);
|
||||
|
||||
var toRemove = new List<GameObject>();
|
||||
foreach (Transform child in ForestObject.transform)
|
||||
toRemove.Add(child.gameObject);
|
||||
|
||||
foreach (var o in toRemove)
|
||||
Object.DestroyImmediate(o);
|
||||
|
||||
foreach (var tree in trees)
|
||||
{
|
||||
var origin = tree.Placement.ToVector3() + (float)tree.Site.GetProperty<double>(CommonSiteProperties.Height) * Vector3.up;
|
||||
Object.Instantiate(GetRandomTree(rng), origin, Quaternion.identity, ForestObject.transform);
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject GetRandomTree(Random generator)
|
||||
{
|
||||
return Trees.RandomElement(generator);
|
||||
}
|
||||
|
||||
public void DrawGizmos(Map map, Component component)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/RenderPass/ForestRender.cs.meta
Normal file
3
Assets/Scripts/RenderPass/ForestRender.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7a96fe45ad140fcb69b84c7d27e5ca9
|
||||
timeCreated: 1574019277
|
Loading…
Reference in New Issue
Block a user