mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Basic prop scatterer + raft attempts
This commit is contained in:
parent
749e776c98
commit
b6568f3325
@ -18,7 +18,7 @@ namespace NewHorizons.Builder.Body
|
||||
icosphere.transform.rotation = Quaternion.Euler(90, 0, 0);
|
||||
icosphere.transform.localPosition = Vector3.zero;
|
||||
|
||||
Mesh mesh = Icosphere.Build(3, module.Scale, module.Scale * 1.2f);
|
||||
Mesh mesh = Icosphere.Build(4, module.Scale, module.Scale * 1.2f);
|
||||
|
||||
icosphere.AddComponent<MeshFilter>();
|
||||
icosphere.GetComponent<MeshFilter>().mesh = mesh;
|
||||
|
||||
@ -54,7 +54,17 @@ namespace NewHorizons.Builder.Body
|
||||
heatVolume.transform.localPosition = Vector3.zero;
|
||||
heatVolume.transform.localScale = Vector3.one;
|
||||
heatVolume.GetComponent<SphereShape>().radius = 1f;
|
||||
heatVolume.name = "HeatVolume";
|
||||
heatVolume.name = "HeatVolume";
|
||||
|
||||
var deathVolume = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/ScaledVolumesRoot/DestructionFluidVolume"), sunGO.transform);
|
||||
deathVolume.transform.localPosition = Vector3.zero;
|
||||
deathVolume.transform.localScale = Vector3.one;
|
||||
deathVolume.GetComponent<SphereCollider>().radius = 1f;
|
||||
deathVolume.name = "DestructionVolume";
|
||||
|
||||
GameObject.Destroy(sunLight.GetComponent<FaceActiveCamera>());
|
||||
GameObject.Destroy(sunLight.GetComponent<CSMTextureCacher>());
|
||||
GameObject.Destroy(sunLight.GetComponent<ProxyShadowLight>());
|
||||
|
||||
PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent<PlanetaryFogController>();
|
||||
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();
|
||||
@ -62,6 +72,8 @@ namespace NewHorizons.Builder.Body
|
||||
SunLightController sunLightController = sunLight.GetComponent<SunLightController>();
|
||||
GameObject.Destroy(sunLight.GetComponent<SunLightParamUpdater>());
|
||||
|
||||
GameObject.Destroy(sunLightController);
|
||||
|
||||
if(starModule.Tint != null)
|
||||
{
|
||||
var colour = starModule.Tint.ToColor32();
|
||||
|
||||
@ -22,9 +22,6 @@ namespace NewHorizons.Builder.Body
|
||||
TSR.maxLOD = 7;
|
||||
TSR.LODBias = 2;
|
||||
TSR.LODRadius = 2f;
|
||||
|
||||
//TessSphereSectorToggle TSST = waterGO.AddComponent<TessSphereSectorToggle>();
|
||||
//TSST.SetValue("_sector", sector);
|
||||
|
||||
OceanEffectController OEC = waterGO.AddComponent<OceanEffectController>();
|
||||
OEC.SetValue("_sector", sector);
|
||||
|
||||
@ -13,7 +13,7 @@ namespace NewHorizons.Builder.General
|
||||
{
|
||||
static class DetectorBuilder
|
||||
{
|
||||
public static void Make(GameObject body, OWRigidbody OWRB, AstroObject primaryBody, AstroObject astroObject)
|
||||
public static void Make(GameObject body, OWRigidbody OWRB, AstroObject primaryBody, AstroObject astroObject, bool inherit = true)
|
||||
{
|
||||
GameObject detectorGO = new GameObject("FieldDetector");
|
||||
detectorGO.SetActive(false);
|
||||
@ -22,7 +22,7 @@ namespace NewHorizons.Builder.General
|
||||
detectorGO.layer = 20;
|
||||
|
||||
ConstantForceDetector forceDetector = detectorGO.AddComponent<ConstantForceDetector>();
|
||||
forceDetector.SetValue("_inheritElement0", true);
|
||||
forceDetector.SetValue("_inheritElement0", inherit);
|
||||
OWRB.RegisterAttachedForceDetector(forceDetector);
|
||||
|
||||
GravityVolume parentGravityVolume = primaryBody.GetAttachedOWRigidbody().GetAttachedGravityVolume();
|
||||
@ -30,7 +30,7 @@ namespace NewHorizons.Builder.General
|
||||
{
|
||||
forceDetector.SetValue("_detectableFields", new ForceVolume[] { parentGravityVolume });
|
||||
}
|
||||
else
|
||||
else if (astroObject != null)
|
||||
{
|
||||
// It's probably a focal point (or its just broken)
|
||||
var binaryFocalPoint = primaryBody.gameObject.GetComponent<BinaryFocalPoint>();
|
||||
@ -109,8 +109,6 @@ namespace NewHorizons.Builder.General
|
||||
primary.transform.position = point.transform.position + r1 * separation.normalized;
|
||||
secondary.transform.position = point.transform.position - r2 * separation.normalized;
|
||||
|
||||
Logger.Log($"{primary.transform.position}, {secondary.transform.position}, {point.transform.position}");
|
||||
|
||||
// Set detectable fields
|
||||
primaryCFD.SetValue("_detectableFields", new ForceVolume[] { secondaryGV });
|
||||
primaryCFD.SetValue("_inheritDetector", point.GetAttachedOWRigidbody().GetAttachedForceDetector());
|
||||
@ -121,13 +119,6 @@ namespace NewHorizons.Builder.General
|
||||
secondaryCFD.SetValue("_inheritDetector", point.GetAttachedOWRigidbody().GetAttachedForceDetector());
|
||||
secondaryCFD.SetValue("_activeInheritedDetector", point.GetAttachedOWRigidbody().GetAttachedForceDetector());
|
||||
secondaryCFD.SetValue("_inheritElement0", false);
|
||||
|
||||
// Update speeds
|
||||
var direction = Vector3.Cross(separation, Vector3.up).normalized;
|
||||
var m1 = Gm1 / GravityVolume.GRAVITATIONAL_CONSTANT;
|
||||
var m2 = Gm2 / GravityVolume.GRAVITATIONAL_CONSTANT;
|
||||
var reducedMass = m1 * m2 / (m1 + m2);
|
||||
var totalMass = m1 + m2;
|
||||
|
||||
// They must have the same eccentricity
|
||||
var parameterizedAstroObject = primary.GetComponent<ParameterizedAstroObject>();
|
||||
@ -145,6 +136,15 @@ namespace NewHorizons.Builder.General
|
||||
p = parameterizedAstroObject.keplerElements.ArgumentOfPeriapsis;
|
||||
}
|
||||
|
||||
// Update speeds
|
||||
var direction = Vector3.Cross(separation, Vector3.up).normalized;
|
||||
if (direction.sqrMagnitude == 0) direction = Vector3.left;
|
||||
|
||||
var m1 = Gm1 / GravityVolume.GRAVITATIONAL_CONSTANT;
|
||||
var m2 = Gm2 / GravityVolume.GRAVITATIONAL_CONSTANT;
|
||||
var reducedMass = m1 * m2 / (m1 + m2);
|
||||
var totalMass = m1 + m2;
|
||||
|
||||
var r = separation.magnitude;
|
||||
|
||||
// Start them off at their periapsis
|
||||
@ -156,38 +156,58 @@ namespace NewHorizons.Builder.General
|
||||
if(parameterizedAstroObject2 != null) parameterizedAstroObject2.keplerElements = secondaryKeplerElements;
|
||||
|
||||
// Finally we update the speeds
|
||||
var b = r * Mathf.Sqrt(1 - ecc * ecc);
|
||||
float v = Mathf.Sqrt(GravityVolume.GRAVITATIONAL_CONSTANT * totalMass * (1 - ecc * ecc) / Mathf.Pow(r, exponent - 1));
|
||||
var v2 = v / (1f + (m2 / m2));
|
||||
var v2 = v / (1f + (m2 / m1));
|
||||
var v1 = v - v2;
|
||||
|
||||
// Rotate around argument of periapsis
|
||||
var periapsisRotation = Quaternion.AngleAxis(p, Vector3.up);
|
||||
var ascendingAxis = Quaternion.AngleAxis(p + l, Vector3.up) * Vector3.right;
|
||||
var longitudeRotation = Quaternion.AngleAxis(i, ascendingAxis);
|
||||
|
||||
//direction = periapsisRotation * longitudeRotation * direction;
|
||||
// Rotate
|
||||
var rot = Quaternion.AngleAxis(l + p + 180f, Vector3.up);
|
||||
var incAxis = Quaternion.AngleAxis(l, Vector3.up) * Vector3.left;
|
||||
var incRot = Quaternion.AngleAxis(i, incAxis);
|
||||
|
||||
//Do this next tick for... reasons?
|
||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => primaryRB.SetVelocity(direction * v1));
|
||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => secondaryRB.SetVelocity(direction * -v2));
|
||||
var focalPointMotion = point.gameObject.GetComponent<InitialMotion>();
|
||||
var focalPointVelocity = focalPointMotion == null ? Vector3.zero : focalPointMotion.GetInitVelocity();
|
||||
|
||||
var d1 = Vector3.Cross(OrbitalHelper.RotateTo(Vector3.up, primaryKeplerElements), separation.normalized);
|
||||
var d2 = Vector3.Cross(OrbitalHelper.RotateTo(Vector3.up, primaryKeplerElements), separation.normalized);
|
||||
|
||||
var primaryInitialMotion = primary.gameObject.GetComponent<InitialMotion>();
|
||||
primaryInitialMotion.SetValue("_initLinearDirection", d1);
|
||||
primaryInitialMotion.SetValue("_initLinearSpeed", v1);
|
||||
|
||||
var secondaryInitialMotion = secondary.gameObject.GetComponent<InitialMotion>();
|
||||
secondaryInitialMotion.SetValue("_initLinearDirection", d2);
|
||||
secondaryInitialMotion.SetValue("_initLinearSpeed", -v2);
|
||||
|
||||
Logger.Log($"Velocity: {d1}, {v1}, {d2}, {v2}");
|
||||
|
||||
// InitialMotion already set its speed so we overwrite that
|
||||
if (!primaryInitialMotion.GetValue<bool>("_isInitVelocityDirty"))
|
||||
{
|
||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => primaryRB.SetVelocity(d1 * v1 + focalPointVelocity));
|
||||
}
|
||||
if (!secondaryInitialMotion.GetValue<bool>("_isInitVelocityDirty"))
|
||||
{
|
||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => primaryRB.SetVelocity(d2 * -v2 + focalPointVelocity));
|
||||
}
|
||||
|
||||
// If they have tracking orbits set the period
|
||||
var period = 2 * Mathf.PI * Mathf.Sqrt(Mathf.Pow(r, exponent + 1) / (GravityVolume.GRAVITATIONAL_CONSTANT * totalMass));
|
||||
|
||||
if (exponent == 1) period /= 3f;
|
||||
|
||||
// Only one of these won't be null, the other one gets done next tick
|
||||
var trackingOrbitPrimary = primary.GetComponentInChildren<TrackingOrbitLine>();
|
||||
if (trackingOrbitPrimary != null)
|
||||
{
|
||||
trackingOrbitPrimary.TrailTime = period;
|
||||
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => trackingOrbitPrimary.ResetLineVertices(), 15);
|
||||
}
|
||||
|
||||
var trackingOrbitSecondary = secondary.GetComponentInChildren<TrackingOrbitLine>();
|
||||
if (trackingOrbitSecondary != null)
|
||||
{
|
||||
trackingOrbitSecondary.TrailTime = period;
|
||||
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => trackingOrbitSecondary.ResetLineVertices(), 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ namespace NewHorizons.Builder.General
|
||||
{
|
||||
static class GravityBuilder
|
||||
{
|
||||
public static void Make(GameObject body, AstroObject ao, float surfaceAccel, float upperSurface, float lowerSurface, string falloffType)
|
||||
public static void Make(GameObject body, AstroObject ao, float surfaceAccel, float sphereOfInfluence, float surface, string falloffType)
|
||||
{
|
||||
GameObject gravityGO = new GameObject("GravityWell");
|
||||
gravityGO.transform.parent = body.transform;
|
||||
@ -18,7 +18,7 @@ namespace NewHorizons.Builder.General
|
||||
|
||||
SphereCollider SC = gravityGO.AddComponent<SphereCollider>();
|
||||
SC.isTrigger = true;
|
||||
SC.radius = 2 * upperSurface;
|
||||
SC.radius = sphereOfInfluence;
|
||||
|
||||
OWCollider OWC = gravityGO.AddComponent<OWCollider>();
|
||||
OWC.SetLODActivationMask(DynamicOccupant.Player);
|
||||
@ -28,8 +28,8 @@ namespace NewHorizons.Builder.General
|
||||
GravityVolume GV = gravityGO.AddComponent<GravityVolume>();
|
||||
GV.SetValue("_cutoffAcceleration", 0.1f);
|
||||
GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField(falloffType).GetValue(GV));
|
||||
GV.SetValue("_alignmentRadius", 0.75f * upperSurface);
|
||||
GV.SetValue("_upperSurfaceRadius", lowerSurface);
|
||||
GV.SetValue("_alignmentRadius", 1.5f * surface);
|
||||
GV.SetValue("_upperSurfaceRadius", surface);
|
||||
GV.SetValue("_lowerSurfaceRadius", 0);
|
||||
GV.SetValue("_layer", 3);
|
||||
GV.SetValue("_priority", 0);
|
||||
|
||||
@ -104,6 +104,17 @@ namespace NewHorizons.Builder.General
|
||||
ao.transform.root.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public static void RemoveDistantProxyClones()
|
||||
{
|
||||
foreach(ProxyBody proxy in GameObject.FindObjectsOfType<ProxyBody>())
|
||||
{
|
||||
if(proxy.transform.name.Contains("_DistantProxy(Clone"))
|
||||
{
|
||||
GameObject.Destroy(proxy.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RemoveProxy(string name)
|
||||
{
|
||||
if (name.Equals("TowerTwin")) name = "AshTwin";
|
||||
|
||||
@ -35,9 +35,9 @@ namespace NewHorizons.Builder.Orbital
|
||||
if (config.Orbit.Tint != null) color = config.Orbit.Tint.ToColor32();
|
||||
else if (config.Star != null) color = config.Star.Tint.ToColor32();
|
||||
else if (config.Atmosphere != null && config.Atmosphere.CloudTint != null) color = config.Atmosphere.CloudTint.ToColor32();
|
||||
else if (config.Base.BlackHoleSize != 0) color = new Color(1f, 0f, 1f);
|
||||
else if (config.Base.WaterSize != 0) color = Color.blue;
|
||||
else if (config.Base.LavaSize != 0) color = Color.red;
|
||||
else if (config.Base.BlackHoleSize != 0) color = new Color(1f, 0.5f, 1f);
|
||||
else if (config.Base.WaterSize != 0) color = new Color(0.5f, 0.5f, 1f);
|
||||
else if (config.Base.LavaSize != 0) color = new Color(1f, 0.5f, 0.5f);
|
||||
orbitLine.SetValue("_color", color);
|
||||
|
||||
orbitLine.SetValue("_astroObject", astroobject);
|
||||
|
||||
63
NewHorizons/Builder/Props/PlanetaryRaftController.cs
Normal file
63
NewHorizons/Builder/Props/PlanetaryRaftController.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Builder.Props
|
||||
{
|
||||
public class PlanetaryRaftController : MonoBehaviour
|
||||
{
|
||||
private LightSensor[] _lightSensors;
|
||||
private float _acceleration = 5f;
|
||||
private Vector3 _localAcceleration = Vector3.zero;
|
||||
private OWRigidbody _raftBody;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
this._raftBody = base.GetComponent<OWRigidbody>();
|
||||
_lightSensors = GetComponentsInChildren<LightSensor>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (this._lightSensors[0].IsIlluminated())
|
||||
{
|
||||
this._localAcceleration += Vector3.forward * this._acceleration;
|
||||
}
|
||||
if (this._lightSensors[1].IsIlluminated())
|
||||
{
|
||||
this._localAcceleration += Vector3.right * this._acceleration;
|
||||
}
|
||||
if (this._lightSensors[2].IsIlluminated())
|
||||
{
|
||||
this._localAcceleration -= Vector3.forward * this._acceleration;
|
||||
}
|
||||
if (this._lightSensors[3].IsIlluminated())
|
||||
{
|
||||
this._localAcceleration -= Vector3.right * this._acceleration;
|
||||
}
|
||||
if (this._localAcceleration.sqrMagnitude > 0.001f)
|
||||
{
|
||||
this._raftBody.AddLocalAcceleration(this._localAcceleration);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOccupantEnterSector(SectorDetector sectorDetector)
|
||||
{
|
||||
if (sectorDetector.GetOccupantType() == DynamicOccupant.Player)
|
||||
{
|
||||
_raftBody.Unsuspend();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOccupantExitSector(SectorDetector sectorDetector)
|
||||
{
|
||||
if (sectorDetector.GetOccupantType() == DynamicOccupant.Player)
|
||||
{
|
||||
_raftBody.Suspend();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
84
NewHorizons/Builder/Props/PropBuilder.cs
Normal file
84
NewHorizons/Builder/Props/PropBuilder.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using NewHorizons.External;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace NewHorizons.Builder.Props
|
||||
{
|
||||
public static class PropBuilder
|
||||
{
|
||||
public static void Make(GameObject body, string propToClone, Vector3 position, Sector sector)
|
||||
{
|
||||
var prefab = GameObject.Find(propToClone);
|
||||
Make(body, prefab, position, sector);
|
||||
}
|
||||
|
||||
public static void Make(GameObject body, GameObject prefab, Vector3 position, Sector sector)
|
||||
{
|
||||
if (prefab == null) return;
|
||||
|
||||
GameObject prop = GameObject.Instantiate(prefab, sector.transform);
|
||||
prop.transform.localPosition = position;
|
||||
prop.transform.rotation = Quaternion.FromToRotation(prop.transform.TransformDirection(Vector3.up), position.normalized);
|
||||
|
||||
List<string> assetBundles = new List<string>();
|
||||
foreach (var streamingHandle in prop.GetComponentsInChildren<StreamingMeshHandle>())
|
||||
{
|
||||
var assetBundle = streamingHandle.assetBundle;
|
||||
if (!assetBundles.Contains(assetBundle))
|
||||
{
|
||||
assetBundles.Add(assetBundle);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var assetBundle in assetBundles)
|
||||
{
|
||||
StreamingManager.LoadStreamingAssets(assetBundle);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Scatter(GameObject body, PropModule.ScatterInfo[] scatterInfo, float radius, Sector sector)
|
||||
{
|
||||
var area = 4f * Mathf.PI * radius * radius;
|
||||
var points = FibonacciSphere((int)area);
|
||||
|
||||
foreach (var scatterer in scatterInfo)
|
||||
{
|
||||
var prefab = GameObject.Find(scatterer.path);
|
||||
for(int i = 0; i < scatterer.count; i++)
|
||||
{
|
||||
var randomInd = (int)Random.Range(0, points.Count);
|
||||
var point = points[randomInd];
|
||||
Make(body, prefab, point * radius, sector);
|
||||
points.RemoveAt(randomInd);
|
||||
if (points.Count == 0) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Vector3> FibonacciSphere(int samples)
|
||||
{
|
||||
List<Vector3> points = new List<Vector3>();
|
||||
|
||||
var phi = Mathf.PI * (3f - Mathf.Sqrt(5f));
|
||||
|
||||
for(int i = 0; i < samples; i++)
|
||||
{
|
||||
var y = 1 - (i / (float)(samples - 1)) * 2f;
|
||||
var radius = Mathf.Sqrt(1 - y * y);
|
||||
|
||||
var theta = phi * i;
|
||||
|
||||
var x = Mathf.Cos(theta) * radius;
|
||||
var z = Mathf.Sin(theta) * radius;
|
||||
|
||||
points.Add(new Vector3(x, y, z));
|
||||
}
|
||||
return points;
|
||||
}
|
||||
}
|
||||
}
|
||||
73
NewHorizons/Builder/Props/RaftBuilder.cs
Normal file
73
NewHorizons/Builder/Props/RaftBuilder.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using NewHorizons.Builder.General;
|
||||
using OWML.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Logger = NewHorizons.Utility.Logger;
|
||||
|
||||
namespace NewHorizons.Builder.Props
|
||||
{
|
||||
public static class RaftBuilder
|
||||
{
|
||||
private static GameObject originalRaft;
|
||||
|
||||
public static void Make(GameObject body, Vector3 position, Sector sector, OWRigidbody OWRB, AstroObject ao)
|
||||
{
|
||||
if(originalRaft == null) originalRaft = GameObject.Instantiate(GameObject.Find("RingWorld_Body/Sector_RingInterior/Interactibles_RingInterior/Rafts/Raft_Body"));
|
||||
|
||||
GameObject raftObject = new GameObject($"{body.name}Raft");
|
||||
|
||||
GameObject lightSensors = GameObject.Instantiate(GameObject.Find("RingWorld_Body/Sector_RingInterior/Sector_Zone2/Structures_Zone2/RaftHouse_Eye_Zone2/Interactables_RaftHouse_Eye_Zone2/Prefab_IP_RaftDock/RaftSocket/Raft_Body (7)/LightSensorRoot"), raftObject.transform);
|
||||
GameObject geometry = GameObject.Instantiate(GameObject.Find("RingWorld_Body/Sector_RingInterior/Sector_Zone2/Structures_Zone2/RaftHouse_Eye_Zone2/Interactables_RaftHouse_Eye_Zone2/Prefab_IP_RaftDock/RaftSocket/Raft_Body (7)/Structure_IP_Raft"), raftObject.transform);
|
||||
GameObject colliders = GameObject.Instantiate(GameObject.Find("RingWorld_Body/Sector_RingInterior/Sector_Zone2/Structures_Zone2/RaftHouse_Eye_Zone2/Interactables_RaftHouse_Eye_Zone2/Prefab_IP_RaftDock/RaftSocket/Raft_Body (7)/Colliders/"), raftObject.transform);
|
||||
|
||||
raftObject.transform.parent = sector.transform;
|
||||
raftObject.transform.localPosition = position;
|
||||
raftObject.transform.rotation = Quaternion.FromToRotation(raftObject.transform.TransformDirection(Vector3.up), position.normalized);
|
||||
|
||||
foreach (var l in lightSensors.GetComponentsInChildren<SingleLightSensor>())
|
||||
{
|
||||
l.SetValue("_sector", sector);
|
||||
l.OnDetectLight += () => Logger.Log("LIGHT!!!");
|
||||
l.SetValue("_lightSourceMask", LightSourceType.FLASHLIGHT);
|
||||
l.SetDetectorActive(true);
|
||||
l.gameObject.SetActive(true);
|
||||
Logger.Log($"{l}");
|
||||
}
|
||||
|
||||
foreach (var child in raftObject.GetComponentsInChildren<StreamingRenderMeshHandle>())
|
||||
{
|
||||
StreamingManager.LoadStreamingAssets(child.assetBundle);
|
||||
}
|
||||
|
||||
var a = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
a.transform.parent = raftObject.transform;
|
||||
a.transform.localPosition = Vector3.zero;
|
||||
|
||||
//raftObject.AddComponent<PlanetaryRaftController>();
|
||||
|
||||
/*
|
||||
var raftRB = raftObject.AddComponent<OWRigidbody>();
|
||||
raftObject.AddComponent<Rigidbody>();
|
||||
raftObject.AddComponent<KinematicRigidbody>();
|
||||
raftRB.SetVelocity(OWRB.GetVelocity());
|
||||
|
||||
var motion = raftObject.AddComponent<MatchInitialMotion>();
|
||||
motion.SetBodyToMatch(OWRB);
|
||||
|
||||
DetectorBuilder.Make(raftObject, raftRB, ao, null, false);
|
||||
|
||||
var targetBodyAlignment = raftObject.AddComponent<AlignWithTargetBody>();
|
||||
targetBodyAlignment.SetTargetBody(OWRB);
|
||||
targetBodyAlignment.SetUsePhysicsToRotate(true);
|
||||
|
||||
raftObject.GetComponent<CenterOfTheUniverseOffsetApplier>().Init(raftRB);
|
||||
*/
|
||||
|
||||
raftObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
NewHorizons/External/IPlanetConfig.cs
vendored
1
NewHorizons/External/IPlanetConfig.cs
vendored
@ -16,6 +16,7 @@ namespace NewHorizons.External
|
||||
AsteroidBeltModule AsteroidBelt { get; }
|
||||
StarModule Star { get; }
|
||||
FocalPointModule FocalPoint { get; }
|
||||
PropModule Props { get; }
|
||||
SpawnModule Spawn { get; }
|
||||
}
|
||||
}
|
||||
|
||||
42
NewHorizons/External/PlanetConfig.cs
vendored
42
NewHorizons/External/PlanetConfig.cs
vendored
@ -20,6 +20,7 @@ namespace NewHorizons.External
|
||||
public AsteroidBeltModule AsteroidBelt { get; set; }
|
||||
public StarModule Star { get; set; }
|
||||
public FocalPointModule FocalPoint { get; set; }
|
||||
public PropModule Props { get; set; }
|
||||
public SpawnModule Spawn { get; set; }
|
||||
|
||||
public PlanetConfig(Dictionary<string, object> dict)
|
||||
@ -55,47 +56,6 @@ namespace NewHorizons.External
|
||||
}
|
||||
}
|
||||
else Logger.LogError($"{item.Key} {item.Value} is not valid. Is your config formatted correctly?");
|
||||
|
||||
/*
|
||||
switch(item.Key)
|
||||
{
|
||||
case "Base":
|
||||
Base.Build(item.Value as Dictionary<string, object>);
|
||||
break;
|
||||
case "Orbit":
|
||||
Orbit.Build(item.Value as Dictionary<string, object>);
|
||||
break;
|
||||
case "Atmosphere":
|
||||
Atmosphere = new AtmosphereModule();
|
||||
Atmosphere.Build(item.Value as Dictionary<string, object>);
|
||||
break;
|
||||
case "Ring":
|
||||
Ring = new RingModule();
|
||||
Ring.Build(item.Value as Dictionary<string, object>);
|
||||
break;
|
||||
case "HeightMap":
|
||||
HeightMap = new HeightMapModule();
|
||||
HeightMap.Build(item.Value as Dictionary<string, object>);
|
||||
break;
|
||||
case "ProcGen":
|
||||
ProcGen = new ProcGenModule();
|
||||
ProcGen.Build(item.Value as Dictionary<string, object>);
|
||||
break;
|
||||
case "AsteroidBelt":
|
||||
AsteroidBelt = new AsteroidBeltModule();
|
||||
AsteroidBelt.Build(item.Value as Dictionary<string, object>);
|
||||
break;
|
||||
case "Spawn":
|
||||
Spawn = new SpawnModule();
|
||||
Spawn.Build(item.Value as Dictionary<string, object>);
|
||||
break;
|
||||
default:
|
||||
var property = typeof(PlanetConfig).GetProperty(item.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
if (property != null) property.SetValue(this, Convert.ChangeType(item.Value, property.PropertyType));
|
||||
else Logger.LogError($"{item.Key} {item.Value} is not valid. Is your config formatted correctly?");
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
21
NewHorizons/External/PropModule.cs
vendored
Normal file
21
NewHorizons/External/PropModule.cs
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
using NewHorizons.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NewHorizons.External
|
||||
{
|
||||
public class PropModule : Module
|
||||
{
|
||||
public ScatterInfo[] Scatter;
|
||||
public MVector3[] Rafts;
|
||||
|
||||
public class ScatterInfo
|
||||
{
|
||||
public string path;
|
||||
public int count;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ using NewHorizons.Body;
|
||||
using NewHorizons.Builder.Body;
|
||||
using NewHorizons.Builder.General;
|
||||
using NewHorizons.Builder.Orbital;
|
||||
using NewHorizons.Builder.Props;
|
||||
using NewHorizons.External;
|
||||
using NewHorizons.OrbitalPhysics;
|
||||
using NewHorizons.Utility;
|
||||
@ -64,6 +65,7 @@ namespace NewHorizons
|
||||
|
||||
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
Logger.Log($"Scene Loaded: {scene} {mode}");
|
||||
if (scene.name != "SolarSystem") return;
|
||||
|
||||
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>());
|
||||
@ -75,7 +77,7 @@ namespace NewHorizons
|
||||
}
|
||||
|
||||
// Stars then planets then moons
|
||||
BodyList = BodyList.OrderBy(b =>
|
||||
var toLoad = BodyList.OrderBy(b =>
|
||||
(b.Config.BuildPriority != -1 ? b.Config.BuildPriority :
|
||||
(b.Config.FocalPoint != null ? 0 :
|
||||
(b.Config.Star != null) ? 0 :
|
||||
@ -83,9 +85,9 @@ namespace NewHorizons
|
||||
))).ToList();
|
||||
|
||||
var flagNoneLoadedThisPass = true;
|
||||
while(BodyList.Count != 0)
|
||||
while(toLoad.Count != 0)
|
||||
{
|
||||
foreach (var body in BodyList)
|
||||
foreach (var body in toLoad)
|
||||
{
|
||||
if (LoadBody(body))
|
||||
flagNoneLoadedThisPass = false;
|
||||
@ -93,7 +95,7 @@ namespace NewHorizons
|
||||
if (flagNoneLoadedThisPass)
|
||||
{
|
||||
// Try again but default to sun
|
||||
foreach(var body in BodyList)
|
||||
foreach(var body in toLoad)
|
||||
{
|
||||
if (LoadBody(body, true))
|
||||
flagNoneLoadedThisPass = false;
|
||||
@ -105,9 +107,12 @@ namespace NewHorizons
|
||||
return;
|
||||
}
|
||||
}
|
||||
BodyList = NextPassBodies;
|
||||
toLoad = NextPassBodies;
|
||||
NextPassBodies = new List<NewHorizonsBody>();
|
||||
}
|
||||
|
||||
// I don't know what these do but they look really weird from a distance
|
||||
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveDistantProxyClones());
|
||||
}
|
||||
|
||||
private bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = false)
|
||||
@ -192,7 +197,7 @@ namespace NewHorizons
|
||||
var rb = go.GetAttachedOWRigidbody();
|
||||
|
||||
// Do stuff that's shared between generating new planets and updating old ones
|
||||
return SharedGenerateBody(body, go, sector, rb);
|
||||
return SharedGenerateBody(body, go, sector, rb, ao);
|
||||
}
|
||||
|
||||
public static GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false)
|
||||
@ -222,25 +227,14 @@ namespace NewHorizons
|
||||
var atmoSize = body.Config.Atmosphere != null ? body.Config.Atmosphere.Size : 0f;
|
||||
float sphereOfInfluence = Mathf.Max(atmoSize, body.Config.Base.SurfaceSize * 2f);
|
||||
|
||||
// For now, eccentric orbits gotta start at apoapsis and cant be inclined
|
||||
var rot = Quaternion.AngleAxis(body.Config.Orbit.LongitudeOfAscendingNode + body.Config.Orbit.TrueAnomaly + body.Config.Orbit.ArgumentOfPeriapsis + 180f, Vector3.up);
|
||||
if (body.Config.Orbit.Eccentricity != 0)
|
||||
{
|
||||
rot = Quaternion.AngleAxis(body.Config.Orbit.LongitudeOfAscendingNode + body.Config.Orbit.ArgumentOfPeriapsis + 180f, Vector3.up);
|
||||
body.Config.Orbit.Inclination = 0;
|
||||
}
|
||||
|
||||
var incAxis = Quaternion.AngleAxis(body.Config.Orbit.LongitudeOfAscendingNode, Vector3.up) * Vector3.left;
|
||||
var incRot = Quaternion.AngleAxis(body.Config.Orbit.Inclination, incAxis);
|
||||
|
||||
var positionVector = rot * incRot * Vector3.left * body.Config.Orbit.SemiMajorAxis * (1 + body.Config.Orbit.Eccentricity);
|
||||
var positionVector = OrbitalHelper.RotateTo(Vector3.left * body.Config.Orbit.SemiMajorAxis * (1 + body.Config.Orbit.Eccentricity), body.Config.Orbit);
|
||||
|
||||
var outputTuple = BaseBuilder.Make(go, primaryBody, positionVector, body.Config);
|
||||
var ao = (AstroObject)outputTuple.Item1;
|
||||
var owRigidBody = (OWRigidbody)outputTuple.Item2;
|
||||
|
||||
if (body.Config.Base.SurfaceGravity != 0)
|
||||
GravityBuilder.Make(go, ao, body.Config.Base.SurfaceGravity, sphereOfInfluence, body.Config.Base.SurfaceSize, body.Config.Base.GravityFallOff);
|
||||
GravityBuilder.Make(go, ao, body.Config.Base.SurfaceGravity, sphereOfInfluence * (body.Config.Star != null ? 10f : 1f), body.Config.Base.SurfaceSize, body.Config.Base.GravityFallOff);
|
||||
|
||||
if(body.Config.Base.HasReferenceFrame)
|
||||
RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence);
|
||||
@ -272,7 +266,7 @@ namespace NewHorizons
|
||||
FocalPointBuilder.Make(go, body.Config.FocalPoint);
|
||||
|
||||
// Do stuff that's shared between generating new planets and updating old ones
|
||||
go = SharedGenerateBody(body, go, sector, owRigidBody);
|
||||
go = SharedGenerateBody(body, go, sector, owRigidBody, ao);
|
||||
|
||||
body.Object = go;
|
||||
|
||||
@ -303,7 +297,7 @@ namespace NewHorizons
|
||||
return go;
|
||||
}
|
||||
|
||||
private static GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb)
|
||||
private static GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb, AstroObject ao)
|
||||
{
|
||||
if (body.Config.Ring != null)
|
||||
RingBuilder.Make(go, body.Config.Ring, body.Assets);
|
||||
@ -341,6 +335,18 @@ namespace NewHorizons
|
||||
AtmosphereBuilder.Make(go, body.Config.Atmosphere);
|
||||
}
|
||||
|
||||
if (body.Config.Props != null)
|
||||
{
|
||||
if (body.Config.Props.Scatter != null) PropBuilder.Scatter(go, body.Config.Props.Scatter, body.Config.Base.SurfaceSize, sector);
|
||||
if (body.Config.Props.Rafts != null)
|
||||
{
|
||||
foreach(var v in body.Config.Props.Rafts)
|
||||
{
|
||||
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RaftBuilder.Make(go, v, sector, rb, ao));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return go;
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,6 +239,9 @@
|
||||
<Compile Include="Builder\Body\ProcGenBuilder.cs" />
|
||||
<Compile Include="Builder\Body\StarBuilder.cs" />
|
||||
<Compile Include="Builder\Orbital\FocalPointBuilder.cs" />
|
||||
<Compile Include="Builder\Props\PlanetaryRaftController.cs" />
|
||||
<Compile Include="Builder\Props\PropBuilder.cs" />
|
||||
<Compile Include="Builder\Props\RaftBuilder.cs" />
|
||||
<Compile Include="External\AsteroidBeltModule.cs" />
|
||||
<Compile Include="External\AtmosphereModule.cs" />
|
||||
<Compile Include="External\BaseModule.cs" />
|
||||
@ -247,6 +250,7 @@
|
||||
<Compile Include="External\Module.cs" />
|
||||
<Compile Include="External\OrbitModule.cs" />
|
||||
<Compile Include="External\ProcGenModule.cs" />
|
||||
<Compile Include="External\PropModule.cs" />
|
||||
<Compile Include="External\RingModule.cs" />
|
||||
<Compile Include="External\SpawnModule.cs" />
|
||||
<Compile Include="External\StarModule.cs" />
|
||||
|
||||
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using NewHorizons.Utility;
|
||||
using Logger = NewHorizons.Utility.Logger;
|
||||
using NewHorizons.External;
|
||||
|
||||
namespace NewHorizons.OrbitalPhysics
|
||||
{
|
||||
@ -18,6 +19,33 @@ namespace NewHorizons.OrbitalPhysics
|
||||
none
|
||||
}
|
||||
|
||||
public static Vector3 RotateTo(Vector3 vector, KeplerElements elements)
|
||||
{
|
||||
// For now, eccentric orbits gotta start at apoapsis and cant be inclined
|
||||
var rot = Quaternion.AngleAxis(elements.LongitudeOfAscendingNode + elements.TrueAnomaly + elements.ArgumentOfPeriapsis + 180f, Vector3.up);
|
||||
if (elements.Eccentricity != 0)
|
||||
{
|
||||
rot = Quaternion.AngleAxis(elements.LongitudeOfAscendingNode + elements.ArgumentOfPeriapsis + 180f, Vector3.up);
|
||||
}
|
||||
|
||||
var incAxis = Quaternion.AngleAxis(elements.LongitudeOfAscendingNode, Vector3.up) * Vector3.left;
|
||||
var incRot = Quaternion.AngleAxis(elements.Inclination, incAxis);
|
||||
|
||||
return rot * incRot * vector;
|
||||
}
|
||||
|
||||
public static Vector3 RotateTo(Vector3 vector, OrbitModule module)
|
||||
{
|
||||
return RotateTo(vector, KeplerElements.FromOrbitModule(module));
|
||||
}
|
||||
|
||||
public static Vector3 VelocityDirection(Vector3 separation, KeplerElements elements)
|
||||
{
|
||||
var incAxis = Quaternion.AngleAxis(elements.LongitudeOfAscendingNode, Vector3.up) * Vector3.left;
|
||||
var incRot = Quaternion.AngleAxis(elements.Inclination, incAxis);
|
||||
return Vector3.Cross(RotateTo(Vector3.up, elements), separation);
|
||||
}
|
||||
|
||||
public static float GetOrbitalVelocity(float distance, Gravity gravity, KeplerElements kepler)
|
||||
{
|
||||
if (kepler.Eccentricity == 0) return GetCircularOrbitVelocity(distance, gravity, kepler);
|
||||
|
||||
@ -9,6 +9,13 @@ namespace NewHorizons.OrbitalPhysics
|
||||
{
|
||||
public class TrackingOrbitLine : OrbitLine
|
||||
{
|
||||
private Vector3[] _vertices;
|
||||
private float _timer;
|
||||
private bool _firstTimeEnabled = true;
|
||||
|
||||
public float TrailTime = 120f;
|
||||
|
||||
|
||||
protected override void InitializeLineRenderer()
|
||||
{
|
||||
_lineRenderer.positionCount = this._numVerts;
|
||||
@ -31,9 +38,23 @@ namespace NewHorizons.OrbitalPhysics
|
||||
base.Start();
|
||||
_vertices = new Vector3[_numVerts];
|
||||
|
||||
ResetLineVertices();
|
||||
base.enabled = true;
|
||||
_lineRenderer.enabled = false;
|
||||
}
|
||||
|
||||
base.enabled = false;
|
||||
protected override void OnEnterMapView()
|
||||
{
|
||||
if (_firstTimeEnabled)
|
||||
{
|
||||
ResetLineVertices();
|
||||
_firstTimeEnabled = false;
|
||||
}
|
||||
_lineRenderer.enabled = true;
|
||||
}
|
||||
|
||||
protected override void OnExitMapView()
|
||||
{
|
||||
_lineRenderer.enabled = false;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
@ -92,10 +113,5 @@ namespace NewHorizons.OrbitalPhysics
|
||||
}
|
||||
_lineRenderer.SetPositions(_vertices);
|
||||
}
|
||||
|
||||
private Vector3[] _vertices;
|
||||
private float _timer;
|
||||
|
||||
public float TrailTime = 60f;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,11 +44,12 @@ namespace NewHorizons.Utility
|
||||
____upAxisDir *= -1f;
|
||||
}
|
||||
|
||||
public static void OnMapControllerAwake(MapController __instance, ref float ____maxPanDistance, ref float ____maxZoomDistance, ref float ____minPitchAngle)
|
||||
public static void OnMapControllerAwake(MapController __instance, ref float ____maxPanDistance, ref float ____maxZoomDistance, ref float ____minPitchAngle, ref float ____zoomSpeed)
|
||||
{
|
||||
____maxPanDistance *= 4f;
|
||||
____maxZoomDistance *= 6f;
|
||||
____minPitchAngle = -90f;
|
||||
____zoomSpeed *= 4f;
|
||||
}
|
||||
|
||||
public static void OnOWCameraAwake(OWCamera __instance)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user