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

@ -130,7 +130,7 @@ public sealed class VehicleVisualInstance
{
var template = cache.GetOrLoadVehicle(chassisId);
var pkg = template.Package;
float halfHeight = targetHalfHeight ?? pkg.HalfHeight;
float halfHeight = targetHalfHeight ?? (pkg.HalfHeight * visualScale);
float effectiveScale = targetHalfHeight.HasValue && pkg.HalfHeight > 1e-4f
? visualScale * (targetHalfHeight.Value / pkg.HalfHeight)
: visualScale;
@ -524,7 +524,7 @@ public sealed class VehicleVisualInstance
desiredGearFwd = rightX.Cross(upOut).Normalized();
var desiredModelBasis = new Basis(rightX, upOut, desiredGearFwd);
// If the gear GLB's own muzzle points along -Z (recoilless), rotate 180 deg around Y
// If the gear GLB's own forward points along -Z, rotate 180 deg around Y
if (gearTemplate.LocalModelForward.Z < 0f)
{
desiredModelBasis *= new Basis(Vector3.Up, MathF.PI);
@ -750,4 +750,78 @@ public sealed class VehicleVisualInstance
CollectNodeTransforms(cur.GetChild(i), xf, map);
}
}
/// <summary>
/// Computes the highest rendered vertex Y in <see cref="Root"/> local space across the hull
/// and all currently mounted gear meshes.
/// </summary>
public float ComputeMountedMaxY()
{
float maxY = float.NegativeInfinity;
AccumulateMaxYRecursive(ModelRoot, Transform3D.Identity, ref maxY);
if (!float.IsFinite(maxY))
{
return ModelRoot.Position.Y + _template.MaxY * ModelRoot.Scale.Y;
}
return maxY;
}
private static void AccumulateMaxYRecursive(Node cur, Transform3D parentToRoot, ref float maxY)
{
Transform3D toRoot = parentToRoot;
if (cur is Node3D n3d)
{
if (!n3d.Visible)
{
return;
}
toRoot = parentToRoot * n3d.Transform;
}
if (cur is MeshInstance3D mi && mi.Mesh is { } mesh)
{
int surfCount = mesh.GetSurfaceCount();
bool foundVerts = false;
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)
{
Vector3[] verts = arrays[(int)Mesh.ArrayType.Vertex].AsVector3Array();
for (int v = 0; v < verts.Length; v++)
{
float wy = (toRoot * verts[v]).Y;
if (wy > maxY)
{
maxY = wy;
}
}
foundVerts = true;
}
}
if (!foundVerts)
{
Aabb aabb = mesh.GetAabb();
for (int c = 0; c < 8; c++)
{
Vector3 corner = aabb.Position + new Vector3(
(c & 1) != 0 ? aabb.Size.X : 0f,
(c & 2) != 0 ? aabb.Size.Y : 0f,
(c & 4) != 0 ? aabb.Size.Z : 0f);
float wy = (toRoot * corner).Y;
if (wy > maxY)
{
maxY = wy;
}
}
}
}
int childCount = cur.GetChildCount();
for (int i = 0; i < childCount; i++)
{
AccumulateMaxYRecursive(cur.GetChild(i), toRoot, ref maxY);
}
}
}