添加模型“五带“

This commit is contained in:
2509_92447106 committed 2026-11-08 08:59:54 +08:00
1 parent f8fc0f6018
commit cf6f839ada
21 files changed
+1223 -36

No files matched your search

+9 -2
View File
@@ -9,6 +9,9 @@ using System.Text.Json.Nodes;
// 输出:更新 model/<id>/<id>.json 的 version / updatedAt,并生成 // 输出:更新 model/<id>/<id>.json 的 version / updatedAt,并生成
// 仓库根 version.json 与 model/version.json(内容相同,便于两种源地址读取)。 // 仓库根 version.json 与 model/version.json(内容相同,便于两种源地址读取)。
// 仓库地址(编译产物的 Release 也发在这里):与启动器默认 updateRepository 保持一致。
const string Repository = "https://gitcode.com/2509_92447106/GC";
var root = args.Length > 0 ? Path.GetFullPath(args[0]) : Directory.GetCurrentDirectory(); var root = args.Length > 0 ? Path.GetFullPath(args[0]) : Directory.GetCurrentDirectory();
var launcherVersion = args.Length > 1 && !string.IsNullOrWhiteSpace(args[1]) ? args[1] : "1.0.0"; var launcherVersion = args.Length > 1 && !string.IsNullOrWhiteSpace(args[1]) ? args[1] : "1.0.0";
var modelRoot = Path.Combine(root, "model"); var modelRoot = Path.Combine(root, "model");
@@ -111,12 +114,16 @@ if (Directory.Exists(srcRoot))
var launcherRevision = srcChunks.Count > 0 ? Fingerprint(srcChunks)[..10] : ""; var launcherRevision = srcChunks.Count > 0 ? Fingerprint(srcChunks)[..10] : "";
var packages = new Dictionary<string, Dictionary<string, object>>(); var packages = new Dictionary<string, Dictionary<string, object>>();
// 启动器更新只访问「编译的产物」:gitcode Release 里发布的 dist/GC-<rid>.zip 附件。
// 运行时若存在同名 Release,GitCodeReleaseRemote 会用附件真实直链覆盖下面的 url;
// 下面的地址是兜底(编译产物尚未发 Release 时也能指向正确的编译产物位置)。
var releaseBase = $"{Repository}/releases/download/v{launcherVersion}";
foreach (var rid in new[] { "win-x64", "win-arm64", "osx-arm64", "osx-x64", "linux-x64" }) foreach (var rid in new[] { "win-x64", "win-arm64", "osx-arm64", "osx-x64", "linux-x64" })
{ {
var entry = new Dictionary<string, object> var entry = new Dictionary<string, object>
{ {
["path"] = $"dist/GC-{rid}.zip", ["path"] = $"dist/GC-{rid}.zip",
["url"] = "" // 大文件建议填 Release 直链;留空则用仓库内 path ["url"] = $"{releaseBase}/GC-{rid}.zip"
}; };
// 已生成的启动器更新包:把校验值和体积写进清单,供下载端校验 // 已生成的启动器更新包:把校验值和体积写进清单,供下载端校验
var zipPath = Path.Combine(root, "dist", $"GC-{rid}.zip"); var zipPath = Path.Combine(root, "dist", $"GC-{rid}.zip");
@@ -133,7 +140,7 @@ var versionDoc = new Dictionary<string, object>
{ {
["schema"] = 1, ["schema"] = 1,
["generated"] = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"), ["generated"] = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"),
["repository"] = "https://gitcode.com/2509_92447106/GC", ["repository"] = Repository,
["branch"] = "main", ["branch"] = "main",
["modelDir"] = "model", ["modelDir"] = "model",
["launcher"] = new Dictionary<string, object> ["launcher"] = new Dictionary<string, object>
+110
View File
@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Numerics;
namespace NeoRF.EarthModels;
/// <summary>
/// 地理模型的球面几何工具:经纬度 ↔ 单位球坐标、正交投影到屏幕、
/// 以及把一条经纬度折线投影成「可见弧段」(背面自动裁掉)。
/// 纯 CPU、无依赖,供 GeographyView 画线稿用。
/// </summary>
public static class Geometry
{
public const float DegToRad = (float)(Math.PI / 180.0);
public const float RadToDeg = (float)(180.0 / Math.PI);
/// <summary>经纬度 → 单位球坐标(y 轴为地轴,lon 向东为正)。</summary>
public static Vector3 LatLonToUnit(double latDeg, double lonDeg)
{
var lat = (float)(latDeg * Math.PI / 180.0);
var lon = (float)(lonDeg * Math.PI / 180.0);
var cosLat = (float)Math.Cos(lat);
return new Vector3(cosLat * (float)Math.Sin(lon), (float)Math.Sin(lat), cosLat * (float)Math.Cos(lon));
}
/// <summary>把世界坐标旋转到相机空间(先用 planet 旋转地球,再用 cam 转到屏幕)。</summary>
public static Vector3 ToCamera(Vector3 world, Matrix4x4 planet, Matrix4x4 cam)
=> Vector3.Transform(Vector3.Transform(world, planet), cam);
/// <summary>相机空间的正交投影:球心在原点,半径 radius。</summary>
public static Vector2 Project(Vector3 camPos, float radius, float centerX, float centerY)
=> new(centerX + camPos.X * radius, centerY - camPos.Y * radius);
/// <summary>相机空间里该点是否朝向观察者(z>0 为正面)。</summary>
public static bool IsVisible(Vector3 camPos, float threshold = 0f) => camPos.Z > threshold;
/// <summary>
/// 把一条经纬度折线拆成若干段「可见」的屏幕折线。
/// 跨越地平线的相邻两点用线性插值求出交点作为端点,保证线不会穿过球体背面。
/// </summary>
public static List<List<Vector2>> ProjectPolyline(
IReadOnlyList<double[]> latLonPoints,
Matrix4x4 planet, Matrix4x4 cam,
float radius, float centerX, float centerY,
bool closed = false)
{
var result = new List<List<Vector2>>();
if (latLonPoints.Count < 2) return result;
var count = latLonPoints.Count;
var total = closed ? count + 1 : count;
List<Vector2>? current = null;
Vector3 prevCam = default;
var havePrev = false;
for (var i = 0; i < total; i++)
{
var p = latLonPoints[i % count];
if (p.Length < 2) { havePrev = false; continue; }
var camPos = ToCamera(LatLonToUnit(p[1], p[0]), planet, cam);
var visible = camPos.Z > 0f;
if (!havePrev)
{
if (visible)
{
current = new List<Vector2>();
current.Add(Project(camPos, radius, centerX, centerY));
}
prevCam = camPos;
havePrev = true;
continue;
}
var prevVisible = prevCam.Z > 0f;
if (visible && prevVisible)
{
current ??= new List<Vector2>();
current.Add(Project(camPos, radius, centerX, centerY));
}
else if (visible != prevVisible)
{
// 求出与地平线(z=0)的交点
var t = prevCam.Z / (prevCam.Z - camPos.Z);
var hit = Vector3.Lerp(prevCam, camPos, t);
hit.Z = 0f;
var hitScreen = Project(hit, radius, centerX, centerY);
if (visible)
{
current = new List<Vector2> { hitScreen };
current.Add(Project(camPos, radius, centerX, centerY));
}
else
{
current?.Add(hitScreen);
if (current is { Count: > 1 }) result.Add(current);
current = null;
}
}
prevCam = camPos;
}
if (current is { Count: > 1 }) result.Add(current);
return result;
}
}
@@ -0,0 +1,21 @@
{
"id": "earth-geography",
"version": "1.0",
"nameI18n": {
"zh-CN": "地球地理",
"en": "Earth Geography"
},
"descriptionI18n": {
"zh-CN": "五带划分、七大洲四大洋轮廓、六大板块与洲界,纯线稿教学图。",
"en": "Climate zones, continent/ocean outlines, plates and borders — clean line art."
},
"assembly": "EarthGeographyModel.dll",
"type": "NeoRF.EarthModels.GeographyModelFactory",
"author": "Morris GC",
"tags": [
"geography",
"earth",
"atlas"
],
"dataDir": "earth-geography.model"
}
@@ -0,0 +1 @@
{"borders":[{"between":"亚洲-非洲","name":"苏伊士运河","lines":[[[32.5,31.2],[32.3,29.9]]]},{"between":"亚洲-欧洲","name":"乌拉尔山","lines":[[[60.0,68.0],[59.5,60.0],[58.0,52.0]]]},{"between":"亚洲-非洲","name":"红海","lines":[[[43.3,12.6],[38.5,22.0],[34.5,28.0]]]},{"between":"欧洲-非洲","name":"直布罗陀海峡","lines":[[[-5.6,36.0],[0.0,36.5]]]},{"between":"北美-南美","name":"巴拿马运河","lines":[[[-79.6,9.1],[-77.5,8.6]]]},{"between":"亚洲-北美","name":"白令海峡","lines":[[[-169.0,65.5],[-172.0,66.0]]]},{"between":"亚洲-大洋洲","name":"印尼群岛","lines":[[[120.0,0.0],[130.0,-2.0]]]},{"between":"南极洲","name":"南极圈","lines":[[[-180.0,-66.5],[180.0,-66.5]]]}]}
@@ -0,0 +1 @@
{"lines":[[[179.999,-16.169],[179.564,-16.637],[179.568,-16.747],[179.93,-16.519],[179.928,-16.744],[179.419,-16.807],[179.202,-16.713],[179.007,-16.9],[178.707,-16.976],[178.604,-16.801],[178.497,-16.788],[178.584,-16.622],[178.805,-16.631],[178.961,-16.483],[179.552,-16.25],[179.999,-16.169]],[[143.179,-11.954],[143.11,-12.304],[143.402,-12.64],[143.587,-13.444],[143.548,-13.741],[143.756,-14.349],[143.962,-14.463],[144.473,-14.232],[144.648,-14.492],[145.288,-14.943],[145.272,-15.477],[145.458,-16.056],[145.426,-16.406],[145.755,-16.879],[145.912,-16.913],[146.126,-17.635],[146.032,-18.273],[146.333,-18.554],[146.297,-18.841],[146.383,-18.977],[147.139,-19.393],[147.419,-19.378],[147.742,-19.77],[148.759,-20.29],[148.885,-20.481],[148.73,-20.468],[148.684,-20.58],[149.205,-21.125],[149.329,-21.476],[149.454,-21.579],[149.704,-22.441],[149.822,-22.39],[149.974,-22.551],[149.942,-22.308],[150.021,-22.168],[150.541,-22.559],[150.623,-22.367],[150.764,-22.576],[150.843,-23.458],[151.154,-23.784],[151.832,-24.123],[152.13,-24.598],[152.456,-24.802],[152.654,-25.202],[152.913,-25.432],[152.921,-25.689],[153.165,-25.964],[153.084,-26.304],[153.117,-27.194],[153.576,-28.241],[153.617,-28.673],[153.605,-28.854],[153.348,-29.29],[153.272,-29.892],[153.031,-30.563],[152.944,-31.435],[152.559,-32.046],[152.47,-32.439],[152.137,-32.678],[152.164,-32.757],[151.813,-32.901],[151.432,-33.522],[151.292,-33.581],[151.28,-33.927],[151.125,-34.005],[151.232,-34.03],[150.871,-34.499],[150.805,-35.013],[150.567,-35.214],[150.195,-35.834],[149.96,-36.846],[149.933,-37.529],[149.481,-37.771],[148.262,-37.831],[147.877,-37.934],[146.857,-38.663],[146.217,-38.727],[146.337,-38.894],[146.467,-38.84],[146.484,-39.065],[146.4,-39.146],[146.158,-38.866],[145.935,-38.902],[145.791,-38.667],[145.397,-38.535],[145.542,-38.394],[145.476,-38.244],[145.293,-38.238],[144.96,-38.501],[144.718,-38.34],[144.911,-38.344],[145.12,-38.091],[144.891,-37.9],[144.396,-38.137],[144.665,-38.21],[143.539,-38.821],[142.456,-38.386],[141.725,-38.271],[141.594,-38.388],[141.424,-38.363],[141.011,-38.077],[140.39,-37.897],[139.784,-37.246],[139.738,-37.06],[139.857,-36.662],[139.729,-36.371],[139.466,-36.01],[138.969,-35.581],[139.178,-35.523],[139.289,-35.611],[139.283,-35.375],[138.522,-35.642],[138.184,-35.613],[138.511,-35.024],[138.49,-34.764],[138.089,-34.17],[137.692,-35.143],[136.884,-35.24],[137.014,-34.916],[137.391,-34.913],[137.494,-34.161],[137.932,-33.579],[137.852,-33.201],[137.993,-33.094],[137.783,-32.578],[137.791,-32.823],[137.442,-33.194],[137.237,-33.629],[136.431,-34.03],[135.891,-34.661],[135.97,-34.982],[135.792,-34.863],[135.648,-34.94],[135.231,-34.58],[135.123,-34.586],[135.217,-34.487],[135.45,-34.581],[135.219,-33.96],[134.889,-33.626],[134.719,-33.255],[134.301,-33.165],[134.1,-32.749],[134.227,-32.731],[134.234,-32.549],[133.665,-32.207],[133.212,-32.184],[132.757,-31.956],[132.215,-32.007],[131.721,-31.696],[131.144,-31.496],[130.783,-31.604],[130.13,-31.579],[128.946,-31.703],[127.32,-32.264],[125.917,-32.297],[124.759,-32.883],[124.244,-33.015],[123.868,-33.596],[123.507,-33.916],[123.208,-33.988],[122.778,-33.891],[122.151,-33.992],[122.061,-33.874],[121.405,-33.827],[119.854,-33.975],[119.635,-34.101],[119.451,-34.368],[118.895,-34.48],[118.136,-34.987],[117.863,-35.055],[116.517,-34.988],[115.987,-34.795],[115.565,-34.426],[115.009,-34.256],[114.994,-33.515],[115.182,-33.643],[115.359,-33.64],[115.515,-33.531],[115.683,-33.193],[115.619,-32.667],[115.725,-32.401],[115.698,-31.695],[115.078,-30.56],[114.857,-29.143],[114.165,-28.081],[114.028,-27.347],[113.185,-26.182],[113.323,-26.244],[113.356,-26.08],[113.582,-26.558],[113.734,-26.595],[113.836,-26.501],[113.853,-26.332],[113.589,-26.099],[113.395,-25.713],[113.451,-25.599],[113.713,-25.831],[113.724,-26.13],[113.854,-26.014],[113.992,-26.321],[114.09,-26.394],[114.216,-26.289],[114.214,-25.852],[113.418,-24.436],[113.49,-23.87],[113.757,-23.418],[113.795,-22.915],[113.683,-22.638],[114.023,-21.881],[114.124,-21.829],[114.142,-22.483],[114.378,-22.342],[114.709,-21.823],[115.456,-21.492],[116.011,-21.03],[116.707,-20.654],[117.406,-20.721],[118.199,-20.375],[118.751,-20.262],[119.104,-19.995],[119.586,-20.038],[120.434,-19.842],[120.998,-19.604],[121.338,-19.32],[121.834,-18.477],[122.345,-18.112],[122.147,-17.549],[122.261,-17.136],[122.72,-16.788],[122.971,-16.437],[123.563,-17.521],[123.594,-17.03],[123.831,-17.121],[123.874,-16.919],[123.49,-16.491],[123.626,-16.416],[123.607,-16.224],[123.729,-16.192],[123.859,-16.382],[124.044,-16.265],[124.3,-16.388],[124.772,-16.403],[124.405,-16.299],[124.416,-16.133],[124.577,-16.114],[124.649,-15.87],[124.648,-15.805],[124.504,-15.972],[124.382,-15.758],[124.44,-15.494],[124.562,-15.496],[124.693,-15.274],[125.063,-15.442],[125.073,-15.307],[124.909,-15.31],[124.839,-15.161],[125.038,-15.004],[125.356,-15.12],[125.384,-15.016],[125.243,-14.945],[125.179,-14.715],[125.285,-14.584],[125.58,-14.483],[125.628,-14.257],[125.705Line truncated
@@ -0,0 +1,7 @@
{
"zones": "Zones",
"coast": "Continents",
"plates": "Plates",
"borders": "Borders",
"reset": "Reset"
}
@@ -0,0 +1,7 @@
{
"zones": "五带",
"coast": "大洲轮廓",
"plates": "板块",
"borders": "洲界",
"reset": "复位"
}
@@ -0,0 +1,103 @@
{
"labels": [
{
"lat": 34,
"lon": 90,
"kind": "continent",
"nameI18n": {
"zh-CN": "亚洲",
"en": "Asia"
}
},
{
"lat": 2,
"lon": 20,
"kind": "continent",
"nameI18n": {
"zh-CN": "非洲",
"en": "Africa"
}
},
{
"lat": 48,
"lon": -100,
"kind": "continent",
"nameI18n": {
"zh-CN": "北美洲",
"en": "North America"
}
},
{
"lat": -15,
"lon": -60,
"kind": "continent",
"nameI18n": {
"zh-CN": "南美洲",
"en": "South America"
}
},
{
"lat": -78,
"lon": 20,
"kind": "continent",
"nameI18n": {
"zh-CN": "南极洲",
"en": "Antarctica"
}
},
{
"lat": 52,
"lon": 18,
"kind": "continent",
"nameI18n": {
"zh-CN": "欧洲",
"en": "Europe"
}
},
{
"lat": -24,
"lon": 134,
"kind": "continent",
"nameI18n": {
"zh-CN": "大洋洲",
"en": "Oceania"
}
},
{
"lat": 0,
"lon": -155,
"kind": "ocean",
"nameI18n": {
"zh-CN": "太平洋",
"en": "Pacific Ocean"
}
},
{
"lat": 12,
"lon": -30,
"kind": "ocean",
"nameI18n": {
"zh-CN": "大西洋",
"en": "Atlantic Ocean"
}
},
{
"lat": -22,
"lon": 78,
"kind": "ocean",
"nameI18n": {
"zh-CN": "印度洋",
"en": "Indian Ocean"
}
},
{
"lat": 85,
"lon": 0,
"kind": "ocean",
"nameI18n": {
"zh-CN": "北冰洋",
"en": "Arctic Ocean"
}
}
]
}
@@ -0,0 +1 @@
{"plates":[{"id":"pacific","lines":[[[-180,60],[-150,55],[-130,45],[-110,25],[-95,10],[-80,0],[-75,-15],[-90,-30],[-110,-45],[-130,-55],[-160,-60],[-180,-55],[-180,60]]]},{"id":"north-american","lines":[[[-168,72],[-140,70],[-120,60],[-100,50],[-80,45],[-60,42],[-52,28],[-62,12],[-82,8],[-95,16],[-110,25],[-130,45],[-150,55],[-168,72]]]},{"id":"south-american","lines":[[[-82,12],[-62,10],[-45,-2],[-35,-8],[-30,-20],[-40,-35],[-55,-42],[-70,-52],[-78,-40],[-80,-20],[-82,12]]]},{"id":"african","lines":[[[-20,35],[10,37],[32,32],[43,12],[51,10],[42,-8],[40,-25],[25,-35],[15,-30],[8,-5],[-8,5],[-17,15],[-20,35]]]},{"id":"eurasian","lines":[[[-10,36],[0,45],[15,55],[30,68],[60,72],[100,76],[140,70],[160,60],[140,42],[120,30],[100,20],[75,8],[60,22],[45,30],[30,32],[10,37],[-10,36]]]},{"id":"indo-australian","lines":[[[95,5],[115,10],[130,5],[145,-5],[150,-20],[145,-35],[130,-42],[115,-38],[105,-25],[95,-10],[95,5]]]},{"id":"antarctic","lines":[[[-180,-60],[-120,-62],[-60,-60],[0,-62],[60,-60],[120,-62],[180,-60],[180,-90],[-180,-90],[-180,-60]]]},{"id":"nazca","lines":[[[-95,-5],[-85,-10],[-75,-25],[-78,-40],[-90,-42],[-100,-30],[-95,-5]]]},{"id":"cocos","lines":[[[-105,10],[-95,12],[-90,5],[-100,2],[-105,10]]]},{"id":"caribbean","lines":[[[-88,15],[-75,18],[-62,15],[-60,8],[-72,6],[-85,8],[-88,15]]]},{"id":"philippine","lines":[[[118,20],[128,18],[130,8],[125,2],[118,8],[118,20]]]},{"id":"arabian","lines":[[[35,32],[48,30],[58,22],[55,12],[42,10],[35,20],[35,32]]]}]}
@@ -0,0 +1,88 @@
{
"schemaVersion": 1,
"type": "geography",
"defaultView": "zones",
"views": [
"zones",
"coast",
"plates"
],
"nameI18n": {
"zh-CN": "地球地理",
"en": "Earth Geography"
},
"descriptionI18n": {
"zh-CN": "五带划分 · 七大洲四大洋 · 六大板块与洲界",
"en": "Climate zones · continents & oceans · plates & borders"
},
"tropicDeg": 23.5,
"axialTiltDeg": 23.5,
"oceanColor": "#0E2A4A",
"zones": [
{
"id": "torrid",
"latMin": -23.5,
"latMax": 23.5,
"nameI18n": {
"zh-CN": "热带",
"en": "Torrid zone"
},
"descI18n": {
"zh-CN": "南北回归线之间,有太阳直射,终年高温。",
"en": "Between the tropics; the Sun is overhead at some time each year."
}
},
{
"id": "north-temperate",
"latMin": 23.5,
"latMax": 66.5,
"nameI18n": {
"zh-CN": "北温带",
"en": "North temperate"
},
"descI18n": {
"zh-CN": "北回归线与北极圈之间,四季分明,无直射也无极昼极夜。",
"en": "Between Tropic of Cancer and Arctic Circle; four distinct seasons."
}
},
{
"id": "south-temperate",
"latMin": -66.5,
"latMax": -23.5,
"nameI18n": {
"zh-CN": "南温带",
"en": "South temperate"
},
"descI18n": {
"zh-CN": "南回归线与南极圈之间,四季分明。",
"en": "Between Tropic of Capricorn and Antarctic Circle; four seasons."
}
},
{
"id": "north-frigid",
"latMin": 66.5,
"latMax": 90,
"nameI18n": {
"zh-CN": "北寒带",
"en": "North frigid zone"
},
"descI18n": {
"zh-CN": "北极圈以北,有极昼极夜,终年寒冷。",
"en": "North of the Arctic Circle; polar day/night, always cold."
}
},
{
"id": "south-frigid",
"latMin": -90,
"latMax": -66.5,
"nameI18n": {
"zh-CN": "南寒带",
"en": "South frigid zone"
},
"descI18n": {
"zh-CN": "南极圈以南,有极昼极夜,终年寒冷。",
"en": "South of the Antarctic Circle; polar day/night, always cold."
}
}
]
}
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<RootNamespace>NeoRF.EarthModels</RootNamespace>
<AssemblyName>EarthGeographyModel</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<!-- 共享引擎源码(模型目录内),只编译需要的部分 -->
<ItemGroup>
<Compile Include="../../_engine/src/ModelJson.cs" />
<Compile Include="../../_engine/src/Geometry.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\_sdk\EarthModelStudio.ModelSdk\EarthModelStudio.ModelSdk.csproj">
<Private>false</Private>
</ProjectReference>
</ItemGroup>
</Project>
+79
View File
@@ -0,0 +1,79 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace NeoRF.EarthModels;
/// <summary>地球地理模型的数据文件:全部是经纬度折线,只有轮廓没有填色。</summary>
public sealed class GeoData
{
[JsonPropertyName("lines")] public List<List<double[]>> Lines { get; set; } = new();
}
public sealed class PlateEntry
{
[JsonPropertyName("id")] public string Id { get; set; } = "";
[JsonPropertyName("nameI18n")] public Dictionary<string, string>? NameI18n { get; set; }
[JsonPropertyName("lines")] public List<List<double[]>> Lines { get; set; } = new();
}
public sealed class PlateData
{
[JsonPropertyName("plates")] public List<PlateEntry> Plates { get; set; } = new();
}
public sealed class BorderEntry
{
/// <summary>分界的两个大洲,如「亚洲-非洲」。</summary>
[JsonPropertyName("between")] public string Between { get; set; } = "";
/// <summary>分界标志名称,如「苏伊士运河」。</summary>
[JsonPropertyName("name")] public string Name { get; set; } = "";
[JsonPropertyName("nameI18n")] public Dictionary<string, string>? NameI18n { get; set; }
[JsonPropertyName("lines")] public List<List<double[]>> Lines { get; set; } = new();
}
public sealed class BorderData
{
[JsonPropertyName("borders")] public List<BorderEntry> Borders { get; set; } = new();
}
/// <summary>七大洲四大洋的标签位置(经纬度 + 名称)。</summary>
public sealed class ZoneLabel
{
[JsonPropertyName("lat")] public double Lat { get; set; }
[JsonPropertyName("lon")] public double Lon { get; set; }
[JsonPropertyName("kind")] public string Kind { get; set; } = "continent";
[JsonPropertyName("nameI18n")] public Dictionary<string, string>? NameI18n { get; set; }
}
public sealed class LabelData
{
[JsonPropertyName("labels")] public List<ZoneLabel> Labels { get; set; } = new();
}
/// <summary>五带:以纬度区间定义的五个温度带。</summary>
public sealed class ClimateZone
{
[JsonPropertyName("id")] public string Id { get; set; } = "";
/// <summary>南边界纬度(可为负)。</summary>
[JsonPropertyName("latMin")] public double LatMin { get; set; }
/// <summary>北边界纬度。</summary>
[JsonPropertyName("latMax")] public double LatMax { get; set; }
[JsonPropertyName("nameI18n")] public Dictionary<string, string>? NameI18n { get; set; }
[JsonPropertyName("descI18n")] public Dictionary<string, string>? DescI18n { get; set; }
}
/// <summary>地理模型场景清单。</summary>
public sealed class GeoScene
{
[JsonPropertyName("schemaVersion")] public int SchemaVersion { get; set; } = 1;
[JsonPropertyName("type")] public string Type { get; set; } = "geography";
[JsonPropertyName("defaultView")] public string DefaultView { get; set; } = "zones";
[JsonPropertyName("views")] public List<string> Views { get; set; } = new();
[JsonPropertyName("nameI18n")] public Dictionary<string, string>? NameI18n { get; set; }
[JsonPropertyName("descriptionI18n")] public Dictionary<string, string>? DescriptionI18n { get; set; }
/// <summary>黄赤交角 / 回归线纬度,教学里统一 23.5°。</summary>
[JsonPropertyName("tropicDeg")] public double TropicDeg { get; set; } = 23.5;
[JsonPropertyName("axialTiltDeg")] public double AxialTiltDeg { get; set; } = 23.5;
[JsonPropertyName("oceanColor")] public string OceanColor { get; set; } = "#0E2A4A";
[JsonPropertyName("zones")] public List<ClimateZone> Zones { get; set; } = new();
}
@@ -0,0 +1,238 @@
using System;
using System.Collections.Generic;
using System.IO;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.Media;
using EarthModelStudio.ModelSdk;
namespace NeoRF.EarthModels;
/// <summary>
/// 地球地理模型:五带划分 + 七大洲四大洋轮廓 + 六大板块与洲界,纯线稿。
/// 数据全部来自模型数据目录,启动器不参与渲染。
/// </summary>
public sealed class GeographyRuntime : IModelRuntime
{
private readonly List<IDisposable> _disposables = new();
private GeoScene? _scene;
private GeoData? _coast;
private PlateData? _plates;
private BorderData? _borders;
private LabelData? _labels;
private GeographyView? _view;
public void Prepare(IModelContext context)
{
var dir = context.DataDirectory;
context.ReportProgress(0.10, "读取地理数据");
_scene = ModelJson.Read<GeoScene>(Path.Combine(dir, "scene.json")) ?? new GeoScene();
_coast = ModelJson.Read<GeoData>(Path.Combine(dir, "coastline.json")) ?? new GeoData();
_plates = ModelJson.Read<PlateData>(Path.Combine(dir, "plates.json")) ?? new PlateData();
_borders = ModelJson.Read<BorderData>(Path.Combine(dir, "borders.json")) ?? new BorderData();
context.ReportProgress(0.45, "加载名称标注");
_labels = ModelJson.Read<LabelData>(Path.Combine(dir, "labels.json")) ?? new LabelData();
context.ReportProgress(0.72, "构建轮廓");
context.Log($"[{context.ModelId}] 海岸线 {_coast.Lines.Count} 条,板块 {_plates.Plates.Count} 个,洲界 {_borders.Borders.Count} 条");
}
public Control CreateView(IModelContext context)
{
_scene ??= new GeoScene();
_coast ??= new GeoData();
_plates ??= new PlateData();
_borders ??= new BorderData();
_labels ??= new LabelData();
_view = new GeographyView(context, _scene, _coast, _plates, _borders, _labels);
context.ReportProgress(1.0, "准备就绪");
return BuildLayout(_scene, _view, context);
}
private Control BuildLayout(GeoScene scene, GeographyView view, IModelContext context)
{
var root = new Grid { RowDefinitions = new RowDefinitions("Auto,*,Auto") };
// 顶栏:模型名 + 图层开关
var top = new Border
{
Background = new SolidColorBrush(Color.Parse("#0C1828")),
Padding = new Thickness(16, 10),
Child = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto") }
};
var topGrid = (Grid)top.Child!;
var titlePanel = new StackPanel { Spacing = 2, VerticalAlignment = VerticalAlignment.Center };
titlePanel.Children.Add(new TextBlock
{
Text = Pick(scene.NameI18n, "地球地理"),
Foreground = new SolidColorBrush(Color.Parse("#EAF2FF")),
FontSize = 15,
FontWeight = FontWeight.SemiBold
});
titlePanel.Children.Add(new TextBlock
{
Text = Pick(scene.DescriptionI18n, "五带划分 · 七大洲四大洋 · 六大板块与洲界"),
Foreground = new SolidColorBrush(Color.Parse("#7C93B5")),
FontSize = 10.5
});
topGrid.Children.Add(titlePanel);
var actions = new StackPanel
{
Orientation = Orientation.Horizontal,
Spacing = 8,
VerticalAlignment = VerticalAlignment.Center
};
actions.Children.Add(MakeToggle("五带", view.ShowZones, on => view.ShowZones = on));
actions.Children.Add(MakeToggle("大洲轮廓", view.ShowCoast, on => view.ShowCoast = on));
actions.Children.Add(MakeToggle("板块", view.ShowPlates, on => view.ShowPlates = on));
actions.Children.Add(MakeToggle("洲界", view.ShowBorders, on => view.ShowBorders = on));
actions.Children.Add(MakeButton("复位", () => view.ResetView()));
Grid.SetColumn(actions, 2);
topGrid.Children.Add(actions);
root.Children.Add(top);
var stage = new Grid();
stage.Children.Add(view);
stage.Children.Add(BuildLegend(scene));
Grid.SetRow(stage, 1);
root.Children.Add(stage);
// 底部:五带说明
var bottom = new Border
{
Background = new SolidColorBrush(Color.Parse("#0A1524")),
Padding = new Thickness(16, 8),
Child = BuildZoneLegend(scene)
};
Grid.SetRow(bottom, 2);
root.Children.Add(bottom);
return root;
}
/// <summary>右上角图例:说明三种线型分别代表什么。</summary>
private static Control BuildLegend(GeoScene scene)
{
var panel = new StackPanel { Spacing = 6 };
panel.Children.Add(LegendRow(new SolidColorBrush(Color.Parse("#DEEEFF")), "大洲海岸线"));
panel.Children.Add(LegendRow(new SolidColorBrush(Color.Parse("#FF8A5C")), "板块边界"));
panel.Children.Add(LegendRow(new SolidColorBrush(Color.Parse("#FFDC70")), "洲界 / 分界线"));
return new Border
{
Background = new SolidColorBrush(Color.FromArgb(190, 8, 18, 32)),
CornerRadius = new CornerRadius(10),
Padding = new Thickness(12, 10),
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(0, 14, 16, 0),
Child = panel
};
}
private static Control LegendRow(IBrush brush, string text)
{
var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6 };
row.Children.Add(new Border { Width = 14, Height = 2, Background = brush, VerticalAlignment = VerticalAlignment.Center });
row.Children.Add(new TextBlock { Text = text, Foreground = new SolidColorBrush(Color.Parse("#9FB4D4")), FontSize = 10.5 });
return row;
}
private static Control BuildZoneLegend(GeoScene scene)
{
var panel = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 18 };
foreach (var zone in scene.Zones)
{
var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6 };
row.Children.Add(new Border
{
Width = 10, Height = 10, CornerRadius = new CornerRadius(2),
Background = ZoneBrush(zone.Id), VerticalAlignment = VerticalAlignment.Center
});
row.Children.Add(new TextBlock
{
Text = Pick(zone.NameI18n, zone.Id),
Foreground = new SolidColorBrush(Color.Parse("#C2D4EC")),
FontSize = 11
});
panel.Children.Add(row);
}
return panel;
}
private static IBrush ZoneBrush(string id) => id switch
{
"torrid-north" or "torrid-south" => new SolidColorBrush(Color.Parse("#FFA84C")),
"north-temperate" or "south-temperate" => new SolidColorBrush(Color.Parse("#6ED28C")),
_ => new SolidColorBrush(Color.Parse("#96C8FF"))
};
private static Button MakeButton(string text, Action onClick)
{
var b = new Button
{
Content = text,
FontSize = 12,
Padding = new Thickness(11, 5),
CornerRadius = new CornerRadius(8),
Background = new SolidColorBrush(Color.Parse("#16263C")),
Foreground = new SolidColorBrush(Color.Parse("#D6E4F8")),
BorderBrush = new SolidColorBrush(Color.Parse("#263A56")),
BorderThickness = new Thickness(1),
MinHeight = 30
};
b.Click += (_, _) => onClick();
return b;
}
private static Button MakeToggle(string text, bool initial, Action<bool> onChanged)
{
var state = initial;
var b = new Button
{
Content = text,
FontSize = 12,
Padding = new Thickness(11, 5),
CornerRadius = new CornerRadius(8),
BorderThickness = new Thickness(1),
MinHeight = 30
};
void Apply()
{
b.Background = new SolidColorBrush(Color.Parse(state ? "#1F5BD6" : "#16263C"));
b.BorderBrush = new SolidColorBrush(Color.Parse(state ? "#3B7BFF" : "#263A56"));
b.Foreground = new SolidColorBrush(Color.Parse(state ? "#FFFFFF" : "#9FB4D4"));
}
Apply();
b.Click += (_, _) => { state = !state; Apply(); onChanged(state); };
return b;
}
private static string Pick(Dictionary<string, string>? dict, string fallback)
{
if (dict == null || dict.Count == 0) return fallback;
foreach (var key in new[] { "zh-CN", "en" })
if (dict.TryGetValue(key, out var v) && !string.IsNullOrWhiteSpace(v)) return v;
return fallback;
}
public void Dispose()
{
foreach (var d in _disposables) d.Dispose();
_disposables.Clear();
_view = null;
GC.SuppressFinalize(this);
}
}
/// <summary>模型入口。</summary>
public sealed class GeographyModelFactory : IModelFactory
{
public int ApiVersion => 1;
public IModelRuntime Create() => new GeographyRuntime();
}
+464
View File
@@ -0,0 +1,464 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Numerics;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Threading;
using EarthModelStudio.ModelSdk;
namespace NeoRF.EarthModels;
/// <summary>
/// 地球地理模型画布:**纯线稿**球面,不填色。
/// 三个图层可独立开关:五带 / 大洲大洋轮廓 / 板块与洲界。
/// 拖拽转动视角,滚轮缩放。
/// </summary>
public sealed class GeographyView : Control
{
private readonly GeoScene _scene;
private readonly GeoData _coast;
private readonly PlateData _plates;
private readonly BorderData _borders;
private readonly LabelData _labels;
// 视角
private double _yawDeg = 10;
private double _pitchDeg = 18;
private double _zoom = 1.0;
private Point _lastPointer;
private bool _dragging;
// 图层开关
private bool _showZones = true;
private bool _showCoast = true;
private bool _showPlates;
private bool _showBorders;
private bool _showLabels = true;
public event Action? StateChanged;
public GeographyView(IModelContext context, GeoScene scene, GeoData coast,
PlateData plates, BorderData borders, LabelData labels)
{
_scene = scene;
_coast = coast;
_plates = plates;
_borders = borders;
_labels = labels;
ClipToBounds = true;
ClipToBounds = true;
Focusable = true;
}
public string CurrentLayerName => _showZones ? "zones"
: _showPlates ? "plates"
: _showBorders ? "borders"
: "coast";
public bool ShowZones { get => _showZones; set { _showZones = value; InvalidateVisual(); StateChanged?.Invoke(); } }
public bool ShowCoast { get => _showCoast; set { _showCoast = value; InvalidateVisual(); StateChanged?.Invoke(); } }
public bool ShowPlates { get => _showPlates; set { _showPlates = value; InvalidateVisual(); StateChanged?.Invoke(); } }
public bool ShowBorders { get => _showBorders; set { _showBorders = value; InvalidateVisual(); StateChanged?.Invoke(); } }
public bool ShowLabels { get => _showLabels; set { _showLabels = value; InvalidateVisual(); StateChanged?.Invoke(); } }
public void ResetView()
{
_yawDeg = 10;
_pitchDeg = 18;
_zoom = 1.0;
InvalidateVisual();
StateChanged?.Invoke();
}
public void SetView(double yaw, double pitch, double zoom = 1.0)
{
_yawDeg = yaw;
_pitchDeg = pitch;
_zoom = zoom;
InvalidateVisual();
StateChanged?.Invoke();
}
// ---------------------------------------------------------------- 交互
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
_lastPointer = e.GetPosition(this);
_dragging = true;
e.Pointer.Capture(this);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
base.OnPointerMoved(e);
if (!_dragging) return;
var p = e.GetPosition(this);
var dx = p.X - _lastPointer.X;
var dy = p.Y - _lastPointer.Y;
_lastPointer = p;
// 跟手拖动:像素位移换算成角度
_yawDeg -= dx * 0.42;
_pitchDeg = Math.Clamp(_pitchDeg + dy * 0.42, -85, 85);
InvalidateVisual();
StateChanged?.Invoke();
}
protected override void OnPointerReleased(PointerReleasedEventArgs e)
{
base.OnPointerReleased(e);
_dragging = false;
e.Pointer.Capture(null);
}
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
base.OnPointerWheelChanged(e);
_zoom = Math.Clamp(_zoom * (1 + e.Delta.Y * 0.12), 0.55, 4.0);
InvalidateVisual();
StateChanged?.Invoke();
e.Handled = true;
}
// ---------------------------------------------------------------- 渲染
public override void Render(DrawingContext ctx)
{
var size = Bounds.Size;
if (size.Width < 40 || size.Height < 40) return;
DrawBackground(ctx, size);
var cx = (float)(size.Width * 0.5);
var cy = (float)(size.Height * 0.52);
var radius = (float)(Math.Min(size.Width, size.Height) * 0.44 * _zoom);
if (radius < 8) return;
// 相机:先按俯仰转 X,再按偏航转 Y
var cam = Matrix4x4.CreateRotationX((float)(-_pitchDeg * Math.PI / 180.0));
var planet = Matrix4x4.CreateRotationY((float)(_yawDeg * Math.PI / 180.0));
var combined = Matrix4x4.Multiply(planet, cam);
DrawSphereDisc(ctx, cx, cy, radius);
if (_showZones) DrawClimateZones(ctx, combined, cx, cy, radius);
if (_showCoast) DrawCoastlines(ctx, combined, cx, cy, radius);
if (_showPlates) DrawPlates(ctx, combined, cx, cy, radius);
if (_showBorders) DrawBorders(ctx, combined, cx, cy, radius);
if (_showLabels) DrawLabels(ctx, combined, cx, cy, radius);
DrawCompoundSphereOutLine(ctx, cx, cy, radius);
DrawHint(ctx, size, combined, cx, cy, radius);
}
private static readonly IBrush BgTop = new LinearGradientBrush
{
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
GradientStops =
{
new GradientStop(Color.Parse("#0B1726"), 0),
new GradientStop(Color.Parse("#060D18"), 1)
}
};
private void DrawBackground(DrawingContext ctx, Size size)
=> ctx.FillRectangle(BgTop, new Rect(size));
/// <summary>球体本身:极暗的海水底,只为了让白色轮廓看得清。</summary>
private static void DrawSphereDisc(DrawingContext ctx, float cx, float cy, float r)
{
var disc = new RadialGradientBrush
{
Center = new RelativePoint(0.36, 0.32, RelativeUnit.Relative),
GradientOrigin = new RelativePoint(0.36, 0.32, RelativeUnit.Relative),
RadiusX = new RelativeScalar(0.85, RelativeUnit.Relative),
RadiusY = new RelativeScalar(0.85, RelativeUnit.Relative),
GradientStops =
{
new GradientStop(Color.Parse("#12314F"), 0),
new GradientStop(Color.Parse("#0A1E33"), 0.62),
new GradientStop(Color.Parse("#061120"), 1)
}
};
ctx.DrawEllipse(disc, null, new Point(cx, cy), r, r);
}
private static void DrawCompoundSphereOutLine(DrawingContext ctx, float cx, float cy, float r)
{
var pen = new Pen(new SolidColorBrush(Color.FromArgb(190, 150, 200, 255)), 1.4);
ctx.DrawEllipse(null, pen, new Point(cx, cy), r, r);
}
// ---- 五带 ----
private void DrawClimateZones(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r)
{
foreach (var zone in _scene.Zones)
{
// 每个带用半透明色带填充 + 边界纬线
var color = ZoneFillColor(zone.Id);
FillLatBand(ctx, combined, cx, cy, r, zone.LatMin, zone.LatMax, color);
foreach (var lat in new[] { zone.LatMin, zone.LatMax })
{
var pen = Math.Abs(Math.Abs(lat) - _scene.TropicDeg) < 0.5 ? TropicPen
: Math.Abs(Math.Abs(lat) - (90 - _scene.TropicDeg)) < 0.5 ? PolarPen
: ZoneEdgePen;
DrawParallel(ctx, combined, cx, cy, r, lat, pen);
}
}
// 赤道独立强调
var eqPen = new Pen(new SolidColorBrush(Color.FromArgb(235, 120, 220, 255)), 1.8,
new DashStyle(new double[] { 6, 4 }, 0));
DrawParallel(ctx, combined, cx, cy, r, 0, eqPen);
}
/// <summary>把纬度带的球面片填成半透明色(只填可见半球)。</summary>
private static void FillLatBand(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r,
double latMin, double latMax, IBrush brush)
{
// 用「纬线环」的投影轮廓近似填充:采样一圈点拼成多边形
const int n = 96;
for (var band = 0; band < 2; band++)
{
var lat = band == 0 ? latMin : latMax;
var pts = new List<Vector2>(n);
for (var i = 0; i <= n; i++)
{
var lon = -180.0 + 360.0 * i / n;
var p = Geometry.ToCamera(Geometry.LatLonToUnit(lat, lon),
Matrix4x4.Identity, combined);
if (p.Z <= 0) continue;
pts.Add(Geometry.Project(p, r, cx, cy));
}
if (pts.Count < 3) continue;
// 只画这段环带的两条边界,中间填充交给 DrawParallel 视觉上已足够
}
// 实际填充:沿经线密集采样形成条带多边形
const int steps = 60;
var lons = new double[steps + 1];
for (var i = 0; i <= steps; i++) lons[i] = -180.0 + 360.0 * i / steps;
var top = new List<Vector2>();
var bottom = new List<Vector2>();
for (var i = 0; i <= steps; i++)
{
var pTop = Geometry.ToCamera(Geometry.LatLonToUnit(latMax, lons[i]),
Matrix4x4.Identity, combined);
var pBot = Geometry.ToCamera(Geometry.LatLonToUnit(latMin, lons[i]),
Matrix4x4.Identity, combined);
if (pTop.Z <= 0 || pBot.Z <= 0) continue;
top.Add(Geometry.Project(pTop, r, cx, cy));
bottom.Add(Geometry.Project(pBot, r, cx, cy));
}
if (top.Count < 3 || bottom.Count < 3) return;
var geo = new StreamGeometry();
using (var g = geo.Open())
{
g.BeginFigure(Pt(top[0]), true);
for (var i = 1; i < top.Count; i++) g.LineTo(Pt(top[i]));
for (var i = bottom.Count - 1; i >= 0; i--) g.LineTo(Pt(bottom[i]));
g.EndFigure(true);
}
ctx.DrawGeometry(brush, null, geo);
}
private static IBrush ZoneFillColor(string id) => id switch
{
"torrid-north" or "torrid-south" => new SolidColorBrush(Color.FromArgb(30, 255, 168, 76)),
"north-temperate" or "south-temperate" => new SolidColorBrush(Color.FromArgb(30, 110, 210, 140)),
_ => new SolidColorBrush(Color.FromArgb(34, 150, 200, 255))
};
private static void DrawParallel(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r,
double lat, IPen pen)
{
var pts = new List<double[]>(kParallelSamples);
for (var i = 0; i < kParallelSamples; i++)
pts.Add(new[] { -180.0 + 360.0 * i / (kParallelSamples - 1), lat });
DrawGeoPolyline(ctx, pts, combined, cx, cy, r, pen, closed: false);
}
private const int kParallelSamples = 145;
// ---- 海岸线 ----
private void DrawCoastlines(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r)
{
foreach (var line in _coast.Lines)
DrawGeoPolyline(ctx, line, combined, cx, cy, r, CoastPen, closed: true);
}
// ---- 板块边界 ----
private void DrawPlates(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r)
{
foreach (var plate in _plates.Plates)
foreach (var line in plate.Lines)
DrawGeoPolyline(ctx, line, combined, cx, cy, r, PlatePen, closed: true);
if (!_showLabels) return;
foreach (var plate in _plates.Plates)
{
var center = Centroid(plate.Lines);
if (center == null) continue;
var cam = Geometry.ToCamera(Geometry.LatLonToUnit(center[1], center[0]),
Matrix4x4.Identity, combined);
if (cam.Z <= 0.18f) continue;
var pos = Geometry.Project(cam, r, cx, cy);
var name = Pick(plate.NameI18n, plate.Id);
DrawText(ctx, name, pos.X, pos.Y, 11, PlateBrush, TextAlignment.Center);
}
}
// ---- 洲界 ----
private void DrawBorders(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r)
{
foreach (var b in _borders.Borders)
{
foreach (var line in b.Lines)
DrawGeoPolyline(ctx, line, combined, cx, cy, r, BorderPen, closed: false);
// 标志点:取线中点
if (b.Lines.Count == 0 || b.Lines[0].Count == 0) continue;
var mid = b.Lines[0][b.Lines[0].Count / 2];
if (mid.Length < 2) continue;
var cam = Geometry.ToCamera(Geometry.LatLonToUnit(mid[1], mid[0]),
Matrix4x4.Identity, combined);
if (cam.Z <= 0.05f) continue;
var pos = Geometry.Project(cam, r, cx, cy);
DrawDot(ctx, pos, 3.2, BorderBrush);
if (_showLabels)
DrawText(ctx, Pick(b.NameI18n, b.Name), pos.X + 8, pos.Y - 6, 10.5, BorderBrush, TextAlignment.Left);
}
}
// ---- 七大洲四大洋标签 ----
private void DrawLabels(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r)
{
foreach (var label in _labels.Labels)
{
var cam = Geometry.ToCamera(Geometry.LatLonToUnit(label.Lat, label.Lon),
Matrix4x4.Identity, combined);
if (cam.Z <= 0.12f) continue;
var pos = Geometry.Project(cam, r, cx, cy);
var isOcean = label.Kind == "ocean";
var brush = isOcean ? OceanBrush : ContinentBrush;
DrawText(ctx, Pick(label.NameI18n, ""), pos.X, pos.Y,
isOcean ? 11.5 : 12.5, brush, TextAlignment.Center,
isOcean ? FontStyle.Italic : FontStyle.Normal);
}
}
// ---- 通用:画一条经纬度折线(自动裁掉背面)----
private static void DrawGeoPolyline(DrawingContext ctx, IReadOnlyList<double[]> latLon,
Matrix4x4 combined, float cx, float cy, float r, IPen pen, bool closed)
{
var segments = Geometry.ProjectPolyline(latLon, Matrix4x4.Identity, combined, r, cx, cy, closed);
foreach (var seg in segments)
{
if (seg.Count < 2) continue;
var geo = new StreamGeometry();
using (var g = geo.Open())
{
g.BeginFigure(Pt(seg[0]), false);
for (var i = 1; i < seg.Count; i++) g.LineTo(Pt(seg[i]));
g.EndFigure(false);
}
ctx.DrawGeometry(null, pen, geo);
}
}
// ---------------------------------------------------------------- 画笔
private static readonly IPen CoastPen = new Pen(new SolidColorBrush(Color.FromArgb(250, 236, 246, 255)), 1.75)
{ LineJoin = PenLineJoin.Round, LineCap = PenLineCap.Round };
private static readonly IPen PlatePen = new Pen(new SolidColorBrush(Color.FromArgb(210, 255, 138, 92)), 1.5,
new DashStyle(new double[] { 7, 4 }, 0));
private static readonly IPen BorderPen = new Pen(new SolidColorBrush(Color.FromArgb(225, 255, 214, 110)), 1.35,
new DashStyle(new double[] { 3, 3 }, 0));
private static readonly IPen TropicPen = new Pen(new SolidColorBrush(Color.FromArgb(215, 255, 190, 100)), 1.3);
private static readonly IPen PolarPen = new Pen(new SolidColorBrush(Color.FromArgb(205, 150, 205, 255)), 1.3);
private static readonly IPen ZoneEdgePen = new Pen(new SolidColorBrush(Color.FromArgb(120, 190, 220, 255)), 0.9);
private static readonly IBrush ContinentBrush = new SolidColorBrush(Color.FromArgb(245, 232, 242, 255));
private static readonly IBrush OceanBrush = new SolidColorBrush(Color.FromArgb(215, 130, 190, 245));
private static readonly IBrush PlateBrush = new SolidColorBrush(Color.FromArgb(235, 255, 158, 118));
private static readonly IBrush BorderBrush = new SolidColorBrush(Color.FromArgb(240, 255, 220, 128));
// ---------------------------------------------------------------- 文字
private static void DrawText(DrawingContext ctx, string text, double x, double y, double size,
IBrush brush, TextAlignment align, FontStyle style = FontStyle.Normal)
{
if (string.IsNullOrWhiteSpace(text)) return;
var ft = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface(FontFamily.Default, style, FontWeight.SemiBold), size, brush);
var px = align switch
{
TextAlignment.Center => x - ft.Width / 2,
TextAlignment.Right => x - ft.Width,
_ => x
};
ctx.DrawText(ft, new Point(px, y));
}
private static Point Pt(Vector2 v) => new(v.X, v.Y);
private static void DrawDot(DrawingContext ctx, Vector2 p, double radius, IBrush brush)
=> ctx.DrawEllipse(brush, null, Pt(p), radius, radius);
private void DrawHint(DrawingContext ctx, Size size, Matrix4x4 combined, float cx, float cy, float r)
{
// 左下角经纬读数
var lat = _pitchDeg.ToString("0", CultureInfo.InvariantCulture);
var lon = NormalizeLon(_yawDeg).ToString("0", CultureInfo.InvariantCulture);
var text = $"视角 {lat}° / {lon}°";
DrawText(ctx, text, 18, size.Height - 26, 11,
new SolidColorBrush(Color.FromArgb(140, 160, 190, 230)), TextAlignment.Left);
}
private static double NormalizeLon(double deg)
{
var v = deg % 360;
if (v > 180) v -= 360;
if (v < -180) v += 360;
return v;
}
private static string Pick(Dictionary<string, string>? dict, string fallback)
{
if (dict == null || dict.Count == 0) return fallback;
foreach (var key in new[] { "zh-CN", "en" })
if (dict.TryGetValue(key, out var v) && !string.IsNullOrWhiteSpace(v)) return v;
foreach (var kv in dict)
if (!string.IsNullOrWhiteSpace(kv.Value)) return kv.Value;
return fallback;
}
private static double[]? Centroid(List<List<double[]>> lines)
{
var pts = new List<double[]>();
foreach (var l in lines)
foreach (var p in l)
if (p.Length >= 2) pts.Add(p);
if (pts.Count == 0) return null;
// 用球面平均避免经度跨越 ±180 出错
double sx = 0, sy = 0, sz = 0;
foreach (var p in pts)
{
var v = Geometry.LatLonToUnit(p[1], p[0]);
sx += v.X; sy += v.Y; sz += v.Z;
}
var n = Math.Sqrt(sx * sx + sy * sy + sz * sz);
if (n < 1e-9) return null;
sy /= n; sx /= n; sz /= n;
var lat = Math.Asin(Math.Clamp(sy, -1, 1)) * 180.0 / Math.PI;
var lon = Math.Atan2(sx, sz) * 180.0 / Math.PI;
return new[] { lon, lat };
}
}
+1 -1
View File
@@ -24,5 +24,5 @@
"preview": "preview.png", "preview": "preview.png",
"apiVersion": 1, "apiVersion": 1,
"version": "1.0-7380e0cff3", "version": "1.0-7380e0cff3",
"updatedAt": "2026-11-07T12:37:08Z" "updatedAt": "2026-11-07T12:47:48Z"
} }
+1 -1
View File
@@ -24,5 +24,5 @@
"preview": "preview.png", "preview": "preview.png",
"apiVersion": 1, "apiVersion": 1,
"version": "1.0-c74907bbce", "version": "1.0-c74907bbce",
"updatedAt": "2026-11-07T12:37:08Z" "updatedAt": "2026-11-07T12:47:48Z"
} }
+13 -13
View File
@@ -1,38 +1,38 @@
{ {
"schema": 1, "schema": 1,
"generated": "2026-11-07T12:37:08Z", "generated": "2026-11-07T12:47:48Z",
"repository": "https://gitcode.com/2509_92447106/GC", "repository": "https://gitcode.com/2509_92447106/GC",
"branch": "main", "branch": "main",
"modelDir": "model", "modelDir": "model",
"launcher": { "launcher": {
"version": "1.0.1", "version": "1.0.1",
"revision": "342aa82114", "revision": "55f1c85a1c",
"packages": { "packages": {
"win-x64": { "win-x64": {
"path": "dist/GC-win-x64.zip", "path": "dist/GC-win-x64.zip",
"url": "", "url": "https://gitcode.com/2509_92447106/GC/releases/download/v1.0.1/GC-win-x64.zip",
"sha256": "e965ac928e786ce7cda599f89acffbd801f5f9ebc56a9b105e57ab2650505038", "sha256": "020ba381445561002ed65327369d980650950b6243b771264bd3cfddee345b1a",
"size": 39378508 "size": 39376610
}, },
"win-arm64": { "win-arm64": {
"path": "dist/GC-win-arm64.zip", "path": "dist/GC-win-arm64.zip",
"url": "", "url": "https://gitcode.com/2509_92447106/GC/releases/download/v1.0.1/GC-win-arm64.zip",
"sha256": "cde265b004fb56f5bf8e8f61d443e2bec4c5690ece2f68b516d4d0cff4f721e2", "sha256": "b802b467de83a5669bb6e9e5f886f76bfd997ee4e0d400db3900e2da4aae4c8c",
"size": 37684753 "size": 37685056
}, },
"osx-arm64": { "osx-arm64": {
"path": "dist/GC-osx-arm64.zip", "path": "dist/GC-osx-arm64.zip",
"url": "", "url": "https://gitcode.com/2509_92447106/GC/releases/download/v1.0.1/GC-osx-arm64.zip",
"sha256": "1d8b412165a6bb0d27ac32b704a0d1baea4d593368d5605a3f054967dad4a991", "sha256": "a0a68ec0cef59d0b940bc364dad16e69ee3b0a81862f8122392761e566f6f86d",
"size": 39853077 "size": 39855097
}, },
"osx-x64": { "osx-x64": {
"path": "dist/GC-osx-x64.zip", "path": "dist/GC-osx-x64.zip",
"url": "" "url": "https://gitcode.com/2509_92447106/GC/releases/download/v1.0.1/GC-osx-x64.zip"
}, },
"linux-x64": { "linux-x64": {
"path": "dist/GC-linux-x64.zip", "path": "dist/GC-linux-x64.zip",
"url": "" "url": "https://gitcode.com/2509_92447106/GC/releases/download/v1.0.1/GC-linux-x64.zip"
} }
} }
}, },
@@ -1,6 +1,8 @@
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Media;
namespace EarthModelStudio.Views; namespace EarthModelStudio.Views;
@@ -11,6 +13,20 @@ public partial class ConfirmWindow : Window
public ConfirmWindow(string message) public ConfirmWindow(string message)
{ {
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
TransparencyLevelHint = new[] { WindowTransparencyLevel.Transparent };
Background = Brushes.Transparent;
if (this.Content is Control content)
{
this.Content = new Border
{
CornerRadius = new CornerRadius(12),
Background = (this.FindResource("Surface") as IBrush) ?? Brushes.White,
ClipToBounds = true,
Child = content
};
}
var text = this.FindControl<TextBlock>("MessageText"); var text = this.FindControl<TextBlock>("MessageText");
if (text != null) text.Text = message; if (text != null) text.Text = message;
} }
@@ -27,7 +27,8 @@ public sealed class PlayerWindow : Window
Height = 820; Height = 820;
MinWidth = 1000; MinWidth = 1000;
MinHeight = 680; MinHeight = 680;
Background = new SolidColorBrush(Color.Parse("#05070F")); Background = Brushes.Transparent;
TransparencyLevelHint = new[] { WindowTransparencyLevel.Transparent };
WindowStartupLocation = WindowStartupLocation.CenterOwner; WindowStartupLocation = WindowStartupLocation.CenterOwner;
// 与启动器一致:去掉系统标题栏,自己做一个极简顶栏(否则 Esc 之外无法关闭) // 与启动器一致:去掉系统标题栏,自己做一个极简顶栏(否则 Esc 之外无法关闭)
SystemDecorations = Avalonia.Controls.SystemDecorations.None; SystemDecorations = Avalonia.Controls.SystemDecorations.None;
@@ -73,10 +74,18 @@ public sealed class PlayerWindow : Window
foreach (var child in g.Children) foreach (var child in g.Children)
if (child is Button b) b.Click += (_, _) => Close(); if (child is Button b) b.Click += (_, _) => Close();
Content = new DockPanel { LastChildFill = true }; var dock = new DockPanel { LastChildFill = true };
DockPanel.SetDock(titleBar, Dock.Top); DockPanel.SetDock(titleBar, Dock.Top);
((DockPanel)Content).Children.Add(titleBar); dock.Children.Add(titleBar);
((DockPanel)Content).Children.Add(model.View); dock.Children.Add(model.View);
Content = new Border
{
CornerRadius = new CornerRadius(16),
Background = new SolidColorBrush(Color.Parse("#05070F")),
ClipToBounds = true,
Child = dock
};
KeyDown += OnKeyDown; KeyDown += OnKeyDown;
Closed += OnClosed; Closed += OnClosed;
@@ -121,7 +130,8 @@ public sealed class ModelErrorWindow : Window
Title = title; Title = title;
Width = 560; Width = 560;
Height = 340; Height = 340;
Background = new SolidColorBrush(Color.Parse("#0B1226")); Background = Brushes.Transparent;
TransparencyLevelHint = new[] { WindowTransparencyLevel.Transparent };
WindowStartupLocation = WindowStartupLocation.CenterOwner; WindowStartupLocation = WindowStartupLocation.CenterOwner;
var lines = new List<Control> var lines = new List<Control>
@@ -155,6 +165,11 @@ public sealed class ModelErrorWindow : Window
}; };
foreach (var line in lines) panel.Children.Add(line); foreach (var line in lines) panel.Children.Add(line);
if (lines[^1] is Button ok) ok.Click += (_, _) => Close(); if (lines[^1] is Button ok) ok.Click += (_, _) => Close();
Content = panel; Content = new Border
{
CornerRadius = new CornerRadius(12),
Background = new SolidColorBrush(Color.Parse("#0B1226")),
Child = panel
};
} }
} }
+13 -13
View File
@@ -1,38 +1,38 @@
{ {
"schema": 1, "schema": 1,
"generated": "2026-11-07T12:37:08Z", "generated": "2026-11-07T12:47:48Z",
"repository": "https://gitcode.com/2509_92447106/GC", "repository": "https://gitcode.com/2509_92447106/GC",
"branch": "main", "branch": "main",
"modelDir": "model", "modelDir": "model",
"launcher": { "launcher": {
"version": "1.0.1", "version": "1.0.1",
"revision": "342aa82114", "revision": "55f1c85a1c",
"packages": { "packages": {
"win-x64": { "win-x64": {
"path": "dist/GC-win-x64.zip", "path": "dist/GC-win-x64.zip",
"url": "", "url": "https://gitcode.com/2509_92447106/GC/releases/download/v1.0.1/GC-win-x64.zip",
"sha256": "e965ac928e786ce7cda599f89acffbd801f5f9ebc56a9b105e57ab2650505038", "sha256": "020ba381445561002ed65327369d980650950b6243b771264bd3cfddee345b1a",
"size": 39378508 "size": 39376610
}, },
"win-arm64": { "win-arm64": {
"path": "dist/GC-win-arm64.zip", "path": "dist/GC-win-arm64.zip",
"url": "", "url": "https://gitcode.com/2509_92447106/GC/releases/download/v1.0.1/GC-win-arm64.zip",
"sha256": "cde265b004fb56f5bf8e8f61d443e2bec4c5690ece2f68b516d4d0cff4f721e2", "sha256": "b802b467de83a5669bb6e9e5f886f76bfd997ee4e0d400db3900e2da4aae4c8c",
"size": 37684753 "size": 37685056
}, },
"osx-arm64": { "osx-arm64": {
"path": "dist/GC-osx-arm64.zip", "path": "dist/GC-osx-arm64.zip",
"url": "", "url": "https://gitcode.com/2509_92447106/GC/releases/download/v1.0.1/GC-osx-arm64.zip",
"sha256": "1d8b412165a6bb0d27ac32b704a0d1baea4d593368d5605a3f054967dad4a991", "sha256": "a0a68ec0cef59d0b940bc364dad16e69ee3b0a81862f8122392761e566f6f86d",
"size": 39853077 "size": 39855097
}, },
"osx-x64": { "osx-x64": {
"path": "dist/GC-osx-x64.zip", "path": "dist/GC-osx-x64.zip",
"url": "" "url": "https://gitcode.com/2509_92447106/GC/releases/download/v1.0.1/GC-osx-x64.zip"
}, },
"linux-x64": { "linux-x64": {
"path": "dist/GC-linux-x64.zip", "path": "dist/GC-linux-x64.zip",
"url": "" "url": "https://gitcode.com/2509_92447106/GC/releases/download/v1.0.1/GC-linux-x64.zip"
} }
} }
}, },