Lower convergence-point camera look-at

This commit is contained in:
Meta Vens 2026-07-15 22:05:25 +01:00
commit f0883e9644
7 changed files with 81 additions and 34 deletions

View file

@ -63,9 +63,13 @@ The provider selects camera semantics and framing from its authoritative mode.
`planar.top-down-follow.v1` derives a downward presentation from the advertised
target and framing values. `perspective.entity-forward-follow.v1` derives its
view direction from the presented entity rotation and applies the same generic
distance, screen-position, damping, and lens contract. EveUnity owns only the
native camera transform. It cannot collapse distinct provider modes into one
camera opinion or infer a product camera from entity kind.
distance, screen-position, damping, and lens contract. When the provider also
advertises `aim.convergence-point.v1`, the camera and aim marker consume one
derived convergence point from the `aim.presentation` node. The native camera
rotation and position are solved together so the optical axis reaches that
point while the followed entity remains at the advertised screen coordinate.
EveUnity owns only this native projection. It cannot collapse distinct provider
modes into one camera opinion or infer a product camera from entity kind.
## Shared Paths

View file

@ -1,5 +1,6 @@
using System;
using System.Globalization;
using UnityEngine;
#nullable enable
@ -23,6 +24,24 @@ namespace GameCult.Eve.UnityScene
public float MinimumConvergenceDistance { get; }
public float ViewDotRadius { get; }
public bool TryResolveViewPoint(EveUnityPlayableWorldClientHost? host, out Vector3 viewPoint)
{
viewPoint = default;
if (host == null || string.IsNullOrWhiteSpace(ControlledEntityId)) return false;
var controlled = FindMarker(host, ControlledEntityId);
if (controlled == null) return false;
var distance = MinimumConvergenceDistance;
var target = FindMarker(host, ConvergenceTargetEntityId);
if (target != null)
distance = Mathf.Max(distance, Vector3.Distance(controlled.transform.position, target.transform.position));
var forward = controlled.transform.forward;
forward.y = 0f;
if (forward.sqrMagnitude <= 0.0001f) forward = Vector3.forward;
forward.Normalize();
viewPoint = controlled.transform.position + forward * distance;
return true;
}
public static EveUnityAimPresentation? Find(EveUnitySceneProjection? projection) =>
projection == null ? null : Find(projection.Root);
@ -38,6 +57,16 @@ namespace GameCult.Eve.UnityScene
return null;
}
private static EveUnityPlayableWorldEntityMarker? FindMarker(
EveUnityPlayableWorldClientHost host,
string entityId)
{
if (string.IsNullOrWhiteSpace(entityId)) return null;
foreach (var marker in host.SceneRoot.GetComponentsInChildren<EveUnityPlayableWorldEntityMarker>(true))
if (string.Equals(marker.EntityId, entityId, StringComparison.Ordinal)) return marker;
return null;
}
private static string Get(EveUnitySceneNode node, string key) =>
node.Props.TryGetValue(key, out var value) ? value ?? "" : "";

View file

@ -34,22 +34,12 @@ namespace GameCult.Eve.UnityScene
return;
}
var controlled = FindMarker(Current.ControlledEntityId);
if (controlled == null)
if (!Current.TryResolveViewPoint(_host, out var viewPoint))
{
SetVisible(false);
return;
}
var distance = Current.MinimumConvergenceDistance;
var target = FindMarker(Current.ConvergenceTargetEntityId);
if (target != null)
distance = Mathf.Max(distance, Vector3.Distance(controlled.transform.position, target.transform.position));
var forward = controlled.transform.forward;
forward.y = 0f;
if (forward.sqrMagnitude <= 0.0001f) forward = Vector3.forward;
forward.Normalize();
ViewDotPosition = controlled.transform.position + forward * distance;
ViewDotPosition = viewPoint;
EnsureVisuals();
var camera = _host?.ActiveCameraTransform;
@ -69,14 +59,6 @@ namespace GameCult.Eve.UnityScene
private void LateUpdate() => RefreshNow();
private EveUnityPlayableWorldEntityMarker? FindMarker(string entityId)
{
if (_host == null || string.IsNullOrWhiteSpace(entityId)) return null;
foreach (var marker in _host.SceneRoot.GetComponentsInChildren<EveUnityPlayableWorldEntityMarker>(true))
if (string.Equals(marker.EntityId, entityId, StringComparison.Ordinal)) return marker;
return null;
}
private void EnsureVisuals()
{
if (_ring != null) return;

View file

@ -143,7 +143,7 @@ namespace GameCult.Eve.UnityScene
if (activeWorld.CameraRig == "planar.top-down-follow.v1")
return ApplyPlanarTopDown(activeWorld, camera, cameraComponent, player.position, deltaTime);
if (activeWorld.CameraRig == "perspective.entity-forward-follow.v1")
return ApplyEntityForwardFollow(activeWorld, camera, cameraComponent, player, deltaTime);
return ApplyEntityForwardFollow(activeWorld, resolvedHost, camera, cameraComponent, player, deltaTime);
var bounds = CalculateVisualBounds(
player,
@ -204,6 +204,7 @@ namespace GameCult.Eve.UnityScene
private static bool ApplyEntityForwardFollow(
EveUnityPlayableWorldProjection world,
EveUnityPlayableWorldClientHost host,
Transform camera,
Camera? cameraComponent,
Transform target,
@ -226,16 +227,35 @@ namespace GameCult.Eve.UnityScene
forward = Vector3.forward;
forward.Normalize();
var rotation = Quaternion.LookRotation(forward, Vector3.up);
var right = rotation * Vector3.right;
var aspect = cameraComponent != null ? cameraComponent.aspect : 16f / 9f;
var verticalHalfExtent = resolvedDistance * Mathf.Tan(verticalFov * 0.5f * Mathf.Deg2Rad);
var horizontalHalfExtent = verticalHalfExtent * Mathf.Max(0.01f, aspect);
var horizontalOffset = (Mathf.Clamp01(world.CameraTargetScreenX) - 0.5f) * 2f * horizontalHalfExtent;
var verticalOffset = (Mathf.Clamp01(world.CameraTargetScreenY) - 0.5f) * 2f * verticalHalfExtent;
if (string.Equals(world.CameraLookAt, "aim.convergence-point.v1", System.StringComparison.Ordinal))
{
var aim = EveUnityAimPresentation.Find(host.ActiveProjection);
if (aim == null || !aim.TryResolveViewPoint(host, out var aimPoint)) return false;
var targetToAim = aimPoint - target.position;
var targetToAimDistanceSquared = targetToAim.sqrMagnitude;
var screenOffsetSquared = horizontalOffset * horizontalOffset + verticalOffset * verticalOffset;
if (targetToAimDistanceSquared <= screenOffsetSquared + 0.0001f) return false;
var targetToAimDirection = targetToAim.normalized;
var opticalDepthDelta = Mathf.Sqrt(targetToAimDistanceSquared - screenOffsetSquared);
var cameraLocalTargetToAim = new Vector3(
-horizontalOffset,
-verticalOffset,
opticalDepthDelta);
rotation = Quaternion.LookRotation(targetToAimDirection, Vector3.up) *
Quaternion.FromToRotation(cameraLocalTargetToAim.normalized, Vector3.forward);
}
var right = rotation * Vector3.right;
var up = rotation * Vector3.up;
var opticalForward = rotation * Vector3.forward;
var desiredPosition = target.position -
(forward * resolvedDistance) -
(opticalForward * resolvedDistance) -
(right * horizontalOffset) -
(Vector3.up * verticalOffset);
(up * verticalOffset);
var damping = Mathf.Max(0f, world.CameraPositionDamping);
var t = deltaTime <= 0f || damping <= 0f
? 1f

View file

@ -150,7 +150,8 @@ namespace GameCult.Eve.UnityScene
ParseVector3(worldRoot.GetProp("keyLightDirection")),
ParseVector3(worldRoot.GetProp("keyLightColor")),
ParseFloat(worldRoot.GetProp("keyLightIntensity"), 0f),
fieldVolumes);
fieldVolumes,
worldRoot.GetProp("cameraLookAt"));
}
private static EveUnityFieldVolumeProjection BuildFieldVolume(EveSurfaceComponent component) =>
@ -392,7 +393,8 @@ namespace GameCult.Eve.UnityScene
(float x, float y, float z) keyLightDirection = default,
(float r, float g, float b) keyLightColor = default,
float keyLightIntensity = 0f,
IReadOnlyList<EveUnityFieldVolumeProjection>? fieldVolumes = null)
IReadOnlyList<EveUnityFieldVolumeProjection>? fieldVolumes = null,
string cameraLookAt = "")
{
WorldRootId = worldRootId ?? "";
StatePointerId = statePointerId ?? "";
@ -437,6 +439,7 @@ namespace GameCult.Eve.UnityScene
KeyLightColorB = keyLightColor.b;
KeyLightIntensity = keyLightIntensity;
FieldVolumes = fieldVolumes ?? Array.Empty<EveUnityFieldVolumeProjection>();
CameraLookAt = cameraLookAt ?? "";
}
public string WorldRootId { get; }
@ -459,6 +462,8 @@ namespace GameCult.Eve.UnityScene
public string CameraTargetEntityId { get; }
public string CameraLookAt { get; }
public float CameraDistance { get; }
public float CameraVerticalFieldOfViewDegrees { get; }

View file

@ -401,6 +401,7 @@ namespace GameCult.Eve.UnityScene.Tests
Assert.That(projection.PlayableWorld.AssetManifest, Is.EqualTo("cultmesh://aetheria/assets/manifest"));
Assert.That(projection.PlayableWorld.InputProfile, Is.EqualTo("arpg-third-person"));
Assert.That(projection.PlayableWorld.CameraRig, Is.EqualTo("planar.top-down-follow.v1"));
Assert.That(projection.PlayableWorld.CameraLookAt, Is.Empty);
Assert.That(projection.PlayableWorld.CameraTargetEntityId, Is.EqualTo("player-vanguard"));
Assert.That(projection.PlayableWorld.CameraDistance, Is.EqualTo(150f));
Assert.That(projection.PlayableWorld.CameraVerticalFieldOfViewDegrees, Is.EqualTo(60f));
@ -1266,7 +1267,7 @@ namespace GameCult.Eve.UnityScene.Tests
}
[Test]
public void PlayableWorldCameraRigFramesEntityForwardPerspectiveWithoutProviderTypes()
public void PlayableWorldCameraRigFramesEntityAndLooksAtAdvertisedConvergencePointWithoutProviderTypes()
{
var rootObject = new GameObject("generic-forward-world-root");
var hostObject = new GameObject("generic-forward-client");
@ -1285,7 +1286,8 @@ namespace GameCult.Eve.UnityScene.Tests
cameraTargetScreenY: "0.81",
cameraPositionDamping: "0",
cameraNearClipPlane: "1",
cameraFarClipPlane: "4096"),
cameraFarClipPlane: "4096",
cameraLookAt: "aim.convergence-point.v1"),
Advertisement("aetheria.daemon.game"),
"cultmesh://generic/eve/surfaces/forward",
1),
@ -1307,7 +1309,10 @@ namespace GameCult.Eve.UnityScene.Tests
var player = rootObject.GetComponentInChildren<EveUnityPlayableWorldEntityMarker>();
Assert.That(player, Is.Not.Null);
Assert.That(rig.ApplyRig(0f), Is.True);
Assert.That(Vector3.Dot(cameraObject.transform.forward, player!.transform.forward), Is.GreaterThan(0.999f));
var aimPoint = player!.transform.position + player.transform.forward * 50f;
var cameraToAim = (aimPoint - cameraObject.transform.position).normalized;
Assert.That(Vector3.Dot(cameraObject.transform.forward, cameraToAim), Is.GreaterThan(0.999f));
Assert.That(cameraObject.transform.forward.y, Is.GreaterThan(0f));
Assert.That(camera.fieldOfView, Is.EqualTo(60f).Within(0.001f));
Assert.That(camera.nearClipPlane, Is.EqualTo(1f).Within(0.001f));
Assert.That(camera.farClipPlane, Is.EqualTo(4096f).Within(0.001f));
@ -1839,7 +1844,8 @@ namespace GameCult.Eve.UnityScene.Tests
string cameraTargetScreenY = "0.55",
string cameraPositionDamping = "5",
string cameraNearClipPlane = "0.3",
string cameraFarClipPlane = "4096")
string cameraFarClipPlane = "4096",
string cameraLookAt = "")
{
var playableChildren = new List<EveSurfaceComponent>
{
@ -1977,6 +1983,7 @@ namespace GameCult.Eve.UnityScene.Tests
["assetManifest"] = "cultmesh://aetheria/assets/manifest",
["inputProfile"] = "arpg-third-person",
["cameraRig"] = cameraRig,
["cameraLookAt"] = cameraLookAt,
["cameraTargetEntityId"] = "player-vanguard",
["cameraDistance"] = cameraDistance,
["cameraVerticalFieldOfViewDegrees"] = "60",

View file

@ -1,7 +1,7 @@
{
"name": "org.gamecult.eve.unity-scene",
"displayName": "Eve Unity Scene Lowering",
"version": "0.3.40",
"version": "0.3.41",
"unity": "2021.3",
"description": "Provider-agnostic Unity scene shell for gamecult.eve.surface.v1 interactive world surfaces.",
"dependencies": {