Cut 7b: 16 modular Brokkr weapon parts, mfg paint bands 10..14, ClientOrdnanceMirror, audio & tooltips
This commit is contained in:
parent
6f6bfe3c46
commit
6447155efb
27 changed files with 2420 additions and 74 deletions
|
|
@ -95,17 +95,39 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
public required float MaxY { get; init; }
|
||||
}
|
||||
|
||||
public sealed class WeaponPartTemplate
|
||||
{
|
||||
public required string Id { get; init; }
|
||||
public required string Slot { get; init; }
|
||||
public required string GlbPath { get; init; }
|
||||
public required Node3D SceneTemplate { get; init; }
|
||||
public required ArrayMesh SingleSurfaceMesh { get; init; }
|
||||
public required Vector3 Size { get; init; }
|
||||
public required float MinY { get; init; }
|
||||
public required IReadOnlyDictionary<string, Transform3D> SocketsLocal { get; init; }
|
||||
}
|
||||
|
||||
public static readonly string[] ExpectedGearIds =
|
||||
{
|
||||
"mg_762", "autocannon", "recoilless", "copper_rad", "gilded_lance", "gold_radiator"
|
||||
};
|
||||
|
||||
public static readonly string[] ExpectedWeaponPartIds =
|
||||
{
|
||||
"rx_salvage_frame", "rx_korrathi_cradle", "rx_auralian_prism", "rx_vex_pod_rack",
|
||||
"brl_autocannon", "brl_sabot_rail", "brl_prism_lance", "brl_missile_tube",
|
||||
"fd_belt_drum", "fd_rotary_loader", "fd_capacitor_bank", "fd_swarm_magazine",
|
||||
"mz_slotted_brake", "mz_mirv_warhead", "mz_loiter_aero_fin", "mz_plasma_diffuser"
|
||||
};
|
||||
|
||||
private readonly Dictionary<string, VehicleTemplate> _vehicles = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, GearTemplate> _gear = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, WeaponPartTemplate> _weaponParts = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, ArrayMesh> _gearVariantMeshes = new(StringComparer.OrdinalIgnoreCase);
|
||||
private DropPodTemplate? _dropPod;
|
||||
private readonly string _vehiclesDir;
|
||||
private readonly string _gearDir;
|
||||
private readonly string _weaponPartsDir;
|
||||
private bool _disposed;
|
||||
|
||||
public VehicleAssetCache()
|
||||
|
|
@ -118,10 +140,12 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
{
|
||||
throw new DirectoryNotFoundException($"Could not locate gear directory '{_gearDir}'.");
|
||||
}
|
||||
_weaponPartsDir = Path.Combine(_gearDir, "parts");
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, VehicleTemplate> Vehicles => _vehicles;
|
||||
public IReadOnlyDictionary<string, GearTemplate> Gear => _gear;
|
||||
public IReadOnlyDictionary<string, WeaponPartTemplate> WeaponParts => _weaponParts;
|
||||
|
||||
public void PreloadAll()
|
||||
{
|
||||
|
|
@ -133,9 +157,32 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
{
|
||||
GetOrLoadGear(gearId);
|
||||
}
|
||||
foreach (string partId in ExpectedWeaponPartIds)
|
||||
{
|
||||
GetOrLoadWeaponPart(partId);
|
||||
}
|
||||
GetOrLoadDropPod();
|
||||
}
|
||||
|
||||
public WeaponPartTemplate GetOrLoadWeaponPart(string partId)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
if (_weaponParts.TryGetValue(partId, out var cached))
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
string glbPath = Path.Combine(_weaponPartsDir, $"{partId}.glb");
|
||||
if (!File.Exists(glbPath))
|
||||
{
|
||||
throw new FileNotFoundException($"Missing modular weapon part GLB '{partId}': {glbPath}", glbPath);
|
||||
}
|
||||
|
||||
var template = LoadWeaponPartTemplate(partId, glbPath);
|
||||
_weaponParts[partId] = template;
|
||||
return template;
|
||||
}
|
||||
|
||||
public DropPodTemplate GetOrLoadDropPod()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
|
@ -597,6 +644,89 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
};
|
||||
}
|
||||
|
||||
private static WeaponPartTemplate LoadWeaponPartTemplate(string partId, 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 weapon part '{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 weapon part '{glbPath}'.");
|
||||
}
|
||||
ClearOwnerRecursive(sceneRoot);
|
||||
|
||||
var modelTransforms = new Dictionary<Node, Transform3D>();
|
||||
CollectModelTransforms(sceneRoot, Transform3D.Identity, modelTransforms);
|
||||
|
||||
string partSlot = "unknown";
|
||||
var sockets = new Dictionary<string, Transform3D>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
byte[] jsonBytes = ReadGlbJsonChunk(glbPath);
|
||||
using (var jsonDoc = JsonDocument.Parse(jsonBytes))
|
||||
{
|
||||
if (jsonDoc.RootElement.TryGetProperty("nodes", out JsonElement jsonNodes) &&
|
||||
jsonNodes.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
var gltfNodes = state.Nodes;
|
||||
int nodeCount = Math.Min(gltfNodes.Count, jsonNodes.GetArrayLength());
|
||||
for (int i = 0; i < nodeCount; i++)
|
||||
{
|
||||
JsonElement jn = jsonNodes[i];
|
||||
if (!jn.TryGetProperty("extras", out JsonElement extras) || extras.ValueKind != JsonValueKind.Object)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
GltfNode gn = gltfNodes[i];
|
||||
string origName = !string.IsNullOrEmpty(gn.OriginalName)
|
||||
? gn.OriginalName
|
||||
: (jn.TryGetProperty("name", out var nm) ? nm.GetString() ?? $"node_{i}" : $"node_{i}");
|
||||
Node? resolved = ResolveSceneNode(sceneRoot, gn.GetSceneNodePath(state), origName);
|
||||
if (resolved is not Node3D n3d)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (extras.TryGetProperty("rtd.part_slot", out var slotEl) && slotEl.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
partSlot = slotEl.GetString() ?? partSlot;
|
||||
}
|
||||
if (extras.TryGetProperty("rtd.socket", out var sockEl) && sockEl.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
string? sockName = sockEl.GetString();
|
||||
if (!string.IsNullOrWhiteSpace(sockName) && modelTransforms.TryGetValue(n3d, out Transform3D sockXf))
|
||||
{
|
||||
sockets[sockName] = sockXf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ComputeSceneMeshBounds(sceneRoot, out Vector3 bMin, out Vector3 bMax);
|
||||
ArrayMesh bakedMesh = BuildBakedStaticMesh(sceneRoot, coarseMaterials: false);
|
||||
ArrayMesh singleSurfaceMesh = CollapseToSingleSurfaceMechPaintMesh(bakedMesh);
|
||||
|
||||
return new WeaponPartTemplate
|
||||
{
|
||||
Id = partId,
|
||||
Slot = partSlot,
|
||||
GlbPath = glbPath,
|
||||
SceneTemplate = sceneRoot,
|
||||
SingleSurfaceMesh = singleSurfaceMesh,
|
||||
Size = bMax - bMin,
|
||||
MinY = bMin.Y,
|
||||
SocketsLocal = sockets
|
||||
};
|
||||
}
|
||||
|
||||
private static DropPodTemplate LoadDropPodTemplate(string glbPath)
|
||||
{
|
||||
var doc = new GltfDocument();
|
||||
|
|
@ -1453,6 +1583,33 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
string mName = (sm.ResourceName ?? string.Empty).ToLowerInvariant();
|
||||
roughness = Math.Clamp(sm.Roughness, 0.08f, 0.90f);
|
||||
|
||||
if (mName.Contains("mfg_primary"))
|
||||
{
|
||||
Color b = sm.AlbedoColor.SrgbToLinear();
|
||||
linearColor = new Vector3(b.R, b.G, b.B);
|
||||
band = 3;
|
||||
roughness = 0.50f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mName.Contains("mfg_accent"))
|
||||
{
|
||||
Color b = sm.AlbedoColor.SrgbToLinear();
|
||||
linearColor = new Vector3(b.R, b.G, b.B);
|
||||
band = 4;
|
||||
roughness = 0.38f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mName.Contains("mfg_glow"))
|
||||
{
|
||||
Color eCol = (sm.EmissionEnabled ? sm.Emission : sm.AlbedoColor).SrgbToLinear();
|
||||
linearColor = new Vector3(eCol.R, eCol.G, eCol.B);
|
||||
band = 5;
|
||||
roughness = 0.22f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mName.Contains("lamp") || mName.Contains("glow") || mName.Contains("cyan") ||
|
||||
mName.Contains("amber") || mName.Contains("optic_red"))
|
||||
{
|
||||
|
|
@ -2229,8 +2386,16 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
g.SceneTemplate.QueueFree();
|
||||
}
|
||||
}
|
||||
foreach (var wp in _weaponParts.Values)
|
||||
{
|
||||
if (GodotObject.IsInstanceValid(wp.SceneTemplate))
|
||||
{
|
||||
wp.SceneTemplate.QueueFree();
|
||||
}
|
||||
}
|
||||
_vehicles.Clear();
|
||||
_gear.Clear();
|
||||
_weaponParts.Clear();
|
||||
if (_dropPod is not null && GodotObject.IsInstanceValid(_dropPod.SceneTemplate))
|
||||
{
|
||||
_dropPod.SceneTemplate.QueueFree();
|
||||
|
|
|
|||
Loading…
Reference in a new issue