champions-of-luneraria/Assets/Luneraria/Editor/World/LuneWorldCapture.cs
Martin Stickelbroeck 8a72cb165a U2B World Geometry
G1-Karte in Unity (Assets/Luneraria/Scenes/G1_Map.unity), reproduzierbar
gebaut aus dem Godot-Weltgenerator (gebacken), den FBX-Modellen aus U2A und der
Karte des C#-Kerns.

- tools/godot-golden/world_export.gd: backt Gelände (Raster, Farben, Lauf- und
  Standhöhen), Lanebeläge, Plattform, Brücke, Randsteine, Basen, Landmarken,
  Vegetation, Adern, Grottentreppen, Aufstellungsbereiche und Licht. Braucht
  einen echten Renderer (HEADLESS=0); prüft auf Headless-Einheitstransformationen.
- LuneWorldBuilder: Meshes (GUID-stabil), Szene, Licht, Himmel, Post-Processing,
  16 Türme, 2 Ancients und die Grotte aus LuneMap mit Teammaterialien.
- Materialsystem: Luneraria/Surface (Gelände, Kluft-Oberflächen, Fluss, Adern,
  Kristall, G2-Werte mit Teamvarianten und Vertex-AO) und Luneraria/Pad;
  LuneMaterialSet.Dress wie Godots dress.
- View-Assembly: LuneSpace (Unity = (-x, h, y)), LuneGround, LuneCameraMath,
  LuneBuildingView (Zustände intakt bis Ruine).
- Vergleichsbilder mit den Kameraeinstellungen der Godot-G2-Aufnahmen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 16:01:25 +02:00

93 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using Luneraria.Core;
using Luneraria.View;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace Luneraria.EditorTools
{
/// <summary>
/// Screenshots of the G1 map scene with the camera settings of the Godot G2 captures
/// (../saumwacht-godot/tools/luneraria/g2_views.gd), so both can be compared side by side:
/// 15 overview, 01 Blau Ancient, 05 Grenzwacht, 06 Bastion, 07 base towers, 10 grotto.
/// Unity -batchmode -projectPath . -executeMethod Luneraria.EditorTools.LuneWorldCapture.CaptureAll
/// </summary>
public static class LuneWorldCapture
{
public const int Width = 1920;
public const int Height = 1080;
struct View
{
public string Label;
public Vec2 At;
public float Zoom;
public int YawSteps;
}
public static void CaptureAll()
{
int code = 0;
try
{
EditorSceneManager.OpenScene(LuneWorldBuilder.ScenePath, OpenSceneMode.Single);
var ground = AssetDatabase.LoadAssetAtPath<LuneGround>(LuneWorldBuilder.GroundPath);
var map = new LuneMap(new LuneBalance());
Vec2 blue = map.CorePosition(0);
Vec2 red = map.CorePosition(1);
Vec2 outer = map.BuildingDef("rot_mid_outer").Position;
Vec2 inner = map.BuildingDef("rot_mid_inner").Position;
Vec2 baseA = map.BuildingDef("rot_base_1").Position;
Vec2 baseB = map.BuildingDef("rot_base_2").Position;
var views = new List<View>
{
new View { Label = "15-gesamtkarte", At = new Vec2(0, 0), Zoom = LuneCameraMath.OverviewZoom },
new View { Label = "01-ancient-100", At = blue + new Vec2(1.0, -1.0), Zoom = 28f, YawSteps = -1 },
new View { Label = "05-tower1-grenzwacht", At = outer + new Vec2(0, -2.4), Zoom = 14f },
new View { Label = "06-tower2-bastion", At = inner + new Vec2(0, -2.8), Zoom = 14f },
new View { Label = "07-basistuerme", At = (baseA + baseB) * .5 * .5 + red * .5, Zoom = 24f, YawSteps = -1 },
new View { Label = "10-grotte", At = map.GrottoCenter(), Zoom = 20f },
};
string folder = Path.Combine(Path.GetDirectoryName(Application.dataPath), "docs/port/screenshots/u2b");
Directory.CreateDirectory(folder);
Camera camera = Camera.main;
foreach (View view in views)
{
// Godot: look_at_point clamps the focus and puts it on the ground under it.
var focus = new Vec2(Mathf.Clamp((float)view.At.X, -LuneCameraMath.FocusLimit, LuneCameraMath.FocusLimit), Mathf.Clamp((float)view.At.Y, -LuneCameraMath.FocusLimit, LuneCameraMath.FocusLimit));
Vector3 point = LuneSpace.World(focus, ground.StandHeight(focus));
LuneCameraMath.Pose(point, view.Zoom, view.YawSteps * Mathf.PI * .25f, out Vector3 position, out Quaternion rotation);
camera.transform.SetPositionAndRotation(position, rotation);
Render(camera, Path.Combine(folder, view.Label + ".png"));
}
}
catch (Exception error)
{
Debug.LogError("LUNE_CAPTURE failed: " + error);
code = 1;
}
EditorApplication.Exit(code);
}
public static void Render(Camera camera, string file)
{
var target = new RenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32) { antiAliasing = 4 };
camera.aspect = (float)Width / Height;
camera.targetTexture = target;
camera.Render();
RenderTexture.active = target;
var image = new Texture2D(Width, Height, TextureFormat.RGB24, false);
image.ReadPixels(new Rect(0, 0, Width, Height), 0, 0);
image.Apply();
File.WriteAllBytes(file, image.EncodeToPNG());
RenderTexture.active = null;
camera.targetTexture = null;
UnityEngine.Object.DestroyImmediate(target);
UnityEngine.Object.DestroyImmediate(image);
Debug.Log("LUNE_CAPTURE wrote " + file);
}
}
}