Fix Cut 3b Soul Pass #1 vehicle orientation, grounding, rig, halo, and debris findings

This commit is contained in:
Meta Vens 2026-12-04 21:08:50 +01:00
commit 3e90ba2dc3
6 changed files with 750 additions and 95 deletions

View file

@ -562,19 +562,29 @@ public partial class Smoke : Node
mountedMeshes++;
if (m.Spec.Kind == HardpointKind.Weapon)
{
var gTemplate = cache.GetOrLoadGear(m.Spec.Id switch
(string frontPart, string rearPart) = m.Spec.Id switch
{
"mg_762" or "pd_flak" => "mg_762",
"autocannon" or "flak" => "autocannon",
"recoilless" => "recoilless",
_ => "gilded_lance"
});
// Anchor's model-space transform * gNode local transform * gear's LocalModelForward gives muzzle dir in vehicle space (+Z forward)
var pkgHp = System.Linq.Enumerable.First(pkg.Hardpoints, h => h.Id == m.HardpointId);
Basis anchorBasis = vis.Template.Anchors[pkgHp.AnchorId].ModelSpaceTransform.Basis.Orthonormalized();
Vector3 muzzleVeh = (anchorBasis * (gNode.Basis.Orthonormalized() * gTemplate.LocalModelForward)).Normalized();
Check(muzzleVeh.Z > 0.75f,
$"Expected weapon '{m.Spec.Id}' on '{spec.Id}.{m.HardpointId}' to point forward (+Z), got muzzle={muzzleVeh}");
"mg_762" or "pd_flak" => ("barrel_inner", "receiver"),
"autocannon" or "flak" => ("muzzle_brake_L", "gun_housing"),
"recoilless" => ("sight_tube", "breech_band"),
_ => ("condenser_ring_2", "ivory_cowl")
};
Vector3? frontC = ComputeSubtreeVertexCentroidInAncestor(gNode, vis.ModelRoot, frontPart);
Vector3? rearC = ComputeSubtreeVertexCentroidInAncestor(gNode, vis.ModelRoot, rearPart);
Check(frontC.HasValue && rearC.HasValue,
$"Missing weapon submeshes '{frontPart}'/'{rearPart}' on '{spec.Id}.{m.HardpointId}' ({m.Spec.Id})");
if (frontC.HasValue && rearC.HasValue)
{
Vector3 muzzleDir = (frontC.Value - rearC.Value).Normalized();
if (m.Spec.Id == "recoilless")
{
GD.Print($"SMOKE INFO: recoilless {spec.Id}.{m.HardpointId} sight_tube={frontC.Value} breech={rearC.Value} dir={muzzleDir}");
Check(frontC.Value.Z > rearC.Value.Z + 0.20f,
$"Expected recoilless sight_tube (+Z) ahead of breech_band on '{spec.Id}.{m.HardpointId}', got sight={frontC.Value}, breech={rearC.Value}");
}
Check(muzzleDir.Z > 0.75f,
$"Expected weapon '{m.Spec.Id}' on '{spec.Id}.{m.HardpointId}' mesh geometry to point forward (+Z), got dir={muzzleDir}");
}
}
}
}
@ -700,6 +710,216 @@ public partial class Smoke : Node
debris.QueueFree();
}
// 4. Full Paladin hull + gear strip retains >160 pieces without mid-air eviction (MaxActiveDebris = 256)
{
var debris = new DebrisSystem { Name = "SmokePaladinDebrisTest" };
AddChild(debris);
var palGrid = Catalog.CreateWithDefaultLoadout(Catalog.Paladin);
var palVis = VehicleVisualInstance.Create(cache, "paladin", VehicleVisualRole.Player);
AddChild(palVis.Root);
palVis.SyncMountedGear(palGrid);
for (int cy = 0; cy < palGrid.Spec.Height; cy++)
{
for (int cx = 0; cx < palGrid.Spec.Width; cx++)
{
palGrid.Armor[cx, cy] = 0f;
}
}
palVis.SyncDamageAndHeat(palGrid, debris, new Vector3(1f, 0f, 3f));
GD.Print($"SMOKE INFO: Full Paladin strip debris.ActiveCount={debris.ActiveCount}");
Check(debris.ActiveCount > 160 && debris.ActiveCount <= 256,
$"Expected full Paladin strip to retain >160 debris pieces under 256 cap, got {debris.ActiveCount}");
palVis.Root.QueueFree();
debris.QueueFree();
}
// 5. All 15 ChassisDrop salvage wrecks ground within 0.05m of terrain & PickedUp frees drop nodes cleanly
{
var drops = _main.Session.State.GroundDrops;
int baseCount = drops.Count;
_main.Arena.Sync(_main.Session, 1.0f, 1f / 60f);
int dropNodesBefore = _main.Arena.DropGroupChildCount;
int trackedBefore = _main.Arena.ActiveDropVisualCount;
int nextId = 90000;
var added = new List<GroundDrop>(Catalog.AllChassis.Count);
float maxGroundErr = 0f;
for (int i = 0; i < Catalog.AllChassis.Count; i++)
{
var spec = Catalog.AllChassis[i];
float dx = -80f + i * 11f;
float dz = -40f;
var d = new GroundDrop(nextId++, dx, dz, spec, null);
drops.Add(d);
added.Add(d);
}
_main.Arena.Sync(_main.Session, 1.0f, 1f / 60f);
Check(_main.Arena.ActiveDropVisualCount == trackedBefore + added.Count,
$"Expected {trackedBefore + added.Count} tracked drop visuals, got {_main.Arena.ActiveDropVisualCount}");
for (int i = 0; i < added.Count; i++)
{
var d = added[i];
Node3D? dropNode = _main.Arena.GetNodeOrNull<Node3D>($"GroundDrops/Drop_{d.Id}");
Check(dropNode is not null, $"Missing Drop_{d.Id} node for ChassisDrop '{d.Chassis!.Id}'");
if (dropNode is not null)
{
Node3D? actorNode = dropNode.GetNodeOrNull<Node3D>($"Actor_{d.Chassis!.Id}");
Check(actorNode is not null, $"Missing Actor_{d.Chassis!.Id} under Drop_{d.Id}");
if (actorNode is not null)
{
float minWorldY = ComputeSubtreeMinWorldY(actorNode, dropNode.Position.Y);
float terrainY = _main.Session.State.Terrain.SampleHeight(d.X, d.Z);
float err = MathF.Abs(minWorldY - terrainY);
if (err > maxGroundErr) maxGroundErr = err;
Check(err <= 0.05f,
$"ChassisDrop '{d.Chassis!.Id}' buried/floating: minWorldY={minWorldY:F4}m terrainY={terrainY:F4}m err={err:F4}m");
}
}
}
GD.Print($"SMOKE INFO: ChassisDrop max ground err={maxGroundErr:F4}m across {added.Count} chassis");
for (int i = 0; i < added.Count; i++)
{
added[i].PickedUp = true;
}
_main.Arena.Sync(_main.Session, 1.1f, 1f / 60f);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
Check(_main.Arena.ActiveDropVisualCount == trackedBefore,
$"Expected picked-up drops removed from _dropVisuals ({trackedBefore}), got {_main.Arena.ActiveDropVisualCount}");
Check(_main.Arena.DropGroupChildCount == dropNodesBefore,
$"Expected picked-up drop nodes freed from GroundDrops ({dropNodesBefore}), got {_main.Arena.DropGroupChildCount}");
drops.RemoveRange(baseCount, added.Count);
}
// 6. All 7 walkers stay grounded (minVertexY - restMinY >= -0.05m) and swing along +Z/-Z through a full stride cycle
{
var walkerChecks = new (string Id, string? FootNode, string? PelvisNode, bool CheckSagittal)[]
{
("raptor", "LegL.Cannon", "Pelvis", true),
("spectre", "LegL.Cannon", "Pelvis", true),
("manticore", "FootFL", "Hull", true),
("bastion", "Ankle.fl", "Trunk", true),
("breaker", "LegL.Foot", "Pelvis", true),
("paladin", "LegL.Ankle", "Pelvis", true),
("kestrel", null, null, false),
};
foreach (var (wId, footNodeName, pelvisNodeName, checkSagittal) in walkerChecks)
{
var vis = VehicleVisualInstance.Create(cache, wId, VehicleVisualRole.Player);
float restMinY = ComputeSubtreeMinWorldY(vis.ModelRoot, 0f, relativeToModelRoot: true);
float worstRelMinY = float.PositiveInfinity;
float minFootZ = float.PositiveInfinity, maxFootZ = float.NegativeInfinity;
float minFootX = float.PositiveInfinity, maxFootX = float.NegativeInfinity;
Node3D? footNode = footNodeName is not null ? vis.GetNamedNode(footNodeName) : null;
Node3D? pelvisNode = pelvisNodeName is not null ? vis.GetNamedNode(pelvisNodeName) : null;
var walkInp = new VehicleRigDriveInput(
new Vector3(0f, 0f, 8f), 0f, 0f, 0f, 0f, 1f, 0f, 1f, 0.05f);
for (int step = 0; step < 48; step++)
{
VehicleRigAnimator.Update(vis, in walkInp, Basis.Identity);
float curMinY = ComputeSubtreeMinWorldY(vis.ModelRoot, 0f, relativeToModelRoot: true);
float relMinY = curMinY - restMinY;
if (relMinY < worstRelMinY) worstRelMinY = relMinY;
Check(!float.IsNaN(curMinY), $"NaN vertex Y on walker '{wId}' step {step}");
if (footNode is not null && pelvisNode is not null)
{
Vector3 fPos = TransformPointToAncestor(footNode, pelvisNode, Vector3.Zero);
if (fPos.Z < minFootZ) minFootZ = fPos.Z;
if (fPos.Z > maxFootZ) maxFootZ = fPos.Z;
if (fPos.X < minFootX) minFootX = fPos.X;
if (fPos.X > maxFootX) maxFootX = fPos.X;
}
}
float zSpan = footNode is not null ? maxFootZ - minFootZ : 0f;
float xSpan = footNode is not null ? maxFootX - minFootX : 0f;
GD.Print($"SMOKE INFO: Walker {wId} stride minFootY={worstRelMinY:F4}m zSpan={zSpan:F3}m xSpan={xSpan:F3}m");
Check(worstRelMinY >= -0.05f,
$"Walker '{wId}' foot plunged below rest floor: minRelY={worstRelMinY:F4}m");
if (checkSagittal && footNode is not null)
{
Check(zSpan > 0.12f,
$"Expected walker '{wId}' foot '{footNodeName}' to stride along Z > 0.12m, got {zSpan:F3}m");
Check(xSpan < 0.03f,
$"Expected walker '{wId}' foot '{footNodeName}' to swing cleanly in sagittal plane (xSpan < 0.03m), got {xSpan:F3}m");
}
vis.Root.QueueFree();
}
}
// 7. VehicleRigAnimator.Update with dt == 0 is a strict no-op unless snap == true
{
var anvilVis = VehicleVisualInstance.Create(cache, "anvil", VehicleVisualRole.Player);
var driveInp = new VehicleRigDriveInput(
new Vector3(0f, 0f, 6f), 0f, 0.2f, 5f, 0.2f, 0.5f, 0f, 1f, 1f / 60f);
for (int s = 0; s < 10; s++)
{
VehicleRigAnimator.Update(anvilVis, in driveInp, Basis.Identity);
}
var beforeTransforms = new Dictionary<string, Transform3D>();
foreach (var (jid, j) in anvilVis.Joints)
{
beforeTransforms[jid] = j.Node.Transform;
}
var zeroDtInp = new VehicleRigDriveInput(
new Vector3(0f, 0f, 12f), 0f, 1.9f, 35f, -1f, 1f, 0f, 1f, 0f);
VehicleRigAnimator.Update(anvilVis, in zeroDtInp, Basis.Identity);
float maxDelta = 0f;
foreach (var (jid, before) in beforeTransforms)
{
Transform3D after = anvilVis.Joints[jid].Node.Transform;
float dOrigin = (after.Origin - before.Origin).Length();
float dRot = before.Basis.GetRotationQuaternion().AngleTo(after.Basis.GetRotationQuaternion());
maxDelta = MathF.Max(maxDelta, MathF.Max(dOrigin, dRot));
}
VehicleRigAnimator.Update(anvilVis, in zeroDtInp, Basis.Identity, snap: true);
Transform3D snapped = anvilVis.Joints["joint.turret_yaw"].Node.Transform;
float snapDelta = beforeTransforms["joint.turret_yaw"].Basis.GetRotationQuaternion()
.AngleTo(snapped.Basis.GetRotationQuaternion());
GD.Print($"SMOKE INFO: Rig dt=0 maxDelta={maxDelta:F6} snapDelta={snapDelta:F4}rad");
Check(maxDelta < 1e-6f, $"Expected dt == 0 Update (snap=false) to be a strict no-op, got maxDelta={maxDelta:F6}");
Check(snapDelta > 0.5f, $"Expected dt == 0 Update (snap=true) to snap turret cleanly, got snapDelta={snapDelta:F4}rad");
anvilVis.Root.QueueFree();
}
// 8. Spectator halo sits >= 0.75m above mounted dorsal gear (including Patron with turbo_core)
{
_main.Arena.Sync(_main.Session, 1.5f, 1f / 60f);
bool sawPatron = false;
foreach (var s in _main.Session.State.Spectators.Spectators)
{
if (!s.Alive) continue;
var vis = _main.Arena.GetSpectatorVisual(s.Id);
float? haloY = _main.Arena.GetSpectatorHaloLocalY(s.Id);
Check(vis is not null && haloY.HasValue, $"Missing spectator visual/halo for spectator #{s.Id}");
if (vis is not null && haloY.HasValue)
{
float topY = vis.ComputeMountedMaxY();
float clearance = haloY.Value - topY;
if (s.Tier == SpectatorTier.Patron)
{
sawPatron = true;
GD.Print($"SMOKE INFO: Spectator #{s.Id} ({s.Tier}/{s.Grid.Spec.Id}) mountedMaxY={topY:F3}m haloY={haloY.Value:F3}m clearance={clearance:F3}m");
}
Check(clearance >= 0.74f,
$"Spectator #{s.Id} ({s.Tier}/{s.Grid.Spec.Id}) halo clearance < 0.74m: topY={topY:F3}m haloY={haloY.Value:F3}m clearance={clearance:F3}m");
}
}
Check(sawPatron, "Expected at least one alive Patron spectator in arena");
}
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
}
@ -738,6 +958,112 @@ public partial class Smoke : Node
return count;
}
private static Vector3 TransformPointToAncestor(Node3D node, Node3D ancestor, Vector3 localPt)
{
Transform3D xf = Transform3D.Identity;
for (Node? cur = node; cur is Node3D n3d && cur != ancestor; cur = cur.GetParent())
{
xf = n3d.Transform * xf;
}
return xf * localPt;
}
private static Vector3? ComputeSubtreeVertexCentroidInAncestor(Node3D subRoot, Node3D ancestor, string partName)
{
Vector3 sum = Vector3.Zero;
int count = 0;
AccumulatePartCentroidRecursive(subRoot, ancestor, partName, ref sum, ref count);
return count > 0 ? sum / count : null;
}
private static void AccumulatePartCentroidRecursive(
Node cur,
Node3D ancestor,
string partName,
ref Vector3 sum,
ref int count)
{
if (cur is MeshInstance3D mi && mi.Mesh is { } mesh &&
mi.Name.ToString().Equals(partName, StringComparison.OrdinalIgnoreCase))
{
Transform3D toAnc = Transform3D.Identity;
for (Node? p = mi; p is Node3D n3d && p != ancestor; p = p.GetParent())
{
toAnc = n3d.Transform * toAnc;
}
int surfCount = mesh.GetSurfaceCount();
for (int s = 0; s < surfCount; s++)
{
var arrays = mesh.SurfaceGetArrays(s);
if (arrays.Count <= (int)Mesh.ArrayType.Vertex ||
arrays[(int)Mesh.ArrayType.Vertex].VariantType != Variant.Type.PackedVector3Array)
{
continue;
}
Vector3[] verts = arrays[(int)Mesh.ArrayType.Vertex].AsVector3Array();
for (int v = 0; v < verts.Length; v++)
{
sum += toAnc * verts[v];
count++;
}
}
}
for (int i = 0; i < cur.GetChildCount(); i++)
{
AccumulatePartCentroidRecursive(cur.GetChild(i), ancestor, partName, ref sum, ref count);
}
}
private static float ComputeSubtreeMinWorldY(Node3D root, float baseWorldY, bool relativeToModelRoot = false)
{
float minY = float.PositiveInfinity;
if (relativeToModelRoot)
{
Transform3D id = Transform3D.Identity;
for (int i = 0; i < root.GetChildCount(); i++)
{
AccumulateMinYRecursive(root.GetChild(i), id, ref minY);
}
}
else
{
AccumulateMinYRecursive(root, new Transform3D(Basis.Identity, new Vector3(0f, baseWorldY, 0f)), ref minY);
}
return minY;
}
private static void AccumulateMinYRecursive(Node cur, Transform3D parentXf, ref float minY)
{
Transform3D xf = cur is Node3D n3d ? parentXf * n3d.Transform : parentXf;
if (cur is MeshInstance3D mi && mi.Mesh is { } mesh)
{
int surfCount = mesh.GetSurfaceCount();
for (int s = 0; s < surfCount; s++)
{
var arrays = mesh.SurfaceGetArrays(s);
if (arrays.Count <= (int)Mesh.ArrayType.Vertex ||
arrays[(int)Mesh.ArrayType.Vertex].VariantType != Variant.Type.PackedVector3Array)
{
continue;
}
Vector3[] verts = arrays[(int)Mesh.ArrayType.Vertex].AsVector3Array();
for (int v = 0; v < verts.Length; v++)
{
float wy = (xf * verts[v]).Y;
if (wy < minY)
{
minY = wy;
}
}
}
}
for (int i = 0; i < cur.GetChildCount(); i++)
{
AccumulateMinYRecursive(cur.GetChild(i), xf, ref minY);
}
}
private static bool HasNaN(Transform3D t)
{
return !t.Origin.IsFinite()