Implement cubemap skybox, multi-active skyboxes, and 2D scene backgrounds

- Server: Add SkyboxType + 6 CubeUrl fields to SkyboxDefinition entity
- Server: EF migration AddSkyboxCubemapType
- Server: GetSkyboxConfigResponse now returns array of all active skyboxes
- Admin: SkyboxManagerPage supports Panoramic/AnimatedPanorama/Cubemap types,
  6 face URL fields for cubemap, and independent per-skybox active toggle
- Client: ContentCache fetches + caches skyboxes; adds get_random_skybox,
  get_skybox_bg_url, load_texture_async, apply_scene_background helpers
- Client: game_screen replaces _fetch_skybox with ContentCache-based approach;
  adds _load_cubemap_skybox / _apply_cubemap_images / _apply_cubemap_material
- Client: 12 2D scene scripts call ContentCache.apply_scene_background(self)
  in _ready() to replace solid-color backgrounds with CDN skybox images

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-25 16:11:02 -04:00
co-authored by Claude Happy
parent 453f008620
commit 843660dfce
22 changed files with 1184 additions and 124 deletions
@@ -12,7 +12,17 @@
<h1 class="mb-0">Skyboxes</h1>
<div class="text-muted small">
Configure 3D environment skyboxes displayed in gameplay scenes.
Only the active skybox is sent to clients.
@{
var activeCount = _skyboxes.Count(s => s.IsActive);
}
@if (activeCount == 0)
{
<span>No active skyboxes — clients use the procedural sky.</span>
}
else
{
<span><strong>@activeCount</strong> active skybox@(activeCount == 1 ? "" : "es") — client picks one randomly per session.</span>
}
</div>
</div>
<button class="btn btn-outline-secondary btn-sm" @onclick="LoadAsync" disabled="@_loading">
@@ -45,10 +55,10 @@
<thead>
<tr>
<th>Name</th>
<th style="width:100px" class="text-center">Type</th>
<th>CDN Path</th>
<th style="width:90px" class="text-center">Frames</th>
<th style="width:80px" class="text-center">FPS</th>
<th style="width:160px">Type</th>
<th>CDN Path / Face URLs</th>
<th style="width:80px" class="text-center">Frames</th>
<th style="width:70px" class="text-center">FPS</th>
<th style="width:80px" class="text-center">Active</th>
<th style="width:130px"></th>
</tr>
@@ -57,34 +67,70 @@
@foreach (var s in _skyboxes.OrderByDescending(s => s.IsActive).ThenBy(s => s.Name))
{
var skybox = s;
var skyboxType = skybox.SkyboxType ?? "Panoramic";
<tr class="@(skybox.IsActive ? "table-success" : "")">
<td>
<input @bind="skybox.Name" class="form-control form-control-sm"
placeholder="e.g. Night Sky" />
</td>
<td class="text-center">
<div class="form-check form-switch d-flex justify-content-center">
<input @bind="skybox.IsAnimated" type="checkbox"
class="form-check-input" role="switch"
title="@(skybox.IsAnimated ? "Animated" : "Static")" />
<label class="form-check-label ms-2 small text-muted">
@(skybox.IsAnimated ? "Anim" : "Static")
</label>
</div>
<td>
<select @bind="skybox.SkyboxType" class="form-select form-select-sm">
<option value="Panoramic">Panoramic</option>
<option value="AnimatedPanorama">Animated Panorama</option>
<option value="Cubemap">Cubemap</option>
</select>
</td>
<td>
<input @bind="skybox.CdnPath" class="form-control form-control-sm"
placeholder="https://cdn.sor.gg/skyboxes/…" />
@if (skyboxType == "Cubemap")
{
<div class="row g-1">
<div class="col-6">
<label class="form-label small mb-0">+X Right</label>
<input @bind="skybox.CubePxUrl" class="form-control form-control-sm"
placeholder="https://cdn…/px.png" />
</div>
<div class="col-6">
<label class="form-label small mb-0">-X Left</label>
<input @bind="skybox.CubeNxUrl" class="form-control form-control-sm"
placeholder="https://cdn…/nx.png" />
</div>
<div class="col-6">
<label class="form-label small mb-0">+Y Top</label>
<input @bind="skybox.CubePyUrl" class="form-control form-control-sm"
placeholder="https://cdn…/py.png" />
</div>
<div class="col-6">
<label class="form-label small mb-0">-Y Bottom</label>
<input @bind="skybox.CubeNyUrl" class="form-control form-control-sm"
placeholder="https://cdn…/ny.png" />
</div>
<div class="col-6">
<label class="form-label small mb-0">+Z Front (2D bg)</label>
<input @bind="skybox.CubePzUrl" class="form-control form-control-sm"
placeholder="https://cdn…/pz.png" />
</div>
<div class="col-6">
<label class="form-label small mb-0">-Z Back</label>
<input @bind="skybox.CubeNzUrl" class="form-control form-control-sm"
placeholder="https://cdn…/nz.png" />
</div>
</div>
}
else
{
<input @bind="skybox.CdnPath" class="form-control form-control-sm"
placeholder="@(skyboxType == "AnimatedPanorama" ? "https://cdn.sor.gg/skyboxes/aurora (base folder)" : "https://cdn.sor.gg/skyboxes/night.png")" />
}
</td>
<td class="text-center">
<input @bind="skybox.FrameCount" type="number" min="1"
class="form-control form-control-sm text-center"
disabled="@(!skybox.IsAnimated)" />
disabled="@(skyboxType != "AnimatedPanorama")" />
</td>
<td class="text-center">
<input @bind="skybox.Fps" type="number" min="1" max="60" step="1"
class="form-control form-control-sm text-center"
disabled="@(!skybox.IsAnimated)" />
disabled="@(skyboxType != "AnimatedPanorama")" />
</td>
<td class="text-center">
<span class="badge @(skybox.IsActive ? "bg-success" : "bg-secondary")">
@@ -126,57 +172,92 @@
<div class="card shadow-sm">
<div class="card-header fw-medium">Add Skybox</div>
<div class="card-body">
<div class="row g-2 align-items-end">
<div class="col-md-2">
<div class="row g-2 align-items-end mb-2">
<div class="col-md-3">
<label class="form-label small">Name</label>
<input @bind="_newName" class="form-control form-control-sm" placeholder="Night Sky" />
</div>
<div class="col-md-1 text-center">
<label class="form-label small d-block">Animated</label>
<div class="form-check form-switch d-flex justify-content-center pt-1">
<input @bind="_newIsAnimated" type="checkbox" class="form-check-input" role="switch" />
</div>
<div class="col-md-2">
<label class="form-label small">Type</label>
<select @bind="_newSkyboxType" class="form-select form-select-sm">
<option value="Panoramic">Panoramic</option>
<option value="AnimatedPanorama">Animated Panorama</option>
<option value="Cubemap">Cubemap</option>
</select>
</div>
<div class="col-md-4">
<label class="form-label small">
CDN Path
@if (_newIsAnimated)
{
<span class="text-muted ms-1">(base folder — frames at /0.png, /1.png …)</span>
}
else
{
<span class="text-muted ms-1">(full URL to panoramic image)</span>
}
</label>
<input @bind="_newCdnPath" class="form-control form-control-sm"
placeholder="https://cdn.sor.gg/skyboxes/…" />
</div>
@if (_newIsAnimated)
@if (_newSkyboxType != "Cubemap")
{
<div class="col-md-1">
<label class="form-label small">Frames</label>
<input @bind="_newFrameCount" type="number" min="1"
class="form-control form-control-sm" />
</div>
<div class="col-md-1">
<label class="form-label small">FPS</label>
<input @bind="_newFps" type="number" min="1" max="60" step="1"
class="form-control form-control-sm" />
<div class="col-md-4">
<label class="form-label small">
CDN Path
@if (_newSkyboxType == "AnimatedPanorama")
{
<span class="text-muted ms-1">(base folder — frames at /0.png, /1.png …)</span>
}
else
{
<span class="text-muted ms-1">(full URL to panoramic image)</span>
}
</label>
<input @bind="_newCdnPath" class="form-control form-control-sm"
placeholder="https://cdn.sor.gg/skyboxes/…" />
</div>
@if (_newSkyboxType == "AnimatedPanorama")
{
<div class="col-md-1">
<label class="form-label small">Frames</label>
<input @bind="_newFrameCount" type="number" min="1"
class="form-control form-control-sm" />
</div>
<div class="col-md-1">
<label class="form-label small">FPS</label>
<input @bind="_newFps" type="number" min="1" max="60" step="1"
class="form-control form-control-sm" />
</div>
}
}
<div class="col-md-2">
<button class="btn btn-primary btn-sm w-100"
@onclick="AddAsync"
disabled="@(string.IsNullOrWhiteSpace(_newName) || string.IsNullOrWhiteSpace(_newCdnPath))">
disabled="@IsAddDisabled()">
<i class="bi bi-plus-lg me-1"></i>Add
</button>
</div>
</div>
<div class="text-muted small mt-2">
<strong>Static</strong>: Set CDN path to a single panoramic/equirectangular image (PNG/JPG recommended).<br />
<strong>Animated</strong>: Upload frames as <code>/0.png</code>, <code>/1.png</code>, … <code>/{FrameCount-1}.png</code>
inside the base folder, then set CDN path to that folder URL.
@if (_newSkyboxType == "Cubemap")
{
<div class="row g-2 mb-2">
<div class="col-md-4">
<label class="form-label small">+X Right</label>
<input @bind="_newCubePxUrl" class="form-control form-control-sm" placeholder="https://cdn…/px.png" />
</div>
<div class="col-md-4">
<label class="form-label small">-X Left</label>
<input @bind="_newCubeNxUrl" class="form-control form-control-sm" placeholder="https://cdn…/nx.png" />
</div>
<div class="col-md-4">
<label class="form-label small">+Y Top</label>
<input @bind="_newCubePyUrl" class="form-control form-control-sm" placeholder="https://cdn…/py.png" />
</div>
<div class="col-md-4">
<label class="form-label small">-Y Bottom</label>
<input @bind="_newCubeNyUrl" class="form-control form-control-sm" placeholder="https://cdn…/ny.png" />
</div>
<div class="col-md-4">
<label class="form-label small">+Z Front <span class="text-muted">(also 2D bg)</span></label>
<input @bind="_newCubePzUrl" class="form-control form-control-sm" placeholder="https://cdn…/pz.png" />
</div>
<div class="col-md-4">
<label class="form-label small">-Z Back</label>
<input @bind="_newCubeNzUrl" class="form-control form-control-sm" placeholder="https://cdn…/nz.png" />
</div>
</div>
}
<div class="text-muted small mt-1">
<strong>Panoramic</strong>: Set CDN path to a single equirectangular image (PNG/JPG recommended).<br />
<strong>Animated Panorama</strong>: Upload frames as <code>/0.png</code>, <code>/1.png</code>, … <code>/{FrameCount-1}.png</code>
inside the base folder, then set CDN path to that folder URL.<br />
<strong>Cubemap</strong>: Supply six face images (+X/-X/+Y/-Y/+Z/-Z). The +Z (Front) face also appears as the 2D background in non-game scenes.
</div>
</div>
</div>
@@ -187,11 +268,17 @@
private string? _message;
private bool _isError;
private string _newName = "";
private bool _newIsAnimated = false;
private string _newCdnPath = "";
private int _newFrameCount = 1;
private float _newFps = 24f;
private string _newName = "";
private string _newSkyboxType = "Panoramic";
private string _newCdnPath = "";
private int _newFrameCount = 1;
private float _newFps = 24f;
private string _newCubePxUrl = "";
private string _newCubeNxUrl = "";
private string _newCubePyUrl = "";
private string _newCubeNyUrl = "";
private string _newCubePzUrl = "";
private string _newCubeNzUrl = "";
protected override async Task OnInitializedAsync() => await LoadAsync();
@@ -202,9 +289,19 @@
_loading = false;
}
private bool IsAddDisabled()
{
if (string.IsNullOrWhiteSpace(_newName)) return true;
if (_newSkyboxType == "Cubemap") return false; // face URLs are optional individually
return string.IsNullOrWhiteSpace(_newCdnPath);
}
private async Task SaveAsync(SkyboxDefinition skybox)
{
if (!skybox.IsAnimated) { skybox.FrameCount = 1; skybox.Fps = 0f; }
var type = skybox.SkyboxType ?? "Panoramic";
if (type != "AnimatedPanorama") { skybox.FrameCount = 1; skybox.Fps = 0f; }
// Keep IsAnimated in sync with SkyboxType for backward compat
skybox.IsAnimated = type == "AnimatedPanorama";
try
{
await Db.SaveChangesAsync();
@@ -220,14 +317,11 @@
private async Task SetActiveAsync(SkyboxDefinition skybox)
{
// Deactivate all, then activate the chosen one.
foreach (var s in _skyboxes)
s.IsActive = false;
skybox.IsActive = true;
try
{
await Db.SaveChangesAsync();
_message = $"\"{skybox.Name}\" is now the active skybox.";
_message = $"\"{skybox.Name}\" is now active.";
_isError = false;
}
catch (Exception ex)
@@ -243,7 +337,7 @@
try
{
await Db.SaveChangesAsync();
_message = $"\"{skybox.Name}\" deactivated. No skybox is now active (clients use procedural sky).";
_message = $"\"{skybox.Name}\" deactivated.";
_isError = false;
}
catch (Exception ex)
@@ -272,14 +366,23 @@
private async Task AddAsync()
{
var isCubemap = _newSkyboxType == "Cubemap";
var isAnimated = _newSkyboxType == "AnimatedPanorama";
var s = new SkyboxDefinition
{
Id = Guid.NewGuid(),
Name = _newName.Trim(),
IsAnimated = _newIsAnimated,
CdnPath = _newCdnPath.Trim(),
FrameCount = _newIsAnimated ? Math.Max(1, _newFrameCount) : 1,
Fps = _newIsAnimated ? Math.Max(1f, _newFps) : 0f,
SkyboxType = _newSkyboxType,
IsAnimated = isAnimated,
CdnPath = isCubemap ? "" : _newCdnPath.Trim(),
FrameCount = isAnimated ? Math.Max(1, _newFrameCount) : 1,
Fps = isAnimated ? Math.Max(1f, _newFps) : 0f,
CubePxUrl = isCubemap ? NullIfEmpty(_newCubePxUrl) : null,
CubeNxUrl = isCubemap ? NullIfEmpty(_newCubeNxUrl) : null,
CubePyUrl = isCubemap ? NullIfEmpty(_newCubePyUrl) : null,
CubeNyUrl = isCubemap ? NullIfEmpty(_newCubeNyUrl) : null,
CubePzUrl = isCubemap ? NullIfEmpty(_newCubePzUrl) : null,
CubeNzUrl = isCubemap ? NullIfEmpty(_newCubeNzUrl) : null,
IsActive = false,
CreatedAt = DateTimeOffset.UtcNow,
};
@@ -289,9 +392,10 @@
await Db.SaveChangesAsync();
_skyboxes.Add(s);
_newName = _newCdnPath = "";
_newIsAnimated = false;
_newSkyboxType = "Panoramic";
_newFrameCount = 1;
_newFps = 24f;
_newCubePxUrl = _newCubeNxUrl = _newCubePyUrl = _newCubeNyUrl = _newCubePzUrl = _newCubeNzUrl = "";
_message = $"Skybox \"{s.Name}\" added.";
_isError = false;
}
@@ -301,4 +405,7 @@
_isError = true;
}
}
private static string? NullIfEmpty(string s) =>
string.IsNullOrWhiteSpace(s) ? null : s.Trim();
}