Fix: 3D model loading for units/tiles + tile model server pipeline

- ModelCache: switch GLTFDocument.append_from_buffer (was append_from_file
  which returned ERR_BUSY/43); validate GLB magic bytes; explicit signal
  disconnect before queue_free to avoid freed-lambda errors
- ContentCache: add tile model fetch (content.tile_models), disk cache at
  user://content/tile_models.json, get_tile_model_url() API
- game_screen: _add_tile now loads tile CDN model via ModelCache when bound
- Server: ContentGetTileModelsHandler (content.tile_models msg), registered
  in ServiceRegistration; TileModelDto / GetTileModelsResponse added to
  ContentMessages

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-09 13:34:17 -04:00
co-authored by Claude Happy
parent e815dd708f
commit 6dda0edf17
7 changed files with 200 additions and 32 deletions
+10
View File
@@ -16,6 +16,9 @@ public sealed record GetCardSetsRequest;
/// <summary>Fetch a single card definition by ID including assets and animations.</summary>
public sealed record GetCardDefinitionRequest(Guid Id);
/// <summary>Fetch all tile model bindings (affinity × shape → CDN URL).</summary>
public sealed record GetTileModelsRequest;
// ── Response / DTO types (server → client) ────────────────────────────────────
public sealed record SyncCardDefinitionsResponse(
@@ -27,6 +30,13 @@ public sealed record GetCardSetsResponse(IEnumerable<CardSetDto> Sets);
public sealed record GetCardDefinitionResponse(CardDefinitionDto? Card);
public sealed record GetTileModelsResponse(IEnumerable<TileModelDto> Bindings);
public sealed record TileModelDto(
string Affinity,
string Shape,
string ModelPublicUrl);
// ── DTOs ──────────────────────────────────────────────────────────────────────
public sealed record CardSetDto(
@@ -0,0 +1,42 @@
namespace SOR.Content.Handlers;
using Microsoft.EntityFrameworkCore;
using SOR.Database.Contexts;
using SOR.Networking.Abstractions.Messaging;
using SOR.Networking.Abstractions.Transport;
using SOR.Shared.Networking;
/// <summary>
/// content.tile_models — returns all tile model bindings.
/// Each binding maps an (Affinity × Shape) pair to a CDN model URL.
/// The client uses these to render the correct 3D tile mesh on the board.
/// </summary>
internal sealed class ContentGetTileModelsHandler : IMessageHandler
{
private readonly IMessageSerializer _serializer;
private readonly CatalogDbContext _catalogDb;
public ContentGetTileModelsHandler(IMessageSerializer serializer, CatalogDbContext catalogDb)
{
_serializer = serializer;
_catalogDb = catalogDb;
}
public string MessageType => "content.tile_models";
public async Task<IServerMessage?> HandleAsync(
IClientMessage message,
AuthenticatedConnection connection,
CancellationToken ct)
{
var bindings = await _catalogDb.TileModelBindings
.Select(b => new TileModelDto(
b.Affinity.ToString(),
b.Shape.ToString(),
b.ModelPublicUrl))
.ToListAsync(ct);
return ServerMessage.Reply("content.tile_models.ack", message.Seq,
new GetTileModelsResponse(bindings));
}
}
@@ -21,6 +21,7 @@ public static class ServiceRegistration
services.AddTransient<IMessageHandler, ContentSyncHandler>();
services.AddTransient<IMessageHandler, ContentGetCardSetsHandler>();
services.AddTransient<IMessageHandler, ContentGetCardDefinitionHandler>();
services.AddTransient<IMessageHandler, ContentGetTileModelsHandler>();
return services;
}