3D-Arena (Duell, Hub, Freiheit, Erstellung, Bestenliste), Retiarius beidhändig, Waffen je Klasse, Einführung, Willkommen, weniger Reiter, Wirtschaft ohne Taberna, Kantenglättung, Leuchten, weiche Schatten, Gamepad, Absturz-Protokoll
Stand von main 20cd8ba2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -101,6 +101,43 @@ namespace GladiatorIdle.Gfx
|
||||
return result;
|
||||
}
|
||||
|
||||
// ── Mipmaps: verkleinerte Stufen für Texturen, die schräg oder weit weg zu sehen sind
|
||||
// (Sand, Mauer, Publikum, Figuren) – sonst flimmern sie in der Tiefe ──
|
||||
static readonly Dictionary<Texture2D, Texture2D> _mipped = new();
|
||||
|
||||
/// Dieselbe Textur mit allen Mipmap-Stufen (einmal je Quelle).
|
||||
public static Texture2D Mipmapped(Texture2D src)
|
||||
{
|
||||
if (src.LevelCount > 1) return src;
|
||||
if (_mipped.TryGetValue(src, out var t)) return t;
|
||||
var data = new Color[src.Width * src.Height];
|
||||
src.GetData(data);
|
||||
return _mipped[src] = MipTexture(data, src.Width, src.Height);
|
||||
}
|
||||
|
||||
/// Textur aus Pixeln mit Mipmap-Stufen (2×2-Mittel je Stufe).
|
||||
public static Texture2D MipTexture(Color[] data, int w, int h)
|
||||
{
|
||||
var t = new Texture2D(_gd, w, h, true, SurfaceFormat.Color);
|
||||
t.SetData(0, null, data, 0, data.Length);
|
||||
var cur = data; int cw = w, ch = h;
|
||||
for (int level = 1; level < t.LevelCount; level++)
|
||||
{
|
||||
int nw = Math.Max(1, cw / 2), nh = Math.Max(1, ch / 2);
|
||||
var next = new Color[nw * nh];
|
||||
for (int y = 0; y < nh; y++)
|
||||
for (int x = 0; x < nw; x++)
|
||||
{
|
||||
int x0 = Math.Min(cw - 1, x * 2), x1 = Math.Min(cw - 1, x * 2 + 1), y0 = Math.Min(ch - 1, y * 2), y1 = Math.Min(ch - 1, y * 2 + 1);
|
||||
var a = cur[y0 * cw + x0]; var b = cur[y0 * cw + x1]; var c = cur[y1 * cw + x0]; var d = cur[y1 * cw + x1];
|
||||
next[y * nw + x] = new Color((a.R + b.R + c.R + d.R + 2) / 4, (a.G + b.G + c.G + d.G + 2) / 4, (a.B + b.B + c.B + d.B + 2) / 4, (a.A + b.A + c.A + d.A + 2) / 4);
|
||||
}
|
||||
t.SetData(level, null, next, 0, next.Length);
|
||||
cur = next; cw = nw; ch = nh;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/// Bild eines Video-Sprites: Farbe vor Schwarz (JPEG, also schon vormultipliziert)
|
||||
/// plus Deckkraft (Graustufen-PNG) — zusammengesetzt zu einer Textur.
|
||||
public static Texture2D? LoadFrame(string relBase)
|
||||
@@ -160,8 +197,8 @@ namespace GladiatorIdle.Gfx
|
||||
var data = new Color[src.Width * src.Height];
|
||||
src.GetData(data);
|
||||
PaintPixels(data, colorIndex);
|
||||
t = new Texture2D(_gd, src.Width, src.Height);
|
||||
t.SetData(data);
|
||||
if (src.LevelCount > 1) t = MipTexture(data, src.Width, src.Height); // Figuren: Stufen behalten
|
||||
else { t = new Texture2D(_gd, src.Width, src.Height); t.SetData(data); }
|
||||
_painted[(src, colorIndex)] = t;
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
@@ -67,10 +68,33 @@ namespace GladiatorIdle.Gfx
|
||||
|
||||
public static Model3D? Load(string name) => Load(Assets.Device, name);
|
||||
|
||||
// Vorlagen je Datei: einmal gelesen, danach teilt jede Figur Gitter, Gewichte, Clips und Textur
|
||||
// und hat nur eigene Haltung, eigene Puffer und eigene Waffen (Duellstart ohne Plattenzugriff).
|
||||
static readonly Dictionary<string, Model3D?> _templates = new();
|
||||
|
||||
public static Model3D? Load(GraphicsDevice gd, string name)
|
||||
{
|
||||
string? path = Assets.RootDir is string root ? Path.Combine(root, "Models", name + ".gim") : null;
|
||||
return path != null && File.Exists(path) ? new Model3D(gd, path) : null;
|
||||
if (!_templates.TryGetValue(name, out var t))
|
||||
{
|
||||
string? path = Assets.RootDir is string root ? Path.Combine(root, "Models", name + ".gim") : null;
|
||||
_templates[name] = t = path != null && File.Exists(path) ? new Model3D(gd, path) : null;
|
||||
}
|
||||
return t == null ? null : new Model3D(t);
|
||||
}
|
||||
|
||||
/// Neue Figur auf den geteilten Daten einer Vorlage.
|
||||
Model3D(Model3D src)
|
||||
{
|
||||
_names = src._names; _parent = src._parent; _rest = src._rest; _offset = src._offset;
|
||||
_pos = src._pos; _nrm = src._nrm; _baseCol = src._baseCol; _bi = src._bi; _bw = src._bw;
|
||||
Indices = src.Indices;
|
||||
Clips = src.Clips;
|
||||
Vertices = (VertexPNCT[])src.Vertices.Clone();
|
||||
Bounds = src.Bounds;
|
||||
_texture = src._texture;
|
||||
Unit = src.Unit;
|
||||
_pose = (float[])_rest.Clone(); _from = (float[])_rest.Clone();
|
||||
_global = new Matrix[_names.Length]; _skin = new Matrix[_names.Length];
|
||||
}
|
||||
|
||||
Model3D(GraphicsDevice gd, string path)
|
||||
@@ -113,7 +137,7 @@ namespace GladiatorIdle.Gfx
|
||||
Clips.Add(clip);
|
||||
}
|
||||
if (v2 && r.ReadInt32() is int texLen && texLen > 0)
|
||||
using (var ms = new MemoryStream(r.ReadBytes(texLen))) _texture = Texture2D.FromStream(gd, ms);
|
||||
using (var ms = new MemoryStream(r.ReadBytes(texLen))) _texture = Assets.Mipmapped(Texture2D.FromStream(gd, ms)); // Stufen: kein Flimmern klein/weit weg
|
||||
Vertices = new VertexPNCT[nv];
|
||||
for (int i = 0; i < nv; i++) Vertices[i] = new VertexPNCT { Position = _pos[i], Normal = _nrm[i], Color = _baseCol[i], Uv = uv[i] };
|
||||
Bounds = BoundingBox.CreateFromPoints(_pos);
|
||||
@@ -157,9 +181,7 @@ namespace GladiatorIdle.Gfx
|
||||
nr = gray + (nr - gray) * boost; ng = gray + (ng - gray) * boost; nb = gray + (nb - gray) * boost;
|
||||
data[i] = new Color(Math.Clamp(nr, 0, 1), Math.Clamp(ng, 0, 1), Math.Clamp(nb, 0, 1), c.A / 255f);
|
||||
}
|
||||
var t = new Texture2D(_texture.GraphicsDevice, _texture.Width, _texture.Height);
|
||||
t.SetData(data);
|
||||
_texture = t;
|
||||
_texture = Assets.MipTexture(data, _texture.Width, _texture.Height);
|
||||
_color = -2; // Teamfarbe neu auf die geänderte Textur
|
||||
}
|
||||
|
||||
@@ -225,17 +247,39 @@ namespace GladiatorIdle.Gfx
|
||||
var keep = (float[])_pose.Clone(); bool posed = _posed;
|
||||
int hand = Bone("RightHand");
|
||||
float best = float.MinValue; t = clip.Length * 0.5f;
|
||||
// Zweihand-Waffe: Ausholen hinter dem Kopf, dann Schlag nach vorn – Treffer, wenn die Spitze
|
||||
// am schnellsten nach vorn schnellt (die höchste Hand wäre mitten im Ausholen).
|
||||
var weapon = _twoHand ? Props.Find(p => !p.Shield && !p.NoAvoid && p.Bone == hand) : null;
|
||||
var dirZ = new List<float>();
|
||||
for (int f = 0; f < clip.Frames && hand >= 0; f++)
|
||||
{
|
||||
_posed = true;
|
||||
Pose(clip, f / clip.Fps, false, 1, true, skin: false);
|
||||
if (weapon != null)
|
||||
{
|
||||
var m = weapon.Local * _global[hand];
|
||||
dirZ.Add(Vector3.Normalize(new Vector3(m.M11, m.M12, m.M13)).Z);
|
||||
continue;
|
||||
}
|
||||
float z = _global[hand].Translation.Z;
|
||||
if (z > best) { best = z; t = f / clip.Fps; }
|
||||
}
|
||||
if (dirZ.Count > 0)
|
||||
{
|
||||
// tiefstes Ausholen (Spitze am weitesten nach hinten), danach erster Moment mit Spitze nach vorn
|
||||
int end = Math.Max(1, (int)(dirZ.Count * 0.85f)); // Rückkehr in die Grundhaltung zählt nicht
|
||||
int back = 0;
|
||||
for (int f = 1; f < end; f++) if (dirZ[f] < dirZ[back]) back = f;
|
||||
int hit = -1;
|
||||
for (int f = back; f < end && hit < 0; f++) if (dirZ[f] > 0.6f) hit = f;
|
||||
if (hit < 0) { hit = back; for (int f = back; f < end; f++) if (dirZ[f] > dirZ[hit]) hit = f; }
|
||||
t = hit / clip.Fps;
|
||||
}
|
||||
Array.Copy(keep, _pose, keep.Length); _posed = posed; Bones();
|
||||
return _impact[clip] = t;
|
||||
}
|
||||
readonly Dictionary<Clip, float> _impact = new();
|
||||
bool _twoHand; // Waffe beidhändig (Großschwert-Bewegungen), siehe AimBlades
|
||||
|
||||
/// Figur auf 180 Einheiten Höhe, Füße auf y = 0, mittig (aus der jetzigen Haltung, robust gegen Ausreißer).
|
||||
public Matrix FitNow()
|
||||
@@ -291,12 +335,13 @@ namespace GladiatorIdle.Gfx
|
||||
DynamicVertexBuffer? _vb;
|
||||
bool _dirty;
|
||||
|
||||
public void Draw(GraphicsDevice gd, BasicEffect fx, bool aura = false)
|
||||
/// Zeichnen; <paramref name="depth"/>/<paramref name="blend"/> überschreiben die Zustände (Schatten auf dem Boden).
|
||||
public void Draw(GraphicsDevice gd, BasicEffect fx, bool aura = false, DepthStencilState? depth = null, BlendState? blend = null)
|
||||
{
|
||||
gd.DepthStencilState = aura ? DepthStencilState.None : DepthStencilState.Default;
|
||||
gd.BlendState = aura ? BlendState.Additive : BlendState.Opaque;
|
||||
gd.DepthStencilState = depth ?? (aura ? DepthStencilState.None : DepthStencilState.Default);
|
||||
gd.BlendState = blend ?? (aura ? BlendState.Additive : BlendState.Opaque);
|
||||
gd.RasterizerState = RasterizerState.CullNone;
|
||||
fx.TextureEnabled = _texture != null && !aura;
|
||||
fx.TextureEnabled = _texture != null && !aura && blend == null;
|
||||
fx.Texture = _painted ?? _texture;
|
||||
// Indizes liegen einmal auf der Grafikkarte, Punkte nur nach einer neuen Haltung neu
|
||||
if (_ib == null)
|
||||
@@ -312,7 +357,7 @@ namespace GladiatorIdle.Gfx
|
||||
foreach (var pass in fx.CurrentTechnique.Passes)
|
||||
{
|
||||
pass.Apply();
|
||||
gd.SamplerStates[0] = SamplerState.LinearClamp;
|
||||
gd.SamplerStates[0] = SamplerState.AnisotropicClamp;
|
||||
gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, Indices.Length / 3);
|
||||
}
|
||||
fx.TextureEnabled = false;
|
||||
@@ -390,8 +435,15 @@ namespace GladiatorIdle.Gfx
|
||||
/// Ausrüstung nach Figur: Retiarius Dreizack und Netz, sonst Gladius und Scutum.
|
||||
public void Arm(string art)
|
||||
{
|
||||
if (art.Contains("retiarius")) { AddTrident(); AddNet(); }
|
||||
else { AddSword(); AddShield(); }
|
||||
bool Is(params string[] keys) => keys.Any(k => art.Contains(k));
|
||||
if (Is("retiarius")) { AddTrident(); AddNet(); }
|
||||
else if (Is("thraex")) { AddSword(kind: "sica"); AddShield(kind: "parmula"); }
|
||||
else if (Is("hoplomachus", "eques")) { AddSpear(); AddShield(kind: "round"); }
|
||||
else if (Is("recruit")) { AddSword(kind: "rudis"); AddShield(); }
|
||||
else if (Is("slave")) AddSword(kind: "club");
|
||||
else if (Is("dimachaerus")) { AddSword(); AddSword("Left"); }
|
||||
else if (Is("brawler", "sagittarius", "essedarius", "laquearius", "doctore")) { AddSword(); AddShield(kind: "round"); }
|
||||
else { AddSword(); AddShield(); } // Murmillo, Secutor, Provocator, Prätorianer, Crupellarius, Champions
|
||||
AimBlades();
|
||||
}
|
||||
|
||||
@@ -403,9 +455,22 @@ namespace GladiatorIdle.Gfx
|
||||
{
|
||||
var clip = Find("slash") ?? (Clips.Count > 0 ? Clips[0] : null);
|
||||
if (clip == null) return;
|
||||
float t = ImpactTime(clip);
|
||||
var keep = (float[])_pose.Clone(); bool posed = _posed;
|
||||
_posed = true;
|
||||
// Zweihand-Bewegungen (Großschwert-Pack): in der Grundhaltung liegen beide Hände am Griff –
|
||||
// dann zeigt die Waffe entlang der Linie linke → rechte Hand, gemessen in der Grundhaltung.
|
||||
int rh = Bone("RightHand"), lh = Bone("LeftHand");
|
||||
bool twoHand = false;
|
||||
if (Find("idle") is { } idle && rh >= 0 && lh >= 0)
|
||||
{
|
||||
Pose(idle, 0, false, 1, true, skin: false);
|
||||
var gap = _global[rh].Translation - _global[lh].Translation;
|
||||
float fore = Vector3.Distance(_global[rh].Translation, _global[_parent[rh]].Translation);
|
||||
twoHand = gap.Length() < fore * 0.8f;
|
||||
}
|
||||
_twoHand = twoHand;
|
||||
float t = twoHand ? 0 : ImpactTime(clip);
|
||||
if (twoHand) clip = Find("idle")!;
|
||||
Pose(clip, t, false, 1, true, skin: false);
|
||||
foreach (var p in Props)
|
||||
{
|
||||
@@ -413,9 +478,12 @@ namespace GladiatorIdle.Gfx
|
||||
var m = p.Local * _global[p.Bone];
|
||||
var dir = Vector3.Normalize(new Vector3(m.M11, m.M12, m.M13));
|
||||
var (fa, fu, fs) = ArmFrame(p.Bone);
|
||||
BladeLog = $"blade z {dir.Z:0.00} arm {Vector3.Dot(dir, fa):0.000} up {Vector3.Dot(dir, fu):0.000} side {Vector3.Dot(dir, fs):0.000}"; // i18n-ok
|
||||
BladeLog = $"blade z {dir.Z:0.00} arm {Vector3.Dot(dir, fa):0.000} up {Vector3.Dot(dir, fu):0.000} side {Vector3.Dot(dir, fs):0.000} twohand {twoHand}"; // i18n-ok
|
||||
// Ziel: Lage wie bei den Figuren mit sauberem Skelett (gemessen an vier Figuren)
|
||||
var target = Vector3.Normalize(fa * 0.31f + fu * 0.36f + fs * 0.88f);
|
||||
float mirror = _names[p.Bone].Contains("Left") ? -1 : 1; // linke Hand: gespiegelt
|
||||
var target = twoHand && p.Bone == rh
|
||||
? Vector3.Normalize(_global[rh].Translation - _global[lh].Translation)
|
||||
: Vector3.Normalize(fa * 0.31f + fu * 0.36f + fs * (0.88f * mirror));
|
||||
float cos = MathHelper.Clamp(Vector3.Dot(dir, target), -1, 1);
|
||||
if (cos < 0.97f)
|
||||
{
|
||||
@@ -509,22 +577,73 @@ namespace GladiatorIdle.Gfx
|
||||
}
|
||||
|
||||
/// Gladius in der Faust (Knochen-Präfix "Right"/"Left"). Klinge zeigt vom kleinen Finger zum Zeigefinger.
|
||||
public void AddSword(string side = "Right")
|
||||
public void AddSword(string side = "Right", string kind = "gladius")
|
||||
{
|
||||
var b = new MeshBuilder();
|
||||
var steel = new Color(196, 200, 206); var brass = new Color(176, 136, 62); var wood = new Color(92, 58, 34);
|
||||
b.Box(new Vector3(-9, 0, 0), new Vector3(1.5f, 3.6f, 3.6f), brass); // Knauf
|
||||
b.Box(new Vector3(-3.5f, 0, 0), new Vector3(10, 3, 3), wood); // Griff
|
||||
b.Box(new Vector3(2.2f, 0, 0), new Vector3(1.6f, 4, 11), brass); // Parierstange
|
||||
b.Box(new Vector3(30, 0, 0), new Vector3(54, 0.8f, 5.2f), steel); // Klinge
|
||||
b.Box(new Vector3(60, 0, 0), new Vector3(6, 0.7f, 2.6f), steel); // Spitze
|
||||
var lightWood = new Color(150, 112, 70);
|
||||
float length = 63;
|
||||
switch (kind)
|
||||
{
|
||||
case "rudis": // Holzschwert der Rekruten
|
||||
b.Box(new Vector3(-3.5f, 0, 0), new Vector3(10, 3, 3), wood);
|
||||
b.Box(new Vector3(2, 0, 0), new Vector3(2, 3.6f, 8), wood);
|
||||
b.Box(new Vector3(28, 0, 0), new Vector3(50, 1.6f, 4.6f), lightWood);
|
||||
b.Box(new Vector3(55, 0, 0), new Vector3(4, 1.4f, 3), lightWood);
|
||||
length = 57; break;
|
||||
case "sica": // gebogenes Kurzschwert der Thraker: Klinge biegt zur Schneide hin
|
||||
{
|
||||
b.Box(new Vector3(-9, 0, 0), new Vector3(1.5f, 3.6f, 3.6f), brass);
|
||||
b.Box(new Vector3(-3.5f, 0, 0), new Vector3(10, 3, 3), wood);
|
||||
b.Box(new Vector3(2, 0, 0), new Vector3(1.6f, 4, 8), brass);
|
||||
var at = new Vector3(3, 0, 0); float angle = 0;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
float seg = i < 4 ? 11 : 9, width = i < 4 ? 4.6f : 3;
|
||||
var dir = new Vector3(MathF.Cos(angle), 0, -MathF.Sin(angle));
|
||||
b.Box(at + dir * seg / 2, new Vector3(seg + 0.6f, 0.8f, width), steel, Matrix.CreateRotationY(angle));
|
||||
at += dir * seg;
|
||||
angle += MathHelper.ToRadians(11);
|
||||
}
|
||||
length = 50; break;
|
||||
}
|
||||
case "club": // Knüppel: dicker werdendes Holz
|
||||
b.Box(new Vector3(-3, 0, 0), new Vector3(12, 3.2f, 3.2f), wood);
|
||||
for (int i = 0; i < 4; i++)
|
||||
b.Box(new Vector3(8 + i * 11, 0, 0), new Vector3(11.5f, 4 + i * 1.3f, 4 + i * 1.3f), i % 2 == 0 ? wood : lightWood);
|
||||
length = 50; break;
|
||||
default: // Gladius
|
||||
b.Box(new Vector3(-9, 0, 0), new Vector3(1.5f, 3.6f, 3.6f), brass);
|
||||
b.Box(new Vector3(-3.5f, 0, 0), new Vector3(10, 3, 3), wood);
|
||||
b.Box(new Vector3(2.2f, 0, 0), new Vector3(1.6f, 4, 11), brass);
|
||||
b.Box(new Vector3(30, 0, 0), new Vector3(54, 0.8f, 5.2f), steel);
|
||||
b.Box(new Vector3(60, 0, 0), new Vector3(6, 0.7f, 2.6f), steel);
|
||||
break;
|
||||
}
|
||||
var sword = b.Build(Bone(side + "Hand"), Grip(side));
|
||||
sword.Length = 63;
|
||||
sword.Length = length;
|
||||
Props.Add(sword);
|
||||
}
|
||||
|
||||
/// Speer (Hasta) der Hoplomachi und Equites, in der Mitte gefasst: Blattspitze nach vorn.
|
||||
public void AddSpear(string side = "Right")
|
||||
{
|
||||
var b = new MeshBuilder();
|
||||
var wood = new Color(118, 82, 48); var bronze = new Color(184, 140, 70); var steel = new Color(200, 204, 210);
|
||||
b.Box(new Vector3(25, 0, 0), new Vector3(170, 2.4f, 2.4f), wood); // Schaft (-60 … +110)
|
||||
b.Box(new Vector3(-61, 0, 0), new Vector3(4, 3, 3), bronze); // Schuh
|
||||
b.Box(new Vector3(111, 0, 0), new Vector3(5, 3.2f, 3.2f), bronze); // Tülle
|
||||
// Blatt: zwei schräge Hälften bilden die Raute
|
||||
b.Box(new Vector3(121, 0, 1.3f), new Vector3(16, 0.8f, 2.6f), steel, Matrix.CreateRotationY(MathHelper.ToRadians(-9)));
|
||||
b.Box(new Vector3(121, 0, -1.3f), new Vector3(16, 0.8f, 2.6f), steel, Matrix.CreateRotationY(MathHelper.ToRadians(9)));
|
||||
b.Box(new Vector3(131, 0, 0), new Vector3(7, 0.7f, 1.6f), steel);
|
||||
var p = b.Build(Bone(side + "Hand"), Grip(side));
|
||||
p.Length = 134;
|
||||
Props.Add(p);
|
||||
}
|
||||
|
||||
/// Gewölbter Schild (Scutum) am Unterarm, Bemalung in Magenta (Teamfarbe), Bronzerand und Buckel.
|
||||
public void AddShield(string side = "Left")
|
||||
public void AddShield(string side = "Left", string kind = "scutum")
|
||||
{
|
||||
var fa = BindPos(side + "ForeArm"); var h = BindPos(side + "Hand");
|
||||
var m = BindPos(side + "HandMiddle1"); var ix = BindPos(side + "HandIndex1"); var pk = BindPos(side + "HandPinky1"); var th = BindPos(side + "HandThumb1");
|
||||
@@ -538,11 +657,23 @@ namespace GladiatorIdle.Gfx
|
||||
var centre = m + knuckles * 7 * Unit;
|
||||
var b = new MeshBuilder();
|
||||
var face = new Color(190, 30, 160); var rim = new Color(150, 112, 52); var boss = new Color(182, 150, 80);
|
||||
const float W = 50, H = 72, BEND = 0.011f;
|
||||
// x: Länge (entlang des Arms), y: Breite, z: nach außen (weg vom Arm), gewölbt um die Längsachse
|
||||
b.Curved(W, H, BEND, face, 1.2f);
|
||||
b.Rim(W, H, BEND, rim);
|
||||
b.Dome(new Vector3(0, 0, 2.5f), 9, 5, boss);
|
||||
float W = 50, H = 72, BEND = 0.011f;
|
||||
if (kind == "round")
|
||||
{
|
||||
// Rundschild (Parma): flach gewölbte Scheibe mit Rand und Buckel
|
||||
W = H = 60; BEND = 0.006f;
|
||||
b.Disc(30, BEND, face, 1.2f);
|
||||
b.Ring(30, BEND, rim);
|
||||
b.Dome(new Vector3(0, 0, 1.5f), 8, 5, boss);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kind == "parmula") { W = 40; H = 48; BEND = 0.02f; } // kleiner Schild der Thraker
|
||||
// x: Länge (entlang des Arms), y: Breite, z: nach außen (weg vom Arm), gewölbt um die Längsachse
|
||||
b.Curved(W, H, BEND, face, 1.2f);
|
||||
b.Rim(W, H, BEND, rim);
|
||||
b.Dome(new Vector3(0, 0, 2.5f), kind == "parmula" ? 6 : 9, kind == "parmula" ? 4 : 5, boss);
|
||||
}
|
||||
// x (Höhe) = Griff (senkrecht gehalten, wie die Mixamo-Schildbewegungen es erwarten),
|
||||
// y (Breite) = Knöchel × Griff, z (außen) = x × y = Knöchelrichtung
|
||||
var shield = b.Build(Bone(side + "Hand"), Matrix.CreateScale(Unit) * Attach(Bone(side + "Hand"), across, Vector3.Cross(knuckles, across), centre));
|
||||
@@ -710,10 +841,11 @@ namespace GladiatorIdle.Gfx
|
||||
_i.AddRange(new[] { o, o + 1, o + 2, o, o + 2, o + 3 });
|
||||
}
|
||||
|
||||
public void Box(Vector3 c, Vector3 s, Color col)
|
||||
public void Box(Vector3 c, Vector3 s, Color col, Matrix? rot = null)
|
||||
{
|
||||
var h = s / 2;
|
||||
Vector3 P(float x, float y, float z) => c + new Vector3(x * h.X, y * h.Y, z * h.Z);
|
||||
var r = rot ?? Matrix.Identity;
|
||||
Vector3 P(float x, float y, float z) => c + Vector3.TransformNormal(new Vector3(x * h.X, y * h.Y, z * h.Z), r);
|
||||
Quad(P(-1, -1, 1), P(1, -1, 1), P(1, 1, 1), P(-1, 1, 1), col);
|
||||
Quad(P(1, -1, -1), P(-1, -1, -1), P(-1, 1, -1), P(1, 1, -1), col);
|
||||
Quad(P(-1, 1, -1), P(-1, 1, 1), P(1, 1, 1), P(1, 1, -1), col);
|
||||
@@ -772,6 +904,34 @@ namespace GladiatorIdle.Gfx
|
||||
}
|
||||
}
|
||||
|
||||
/// Runde, leicht gewölbte Scheibe (Rundschild), Vorder- und Rückseite.
|
||||
public void Disc(float r, float bend, Color col, float thick)
|
||||
{
|
||||
const int SEG = 28, RINGS = 4;
|
||||
var back = new Color(110, 78, 46);
|
||||
Vector3 S(float rad, float a, float off) => new(MathF.Cos(a) * rad, MathF.Sin(a) * rad, -bend * rad * rad + off);
|
||||
for (int side = 0; side < 2; side++)
|
||||
for (int k = 0; k < RINGS; k++)
|
||||
for (int i = 0; i < SEG; i++)
|
||||
{
|
||||
float r0 = r * k / RINGS, r1 = r * (k + 1) / RINGS, a0 = MathF.Tau * i / SEG, a1 = MathF.Tau * (i + 1) / SEG;
|
||||
float off = side == 0 ? 0 : -thick;
|
||||
Quad(S(r0, a0, off), S(r1, a0, off), S(r1, a1, off), S(r0, a1, off), side == 0 ? col : back);
|
||||
}
|
||||
}
|
||||
|
||||
/// Rand eines Rundschilds aus kurzen, gedrehten Stücken.
|
||||
public void Ring(float r, float bend, Color col)
|
||||
{
|
||||
const int SEG = 20;
|
||||
for (int i = 0; i < SEG; i++)
|
||||
{
|
||||
float a = MathF.Tau * (i + 0.5f) / SEG;
|
||||
var c = new Vector3(MathF.Cos(a) * r, MathF.Sin(a) * r, -bend * r * r + 0.6f);
|
||||
Box(c, new Vector3(3, MathF.Tau * r / SEG + 0.4f, 3), col, Matrix.CreateRotationZ(a));
|
||||
}
|
||||
}
|
||||
|
||||
public Prop Build(int bone, Matrix local)
|
||||
{
|
||||
var v = _v.ToArray();
|
||||
|
||||
84
Mono/Gfx/PostFx.cs
Normal file
84
Mono/Gfx/PostFx.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace GladiatorIdle.Gfx
|
||||
{
|
||||
/// <summary>
|
||||
/// Nachbearbeitung ohne eigene Shader: das Bild entsteht in einer Zwischenfläche (mit
|
||||
/// Kantenglättung/MSAA), danach Nachleuchten (Bloom) aus SpriteBatch und Mischmodi:
|
||||
/// verkleinern, dunkle Anteile abziehen (helle bleiben übrig), in drei Stufen weich
|
||||
/// verkleinern und additiv über das Bild legen.
|
||||
/// </summary>
|
||||
internal sealed class PostFx
|
||||
{
|
||||
RenderTarget2D? _scene, _a, _b, _c;
|
||||
int _msaa = -1;
|
||||
|
||||
// dunkle Anteile abziehen: Ziel = Ziel − Quelle
|
||||
static readonly BlendState Subtract = new()
|
||||
{
|
||||
ColorBlendFunction = BlendFunction.ReverseSubtract, ColorSourceBlend = Blend.One, ColorDestinationBlend = Blend.One,
|
||||
AlphaBlendFunction = BlendFunction.Add, AlphaSourceBlend = Blend.Zero, AlphaDestinationBlend = Blend.One,
|
||||
};
|
||||
|
||||
static RenderTarget2D Make(GraphicsDevice gd, int w, int h, int msaa, DepthFormat depth) =>
|
||||
new(gd, Math.Max(1, w), Math.Max(1, h), false, SurfaceFormat.Color, depth, msaa, RenderTargetUsage.PreserveContents);
|
||||
|
||||
/// Zeichnen in die Zwischenfläche beginnen (Größe wie der Bildschirm).
|
||||
public void Begin(GraphicsDevice gd, int w, int h, bool antiAlias)
|
||||
{
|
||||
int msaa = antiAlias ? 4 : 0;
|
||||
if (_scene == null || _scene.Width != w || _scene.Height != h || _msaa != msaa)
|
||||
{
|
||||
_scene?.Dispose(); _a?.Dispose(); _b?.Dispose(); _c?.Dispose();
|
||||
_scene = Make(gd, w, h, msaa, DepthFormat.Depth24Stencil8);
|
||||
_a = Make(gd, w / 4, h / 4, 0, DepthFormat.None);
|
||||
_b = Make(gd, w / 8, h / 8, 0, DepthFormat.None);
|
||||
_c = Make(gd, w / 16, h / 16, 0, DepthFormat.None);
|
||||
_msaa = msaa;
|
||||
}
|
||||
gd.SetRenderTarget(_scene);
|
||||
}
|
||||
|
||||
/// Fertiges Bild nach <paramref name="output"/> (null = Bildschirm), mit Nachleuchten der Stärke <paramref name="bloom"/>.
|
||||
public void End(GraphicsDevice gd, SpriteBatch sb, RenderTarget2D? output, float bloom, float threshold = 0.76f)
|
||||
{
|
||||
if (_scene == null) return;
|
||||
if (bloom > 0)
|
||||
{
|
||||
// ¼: verkleinern, dann Schwelle abziehen (nur Helles bleibt)
|
||||
Blit(gd, sb, _scene, _a!, BlendState.Opaque, Color.White);
|
||||
sb.Begin(SpriteSortMode.Immediate, Subtract);
|
||||
sb.Draw(Assets.Pixel, new Rectangle(0, 0, _a!.Width, _a.Height), new Color(threshold, threshold, threshold, 0f));
|
||||
sb.End();
|
||||
// ⅛ und 1/16: weiter verkleinern = weicher
|
||||
Blit(gd, sb, _a, _b!, BlendState.Opaque, Color.White);
|
||||
Blit(gd, sb, _b!, _c!, BlendState.Opaque, Color.White);
|
||||
}
|
||||
gd.SetRenderTarget(output);
|
||||
int w = output?.Width ?? gd.PresentationParameters.BackBufferWidth, h = output?.Height ?? gd.PresentationParameters.BackBufferHeight;
|
||||
sb.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp);
|
||||
sb.Draw(_scene, new Rectangle(0, 0, w, h), Color.White);
|
||||
sb.End();
|
||||
if (bloom > 0)
|
||||
{
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp);
|
||||
var full = new Rectangle(0, 0, w, h);
|
||||
sb.Draw(_a, full, Color.White * (0.30f * bloom));
|
||||
sb.Draw(_b, full, Color.White * (0.45f * bloom));
|
||||
sb.Draw(_c, full, Color.White * (0.60f * bloom));
|
||||
sb.End();
|
||||
}
|
||||
}
|
||||
|
||||
static void Blit(GraphicsDevice gd, SpriteBatch sb, Texture2D from, RenderTarget2D to, BlendState blend, Color c)
|
||||
{
|
||||
gd.SetRenderTarget(to);
|
||||
gd.Clear(Color.Black);
|
||||
sb.Begin(SpriteSortMode.Immediate, blend, SamplerState.LinearClamp);
|
||||
sb.Draw(from, new Rectangle(0, 0, to.Width, to.Height), c);
|
||||
sb.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,10 @@ namespace GladiatorIdle.Gfx
|
||||
D.Rect(sb, r, fill * 0.95f);
|
||||
D.Rect(sb, new RectangleF(r.X + 2, r.Y + 2, r.Width - 4, (r.Height - 4) * 0.45f), Color.White * (hover ? 0.08f : 0.04f));
|
||||
D.Frame(sb, r, !enabled ? new Color(60, 48, 36) : selected || hover ? a : D.Border, selected ? 3 : 2);
|
||||
D.Text(sb, Assets.SansBold, size, text, r.Center, !enabled ? D.Dim : selected ? Color.White : D.Sand, Align.Center);
|
||||
// Beschriftung passt sich an (längere Texte in anderen Sprachen): verkleinern bis sie in den Knopf passt
|
||||
float fit = size, room = r.Width - 18;
|
||||
while (fit > 11 && D.Measure(Assets.SansBold, fit, text).X > room) fit -= 1;
|
||||
D.Text(sb, Assets.SansBold, fit, text, r.Center, !enabled ? D.Dim : selected ? Color.White : D.Sand, Align.Center);
|
||||
return enabled && Hit(r);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user