772 lines
32 KiB
C#
772 lines
32 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Godot;
|
|
using RustToDust.Core;
|
|
using RustToDust.Ymir;
|
|
|
|
namespace RustToDust.Client;
|
|
|
|
/// <summary>
|
|
/// Renders the 3D arena entities from <see cref="ArenaSession"/>:
|
|
/// cover ruins, shrinking Safe Circle ring, 6 distinct chassis silhouettes,
|
|
/// 3 alien spectator tiers + status halos/lock lasers, salvage drops, and weapon tracers.
|
|
/// </summary>
|
|
public partial class ArenaRenderer : Node3D
|
|
{
|
|
private static readonly Color OlivePaint = Color.FromHtml("#9bb06a");
|
|
private static readonly Color SignalOrange = Color.FromHtml("#e08a4a");
|
|
private static readonly Color RivalSteel = Color.FromHtml("#6a584b");
|
|
private static readonly Color RivalAccent = Color.FromHtml("#b64a32");
|
|
private static readonly Color TouristGold = Color.FromHtml("#e6b838");
|
|
private static readonly Color TouristIvory = Color.FromHtml("#f2ead8");
|
|
private static readonly Color PatronTeal = Color.FromHtml("#2d7a78");
|
|
private static readonly Color PatronBronze = Color.FromHtml("#a86c36");
|
|
private static readonly Color ExemplarObsidian = Color.FromHtml("#18181d");
|
|
private static readonly Color ExemplarCrimson = Color.FromHtml("#c92a2a");
|
|
private static readonly Color CyanSalvage = Color.FromHtml("#44d9e8");
|
|
private static readonly Color CoverRust = Color.FromHtml("#4d433b");
|
|
private static readonly Color BermDark = Color.FromHtml("#2c2723");
|
|
|
|
private sealed class ActorVisual
|
|
{
|
|
public Node3D Root = null!;
|
|
public Node3D? AimPivot;
|
|
public StandardMaterial3D HeatMat = null!;
|
|
public MeshInstance3D? HaloMesh;
|
|
public StandardMaterial3D? HaloMat;
|
|
public MeshInstance3D? LaserMesh;
|
|
public StandardMaterial3D? LaserMat;
|
|
public string ChassisId = "";
|
|
}
|
|
|
|
private Node3D _staticGroup = null!;
|
|
private Node3D _actorsGroup = null!;
|
|
private Node3D _dropsGroup = null!;
|
|
private Node3D _tracersGroup = null!;
|
|
private MeshInstance3D _safeRingMesh = null!;
|
|
private ImmediateMesh _safeRingImm = null!;
|
|
|
|
private readonly Dictionary<int, ActorVisual> _contenderVisuals = new();
|
|
private readonly Dictionary<int, ActorVisual> _spectatorVisuals = new();
|
|
private readonly Dictionary<int, Node3D> _dropVisuals = new();
|
|
private readonly List<MeshInstance3D> _tracerPool = new();
|
|
|
|
private StandardMaterial3D _safeRingMat = null!;
|
|
private StandardMaterial3D _coverMat = null!;
|
|
private StandardMaterial3D _bermMat = null!;
|
|
private StandardMaterial3D _humanCrateMat = null!;
|
|
private StandardMaterial3D _imperialCrateMat = null!;
|
|
private StandardMaterial3D _cyanBeaconMat = null!;
|
|
private MatchState? _builtForState;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_staticGroup = new Node3D { Name = "StaticArena" };
|
|
_actorsGroup = new Node3D { Name = "Actors" };
|
|
_dropsGroup = new Node3D { Name = "GroundDrops" };
|
|
_tracersGroup = new Node3D { Name = "Tracers" };
|
|
AddChild(_staticGroup);
|
|
AddChild(_actorsGroup);
|
|
AddChild(_dropsGroup);
|
|
AddChild(_tracersGroup);
|
|
|
|
_coverMat = new StandardMaterial3D { AlbedoColor = CoverRust, Roughness = 0.88f, Metallic = 0.25f };
|
|
_bermMat = new StandardMaterial3D { AlbedoColor = BermDark, Roughness = 0.94f, Metallic = 0.1f };
|
|
_humanCrateMat = new StandardMaterial3D { AlbedoColor = OlivePaint, Roughness = 0.65f, Metallic = 0.3f };
|
|
_imperialCrateMat = new StandardMaterial3D
|
|
{
|
|
AlbedoColor = TouristGold,
|
|
Roughness = 0.35f,
|
|
Metallic = 0.8f,
|
|
EmissionEnabled = true,
|
|
Emission = TouristGold,
|
|
EmissionEnergyMultiplier = 1.4f
|
|
};
|
|
_cyanBeaconMat = new StandardMaterial3D
|
|
{
|
|
AlbedoColor = CyanSalvage,
|
|
EmissionEnabled = true,
|
|
Emission = CyanSalvage,
|
|
EmissionEnergyMultiplier = 1.5f,
|
|
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
|
};
|
|
_cyanBeaconMat.AlbedoColor = new Color(CyanSalvage.R, CyanSalvage.G, CyanSalvage.B, 0.72f);
|
|
|
|
_safeRingImm = new ImmediateMesh();
|
|
_safeRingMat = new StandardMaterial3D
|
|
{
|
|
AlbedoColor = new Color(1.0f, 0.38f, 0.14f, 0.78f),
|
|
EmissionEnabled = true,
|
|
Emission = new Color(1.0f, 0.32f, 0.08f),
|
|
EmissionEnergyMultiplier = 1.6f,
|
|
Transparency = BaseMaterial3D.TransparencyEnum.Alpha,
|
|
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
|
CullMode = BaseMaterial3D.CullModeEnum.Disabled
|
|
};
|
|
_safeRingMesh = new MeshInstance3D
|
|
{
|
|
Name = "SafeRing",
|
|
Mesh = _safeRingImm,
|
|
MaterialOverride = _safeRingMat,
|
|
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
|
};
|
|
AddChild(_safeRingMesh);
|
|
}
|
|
|
|
public void Sync(ArenaSession session, float elapsedSeconds)
|
|
{
|
|
var state = session.State;
|
|
if (!ReferenceEquals(_builtForState, state))
|
|
{
|
|
RebuildStaticArena(state);
|
|
ClearDynamicVisuals();
|
|
_builtForState = state;
|
|
}
|
|
|
|
UpdateSafeCircleRing(state.Terrain, state.Spectators.SafeRadius);
|
|
SyncContenders(session);
|
|
SyncSpectators(session, elapsedSeconds);
|
|
SyncGroundDrops(state, elapsedSeconds);
|
|
SyncTracers(state.Tracers);
|
|
}
|
|
|
|
private void RebuildStaticArena(MatchState state)
|
|
{
|
|
ClearChildren(_staticGroup);
|
|
|
|
for (int i = 0; i < state.ArenaCoverBoxes.Count; i++)
|
|
{
|
|
var b = state.ArenaCoverBoxes[i];
|
|
var mesh = new MeshInstance3D
|
|
{
|
|
Mesh = new BoxMesh { Size = new Vector3(b.HalfX * 2f, b.HalfY * 2f, b.HalfZ * 2f) },
|
|
MaterialOverride = _coverMat,
|
|
Position = new Vector3(b.X, b.Y, b.Z)
|
|
};
|
|
_staticGroup.AddChild(mesh);
|
|
}
|
|
|
|
for (int i = 0; i < state.ArenaBoundaryBoxes.Count; i++)
|
|
{
|
|
var b = state.ArenaBoundaryBoxes[i];
|
|
var mesh = new MeshInstance3D
|
|
{
|
|
Mesh = new BoxMesh { Size = new Vector3(b.HalfX * 2f, b.HalfY * 2f, b.HalfZ * 2f) },
|
|
MaterialOverride = _bermMat,
|
|
Position = new Vector3(b.X, b.Y, b.Z)
|
|
};
|
|
_staticGroup.AddChild(mesh);
|
|
}
|
|
}
|
|
|
|
private void ClearDynamicVisuals()
|
|
{
|
|
ClearChildren(_actorsGroup);
|
|
ClearChildren(_dropsGroup);
|
|
_contenderVisuals.Clear();
|
|
_spectatorVisuals.Clear();
|
|
_dropVisuals.Clear();
|
|
}
|
|
|
|
private void UpdateSafeCircleRing(TerrainField terrain, float safeRadius)
|
|
{
|
|
_safeRingImm.ClearSurfaces();
|
|
_safeRingImm.SurfaceBegin(Mesh.PrimitiveType.Triangles);
|
|
|
|
const int segments = 96;
|
|
const float halfThick = 0.65f;
|
|
float rInner = MathF.Max(2f, safeRadius - halfThick);
|
|
float rOuter = safeRadius + halfThick;
|
|
|
|
for (int i = 0; i < segments; i++)
|
|
{
|
|
float a0 = (i / (float)segments) * MathF.Tau;
|
|
float a1 = ((i + 1) / (float)segments) * MathF.Tau;
|
|
float c0 = MathF.Cos(a0), s0 = MathF.Sin(a0);
|
|
float c1 = MathF.Cos(a1), s1 = MathF.Sin(a1);
|
|
|
|
float x0i = c0 * rInner, z0i = s0 * rInner;
|
|
float x0o = c0 * rOuter, z0o = s0 * rOuter;
|
|
float x1i = c1 * rInner, z1i = s1 * rInner;
|
|
float x1o = c1 * rOuter, z1o = s1 * rOuter;
|
|
|
|
float y0 = terrain.SampleHeight(c0 * safeRadius, s0 * safeRadius) + 0.42f;
|
|
float y1 = terrain.SampleHeight(c1 * safeRadius, s1 * safeRadius) + 0.42f;
|
|
|
|
var p0i = new Vector3(x0i, y0, z0i);
|
|
var p0o = new Vector3(x0o, y0, z0o);
|
|
var p1i = new Vector3(x1i, y1, z1i);
|
|
var p1o = new Vector3(x1o, y1, z1o);
|
|
|
|
_safeRingImm.SurfaceAddVertex(p0i);
|
|
_safeRingImm.SurfaceAddVertex(p0o);
|
|
_safeRingImm.SurfaceAddVertex(p1o);
|
|
|
|
_safeRingImm.SurfaceAddVertex(p0i);
|
|
_safeRingImm.SurfaceAddVertex(p1o);
|
|
_safeRingImm.SurfaceAddVertex(p1i);
|
|
}
|
|
|
|
_safeRingImm.SurfaceEnd();
|
|
}
|
|
|
|
private void SyncContenders(ArenaSession session)
|
|
{
|
|
var view = session.World.View;
|
|
var contenders = session.State.Contenders;
|
|
|
|
for (int i = 0; i < contenders.Count; i++)
|
|
{
|
|
var c = contenders[i];
|
|
if (!c.Alive)
|
|
{
|
|
if (_contenderVisuals.TryGetValue(c.Id, out var deadVis))
|
|
{
|
|
deadVis.Root.Visible = false;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (!_contenderVisuals.TryGetValue(c.Id, out var vis) || vis.ChassisId != c.Grid.Spec.Id)
|
|
{
|
|
if (vis is not null)
|
|
{
|
|
vis.Root.QueueFree();
|
|
}
|
|
vis = BuildChassisVisual(
|
|
c.Grid.Spec.Id,
|
|
primary: c.IsPlayer ? OlivePaint : RivalSteel,
|
|
accent: c.IsPlayer ? SignalOrange : RivalAccent,
|
|
isSpectator: false,
|
|
tier: SpectatorTier.Patron);
|
|
_actorsGroup.AddChild(vis.Root);
|
|
_contenderVisuals[c.Id] = vis;
|
|
}
|
|
|
|
vis.Root.Visible = true;
|
|
var body = session.GetContenderBody(c.Id);
|
|
if (body is { } h)
|
|
{
|
|
int lane = h.Lane;
|
|
var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
|
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
|
vis.Root.Transform = new Transform3D(new Basis(q), pos);
|
|
}
|
|
else
|
|
{
|
|
vis.Root.Position = new Vector3(c.X, c.Y, c.Z);
|
|
vis.Root.Rotation = new Vector3(0f, c.Yaw, 0f);
|
|
}
|
|
|
|
if (vis.AimPivot is not null)
|
|
{
|
|
float aimYawWorld = MathF.Atan2(c.AimX - c.X, c.AimZ - c.Z);
|
|
float relYaw = MatchRules.NormalizeAngle(aimYawWorld - c.Yaw);
|
|
vis.AimPivot.Rotation = new Vector3(0f, relYaw, 0f);
|
|
}
|
|
|
|
UpdateHeatGlow(vis.HeatMat, c.Grid);
|
|
}
|
|
}
|
|
|
|
private void SyncSpectators(ArenaSession session, float elapsedSeconds)
|
|
{
|
|
var view = session.World.View;
|
|
var specs = session.State.Spectators.Spectators;
|
|
|
|
for (int i = 0; i < specs.Count; i++)
|
|
{
|
|
var s = specs[i];
|
|
if (!s.Alive)
|
|
{
|
|
if (_spectatorVisuals.TryGetValue(s.Id, out var deadVis))
|
|
{
|
|
deadVis.Root.Visible = false;
|
|
if (deadVis.LaserMesh is not null)
|
|
{
|
|
deadVis.LaserMesh.Visible = false;
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (!_spectatorVisuals.TryGetValue(s.Id, out var vis))
|
|
{
|
|
var (primary, accent) = s.Tier switch
|
|
{
|
|
SpectatorTier.Tourist => (TouristGold, TouristIvory),
|
|
SpectatorTier.Patron => (PatronTeal, PatronBronze),
|
|
_ => (ExemplarObsidian, ExemplarCrimson)
|
|
};
|
|
vis = BuildChassisVisual(s.Grid.Spec.Id, primary, accent, isSpectator: true, tier: s.Tier);
|
|
_actorsGroup.AddChild(vis.Root);
|
|
_spectatorVisuals[s.Id] = vis;
|
|
}
|
|
|
|
vis.Root.Visible = true;
|
|
var body = session.GetSpectatorBody(s.Id);
|
|
Vector3 specPos;
|
|
if (body is { } h)
|
|
{
|
|
int lane = h.Lane;
|
|
specPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
|
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
|
vis.Root.Transform = new Transform3D(new Basis(q), specPos);
|
|
}
|
|
else
|
|
{
|
|
specPos = new Vector3(s.X, s.Y, s.Z);
|
|
vis.Root.Position = specPos;
|
|
vis.Root.Rotation = new Vector3(0f, s.Yaw, 0f);
|
|
}
|
|
|
|
// Status halo
|
|
if (vis.HaloMat is not null && vis.HaloMesh is not null)
|
|
{
|
|
if (s.Stance == SpectatorStance.Neutral)
|
|
{
|
|
vis.HaloMat.AlbedoColor = new Color(0.88f, 0.65f, 0.25f, 0.45f);
|
|
vis.HaloMat.Emission = new Color(0.88f, 0.65f, 0.25f);
|
|
vis.HaloMat.EmissionEnergyMultiplier = 0.6f;
|
|
}
|
|
else if (s.Stance == SpectatorStance.Cleared)
|
|
{
|
|
vis.HaloMat.AlbedoColor = new Color(1.0f, 0.22f, 0.18f, 0.9f);
|
|
vis.HaloMat.Emission = new Color(1.0f, 0.2f, 0.15f);
|
|
vis.HaloMat.EmissionEnergyMultiplier = 2.0f;
|
|
}
|
|
else
|
|
{
|
|
float pulse = 1.6f + 1.2f * MathF.Sin(elapsedSeconds * 10f);
|
|
vis.HaloMat.AlbedoColor = new Color(1.0f, 0.1f, 0.1f, 0.95f);
|
|
vis.HaloMat.Emission = new Color(1.0f, 0.08f, 0.08f);
|
|
vis.HaloMat.EmissionEnergyMultiplier = pulse;
|
|
}
|
|
}
|
|
|
|
// Lock-on laser beam when Cleared or Provoked
|
|
if (vis.LaserMesh is not null)
|
|
{
|
|
ContenderState? target = s.TargetContenderId.HasValue &&
|
|
s.TargetContenderId.Value >= 0 &&
|
|
s.TargetContenderId.Value < session.State.Contenders.Count
|
|
? session.State.Contenders[s.TargetContenderId.Value]
|
|
: null;
|
|
|
|
if (s.Stance != SpectatorStance.Neutral && target is { Alive: true })
|
|
{
|
|
Vector3 start = specPos + new Vector3(0f, s.Grid.Spec.HalfHeight * 0.7f, 0f);
|
|
Vector3 end = new Vector3(target.X, target.Y + target.Grid.Spec.HalfHeight * 0.3f, target.Z);
|
|
float dist = start.DistanceTo(end);
|
|
if (dist > 0.5f)
|
|
{
|
|
vis.LaserMesh.Visible = true;
|
|
vis.LaserMesh.GlobalPosition = (start + end) * 0.5f;
|
|
Vector3 dir = (end - start) / dist;
|
|
Vector3 up = MathF.Abs(dir.Dot(Vector3.Up)) > 0.99f ? Vector3.Right : Vector3.Up;
|
|
vis.LaserMesh.LookAt(end, up);
|
|
vis.LaserMesh.Scale = new Vector3(1f, 1f, dist);
|
|
}
|
|
else
|
|
{
|
|
vis.LaserMesh.Visible = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
vis.LaserMesh.Visible = false;
|
|
}
|
|
}
|
|
|
|
UpdateHeatGlow(vis.HeatMat, s.Grid);
|
|
}
|
|
}
|
|
|
|
private void SyncGroundDrops(MatchState state, float elapsedSeconds)
|
|
{
|
|
for (int i = 0; i < state.GroundDrops.Count; i++)
|
|
{
|
|
var d = state.GroundDrops[i];
|
|
if (d.PickedUp)
|
|
{
|
|
if (_dropVisuals.TryGetValue(d.Id, out var pickedNode))
|
|
{
|
|
pickedNode.Visible = false;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (!_dropVisuals.TryGetValue(d.Id, out var node))
|
|
{
|
|
node = BuildGroundDropVisual(d, state.Terrain);
|
|
_dropsGroup.AddChild(node);
|
|
_dropVisuals[d.Id] = node;
|
|
}
|
|
|
|
node.Visible = true;
|
|
float bob = d.Module is not null ? MathF.Sin(elapsedSeconds * 2.5f + d.Id) * 0.12f : 0f;
|
|
float baseY = state.Terrain.SampleHeight(d.X, d.Z);
|
|
node.Position = new Vector3(d.X, baseY + bob, d.Z);
|
|
if (d.Module is not null)
|
|
{
|
|
node.Rotation = new Vector3(0f, elapsedSeconds * 0.9f + d.Id, 0f);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SyncTracers(IReadOnlyList<TracerEvent> tracers)
|
|
{
|
|
while (_tracerPool.Count < tracers.Count)
|
|
{
|
|
var mat = new StandardMaterial3D
|
|
{
|
|
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
|
EmissionEnabled = true
|
|
};
|
|
var mesh = new MeshInstance3D
|
|
{
|
|
Mesh = new BoxMesh { Size = new Vector3(0.14f, 0.14f, 1.0f) },
|
|
MaterialOverride = mat,
|
|
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
|
};
|
|
_tracersGroup.AddChild(mesh);
|
|
_tracerPool.Add(mesh);
|
|
}
|
|
|
|
for (int i = 0; i < _tracerPool.Count; i++)
|
|
{
|
|
var m = _tracerPool[i];
|
|
if (i >= tracers.Count)
|
|
{
|
|
m.Visible = false;
|
|
continue;
|
|
}
|
|
|
|
var t = tracers[i];
|
|
var start = new Vector3(t.StartX, t.StartY, t.StartZ);
|
|
var end = new Vector3(t.EndX, t.EndY, t.EndZ);
|
|
float dist = start.DistanceTo(end);
|
|
if (dist < 0.1f)
|
|
{
|
|
m.Visible = false;
|
|
continue;
|
|
}
|
|
|
|
m.Visible = true;
|
|
m.Position = (start + end) * 0.5f;
|
|
Vector3 dir = (end - start).Normalized();
|
|
Vector3 up = MathF.Abs(dir.Dot(Vector3.Up)) > 0.95f ? Vector3.Right : Vector3.Up;
|
|
m.LookAt(end, up);
|
|
m.Scale = new Vector3(1f, 1f, dist);
|
|
|
|
var col = new Color(
|
|
((t.ColorRgba >> 24) & 0xFF) / 255f,
|
|
((t.ColorRgba >> 16) & 0xFF) / 255f,
|
|
((t.ColorRgba >> 8) & 0xFF) / 255f,
|
|
1f);
|
|
if (m.MaterialOverride is StandardMaterial3D sm)
|
|
{
|
|
sm.AlbedoColor = col;
|
|
sm.Emission = col;
|
|
sm.EmissionEnergyMultiplier = 2.5f;
|
|
}
|
|
}
|
|
}
|
|
|
|
private Node3D BuildGroundDropVisual(GroundDrop drop, TerrainField terrain)
|
|
{
|
|
var root = new Node3D { Name = $"Drop_{drop.Id}" };
|
|
if (drop.Module is { } mod)
|
|
{
|
|
var mat = mod.IsImperial ? _imperialCrateMat : _humanCrateMat;
|
|
root.AddChild(new MeshInstance3D
|
|
{
|
|
Mesh = new BoxMesh { Size = new Vector3(1.1f, 0.8f, 1.1f) },
|
|
MaterialOverride = mat,
|
|
Position = new Vector3(0f, 0.5f, 0f)
|
|
});
|
|
if (mod.IsImperial)
|
|
{
|
|
root.AddChild(new MeshInstance3D
|
|
{
|
|
Mesh = new CylinderMesh { TopRadius = 0.08f, BottomRadius = 0.25f, Height = 5.5f, RadialSegments = 8 },
|
|
MaterialOverride = _imperialCrateMat,
|
|
Position = new Vector3(0f, 3.0f, 0f)
|
|
});
|
|
}
|
|
}
|
|
else if (drop.Chassis is { } ch)
|
|
{
|
|
var hull = BuildChassisVisual(ch.Id, new Color(0.32f, 0.35f, 0.36f), CyanSalvage, isSpectator: false, tier: SpectatorTier.Patron);
|
|
hull.Root.Position = new Vector3(0f, ch.HalfHeight * 0.85f, 0f);
|
|
hull.Root.Scale = new Vector3(0.85f, 0.85f, 0.85f);
|
|
root.AddChild(hull.Root);
|
|
|
|
var ring = new MeshInstance3D
|
|
{
|
|
Mesh = new CylinderMesh { TopRadius = 2.6f, BottomRadius = 2.8f, Height = 0.14f, RadialSegments = 18 },
|
|
MaterialOverride = _cyanBeaconMat,
|
|
Position = new Vector3(0f, 0.15f, 0f)
|
|
};
|
|
root.AddChild(ring);
|
|
}
|
|
return root;
|
|
}
|
|
|
|
private ActorVisual BuildChassisVisual(
|
|
string chassisId,
|
|
Color primary,
|
|
Color accent,
|
|
bool isSpectator,
|
|
SpectatorTier tier)
|
|
{
|
|
var root = new Node3D { Name = $"Chassis_{chassisId}" };
|
|
var bodyMat = new StandardMaterial3D { AlbedoColor = primary, Roughness = 0.55f, Metallic = 0.45f };
|
|
var accentMat = new StandardMaterial3D { AlbedoColor = accent, Roughness = 0.45f, Metallic = 0.55f };
|
|
var darkMat = new StandardMaterial3D { AlbedoColor = new Color(0.14f, 0.15f, 0.14f), Roughness = 0.8f, Metallic = 0.35f };
|
|
var heatMat = new StandardMaterial3D
|
|
{
|
|
AlbedoColor = accent,
|
|
Roughness = 0.4f,
|
|
Metallic = 0.6f,
|
|
EmissionEnabled = true,
|
|
Emission = new Color(1.0f, 0.35f, 0.1f),
|
|
EmissionEnergyMultiplier = 0.0f
|
|
};
|
|
|
|
var aimPivot = new Node3D { Name = "AimPivot" };
|
|
root.AddChild(aimPivot);
|
|
|
|
switch (chassisId)
|
|
{
|
|
case "buggy":
|
|
BuildBuggyParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
|
|
break;
|
|
case "technical":
|
|
BuildTechnicalParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
|
|
break;
|
|
case "tank":
|
|
BuildTankParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
|
|
break;
|
|
case "manticore":
|
|
BuildManticoreParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
|
|
break;
|
|
case "raptor":
|
|
case "exemplar_frame":
|
|
BuildRaptorParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat, isExemplar: chassisId == "exemplar_frame");
|
|
break;
|
|
case "paladin":
|
|
BuildPaladinParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat, isTourist: isSpectator && tier == SpectatorTier.Tourist);
|
|
break;
|
|
default:
|
|
BuildBuggyParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
|
|
break;
|
|
}
|
|
|
|
var vis = new ActorVisual
|
|
{
|
|
Root = root,
|
|
AimPivot = aimPivot,
|
|
HeatMat = heatMat,
|
|
ChassisId = chassisId
|
|
};
|
|
|
|
if (isSpectator)
|
|
{
|
|
var haloMat = new StandardMaterial3D
|
|
{
|
|
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
|
EmissionEnabled = true,
|
|
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
|
};
|
|
var halo = new MeshInstance3D
|
|
{
|
|
Mesh = new CylinderMesh { TopRadius = 2.4f, BottomRadius = 2.4f, Height = 0.1f, RadialSegments = 16 },
|
|
MaterialOverride = haloMat,
|
|
Position = new Vector3(0f, 3.3f, 0f),
|
|
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
|
};
|
|
root.AddChild(halo);
|
|
vis.HaloMesh = halo;
|
|
vis.HaloMat = haloMat;
|
|
|
|
var laserMat = new StandardMaterial3D
|
|
{
|
|
AlbedoColor = new Color(1f, 0.15f, 0.15f, 0.85f),
|
|
EmissionEnabled = true,
|
|
Emission = new Color(1f, 0.12f, 0.1f),
|
|
EmissionEnergyMultiplier = 2.2f,
|
|
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
|
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
|
};
|
|
var laser = new MeshInstance3D
|
|
{
|
|
Mesh = new BoxMesh { Size = new Vector3(0.08f, 0.08f, 1.0f) },
|
|
MaterialOverride = laserMat,
|
|
Visible = false,
|
|
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
|
};
|
|
_actorsGroup.AddChild(laser);
|
|
vis.LaserMesh = laser;
|
|
vis.LaserMat = laserMat;
|
|
}
|
|
|
|
return vis;
|
|
}
|
|
|
|
private static void BuildBuggyParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat)
|
|
{
|
|
AddBox(root, new Vector3(1.5f, 0.45f, 2.9f), new Vector3(0f, -0.25f, 0f), bodyMat);
|
|
AddBox(root, new Vector3(1.1f, 0.45f, 1.3f), new Vector3(0f, 0.25f, -0.2f), accentMat); // rollcage canopy
|
|
AddBox(root, new Vector3(0.8f, 0.32f, 0.5f), new Vector3(0f, 0.15f, -1.35f), heatMat); // rear radiator
|
|
// 4 wheels
|
|
AddWheel(root, new Vector3(-0.98f, -0.45f, 1.05f), 0.36f, 0.32f, darkMat);
|
|
AddWheel(root, new Vector3( 0.98f, -0.45f, 1.05f), 0.36f, 0.32f, darkMat);
|
|
AddWheel(root, new Vector3(-0.98f, -0.45f, -1.05f), 0.36f, 0.32f, darkMat);
|
|
AddWheel(root, new Vector3( 0.98f, -0.45f, -1.05f), 0.36f, 0.32f, darkMat);
|
|
// Roof MG turret
|
|
aimPivot.Position = new Vector3(0f, 0.6f, 0f);
|
|
AddBox(aimPivot, new Vector3(0.45f, 0.26f, 0.55f), Vector3.Zero, darkMat);
|
|
AddBox(aimPivot, new Vector3(0.12f, 0.12f, 1.25f), new Vector3(0f, 0.04f, 0.65f), accentMat);
|
|
}
|
|
|
|
private static void BuildTechnicalParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat)
|
|
{
|
|
AddBox(root, new Vector3(2.0f, 0.55f, 4.2f), new Vector3(0f, -0.25f, 0f), bodyMat);
|
|
AddBox(root, new Vector3(1.85f, 0.72f, 1.5f), new Vector3(0f, 0.35f, 0.85f), accentMat); // armored cab
|
|
AddBox(root, new Vector3(1.9f, 0.38f, 2.0f), new Vector3(0f, 0.20f, -0.95f), bodyMat); // bed walls
|
|
AddBox(root, new Vector3(1.2f, 0.30f, 0.4f), new Vector3(0f, 0.20f, -2.0f), heatMat); // tail radiator
|
|
AddWheel(root, new Vector3(-1.12f, -0.55f, 1.45f), 0.44f, 0.36f, darkMat);
|
|
AddWheel(root, new Vector3( 1.12f, -0.55f, 1.45f), 0.44f, 0.36f, darkMat);
|
|
AddWheel(root, new Vector3(-1.12f, -0.55f, -1.45f), 0.44f, 0.36f, darkMat);
|
|
AddWheel(root, new Vector3( 1.12f, -0.55f, -1.45f), 0.44f, 0.36f, darkMat);
|
|
aimPivot.Position = new Vector3(0f, 0.72f, -0.8f);
|
|
AddBox(aimPivot, new Vector3(0.65f, 0.4f, 0.7f), Vector3.Zero, darkMat);
|
|
AddBox(aimPivot, new Vector3(0.14f, 0.14f, 1.7f), new Vector3(-0.18f, 0.08f, 0.8f), accentMat);
|
|
AddBox(aimPivot, new Vector3(0.14f, 0.14f, 1.7f), new Vector3( 0.18f, 0.08f, 0.8f), accentMat);
|
|
}
|
|
|
|
private static void BuildTankParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat)
|
|
{
|
|
AddBox(root, new Vector3(2.4f, 0.85f, 4.6f), new Vector3(0f, -0.2f, 0f), bodyMat);
|
|
AddBox(root, new Vector3(0.55f, 0.72f, 4.9f), new Vector3(-1.32f, -0.45f, 0f), darkMat); // left track pod
|
|
AddBox(root, new Vector3(0.55f, 0.72f, 4.9f), new Vector3( 1.32f, -0.45f, 0f), darkMat); // right track pod
|
|
AddBox(root, new Vector3(1.6f, 0.35f, 0.7f), new Vector3(0f, 0.25f, -1.7f), heatMat); // rear engine deck
|
|
aimPivot.Position = new Vector3(0f, 0.65f, 0.2f);
|
|
AddBox(aimPivot, new Vector3(1.75f, 0.68f, 2.2f), Vector3.Zero, accentMat);
|
|
AddBox(aimPivot, new Vector3(0.24f, 0.24f, 3.0f), new Vector3(0f, 0.05f, 2.0f), darkMat); // main cannon
|
|
}
|
|
|
|
private static void BuildManticoreParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat)
|
|
{
|
|
// Wide dorsal carapace + 4 splayed articulated legs + radiator flanks
|
|
AddBox(root, new Vector3(2.2f, 0.75f, 2.8f), new Vector3(0f, 0.25f, 0f), bodyMat);
|
|
AddBox(root, new Vector3(1.3f, 0.55f, 1.2f), new Vector3(0f, 0.45f, 1.2f), accentMat); // chin armor
|
|
AddBox(root, new Vector3(0.45f, 0.45f, 1.4f), new Vector3(-1.25f, 0.45f, -0.4f), heatMat);
|
|
AddBox(root, new Vector3(0.45f, 0.45f, 1.4f), new Vector3( 1.25f, 0.45f, -0.4f), heatMat);
|
|
|
|
Vector3[] legAnchors =
|
|
{
|
|
new(-1.35f, -0.35f, 1.25f),
|
|
new( 1.35f, -0.35f, 1.25f),
|
|
new(-1.35f, -0.35f, -1.25f),
|
|
new( 1.35f, -0.35f, -1.25f)
|
|
};
|
|
for (int i = 0; i < legAnchors.Length; i++)
|
|
{
|
|
AddBox(root, new Vector3(0.42f, 1.35f, 0.42f), legAnchors[i], darkMat);
|
|
AddBox(root, new Vector3(0.68f, 0.26f, 0.68f), legAnchors[i] + new Vector3(0f, -0.7f, 0f), accentMat);
|
|
}
|
|
|
|
aimPivot.Position = new Vector3(0f, 0.8f, 0.2f);
|
|
AddBox(aimPivot, new Vector3(0.9f, 0.38f, 1.0f), Vector3.Zero, darkMat);
|
|
AddBox(aimPivot, new Vector3(0.18f, 0.18f, 1.7f), new Vector3(-0.6f, 0f, 0.75f), accentMat);
|
|
AddBox(aimPivot, new Vector3(0.18f, 0.18f, 1.7f), new Vector3( 0.6f, 0f, 0.75f), accentMat);
|
|
}
|
|
|
|
private static void BuildRaptorParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat, bool isExemplar)
|
|
{
|
|
float scale = isExemplar ? 0.78f : 1.0f;
|
|
// Tall bipedal legs
|
|
AddBox(root, new Vector3(0.42f * scale, 1.85f * scale, 0.52f * scale), new Vector3(-0.62f * scale, -0.8f * scale, 0f), darkMat);
|
|
AddBox(root, new Vector3(0.42f * scale, 1.85f * scale, 0.52f * scale), new Vector3( 0.62f * scale, -0.8f * scale, 0f), darkMat);
|
|
// Angled torso + head sensor
|
|
AddBox(root, new Vector3(1.55f * scale, 1.15f * scale, 1.25f * scale), new Vector3(0f, 0.45f * scale, 0f), bodyMat);
|
|
AddBox(root, new Vector3(0.65f * scale, 0.45f * scale, 0.85f * scale), new Vector3(0f, 1.25f * scale, 0.25f * scale), accentMat);
|
|
AddBox(root, new Vector3(0.95f * scale, 0.55f * scale, 0.35f * scale), new Vector3(0f, 0.6f * scale, -0.75f * scale), heatMat);
|
|
|
|
aimPivot.Position = new Vector3(0f, 0.5f * scale, 0f);
|
|
AddBox(aimPivot, new Vector3(0.32f * scale, 0.35f * scale, 1.55f * scale), new Vector3(-1.05f * scale, 0f, 0.55f * scale), accentMat);
|
|
AddBox(aimPivot, new Vector3(0.32f * scale, 0.35f * scale, 1.55f * scale), new Vector3( 1.05f * scale, 0f, 0.55f * scale), accentMat);
|
|
}
|
|
|
|
private static void BuildPaladinParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat, bool isTourist)
|
|
{
|
|
// Broad heavy bipedal silhouette + shoulder pods + chest reactor
|
|
AddBox(root, new Vector3(0.68f, 2.0f, 0.82f), new Vector3(-0.85f, -1.1f, 0f), darkMat);
|
|
AddBox(root, new Vector3(0.68f, 2.0f, 0.82f), new Vector3( 0.85f, -1.1f, 0f), darkMat);
|
|
AddBox(root, new Vector3(2.25f, 1.65f, 1.65f), new Vector3(0f, 0.45f, 0f), bodyMat);
|
|
AddBox(root, new Vector3(0.85f, 0.75f, 0.35f), new Vector3(0f, 0.55f, 0.85f), heatMat); // chest reactor
|
|
// Twin shoulder pods
|
|
AddBox(root, new Vector3(0.75f, 0.72f, 1.15f), new Vector3(-1.35f, 1.45f, 0f), accentMat);
|
|
AddBox(root, new Vector3(0.75f, 0.72f, 1.15f), new Vector3( 1.35f, 1.45f, 0f), accentMat);
|
|
|
|
if (isTourist)
|
|
{
|
|
// Gaudy gilded luxury dome on top so Tourists are unmistakable loot pinatas
|
|
var dome = new MeshInstance3D
|
|
{
|
|
Mesh = new CylinderMesh { TopRadius = 0.5f, BottomRadius = 0.95f, Height = 0.75f, RadialSegments = 12 },
|
|
MaterialOverride = bodyMat,
|
|
Position = new Vector3(0f, 1.65f, 0f)
|
|
};
|
|
root.AddChild(dome);
|
|
}
|
|
|
|
aimPivot.Position = new Vector3(0f, 0.45f, 0f);
|
|
AddBox(aimPivot, new Vector3(0.45f, 0.48f, 2.0f), new Vector3(-1.45f, 0f, 0.65f), accentMat);
|
|
AddBox(aimPivot, new Vector3(0.45f, 0.48f, 2.0f), new Vector3( 1.45f, 0f, 0.65f), accentMat);
|
|
}
|
|
|
|
private static void AddBox(Node3D parent, Vector3 size, Vector3 pos, Material mat)
|
|
{
|
|
parent.AddChild(new MeshInstance3D
|
|
{
|
|
Mesh = new BoxMesh { Size = size },
|
|
MaterialOverride = mat,
|
|
Position = pos
|
|
});
|
|
}
|
|
|
|
private static void AddWheel(Node3D parent, Vector3 pos, float radius, float width, Material mat)
|
|
{
|
|
parent.AddChild(new MeshInstance3D
|
|
{
|
|
Mesh = new CylinderMesh { TopRadius = radius, BottomRadius = radius, Height = width, RadialSegments = 12 },
|
|
MaterialOverride = mat,
|
|
Position = pos,
|
|
Rotation = new Vector3(0f, 0f, MathF.PI * 0.5f)
|
|
});
|
|
}
|
|
|
|
private static void UpdateHeatGlow(StandardMaterial3D heatMat, ChassisGrid grid)
|
|
{
|
|
float maxTemp = ChassisGrid.AmbientTemp;
|
|
for (int i = 0; i < grid.Mounted.Count; i++)
|
|
{
|
|
maxTemp = MathF.Max(maxTemp, grid.Mounted[i].CurrentTemp);
|
|
}
|
|
float glow = Math.Clamp((maxTemp - 65f) / 110f, 0f, 1f);
|
|
heatMat.EmissionEnergyMultiplier = glow * 2.6f;
|
|
}
|
|
|
|
private static void ClearChildren(Node parent)
|
|
{
|
|
for (int i = parent.GetChildCount() - 1; i >= 0; i--)
|
|
{
|
|
var child = parent.GetChild(i);
|
|
parent.RemoveChild(child);
|
|
child.QueueFree();
|
|
}
|
|
}
|
|
}
|