mirror of
https://github.com/Xevion/procedural-placement.git
synced 2025-12-06 17:16:03 -06:00
fix poisson disc sampling
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NUnit.Framework.Constraints;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public static class PointGeneration {
|
public static class PointGeneration {
|
||||||
@@ -11,7 +10,7 @@ public static class PointGeneration {
|
|||||||
new Vector2(
|
new Vector2(
|
||||||
Random.Range(0, regionSize.x * 2),
|
Random.Range(0, regionSize.x * 2),
|
||||||
Random.Range(0, regionSize.y * 2)
|
Random.Range(0, regionSize.y * 2)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return points;
|
return points;
|
||||||
@@ -56,6 +55,7 @@ public static class PointGeneration {
|
|||||||
private static bool IsValidPoint(Vector2 point, Vector2 region) {
|
private static bool IsValidPoint(Vector2 point, Vector2 region) {
|
||||||
return point.x >= 0 && point.y >= 0 && point.x < region.x && point.y < region.y;
|
return point.x >= 0 && point.y >= 0 && point.x < region.x && point.y < region.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool poisson_valid(Vector2 candidate, Vector2 regionSize, float cellSize, List<Vector2> points,
|
private static bool poisson_valid(Vector2 candidate, Vector2 regionSize, float cellSize, List<Vector2> points,
|
||||||
int[,] grid, float radius) {
|
int[,] grid, float radius) {
|
||||||
// Check that the point is valid
|
// Check that the point is valid
|
||||||
@@ -71,13 +71,13 @@ public static class PointGeneration {
|
|||||||
|
|
||||||
for (int x = searchStartX; x <= searchEndX; x++) {
|
for (int x = searchStartX; x <= searchEndX; x++) {
|
||||||
for (int y = searchStartY; y <= searchEndY; y++) {
|
for (int y = searchStartY; y <= searchEndY; y++) {
|
||||||
|
// Acquire the index of the point responsible
|
||||||
int pointIndex = grid[x, y] - 1;
|
int pointIndex = grid[x, y] - 1;
|
||||||
if (pointIndex == -1) continue;
|
if (pointIndex == -1) continue; // Don't calculate
|
||||||
|
|
||||||
float sqrDst = (candidate - points[pointIndex]).sqrMagnitude;
|
float sqrDst = (candidate - points[pointIndex]).sqrMagnitude;
|
||||||
if (sqrDst < radius * radius) {
|
if (sqrDst < radius * radius)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,9 +149,10 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 95149e3ad64fa7149affeaeb9f8e273b, type: 3}
|
m_Script: {fileID: 11500000, guid: 95149e3ad64fa7149affeaeb9f8e273b, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
numPoints: 50000
|
samplingMethod: 1
|
||||||
cubeSize: 0.1
|
numPoints: 428
|
||||||
regionSize: {x: 50, y: 50}
|
sphereSize: 0.18
|
||||||
|
regionSize: {x: 180, y: 100}
|
||||||
--- !u!4 &2048189740
|
--- !u!4 &2048189740
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user