Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions SpaceScrapper/Assets/Debug.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions SpaceScrapper/Assets/Debug/DebugAssembly.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "DebugAssembly",
"rootNamespace": "",
"references": [
"GUID:a1d73af5f72ca4e929569ac515d86db8"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions SpaceScrapper/Assets/Debug/DebugAssembly.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions SpaceScrapper/Assets/Debug/PoissonSamplingTest.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions SpaceScrapper/Assets/Debug/PoissonSamplingTest/PointsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using SpaceScrapper.MathLib;
using UnityEditor;
using UnityEngine;
using Random = UnityEngine.Random;

namespace SpaceScrapper.Debug.PoissonSamplingTest
{
[ExecuteInEditMode]
public class PointsManager : MonoBehaviour
{
[SerializeField]
private int seed;

[Tooltip("Region within which points will be distributed.")]
[SerializeField]
private Bounds region;

[Tooltip("Maximum iteration before stopping sampling with current point")]
[Range(10, 500)]
[SerializeField]
private int maxSamplingTries = 30;

[Range(0.1f, 100f)]
[SerializeField]
private float samplingRadius = 1;

private List<Vector2> points;

public void GeneratePoints()
{
Random.InitState(seed);
points = PoissonDiscSampling.GeneratePoints(samplingRadius, region.size, maxSamplingTries);
UnityEngine.Debug.Log($"Generated {points.Count} points");
SceneView.RepaintAll();
}

private void OnDrawGizmos()
{
// Draw Bounding box
Gizmos.color = Color.yellow;
Gizmos.DrawWireCube(region.center, region.size);

if (points == null) return;

Gizmos.color = Color.red;
foreach (var v in points)
{
Gizmos.DrawSphere((Vector3)v - region.extents, samplingRadius/10f);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using UnityEditor;
using UnityEngine;

namespace SpaceScrapper.Debug.PoissonSamplingTest
{

[CustomEditor(typeof(PointsManager), false)]
public class PointsManagerEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();

EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
if (GUILayout.Button("Generate"))
{
((PointsManager)target).GeneratePoints();
}
EditorGUI.EndDisabledGroup();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading