Skip to content

Commit

Permalink
fix the heightmap proxy caster guy and also asteroid belt now (#1002)
Browse files Browse the repository at this point in the history
## Minor features
- Added an option to use a detail for asteroid belts, instead of just
procgen.
- Also added asteroid belt options for gravity and random orientation.

## Bug fixes
- Fixed the proxy shadow caster on heightmaps, so they cast shadows onto
other bodies better (fixes #1001)
  • Loading branch information
xen-42 authored Jan 6, 2025
2 parents 8752778 + 11d58e0 commit d983295
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 19 deletions.
37 changes: 28 additions & 9 deletions NewHorizons/Builder/Body/AsteroidBeltBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NewHorizons.External;
using NewHorizons.External.Configs;
using NewHorizons.External.Modules;
using NewHorizons.External.Modules.Props;
using NewHorizons.External.SerializableData;
using NewHorizons.Handlers;
using NewHorizons.Utility.OWML;
Expand Down Expand Up @@ -36,7 +37,7 @@ public static void Make(string bodyName, PlanetConfig parentConfig, IModBehaviou

config.Base = new BaseModule()
{
surfaceGravity = 1,
surfaceGravity = belt.gravity,
surfaceSize = size,
gravityFallOff = GravityFallOff.InverseSquared
};
Expand All @@ -49,7 +50,8 @@ public static void Make(string bodyName, PlanetConfig parentConfig, IModBehaviou
trueAnomaly = 360f * (i + Random.Range(-0.2f, 0.2f)) / (float)count,
primaryBody = bodyName,
semiMajorAxis = Random.Range(belt.innerRadius, belt.outerRadius),
showOrbitLine = false
showOrbitLine = false,
isTidallyLocked = true
};

config.ReferenceFrame = new ReferenceFrameModule()
Expand All @@ -62,20 +64,37 @@ public static void Make(string bodyName, PlanetConfig parentConfig, IModBehaviou
enabled = false
};

config.ProcGen = belt.procGen;
if (config.ProcGen == null)
if (!string.IsNullOrEmpty(belt.assetBundle) || !string.IsNullOrEmpty(belt.path))
{
config.ProcGen = new ProcGenModule()
config.Props = new PropModule()
{
scale = size,
color = new MColor(126, 94, 73)
details = new DetailInfo[1]
{
new DetailInfo()
{
assetBundle = belt.assetBundle,
path = belt.path,
scale = size,
rotation = belt.randomOrientation ? Random.rotation.eulerAngles : Vector3.zero,
keepLoaded = true
}
}
};

}
else
else if (belt.procGen != null)
{
// Still update the size
config.ProcGen = belt.procGen;
config.ProcGen.scale = size;
}
else
{
config.ProcGen = new ProcGenModule()
{
scale = size,
color = new MColor(126, 94, 73)
};
}

var asteroid = new NewHorizonsBody(config, mod);
PlanetCreationHandler.GenerateBody(asteroid);
Expand Down
7 changes: 4 additions & 3 deletions NewHorizons/Builder/Body/HeightMapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ public static GameObject Make(GameObject planetGO, Sector sector, HeightMapModul
level2.name += "1";

LODGroup.RecalculateBounds();

// do this only for LOD because only the main body uses LOD, while title screen and proxies dont
var superGroup = planetGO.GetComponent<ProxyShadowCasterSuperGroup>();
if (superGroup != null) level2.gameObject.AddComponent<ProxyShadowCaster>()._superGroup = superGroup;
}

var cubeSphereSC = cubeSphere.AddComponent<SphereCollider>();
cubeSphereSC.radius = Mathf.Min(module.minHeight, module.maxHeight) * Mathf.Min(stretch.x, stretch.y, stretch.z);

var superGroup = planetGO.GetComponent<ProxyShadowCasterSuperGroup>();
if (superGroup != null) cubeSphere.AddComponent<ProxyShadowCaster>()._superGroup = superGroup;

cubeSphere.SetActive(true);

// Now that we've made the mesh we can delete the heightmap texture
Expand Down
33 changes: 29 additions & 4 deletions NewHorizons/External/Modules/AsteroidBeltModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.ComponentModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;

Expand All @@ -13,7 +13,7 @@ public class AsteroidBeltModule
[Range(-1, 200)] [DefaultValue(-1)] public int amount = -1;

/// <summary>
/// Angle between the rings and the equatorial plane of the planet.
/// Angle between the belt and the equatorial plane of the planet.
/// </summary>
public float inclination;

Expand All @@ -23,7 +23,7 @@ public class AsteroidBeltModule
[Range(0f, double.MaxValue)] public float innerRadius;

/// <summary>
/// Angle defining the point where the rings rise up from the planet's equatorial plane if inclination is nonzero.
/// Angle defining the point where the belt rises up from the planet's equatorial plane if inclination is nonzero.
/// </summary>
public float longitudeOfAscendingNode;

Expand All @@ -45,13 +45,38 @@ public class AsteroidBeltModule
[Range(0f, double.MaxValue)] public float outerRadius;

/// <summary>
/// How the asteroids are generated
/// How the asteroids are generated, unless you supply a detail yourself using "assetBundle" and "path"
/// </summary>
public ProcGenModule procGen;

/// <summary>
/// Number used to randomize asteroid positions
/// </summary>
public int randomSeed;

/// <summary>
/// You can use this to load a custom asset or ingame object, instead of using ProcGen. It will be scaled by "minSize" and "maxSize", so ideally it should be near a 1 meter radius.
/// This is a relative filepath to an asset-bundle to load the prefab defined in `path` from.
/// </summary>
public string assetBundle;

/// <summary>
/// You can use this to load a custom asset or ingame object, instead of using ProcGen. It will be scaled by "minSize" and "maxSize", so ideally it should be near a 1 meter radius.
/// This is either the path in the scene hierarchy of the item to copy or the path to the object in the supplied asset bundle.
/// </summary>
public string path;

/// <summary>
/// Surface gravity of the asteroids.
/// </summary>
[Range(0f, double.MaxValue)]
[DefaultValue(1)]
public float gravity = 1f;

/// <summary>
/// Should the detail of the asteroid be randomly oriented, or should it point towards the center.
/// </summary>
[DefaultValue(true)]
public bool randomOrientation = true;
}
}
26 changes: 23 additions & 3 deletions NewHorizons/Schemas/body_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
},
"inclination": {
"type": "number",
"description": "Angle between the rings and the equatorial plane of the planet.",
"description": "Angle between the belt and the equatorial plane of the planet.",
"format": "float"
},
"innerRadius": {
Expand All @@ -291,7 +291,7 @@
},
"longitudeOfAscendingNode": {
"type": "number",
"description": "Angle defining the point where the rings rise up from the planet's equatorial plane if inclination is nonzero.",
"description": "Angle defining the point where the belt rises up from the planet's equatorial plane if inclination is nonzero.",
"format": "float"
},
"maxSize": {
Expand All @@ -315,13 +315,33 @@
"minimum": 0.0
},
"procGen": {
"description": "How the asteroids are generated",
"description": "How the asteroids are generated, unless you supply a detail yourself using \"assetBundle\" and \"path\"",
"$ref": "#/definitions/ProcGenModule"
},
"randomSeed": {
"type": "integer",
"description": "Number used to randomize asteroid positions",
"format": "int32"
},
"assetBundle": {
"type": "string",
"description": "You can use this to load a custom asset or ingame object, instead of using ProcGen. It will be scaled by \"minSize\" and \"maxSize\", so ideally it should be near a 1 meter radius.\nThis is a relative filepath to an asset-bundle to load the prefab defined in `path` from."
},
"path": {
"type": "string",
"description": "You can use this to load a custom asset or ingame object, instead of using ProcGen. It will be scaled by \"minSize\" and \"maxSize\", so ideally it should be near a 1 meter radius.\nThis is either the path in the scene hierarchy of the item to copy or the path to the object in the supplied asset bundle. "
},
"gravity": {
"type": "number",
"description": "Surface gravity of the asteroids.",
"format": "float",
"default": 1,
"minimum": 0.0
},
"randomOrientation": {
"type": "boolean",
"description": "Should the detail of the asteroid be randomly oriented, or should it point towards the center.",
"default": true
}
}
},
Expand Down

0 comments on commit d983295

Please sign in to comment.