Rearranged modules to support variable size over time

This commit is contained in:
Nick J. Connors 2022-01-09 22:55:18 -05:00
parent eb00d9589f
commit 09a1d8a120
17 changed files with 268 additions and 82 deletions

View File

@ -1,4 +1,5 @@
using OWML.Utils; using NewHorizons.External.VariableSize;
using OWML.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -11,13 +12,13 @@ namespace NewHorizons.Builder.Body
{ {
static class LavaBuilder static class LavaBuilder
{ {
public static void Make(GameObject body, Sector sector, OWRigidbody rb, float lavaSize) public static void Make(GameObject body, Sector sector, OWRigidbody rb, LavaModule module)
{ {
var moltenCore = new GameObject("MoltenCore"); var moltenCore = new GameObject("MoltenCore");
moltenCore.SetActive(false); moltenCore.SetActive(false);
moltenCore.transform.parent = body.transform; moltenCore.transform.parent = body.transform;
moltenCore.transform.localPosition = Vector3.zero; moltenCore.transform.localPosition = Vector3.zero;
moltenCore.transform.localScale = Vector3.one * lavaSize; moltenCore.transform.localScale = Vector3.one * module.Radius;
var lavaSphere = GameObject.Instantiate(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere"), moltenCore.transform); var lavaSphere = GameObject.Instantiate(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere"), moltenCore.transform);
lavaSphere.transform.localScale = Vector3.one; lavaSphere.transform.localScale = Vector3.one;

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using NewHorizons.Utility; using NewHorizons.Utility;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using NewHorizons.External.VariableSize;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {

View File

@ -0,0 +1,18 @@
using NewHorizons.External.VariableSize;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Builder.Body
{
static class SandBuilder
{
public static void Make(GameObject go, Sector sector, OWRigidbody rb, SandModule module)
{
}
}
}

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using NewHorizons.Utility; using NewHorizons.Utility;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using NewHorizons.External.VariableSize;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
@ -26,7 +27,6 @@ namespace NewHorizons.Builder.Body
sunSurface.transform.localScale = Vector3.one; sunSurface.transform.localScale = Vector3.one;
sunSurface.name = "Surface"; sunSurface.name = "Surface";
//var sunLight = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight"), sunGO.transform);
var sunLight = new GameObject(); var sunLight = new GameObject();
sunLight.transform.parent = starGO.transform; sunLight.transform.parent = starGO.transform;
sunLight.transform.localPosition = Vector3.zero; sunLight.transform.localPosition = Vector3.zero;
@ -61,12 +61,26 @@ namespace NewHorizons.Builder.Body
sunAudio.name = "Audio_Star"; sunAudio.name = "Audio_Star";
/* if(starModule.HasAtmosphere)
{
var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform);
sunAtmosphere.transform.localPosition = Vector3.zero; sunAtmosphere.transform.localPosition = Vector3.zero;
sunAtmosphere.transform.localScale = Vector3.one; sunAtmosphere.transform.localScale = Vector3.one;
sunAtmosphere.name = "Atmosphere_Star"; sunAtmosphere.name = "Atmosphere_Star";
*/ PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent<PlanetaryFogController>();
if (starModule.Tint != null)
{
fog.fogTint = starModule.Tint.ToColor32();
sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one * (starModule.Size + 1000) / starModule.Size;
foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>())
{
lod.material.SetColor("_SkyColor", starModule.Tint.ToColor32());
lod.material.SetFloat("_InnerRadius", starModule.Size);
lod.material.SetFloat("_OuterRadius", starModule.Size + 1000);
}
}
fog.fogRadius = starModule.Size * 1.2f;
}
var ambientLightGO = GameObject.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), starGO.transform); var ambientLightGO = GameObject.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), starGO.transform);
ambientLightGO.transform.localPosition = Vector3.zero; ambientLightGO.transform.localPosition = Vector3.zero;
@ -84,7 +98,6 @@ namespace NewHorizons.Builder.Body
deathVolume.GetComponent<SphereCollider>().radius = 1f; deathVolume.GetComponent<SphereCollider>().radius = 1f;
deathVolume.name = "DestructionVolume"; deathVolume.name = "DestructionVolume";
//PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent<PlanetaryFogController>();
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>(); TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();
Light ambientLight = ambientLightGO.GetComponent<Light>(); Light ambientLight = ambientLightGO.GetComponent<Light>();
@ -103,12 +116,11 @@ namespace NewHorizons.Builder.Body
light.color = lightColour; light.color = lightColour;
ambientLight.color = lightColour; ambientLight.color = lightColour;
//fog.fogRadius = starModule.Size * 1.2f;
if(starModule.Tint != null) if(starModule.Tint != null)
{ {
var colour = starModule.Tint.ToColor32(); var colour = starModule.Tint.ToColor32();
//sunLightController.sunColor = colour; //sunLightController.sunColor = colour;
//fog.fogTint = colour;
var sun = GameObject.Find("Sun_Body"); var sun = GameObject.Find("Sun_Body");
var mainSequenceMaterial = sun.GetComponent<SunController>().GetValue<Material>("_startSurfaceMaterial"); var mainSequenceMaterial = sun.GetComponent<SunController>().GetValue<Material>("_startSurfaceMaterial");
@ -118,16 +130,6 @@ namespace NewHorizons.Builder.Body
var mod = 8f * starModule.SolarLuminosity / 255f; var mod = 8f * starModule.SolarLuminosity / 255f;
surface.sharedMaterial.color = new Color(colour.r * mod, colour.g * mod, colour.b * mod); surface.sharedMaterial.color = new Color(colour.r * mod, colour.g * mod, colour.b * mod);
surface.sharedMaterial.SetTexture("_ColorRamp", ImageUtilities.TintImage(_colorOverTime, colour)); surface.sharedMaterial.SetTexture("_ColorRamp", ImageUtilities.TintImage(_colorOverTime, colour));
/*
sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one * (starModule.Size + 1000)/starModule.Size;
foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>())
{
lod.material.SetColor("_SkyColor", colour);
lod.material.SetFloat("_InnerRadius", starModule.Size);
lod.material.SetFloat("_OuterRadius", starModule.Size + 1000);
}
*/
} }
if(starModule.SolarFlareTint != null) if(starModule.SolarFlareTint != null)

View File

@ -1,4 +1,5 @@
using NewHorizons.External; using NewHorizons.External;
using NewHorizons.External.VariableSize;
using OWML.Utils; using OWML.Utils;
using UnityEngine; using UnityEngine;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
@ -7,9 +8,9 @@ namespace NewHorizons.Builder.Body
{ {
static class WaterBuilder static class WaterBuilder
{ {
public static void Make(GameObject body, Sector sector, OWRigidbody rb, IPlanetConfig config) public static void Make(GameObject body, Sector sector, OWRigidbody rb, WaterModule module)
{ {
var waterSize = config.Base.WaterSize; var waterSize = module.Radius;
GameObject waterGO = new GameObject("Water"); GameObject waterGO = new GameObject("Water");
waterGO.SetActive(false); waterGO.SetActive(false);
@ -28,9 +29,9 @@ namespace NewHorizons.Builder.Body
for(int i = 0; i < GDSharedMaterials.Length; i++) for(int i = 0; i < GDSharedMaterials.Length; i++)
{ {
tempArray[i] = new Material(GDSharedMaterials[i]); tempArray[i] = new Material(GDSharedMaterials[i]);
if (config.Base.WaterTint != null) if (module.Tint != null)
{ {
tempArray[i].color = config.Base.WaterTint.ToColor32(); tempArray[i].color = module.Tint.ToColor32();
} }
} }
// TODO: Make water module // TODO: Make water module

View File

@ -15,10 +15,7 @@ namespace NewHorizons.External
public string GravityFallOff { get; set; } = "linear"; public string GravityFallOff { get; set; } = "linear";
public float SurfaceSize { get; set; } public float SurfaceSize { get; set; }
public float SphereOfInfluence { get; set; } public float SphereOfInfluence { get; set; }
public float WaterSize { get; set; }
public MColor32 WaterTint { get; set; }
public float GroundSize { get; set; } public float GroundSize { get; set; }
public float LavaSize { get; set; }
public bool HasCometTail { get; set; } public bool HasCometTail { get; set; }
public bool HasReferenceFrame { get; set; } = true; public bool HasReferenceFrame { get; set; } = true;
public bool CenterOfSolarSystem { get; set; } = false; public bool CenterOfSolarSystem { get; set; } = false;
@ -26,5 +23,8 @@ namespace NewHorizons.External
// Old, see SingularityModule instead // Old, see SingularityModule instead
public float BlackHoleSize { get; set; } public float BlackHoleSize { get; set; }
public float LavaSize { get; set; }
public float WaterSize { get; set; }
public MColor32 WaterTint { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using NewHorizons.Utility; using NewHorizons.External.VariableSize;
using NewHorizons.Utility;
namespace NewHorizons.External namespace NewHorizons.External
{ {
@ -8,7 +9,7 @@ namespace NewHorizons.External
string StarSystem { get; } string StarSystem { get; }
bool Destroy { get; } bool Destroy { get; }
int BuildPriority { get; } int BuildPriority { get; }
BaseModule Base {get;} BaseModule Base { get; }
AtmosphereModule Atmosphere { get; } AtmosphereModule Atmosphere { get; }
OrbitModule Orbit { get; } OrbitModule Orbit { get; }
RingModule Ring { get; } RingModule Ring { get; }
@ -21,5 +22,8 @@ namespace NewHorizons.External
SpawnModule Spawn { get; } SpawnModule Spawn { get; }
SignalModule Signal { get; } SignalModule Signal { get; }
SingularityModule Singularity { get; } SingularityModule Singularity { get; }
LavaModule Lava { get; }
SandModule Sand { get; }
WaterModule Water { get; }
} }
} }

View File

@ -1,4 +1,5 @@
using NewHorizons.Utility; using NewHorizons.External.VariableSize;
using NewHorizons.Utility;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@ -24,6 +25,9 @@ namespace NewHorizons.External
public SpawnModule Spawn { get; set; } public SpawnModule Spawn { get; set; }
public SignalModule Signal { get; set; } public SignalModule Signal { get; set; }
public SingularityModule Singularity { get; set; } public SingularityModule Singularity { get; set; }
public LavaModule Lava { get; set; }
public WaterModule Water { get; set; }
public SandModule Sand { get; set; }
public PlanetConfig(Dictionary<string, object> dict) public PlanetConfig(Dictionary<string, object> dict)
{ {

View File

@ -0,0 +1,15 @@
using NewHorizons.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.External.VariableSize
{
public class LavaModule : VariableSizeModule
{
public float Radius { get; set; }
public MColor32 Tint { get; set; }
}
}

View File

@ -4,9 +4,9 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NewHorizons.External namespace NewHorizons.External.VariableSize
{ {
public class RingModule : Module public class RingModule : VariableSizeModule
{ {
public float InnerRadius { get; set; } public float InnerRadius { get; set; }
public float OuterRadius { get; set; } public float OuterRadius { get; set; }

View File

@ -0,0 +1,15 @@
using NewHorizons.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.External.VariableSize
{
public class SandModule : VariableSizeModule
{
public float Radius { get; set; }
public MColor32 Tint { get; set; }
}
}

View File

@ -5,9 +5,9 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NewHorizons.External namespace NewHorizons.External.VariableSize
{ {
public class SingularityModule : Module public class SingularityModule : VariableSizeModule
{ {
public float Size; public float Size;
public string PairedSingularity; public string PairedSingularity;

View File

@ -5,14 +5,15 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NewHorizons.External namespace NewHorizons.External.VariableSize
{ {
public class StarModule : Module public class StarModule : VariableSizeModule
{ {
public float Size { get; set; } = 2000f; public float Size { get; set; } = 2000f;
public MColor32 Tint { get; set; } public MColor32 Tint { get; set; }
public MColor32 SolarFlareTint { get; set; } public MColor32 SolarFlareTint { get; set; }
public MColor32 LightTint { get; set; } public MColor32 LightTint { get; set; }
public float SolarLuminosity { get; set; } = 1f; public float SolarLuminosity { get; set; } = 1f;
public bool HasAtmosphere { get; set; } = true;
} }
} }

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.External.VariableSize
{
public class VariableSizeModule : Module
{
public TimeValuePair[] Curve { get; set; }
public class TimeValuePair
{
public float Time { get; set; }
public float Value { get; set; }
}
}
}

View File

@ -0,0 +1,15 @@
using NewHorizons.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.External.VariableSize
{
public class WaterModule : VariableSizeModule
{
public float Radius { get; set; }
public MColor32 Tint { get; set; }
}
}

View File

@ -6,6 +6,7 @@ using NewHorizons.Builder.Orbital;
using NewHorizons.Builder.Props; using NewHorizons.Builder.Props;
using NewHorizons.Components; using NewHorizons.Components;
using NewHorizons.External; using NewHorizons.External;
using NewHorizons.External.VariableSize;
using NewHorizons.OrbitalPhysics; using NewHorizons.OrbitalPhysics;
using NewHorizons.Utility; using NewHorizons.Utility;
using OWML.Common; using OWML.Common;
@ -506,11 +507,31 @@ namespace NewHorizons
if (body.Config.Base.HasCometTail) if (body.Config.Base.HasCometTail)
CometTailBuilder.Make(go, body.Config.Base, go.GetComponent<AstroObject>().GetPrimaryBody()); CometTailBuilder.Make(go, body.Config.Base, go.GetComponent<AstroObject>().GetPrimaryBody());
// Backwards compatability
if (body.Config.Base.LavaSize != 0) if (body.Config.Base.LavaSize != 0)
LavaBuilder.Make(go, sector, rb, body.Config.Base.LavaSize); {
var lava = new LavaModule();
lava.Radius = body.Config.Base.LavaSize;
LavaBuilder.Make(go, sector, rb, lava);
}
if (body.Config.Lava != null)
LavaBuilder.Make(go, sector, rb, body.Config.Lava);
// Backwards compatability
if (body.Config.Base.WaterSize != 0) if (body.Config.Base.WaterSize != 0)
WaterBuilder.Make(go, sector, rb, body.Config); {
var water = new WaterModule();
water.Radius = body.Config.Base.WaterSize;
water.Tint = body.Config.Base.WaterTint;
WaterBuilder.Make(go, sector, rb, water);
}
if (body.Config.Water != null)
WaterBuilder.Make(go, sector, rb, body.Config.Water);
if (body.Config.Sand != null)
SandBuilder.Make(go, sector, rb, body.Config.Sand);
if (body.Config.Atmosphere != null) if (body.Config.Atmosphere != null)
{ {

View File

@ -54,50 +54,11 @@
"default": 0, "default": 0,
"description": "An override for the radius of the planet's gravitational sphere of influence. Optional" "description": "An override for the radius of the planet's gravitational sphere of influence. Optional"
}, },
"waterSize": {
"type": "number",
"default": 0,
"description": "Sea level for the planet. Optional"
},
"waterTint": {
"type": "object",
"properties": {
"R": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 255
},
"G": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 255
},
"B": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 255
},
"A": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 255
}
}
},
"groundSize": { "groundSize": {
"type": "number", "type": "number",
"default": 0, "default": 0,
"description": "Radius of the a simple sphere used as the ground for the planet. If you want to use more complex terrain, leave this as 0." "description": "Radius of the a simple sphere used as the ground for the planet. If you want to use more complex terrain, leave this as 0."
}, },
"lavaSize": {
"type": "number",
"default": 0,
"description": "Radius of a sphere of lava. Optional."
},
"hasCometTail": { "hasCometTail": {
"type": "boolean", "type": "boolean",
"default": false "default": false
@ -171,7 +132,7 @@
"useBasicCloudShader": { "useBasicCloudShader": {
"type": "boolean", "type": "boolean",
"default": false, "default": false,
"description" : "Use Giant's deep shader or just apply the cloud texture as is." "description": "Use Giant's deep shader or just apply the cloud texture as is."
}, },
"fogTint": { "fogTint": {
"type": "object", "type": "object",
@ -585,6 +546,10 @@
"minimum": 0, "minimum": 0,
"description": "Relative strenght of the light compared to the sun", "description": "Relative strenght of the light compared to the sun",
"default": 1 "default": 1
},
"hasAtmosphere": {
"type": "boolean",
"default": true
} }
} }
}, },
@ -891,6 +856,110 @@
} }
} }
} }
},
"Water": {
"type": "object",
"properties": {
"radius": {
"type": "number",
"default": 0
},
"tint": {
"type": "object",
"properties": {
"R": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 255
},
"G": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 255
},
"B": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 255
},
"A": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 255
}
}
},
"curve": {
"type": "array",
"items": {
"type": "object",
"properties": {
"time": {
"type": "integer",
"default": 0
},
"value": {
"type": "integer",
"default": 0
}
}
}
}
}
},
"Lava": {
"type": "object",
"properties": {
"radius": {
"type": "number",
"default": 0
},
"curve": {
"type": "array",
"items": {
"type": "object",
"properties": {
"time": {
"type": "integer",
"default": 0
},
"value": {
"type": "integer",
"default": 0
}
}
}
}
}
},
"Sand": {
"type": "object",
"properties": {
"radius": {
"type": "number",
"default": 0
},
"curve": {
"type": "array",
"items": {
"type": "object",
"properties": {
"time": {
"type": "integer",
"default": 0
},
"value": {
"type": "integer",
"default": 0
}
}
}
}
}
} }
} }
} }