mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add min/max height to scatter
This commit is contained in:
parent
17ae3585a7
commit
00ef0e85f3
@ -52,6 +52,9 @@ namespace NewHorizons.Builder.Props
|
|||||||
else prefab = SearchUtilities.Find(propInfo.path);
|
else prefab = SearchUtilities.Find(propInfo.path);
|
||||||
for (int i = 0; i < propInfo.count; i++)
|
for (int i = 0; i < propInfo.count; i++)
|
||||||
{
|
{
|
||||||
|
// Failsafe
|
||||||
|
if (points.Count == 0) break;
|
||||||
|
|
||||||
var randomInd = (int)Random.Range(0, points.Count - 1);
|
var randomInd = (int)Random.Range(0, points.Count - 1);
|
||||||
var point = points[randomInd];
|
var point = points[randomInd];
|
||||||
|
|
||||||
@ -63,19 +66,25 @@ namespace NewHorizons.Builder.Props
|
|||||||
float latitude = sphericals.y;
|
float latitude = sphericals.y;
|
||||||
|
|
||||||
float sampleX = heightMapTexture.width * longitude / 360f;
|
float sampleX = heightMapTexture.width * longitude / 360f;
|
||||||
|
|
||||||
|
// Fix wrapping issue
|
||||||
|
if (sampleX > heightMapTexture.width) sampleX -= heightMapTexture.width;
|
||||||
|
if (sampleX < 0) sampleX += heightMapTexture.width;
|
||||||
|
|
||||||
float sampleY = heightMapTexture.height * latitude / 180f;
|
float sampleY = heightMapTexture.height * latitude / 180f;
|
||||||
|
|
||||||
float relativeHeight = heightMapTexture.GetPixel((int)sampleX, (int)sampleY).r;
|
float relativeHeight = heightMapTexture.GetPixel((int)sampleX, (int)sampleY).r;
|
||||||
height = (relativeHeight * (heightMap.maxHeight - heightMap.minHeight) + heightMap.minHeight);
|
height = (relativeHeight * (heightMap.maxHeight - heightMap.minHeight) + heightMap.minHeight);
|
||||||
|
|
||||||
|
if ((propInfo.minHeight != null && height < propInfo.minHeight) || (propInfo.maxHeight != null && height > propInfo.maxHeight))
|
||||||
|
{
|
||||||
|
// Try this point again
|
||||||
|
i--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Because heightmaps are dumb gotta rotate it 90 degrees around the x axis bc UHHHHHHHHHHHHH
|
// Because heightmaps are dumb gotta rotate it 90 degrees around the x axis bc UHHHHHHHHHHHHH
|
||||||
point = Quaternion.Euler(90, 0, 0) * point;
|
point = Quaternion.Euler(90, 0, 0) * point;
|
||||||
|
|
||||||
// Keep things mostly above water
|
|
||||||
if (config.Water != null && height - 1f < config.Water.size) continue;
|
|
||||||
|
|
||||||
// Move it slightly into the ground
|
|
||||||
height -= 0.01f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var prop = DetailBuilder.MakeDetail(go, sector, prefab, (MVector3)(point.normalized * height), null, propInfo.scale, true);
|
var prop = DetailBuilder.MakeDetail(go, sector, prefab, (MVector3)(point.normalized * height), null, propInfo.scale, true);
|
||||||
|
|||||||
10
NewHorizons/External/Modules/PropModule.cs
vendored
10
NewHorizons/External/Modules/PropModule.cs
vendored
@ -130,6 +130,16 @@ namespace NewHorizons.External.Modules
|
|||||||
/// The number used as entropy for scattering the props
|
/// The number used as entropy for scattering the props
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int seed;
|
public int seed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The lowest height that these object will be placed at (only relevant if there's a heightmap)
|
||||||
|
/// </summary>
|
||||||
|
public float? minHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The highest height that these objects will be placed at (only relevant if there's a heightmap)
|
||||||
|
/// </summary>
|
||||||
|
public float? maxHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonObject]
|
[JsonObject]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user