Cut 6b: Brokkr drop_pod.glb, petal blow-off, retro VFX/audio/juice, drop HUD/camera, and GL3 Sion captures

This commit is contained in:
Meta Vens 2026-12-05 11:45:04 +01:00
commit 5af5d87e06
15 changed files with 1847 additions and 94 deletions

View file

@ -83,6 +83,18 @@ public sealed class VehicleAssetCache : IDisposable
public required IReadOnlyDictionary<string, Vector3> PartCentroidsLocal { get; init; }
}
public sealed class DropPodTemplate
{
public required string GlbPath { get; init; }
public required Node3D SceneTemplate { get; init; }
public required ArrayMesh CoreMesh { get; init; }
public required ArrayMesh PetalMesh { get; init; }
public required Transform3D[] PetalLocalTransforms { get; init; }
public required Vector3 Size { get; init; }
public required float MinY { get; init; }
public required float MaxY { get; init; }
}
public static readonly string[] ExpectedGearIds =
{
"mg_762", "autocannon", "recoilless", "copper_rad", "gilded_lance", "gold_radiator"
@ -91,6 +103,7 @@ public sealed class VehicleAssetCache : IDisposable
private readonly Dictionary<string, VehicleTemplate> _vehicles = new(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, GearTemplate> _gear = new(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, ArrayMesh> _gearVariantMeshes = new(StringComparer.OrdinalIgnoreCase);
private DropPodTemplate? _dropPod;
private readonly string _vehiclesDir;
private readonly string _gearDir;
private bool _disposed;
@ -120,6 +133,25 @@ public sealed class VehicleAssetCache : IDisposable
{
GetOrLoadGear(gearId);
}
GetOrLoadDropPod();
}
public DropPodTemplate GetOrLoadDropPod()
{
ObjectDisposedException.ThrowIf(_disposed, this);
if (_dropPod is not null)
{
return _dropPod;
}
string glbPath = Path.Combine(_vehiclesDir, "drop_pod", "drop_pod.glb");
if (!File.Exists(glbPath))
{
throw new FileNotFoundException($"Missing drop pod GLB: {glbPath}", glbPath);
}
_dropPod = LoadDropPodTemplate(glbPath);
return _dropPod;
}
public VehicleTemplate GetOrLoadVehicle(string vehicleId)
@ -565,6 +597,95 @@ public sealed class VehicleAssetCache : IDisposable
};
}
private static DropPodTemplate LoadDropPodTemplate(string glbPath)
{
var doc = new GltfDocument();
var state = new GltfState();
Error err = doc.AppendFromFile(glbPath, state, flags: 0, basePath: Path.GetDirectoryName(glbPath) ?? string.Empty);
if (err != Error.Ok)
{
throw new InvalidOperationException($"GltfDocument.AppendFromFile failed for drop_pod '{glbPath}': {err}");
}
Node? generated = doc.GenerateScene(state);
if (generated is not Node3D sceneRoot)
{
generated?.QueueFree();
throw new InvalidOperationException($"GltfDocument.GenerateScene did not return a Node3D for drop_pod '{glbPath}'.");
}
ClearOwnerRecursive(sceneRoot);
ComputeSceneMeshBounds(sceneRoot, out Vector3 bMin, out Vector3 bMax);
float yGroundShift = MathF.Abs(bMin.Y) > 1e-4f ? -bMin.Y : 0f;
Transform3D groundShift = new Transform3D(Basis.Identity, new Vector3(0f, yGroundShift, 0f));
var allMeshes = new List<MeshInstance3D>();
CollectAllMeshInstances(sceneRoot, allMeshes);
var coreSources = new List<(Mesh Mesh, Transform3D RelXf)>(allMeshes.Count);
var petalMeshes = new MeshInstance3D?[4];
var petalTransforms = new Transform3D[4];
for (int i = 0; i < allMeshes.Count; i++)
{
MeshInstance3D mi = allMeshes[i];
if (!CanMergeMeshInstance(mi) || mi.Mesh is null)
{
continue;
}
string nodeName = mi.Name.ToString();
int petalIdx = -1;
if (nodeName.StartsWith("Petal_", StringComparison.OrdinalIgnoreCase) &&
int.TryParse(nodeName.AsSpan(6), out int parsedIdx) &&
parsedIdx is >= 0 and < 4)
{
petalIdx = parsedIdx;
}
if (petalIdx >= 0)
{
petalMeshes[petalIdx] = mi;
petalTransforms[petalIdx] = groundShift * ComputeRelativeTransform(sceneRoot, mi);
}
else
{
coreSources.Add((mi.Mesh, groundShift * ComputeRelativeTransform(sceneRoot, mi)));
}
}
for (int p = 0; p < 4; p++)
{
if (petalMeshes[p]?.Mesh is null)
{
sceneRoot.QueueFree();
throw new InvalidOperationException($"drop_pod GLB '{glbPath}' missing Petal_{p} mesh.");
}
}
ArrayMesh coreMesh = CollapseToSingleSurfaceMechPaintMesh(coreSources)
?? throw new InvalidOperationException($"drop_pod GLB '{glbPath}' produced empty CoreMesh.");
var petalSources = new List<(Mesh Mesh, Transform3D RelXf)>(1)
{
(petalMeshes[0]!.Mesh!, Transform3D.Identity)
};
ArrayMesh petalMesh = CollapseToSingleSurfaceMechPaintMesh(petalSources)
?? throw new InvalidOperationException($"drop_pod GLB '{glbPath}' produced empty PetalMesh.");
return new DropPodTemplate
{
GlbPath = glbPath,
SceneTemplate = sceneRoot,
CoreMesh = coreMesh,
PetalMesh = petalMesh,
PetalLocalTransforms = petalTransforms,
Size = bMax - bMin,
MinY = 0f,
MaxY = bMax.Y - bMin.Y
};
}
private static readonly HashSet<string> ExactStructuralNodeNames = new(StringComparer.OrdinalIgnoreCase)
{
"chassis", "hull", "pelvis", "core", "trunk", "waist", "waistlug", "torso.pose", "aim.turret", "hull.pose",
@ -2110,5 +2231,10 @@ public sealed class VehicleAssetCache : IDisposable
}
_vehicles.Clear();
_gear.Clear();
if (_dropPod is not null && GodotObject.IsInstanceValid(_dropPod.SceneTemplate))
{
_dropPod.SceneTemplate.QueueFree();
}
_dropPod = null;
}
}