Files
GC/model/_engine/src/PlanetSceneRuntime.cs
T
Morris 0b2f263dea
PR 审核 / 后端编译 (pull_request) Canceled after 0s
PR 审核 / 后端自检 (pull_request) Canceled after 0s
PR 审核 / 前端检查(Flutter) (pull_request) Canceled after 0s
PR 审核 / 安全扫描 (pull_request) Canceled after 0s
PR 审核 / 审核汇总 (pull_request) Canceled after 0s
chore: 彻底移除 NeoRF 标识,统一为 GC / Morris
- 命名空间 NeoRF.EarthModels / NeoRF.ContourMap / NeoRF.ScaleCalculator
  改为 GC.EarthModels / GC.ContourMap / GC.ScaleCalculator
- 模型清单 type 字段同步更新,五个模型 DLL 全部重新编译并替换
- 程序集 Company 由 NeoRF 改为 Morris
- 模型作者 author 统一为 Morris(原 NeoRF / Morris GC)
- macOS 包标识 cn.neorf.GC 改为 com.xhmcl.GC
- 重算 version.json 与 model/version.json 的 build / manifestSha256 / filesSha256
2026-11-18 06:55:10 +08:00

66 lines
2.4 KiB
C#

using System;
using System.IO;
using Avalonia.Media;
namespace GC.EarthModels;
/// <summary>
/// 模型自己的场景运行时:场景描述 + 预烘焙地表纹理 + 调色板。
/// 数据来自模型数据目录,不依赖启动器。
/// </summary>
public sealed class SceneRuntime
{
public SceneDefinition Scene { get; init; } = new();
public PlanetTexture? Texture { get; init; }
public Color Ocean { get; init; } = Color.Parse("#1B5FA8");
public Color Land { get; init; } = Color.Parse("#4F8C4C");
public Color Ice { get; init; } = Color.Parse("#E6EDF4");
public Color Star { get; init; } = Color.Parse("#FFC24B");
public long MemoryBytes => Texture?.ByteSize ?? 0;
public static SceneRuntime Load(string dataDirectory, int memoryBudgetMb,
Action<double, string?>? progress = null)
{
progress?.Invoke(0.06, "读取场景数据");
var scenePath = Path.Combine(dataDirectory, "scene.json");
var scene = ModelJson.Read<SceneDefinition>(scenePath) ?? new SceneDefinition();
var ocean = Parse(scene.Planet.OceanColor, "#1B5FA8");
var land = Parse(scene.Planet.LandColor, "#4F8C4C");
var ice = Parse(scene.Planet.IceColor, "#E6EDF4");
LandData? landData = null;
var landFile = scene.Planet.LandFile;
if (!string.IsNullOrWhiteSpace(landFile))
{
var path = Path.IsPathRooted(landFile!) ? landFile! : Path.Combine(dataDirectory, landFile!);
progress?.Invoke(0.12, "读取地表轮廓");
landData = LandData.Load(path);
}
// 内存预算决定纹理分辨率(1024 宽约 3 MB)
var width = memoryBudgetMb >= 1024 ? PlanetTexture.DefaultWidth
: memoryBudgetMb >= 512 ? 768
: 512;
progress?.Invoke(0.16, "生成地表纹理");
var texture = PlanetTexture.Build(landData, width, ocean, land, ice,
t => progress?.Invoke(0.16 + t * 0.48, "生成地表纹理"));
progress?.Invoke(0.68, "场景就绪");
return new SceneRuntime
{
Scene = scene,
Texture = texture,
Ocean = ocean,
Land = land,
Ice = ice,
Star = Parse(scene.Star.Color, "#FFC24B")
};
}
private static Color Parse(string? value, string fallback)
=> Color.TryParse(string.IsNullOrWhiteSpace(value) ? fallback : value, out var c) ? c : Color.Parse(fallback);
}