mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add preventOverlap option for better performance, fixed heights
This commit is contained in:
parent
45ea9f02c4
commit
9039c00908
@ -3,6 +3,8 @@ using NewHorizons.External.Modules;
|
||||
using NewHorizons.Utility;
|
||||
using OWML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
using Random = UnityEngine.Random;
|
||||
@ -19,6 +21,21 @@ namespace NewHorizons.Builder.Props
|
||||
{
|
||||
var heightMap = config.HeightMap;
|
||||
|
||||
var makeFibonacciSphere = scatterInfo.Any(x => x.preventOverlap);
|
||||
|
||||
List<Vector3> points = new();
|
||||
|
||||
if (makeFibonacciSphere)
|
||||
{
|
||||
var area = 4f * Mathf.PI * radius * radius;
|
||||
|
||||
// To not use more than 0.5GB of RAM while doing this
|
||||
// Works up to planets with 575 radius before capping
|
||||
var numPoints = Math.Min((int)(area * 10), 41666666);
|
||||
|
||||
points = RandomUtility.FibonacciSphere(numPoints);
|
||||
}
|
||||
|
||||
Texture2D heightMapTexture = null;
|
||||
if (heightMap != null)
|
||||
{
|
||||
@ -57,7 +74,18 @@ namespace NewHorizons.Builder.Props
|
||||
|
||||
for (int i = 0; i < propInfo.count; i++)
|
||||
{
|
||||
var point = Random.insideUnitSphere;
|
||||
Vector3 point;
|
||||
if (propInfo.preventOverlap)
|
||||
{
|
||||
if (points.Count == 0) break;
|
||||
var randomInd = (int)Random.Range(0, points.Count - 1);
|
||||
point = points[randomInd];
|
||||
points.QuickRemoveAt(randomInd);
|
||||
}
|
||||
else
|
||||
{
|
||||
point = Random.onUnitSphere;
|
||||
}
|
||||
|
||||
var height = radius;
|
||||
if (heightMapTexture != null)
|
||||
|
||||
5
NewHorizons/External/Modules/PropModule.cs
vendored
5
NewHorizons/External/Modules/PropModule.cs
vendored
@ -139,6 +139,11 @@ namespace NewHorizons.External.Modules
|
||||
/// The highest height that these objects will be placed at (only relevant if there's a heightmap)
|
||||
/// </summary>
|
||||
public float? maxHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Should we try to prevent overlap between the scattered details? True by default. If it's affecting load times turn it off.
|
||||
/// </summary>
|
||||
[DefaultValue(true)] public bool preventOverlap = true;
|
||||
}
|
||||
|
||||
[JsonObject]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user