mirror of
https://github.com/Xevion/procedural-placement.git
synced 2025-12-06 09:16:02 -06:00
use switch statement for sampling method selection, add tooltips to inspector attributes
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -9,14 +10,19 @@ public enum SamplingTypes {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public class CubeRendering : MonoBehaviour {
|
public class CubeRendering : MonoBehaviour {
|
||||||
|
[Tooltip("The sampling method used to generate points")]
|
||||||
public SamplingTypes samplingMethod = SamplingTypes.Random;
|
public SamplingTypes samplingMethod = SamplingTypes.Random;
|
||||||
|
[Tooltip("The number of points (spheres) placed inside the region")]
|
||||||
public int numPoints = 100;
|
public int numPoints = 100;
|
||||||
|
[Tooltip("The size of the rendered cubes")]
|
||||||
public float cubeSize = 1;
|
public float cubeSize = 1;
|
||||||
|
|
||||||
|
[Tooltip("The Size of the region points are generated in")]
|
||||||
public Vector2 regionSize = Vector2.one;
|
public Vector2 regionSize = Vector2.one;
|
||||||
|
|
||||||
// Store the previous value, only useful for the inspector
|
// Store the previous value, only useful for the inspector
|
||||||
[Tooltip("Testing.")] private int _prevNumPoints;
|
private SamplingTypes _samplingMethod;
|
||||||
|
private int _prevNumPoints;
|
||||||
private Vector2 _prevRegionSize;
|
private Vector2 _prevRegionSize;
|
||||||
|
|
||||||
private List<Vector2> _points;
|
private List<Vector2> _points;
|
||||||
@@ -28,10 +34,15 @@ public class CubeRendering : MonoBehaviour {
|
|||||||
_prevNumPoints = numPoints;
|
_prevNumPoints = numPoints;
|
||||||
_prevRegionSize = regionSize;
|
_prevRegionSize = regionSize;
|
||||||
|
|
||||||
if (samplingMethod == SamplingTypes.Random)
|
switch (samplingMethod) {
|
||||||
|
case SamplingTypes.Random:
|
||||||
_points = PointGeneration.random_sampling(numPoints, regionSize, transform.position);
|
_points = PointGeneration.random_sampling(numPoints, regionSize, transform.position);
|
||||||
else if (samplingMethod == SamplingTypes.Poisson) {
|
break;
|
||||||
|
case SamplingTypes.Poisson:
|
||||||
_points = new List<Vector2>();
|
_points = new List<Vector2>();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,8 +53,8 @@ public class CubeRendering : MonoBehaviour {
|
|||||||
new Vector3(regionSize.x * 2 + cubeSize, regionSize.y * 2 + cubeSize, cubeSize));
|
new Vector3(regionSize.x * 2 + cubeSize, regionSize.y * 2 + cubeSize, cubeSize));
|
||||||
|
|
||||||
// Render spheres at every point
|
// Render spheres at every point
|
||||||
if (_points != null)
|
if (_points == null) return;
|
||||||
foreach (Vector2 point in _points) {
|
foreach (var point in _points) {
|
||||||
Gizmos.DrawSphere(point, cubeSize);
|
Gizmos.DrawSphere(point, cubeSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user