mirror of
https://github.com/Xevion/procedural-placement.git
synced 2025-12-07 20:08:01 -06:00
implement CustomEditor GUI and most of the new handling
This commit is contained in:
@@ -5,10 +5,11 @@ using UnityEngine;
|
||||
public enum SamplingTypes {
|
||||
Random,
|
||||
Poisson,
|
||||
Improved_Poisson
|
||||
ImprovedPoisson
|
||||
};
|
||||
|
||||
public class PointRendering : MonoBehaviour {
|
||||
public String seed = "";
|
||||
[Tooltip("The sampling method used to generate points")]
|
||||
public SamplingTypes samplingMethod = SamplingTypes.Random;
|
||||
[Tooltip("The number of points (spheres) placed inside the region")]
|
||||
@@ -31,9 +32,10 @@ public class PointRendering : MonoBehaviour {
|
||||
private float _radius;
|
||||
private int _retryAttempts;
|
||||
|
||||
private List<Vector2> _points;
|
||||
public List<Vector2> points;
|
||||
|
||||
private void OnValidate() {
|
||||
public void OnValidate() {
|
||||
Debug.Log("Firing onValidate!");
|
||||
// Check to see if point position related values changed. SphereSize is rendering only, so we ignore it.
|
||||
if (numPoints != _prevNumPoints || _prevRegionSize != regionSize
|
||||
|| samplingMethod != _samplingMethod || radius != _radius || retryAttempts != _retryAttempts) {
|
||||
@@ -43,27 +45,24 @@ public class PointRendering : MonoBehaviour {
|
||||
_samplingMethod = samplingMethod;
|
||||
_radius = radius;
|
||||
_retryAttempts = retryAttempts;
|
||||
|
||||
// Handling for different types of point sampling methods
|
||||
float t1 = Time.realtimeSinceStartup;
|
||||
switch (samplingMethod) {
|
||||
case SamplingTypes.Random:
|
||||
_points = PointGeneration.random_sampling(numPoints, regionSize);
|
||||
break;
|
||||
case SamplingTypes.Poisson:
|
||||
_points = PointGeneration.poisson_sampling(numPoints, regionSize, radius, retryAttempts);
|
||||
numPoints = _points.Count;
|
||||
break;
|
||||
case SamplingTypes.Improved_Poisson:
|
||||
_points = PointGeneration.improved_poisson_sampling(numPoints, regionSize, radius, retryAttempts);
|
||||
numPoints = _points.Count;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float t2 = Time.realtimeSinceStartup;
|
||||
Debug.Log($"{samplingMethod} generated {_points.Count:n0} points in {t2 - t1:0.0000} seconds");
|
||||
public void regeneratePoints() {
|
||||
switch (samplingMethod) {
|
||||
case SamplingTypes.Random:
|
||||
points = PointGeneration.random_sampling(numPoints, regionSize);
|
||||
break;
|
||||
case SamplingTypes.Poisson:
|
||||
points = PointGeneration.poisson_sampling(numPoints, regionSize, radius, retryAttempts);
|
||||
numPoints = points.Count;
|
||||
break;
|
||||
case SamplingTypes.ImprovedPoisson:
|
||||
points = PointGeneration.improved_poisson_sampling(numPoints, regionSize, radius, retryAttempts);
|
||||
numPoints = points.Count;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,9 +72,9 @@ public class PointRendering : MonoBehaviour {
|
||||
new Vector3(regionSize.x + sphereSize, regionSize.y + sphereSize, sphereSize));
|
||||
|
||||
// Render spheres at every point
|
||||
if (_points == null) return;
|
||||
if (points == null) return;
|
||||
var pos = transform.position;
|
||||
foreach (var point in _points) {
|
||||
foreach (var point in points) {
|
||||
var center = new Vector3(point.x + pos.x - (regionSize.x / 2), point.y + pos.y - (regionSize.y / 2));
|
||||
Gizmos.DrawSphere(center,
|
||||
sphereSize);
|
||||
|
||||
Reference in New Issue
Block a user