Position rendered zone bodies from daemon poses
This commit is contained in:
parent
95e09dc241
commit
140028d0db
4 changed files with 183 additions and 13 deletions
|
|
@ -730,6 +730,60 @@ public class DaemonRuntimeDocumentTests
|
|||
Assert.AreEqual(-24.9968, height, 0.0001);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonRenderQueriesPublishBodyPosesFromZoneSnapshot()
|
||||
{
|
||||
var zone = new AetheriaRuntimeZoneSnapshotCommit
|
||||
{
|
||||
Orbits = new[]
|
||||
{
|
||||
new AetheriaRuntimeOrbitSnapshotCommit
|
||||
{
|
||||
OrbitKey = "orbit:parent",
|
||||
FixedPositionX = 10,
|
||||
FixedPositionY = 20
|
||||
},
|
||||
new AetheriaRuntimeOrbitSnapshotCommit
|
||||
{
|
||||
OrbitKey = "orbit:child",
|
||||
ParentOrbitKey = "orbit:parent",
|
||||
Distance = 5,
|
||||
Phase = 0.25
|
||||
}
|
||||
},
|
||||
Bodies = new[]
|
||||
{
|
||||
new AetheriaRuntimeBodySnapshotCommit
|
||||
{
|
||||
BodyKey = "body:child",
|
||||
OrbitKey = "orbit:child",
|
||||
Kind = "planet"
|
||||
},
|
||||
new AetheriaRuntimeBodySnapshotCommit
|
||||
{
|
||||
BodyKey = "body:explicit",
|
||||
OrbitKey = "orbit:missing",
|
||||
Kind = "gas_giant",
|
||||
GravityInfluenceCenterX = -3,
|
||||
GravityInfluenceCenterZ = 7
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var poses = AetheriaRuntimeDaemonRenderQueries.QueryBodyPoses(zone);
|
||||
|
||||
Assert.AreEqual(2, poses.Length);
|
||||
Assert.AreEqual("body:child", poses[0].BodyKey);
|
||||
Assert.AreEqual("orbit:parent", poses[0].ParentOrbitKey);
|
||||
Assert.AreEqual(10, poses[0].CenterX, 0.0001);
|
||||
Assert.AreEqual(25, poses[0].CenterZ, 0.0001);
|
||||
Assert.AreEqual(10, poses[0].ParentCenterX, 0.0001);
|
||||
Assert.AreEqual(20, poses[0].ParentCenterZ, 0.0001);
|
||||
Assert.AreEqual("body:explicit", poses[1].BodyKey);
|
||||
Assert.AreEqual(-3, poses[1].CenterX, 0.0001);
|
||||
Assert.AreEqual(7, poses[1].CenterZ, 0.0001);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SoaViewIndexRejectsInvalidRenderGroups()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@ public class ZoneRenderer : MonoBehaviour
|
|||
private PlanetObject[] _suns;
|
||||
private bool _showAsteroidUI;
|
||||
private AetheriaRuntimeZoneSnapshotCommit _daemonZoneSnapshot;
|
||||
private readonly List<AetheriaRuntimeDaemonBodyPose> _daemonBodyPoses = new List<AetheriaRuntimeDaemonBodyPose>();
|
||||
private readonly Dictionary<string, AetheriaRuntimeDaemonBodyPose> _daemonBodyPosesByBodyKey =
|
||||
new Dictionary<string, AetheriaRuntimeDaemonBodyPose>(StringComparer.Ordinal);
|
||||
|
||||
public Dictionary<Wormhole, (GameObject gravity, CompassIcon icon)> WormholeInstances = new Dictionary<Wormhole, (GameObject, CompassIcon)>();
|
||||
private List<ItemPickup> _loot = new List<ItemPickup>();
|
||||
|
|
@ -466,6 +469,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
// }
|
||||
|
||||
Shader.SetGlobalFloat("_AsteroidVerticalOffset", ActionGameManager.Instance.Settings.PlanetSettings.AsteroidVerticalOffset);
|
||||
RefreshDaemonBodyPoses();
|
||||
|
||||
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(MainCamera);
|
||||
bool isVisible(Bounds bounds) => GeometryUtility.TestPlanesAABB(planes, bounds);
|
||||
|
|
@ -504,8 +508,11 @@ public class ZoneRenderer : MonoBehaviour
|
|||
|
||||
foreach (var planet in Planets)
|
||||
{
|
||||
if (!_daemonBodyPosesByBodyKey.TryGetValue(planet.Key, out var pose))
|
||||
continue;
|
||||
|
||||
var planetInstance = Zone.PlanetInstances[planet.Key];
|
||||
var p = Zone.GetOrbitPosition(planetInstance.OrbitKey);
|
||||
var p = new float2((float)pose.CenterX, (float)pose.CenterZ);
|
||||
var height = GetTerrainHeight(p);
|
||||
if (-height > maxDepth) maxDepth = -height;
|
||||
planet.Value.transform.position = new Vector3(p.x, 0, p.y);
|
||||
|
|
@ -513,10 +520,11 @@ public class ZoneRenderer : MonoBehaviour
|
|||
if (planet.Value is GasGiantObject gasGiantObject)
|
||||
{
|
||||
gasGiantObject.GravityWaves.material.SetFloat("_Phase",
|
||||
Zone.Time * ((GasGiant) Zone.PlanetInstances[planet.Key]).GravityWavesSpeed);
|
||||
Zone.Time * ((GasGiant) Zone.PlanetInstances[planet.Key]).GravityWavesSpeed);
|
||||
if (!(planet.Value is SunObject))
|
||||
{
|
||||
var toParent = normalize(Zone.GetOrbitPosition(planetInstance.Orbit.ParentOrbitKey) - p);
|
||||
var parent = new float2((float)pose.ParentCenterX, (float)pose.ParentCenterZ);
|
||||
var toParent = normalize(parent - p);
|
||||
gasGiantObject.SunMaterial.LightingDirection = new Vector3(toParent.x, 0, toParent.y);
|
||||
}
|
||||
}
|
||||
|
|
@ -564,6 +572,17 @@ public class ZoneRenderer : MonoBehaviour
|
|||
// MinimapTintQuad.transform.position = gravPos - Vector3.up*10;
|
||||
}
|
||||
|
||||
private void RefreshDaemonBodyPoses()
|
||||
{
|
||||
AetheriaRuntimeDaemonRenderQueries.QueryBodyPoses(_daemonZoneSnapshot, _daemonBodyPoses);
|
||||
_daemonBodyPosesByBodyKey.Clear();
|
||||
foreach (var pose in _daemonBodyPoses)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(pose.BodyKey))
|
||||
_daemonBodyPosesByBodyKey[pose.BodyKey] = pose;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTerrainHeight(float2 position)
|
||||
{
|
||||
return (float)AetheriaRuntimeDaemonRenderQueries.EvaluateGravityTerrainHeight(
|
||||
|
|
|
|||
Loading…
Reference in a new issue