Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Map: the Spitfires' light propeller blur, satin paint and the 101 plane's ground shadow; nearer shadow, flag off the cockpit (#2728)

Eyal Golan00e8fc59daa8
diff --git a/changelog.d/spitfire-prop-gloss-shadow.md b/changelog.d/spitfire-prop-gloss-shadow.md
new file mode 100644
index 000000000..e283916d2
--- /dev/null
+++ b/changelog.d/spitfire-prop-gloss-shadow.md
@@ -0,0 +1,5 @@
+### Changed
+
+- The Spitfires look more like they are flying: each turning propeller is a light blur, their paint has a satin sheen, and
+ the 101 Squadron Spitfire now casts a soft shadow on the ground. The Egyptian Spitfire's shadow now lies near it (it was
+ about 7 km away), and its flag no longer covers the cockpit in a turn.
diff --git a/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs
index 4ecd8b9ab..4cc50dba3 100644
--- a/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs
+++ b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs
@@ -511,7 +511,9 @@ namespace Statecraft.Game.Map.Collection
var centre = new Vector3(at.x, Statecraft.Game.Map.Units.UnitShowcase.LoopFloor(map!, new Vector3(at.x, 0f, at.y), SpitfireLoopHalfLengthM + size)
+ Statecraft.Game.Map.Units.UnitShowcase.AltitudeM, at.y);
go.transform.position = centre; b = Bounds(go);
- foreach (var r in go.GetComponentsInChildren<Renderer>(true)) r.shadowCastingMode = ShadowCastingMode.On;
+ // The soft disc (Shadow) is its shadow: a cast one would lie about 7.7 km off at the drawn height, a second shadow
+ // (e21's AFTER captures of #2728, 5 November 2026).
+ foreach (var r in go.GetComponentsInChildren<Renderer>(true)) { r.shadowCastingMode = ShadowCastingMode.Off; Gloss(r); }
// The shadow and the flag stand beside the aircraft in this layer, so they neither bank nor turn with it, and go
// with it (its model's originals) when its dates end.
var marks = new GameObject(go.name + SpitfireMarksSuffix);
@@ -521,7 +523,7 @@ namespace Statecraft.Game.Map.Collection
var flag = Flag(marks.transform);
// The aircraft's half box at level, nose east: half its length, its height and its span.
var half = 0.5f * new Vector3(b.size.x, b.size.y, b.size.z);
- loop.Attach(Propeller(go), Shadow(marks.transform), flag, map!.Terrain, 0.5f * ShadowShare * new Vector2(size, b.size.x), half, ground.SeaLevelY);
+ loop.Attach(Propeller(go), Shadow(marks.transform, spitfire: true), flag, map!.Terrain, 0.5f * ShadowShare * new Vector2(size, b.size.x), half, ground.SeaLevelY);
// Edit mode and screenshots hold the loop's start, as the train does (RouteLayer.ModeFor).
loop.Configure(centre, level, b.center - go.transform.position, !Application.isPlaying || VisualShots.Requested());
var cam = Camera.main;
@@ -558,20 +560,39 @@ namespace Statecraft.Game.Map.Collection
disc.transform.SetParent(airframe.transform, false);
disc.transform.localPosition = new Vector3(mesh.center.x, mesh.min.y + PropBehindNoseShare * mesh.size.y, mesh.max.z - radius);
disc.transform.localScale = Vector3.one * radius;
- disc.AddComponent<MeshFilter>().sharedMesh = propMesh != null ? propMesh : propMesh = Own(PropellerDisc());
+ disc.AddComponent<MeshFilter>().sharedMesh = spitfirePropMesh != null ? spitfirePropMesh : spitfirePropMesh = Own(SpitfirePropellerDisc());
var r = disc.AddComponent<MeshRenderer>();
r.sharedMaterial = Blur(); r.shadowCastingMode = ShadowCastingMode.Off; r.receiveShadows = false;
r.localBounds = new Bounds(Vector3.zero, new Vector3(Mathf.Sqrt(2f), 2f * PropLayer, Mathf.Sqrt(2f)));
return disc.transform;
}
+ /// <summary>Gives the Spitfire's renderer <paramref name="r"/> glossy copies of its materials (the streamed model's are
+ /// fully matte): the same shader, maps and colours, with <see cref="Statecraft.Game.Map.Units.UnitShowcase.AircraftSmoothness"/>.
+ /// One copy a source material for this layer, owned by it, so a redraw makes none. A copy whose source is gone (its
+ /// model released under residency, then streamed again as a new material) is destroyed, so they do not pile up.</summary>
+ void Gloss(Renderer r)
+ {
+ foreach (var dead in glossy.Keys.Where(k => k == null).ToList()) { DestroyNow(glossy[dead]); glossy.Remove(dead); }
+ var mats = r.sharedMaterials;
+ for (int i = 0; i < mats.Length; i++)
+ {
+ var m = mats[i];
+ if (m == null || !m.HasProperty(Statecraft.Game.Map.Units.UnitShowcase.SmoothnessProperty)) continue;
+ if (!glossy.TryGetValue(m, out var g)) glossy[m] = g = Own(Statecraft.Game.Map.Units.UnitShowcase.Glossy(m));
+ mats[i] = g;
+ }
+ r.sharedMaterials = mats;
+ }
+
/// <summary>The aircraft's soft shadow on the ground (owner's report: "it doesnt look fliying"), placed by SpitfireLoop
/// where the map's sun casts it.</summary>
- Transform Shadow(Transform parent)
+ Transform Shadow(Transform parent, bool spitfire = false)
{
var go = new GameObject(SpitfireShadowName);
go.transform.SetParent(parent, false);
- go.AddComponent<MeshFilter>().sharedMesh = shadowMesh != null ? shadowMesh : shadowMesh = Own(ShadowDisc());
+ go.AddComponent<MeshFilter>().sharedMesh = spitfire ? spitfireShadowMesh != null ? spitfireShadowMesh : spitfireShadowMesh = Own(SpitfireShadowDisc())
+ : shadowMesh != null ? shadowMesh : shadowMesh = Own(ShadowDisc());
var r = go.AddComponent<MeshRenderer>();
r.sharedMaterial = Blur(); r.shadowCastingMode = ShadowCastingMode.Off; r.receiveShadows = false;
return go.transform;
@@ -646,10 +667,12 @@ namespace Statecraft.Game.Map.Collection
}
static void DestroyMesh(Mesh m) { if (Application.isPlaying) Destroy(m); else DestroyImmediate(m); }
+ static void DestroyNow(UnityEngine.Object o) { if (Application.isPlaying) Destroy(o); else DestroyImmediate(o); }
MapRuntimeAssets? assets;
bool flagMissing;
- Material? blur; Material[]? flagCloth; Mesh? propMesh, shadowMesh, flagMesh;
+ Material? blur; Material[]? flagCloth; Mesh? propMesh, spitfirePropMesh, shadowMesh, spitfireShadowMesh, flagMesh;
+ readonly Dictionary<Material, Material> glossy = new Dictionary<Material, Material>();
/// <summary>Takes <paramref name="o"/>, made once for this layer, to be destroyed with it.</summary>
T Own<T>(T o) where T : UnityEngine.Object
@@ -665,7 +688,7 @@ namespace Statecraft.Game.Map.Collection
/// <summary>A flat disc of radius 1 in the XZ plane (normal +y), one copy at each of <paramref name="layers"/> (its y): a
/// centre and rings of <paramref name="segments"/> vertices at <paramref name="rings"/>, coloured <paramref name="colour"/>
/// with the alpha <paramref name="alpha"/> gives at (radius, angle in degrees from +x towards +z).</summary>
- static Mesh Disc(string name, int segments, float[] rings, float[] layers, Color colour, Func<float, float, float> alpha)
+ internal static Mesh Disc(string name, int segments, float[] rings, float[] layers, Color colour, Func<float, float, float> alpha)
{
int per = 1 + segments * rings.Length, perTris = 3 * segments + 6 * segments * (rings.Length - 1);
var verts = new Vector3[per * layers.Length]; var colours = new Color32[verts.Length]; var tris = new int[perTris * layers.Length];
@@ -695,17 +718,41 @@ namespace Statecraft.Game.Map.Collection
return Statecraft.Game.Map.Units.UnitPlinth.Upload(mesh);
}
- /// <summary>DESIGN VALUES: the propeller's blur, near-black (the units' propeller paint): three blades, each a dark
- /// leading edge whose smear fades behind it (the way SpitfireLoop turns it), over a half-opaque whole disc that dims
- /// the fused model's still blades, clear at the spinner and fading out at the rim; two layers (<see cref="PropLayer"/>).</summary>
+ /// <summary>DESIGN VALUES: the Dakotas' propeller blur, near-black (the units' propeller paint): three blades, each a dark
+ /// leading edge whose smear fades behind it (the way the loop turns it), over a half-opaque whole disc, clear at the
+ /// spinner and fading out at the rim; two layers (<see cref="PropLayer"/>).</summary>
static Mesh PropellerDisc() => Disc("SpitfirePropellerBlur", 72, new[] { 0.18f, 0.4f, 0.7f, 0.9f, 1f }, new[] { -PropLayer, PropLayer }, new Color(0.06f, 0.06f, 0.06f), (r, deg) =>
r >= 1f ? 0f : Mathf.Min(1f, r / 0.4f) * (0.45f + 0.45f * Mathf.Exp(-Mathf.Repeat(-deg, 120f) / 35f)));
- /// <summary>DESIGN VALUES: the shadow, a dark warm grey (the map's shadows are warm under its sun), 0.42 opaque at its
+ /// <summary>DESIGN VALUES (agent-chosen, coordinator-approved plan, 5 November 2026; checked in captures): the Spitfire's
+ /// propeller blur, light (a turning propeller reads as a pale haze against the ground): three blades, each a brighter
+ /// streak whose smear fades behind it (the way SpitfireLoop turns it), over a faint whole disc that softens the fused
+ /// model's still blades, clear at the spinner and fading out at the rim; two layers (<see cref="PropLayer"/>).</summary>
+ static Mesh SpitfirePropellerDisc() => Disc("SpitfirePropellerBlur", 72, new[] { 0.18f, 0.4f, 0.7f, 0.9f, 1f }, new[] { -PropLayer, PropLayer }, PropBlurColour,
+ (r, deg) => r >= 1f ? 0f : Mathf.Min(1f, r / 0.4f) * PropBlurAlpha(deg, 120f, 0f));
+
+ /// <summary>DESIGN VALUE: the light propeller blurs' colour, a pale warm grey (the Spitfire's and the 101 Squadron
+ /// aircraft's, UnitShowcase.PropellerBlur).</summary>
+ internal static readonly Color PropBlurColour = new Color(0.82f, 0.81f, 0.78f);
+
+ /// <summary>DESIGN VALUES: a light blur's opacity at <paramref name="deg"/> round the disc for blades every
+ /// <paramref name="spacing"/> degrees whose leading edges are at <paramref name="edge"/>: a faint 0.22 everywhere and up
+ /// to 0.55 at a blade, fading behind it (the disc's angle grows as both loops turn their propellers).</summary>
+ internal static float PropBlurAlpha(float deg, float spacing, float edge) =>
+ 0.22f + 0.33f * Mathf.Exp(-Mathf.Repeat(edge - deg, spacing) / (0.25f * spacing));
+
+ /// <summary>DESIGN VALUES: the Dakotas' shadow, a dark warm grey (the map's shadows are warm under its sun), 0.42 opaque at its
/// middle and fading to nothing at its rim, (1 - r²)^1.5.</summary>
- static Mesh ShadowDisc() => Disc("SpitfireShadow", 48, new[] { 0.3f, 0.55f, 0.75f, 0.9f, 1f }, new[] { 0f }, new Color(0.10f, 0.08f, 0.06f), (r, _) =>
+ internal static Mesh ShadowDisc() => Disc("DakotaShadow", 48, new[] { 0.3f, 0.55f, 0.75f, 0.9f, 1f }, new[] { 0f }, new Color(0.10f, 0.08f, 0.06f), (r, _) =>
0.42f * Mathf.Pow(1f - r * r, 1.5f));
+ /// <summary>DESIGN VALUES (agent-chosen, from e21's AFTER captures of #2728, 5 November 2026: the near disc at 0.42 was
+ /// too faint over sand and sea, and 0.6 over the brown hills in v2): the Spitfires' shadow, as <see cref="ShadowDisc"/>
+ /// (the Dakotas', unchanged) but 0.75 opaque at its middle, still fading to nothing at its rim; it is now their only
+ /// shadow (they cast none, Fly).</summary>
+ internal static Mesh SpitfireShadowDisc() => Disc("SpitfireShadow", 48, new[] { 0.3f, 0.55f, 0.75f, 0.9f, 1f }, new[] { 0f }, new Color(0.10f, 0.08f, 0.06f), (r, _) =>
+ 0.75f * Mathf.Pow(1f - r * r, 1.5f));
+
/// <summary>The ground the other 1948 Collection layers hold (GameRoot shows them first), for the C-54 to keep off, as
/// SpecialBuildingModels keeps off the people and the wildlife: the civilians (#666), the wildlife (#670), the farm
/// scenes drawn (#667) and the fort, barracks and factory drawn (#707). Show compares it, so the plane moves when they
diff --git a/unity/Assets/Scripts/Map/Collection/SpitfireLoop.cs b/unity/Assets/Scripts/Map/Collection/SpitfireLoop.cs
index a4ffee398..8ce2890d8 100644
--- a/unity/Assets/Scripts/Map/Collection/SpitfireLoop.cs
+++ b/unity/Assets/Scripts/Map/Collection/SpitfireLoop.cs
@@ -46,8 +46,24 @@ namespace Statecraft.Game.Map.Collection
Vector3 centre, offset; Quaternion level; bool still;
Transform? prop, shadow, flag; Terrain? ground; Vector2 shadowHalf; Vector3 half; float flagHalf, seaY;
- /// <summary>DESIGN VALUE: the gap (m) between the aircraft's box top and the flag's lower edge.</summary>
- public const float FlagClearM = 150f;
+ /// <summary>DESIGN VALUE: the gap (m) between the top of the aircraft's tail and the flag's lower edge. 150 m left it
+ /// floating detached above the tail in the end turns (e21's captures of #2728, v2, 5 November 2026).</summary>
+ public const float FlagClearM = 60f;
+
+ /// <summary>MEASURED from Tal's model (its FBX's vertices, 5 November 2026), for how high the banked tail reaches
+ /// (<see cref="TailTopOver"/>). The model sits in its ground attitude, tail down, so its box's top is the propeller's tip
+ /// and its bottom the tail wheel. The fin's top stands only 0.19 of the box's half height over the box's centre (0.20,
+ /// with a margin). The tailplane reaches 0.273 of the half span out (0.28), its tips 0.414 of the half height under the
+ /// centre (0.41). With these the estimate meets the measured tail top within 0.003 of the half height at every bank to
+ /// 35 degrees. Taking the whole half height for the fin (as before) put the flag about 600 m too high.</summary>
+ public const float TailFinShare = 0.20f, TailplaneReachShare = 0.28f, TailplaneDropShare = 0.41f;
+
+ /// <summary>DESIGN VALUE (agent-chosen, coordinator-agreed, 5 November 2026; checked in captures): the shadow is cast as
+ /// if the aircraft flew at this share of its drawn height over the ground under it. The aircraft is drawn 420 times life
+ /// size (UnitShowcase.AircraftScale) at UnitShowcase.AltitudeM, so the true ray lays its shadow about 7 km away at
+ /// MapLighting's 30 degree sun, too far to read as its shadow; at a quarter it lies about 1.8 km away (half an airframe's length), on
+ /// the same sun's line. The Spitfires use it; the Dakotas' shadows keep the full height (1, the default).</summary>
+ public const float ShadowHeightShare = 0.25f;
/// <summary>How far the top of the aircraft's box stands over its centre at <paramref name="bankDegrees"/>: its half box
/// <paramref name="half"/> (half its length, height and span) rolled about its length.</summary>
@@ -57,6 +73,16 @@ namespace Statecraft.Game.Map.Collection
return half.z * Mathf.Abs(Mathf.Sin(b)) + half.y * Mathf.Cos(b);
}
+ /// <summary>How far the top of the aircraft's tail stands over its centre at <paramref name="bankDegrees"/>, rolled about
+ /// its length: the higher of the fin's top (<see cref="TailFinShare"/> of the half height) and the raised tailplane tip
+ /// (<see cref="TailplaneReachShare"/> of the half span out, <see cref="TailplaneDropShare"/> of the half height under the
+ /// centre). Far lower than <see cref="TopOver"/>, whose raised wingtip is nowhere near the tail.</summary>
+ public static float TailTopOver(Vector3 half, float bankDegrees)
+ {
+ float b = bankDegrees * Mathf.Deg2Rad, cos = Mathf.Cos(b), sin = Mathf.Abs(Mathf.Sin(b));
+ return Mathf.Max(TailFinShare * half.y * cos, TailplaneReachShare * half.z * sin - TailplaneDropShare * half.y * cos);
+ }
+
/// <summary>The animation clock, Time.time. Test seam (internal; the tests see it through InternalsVisibleTo): an
/// EditMode test has no frame clock.</summary>
internal static Func<float> Clock = () => Time.time;
@@ -106,10 +132,11 @@ namespace Statecraft.Game.Map.Collection
transform.position = drawn - turn * offset;
// The angle in double: a float product with the clock loses whole degrees after hours (review of #2260).
if (prop != null) prop.localRotation = Quaternion.AngleAxis(-(float)((double)seconds * PropDegreesPerSecond % 360.0), Vector3.up);
- // The flag over the tail, its lower edge FlagClearM over the top of the aircraft's box at this bank: clear of the
- // airframe at every bank and heading.
- if (flag != null) flag.position = drawn - forward * half.x + Vector3.up * (TopOver(half, bank) + FlagClearM + flagHalf * flag.lossyScale.y);
- if (shadow != null && ground != null) LayShadow(shadow, ground, seaY, shadowHalf, drawn, forward, bank);
+ // The flag over the tail, its lower edge FlagClearM over the top of the tail at this bank: clear of it at every bank
+ // and heading. Not over the box's top: in a bank that is the raised wingtip, and a flag that high was drawn over the
+ // cockpit from the map's camera (e21's captures, 5 November 2026).
+ if (flag != null) flag.position = drawn - forward * half.x + Vector3.up * (TailTopOver(half, bank) + FlagClearM + flagHalf * flag.lossyScale.y);
+ if (shadow != null && ground != null) LayShadow(shadow, ground, seaY, shadowHalf, drawn, forward, bank, heightShare: ShadowHeightShare);
}
/// <summary>Lays <paramref name="shadow"/> (half <paramref name="shadowHalf"/> across and along the heading) for an
@@ -129,10 +156,17 @@ namespace Statecraft.Game.Map.Collection
/// where the ray falls to the lowest surface there can be (the sea's, or the terrain's base), so the ground is crossed
/// between them whatever its slope or the sun's height; a march in <see cref="ShadowMarchM"/> steps finds the first
/// crossing, and each halving halves that step, to under
- /// <see cref="ShadowConvergeM"/> along the ray, at most <see cref="ShadowConvergeSteps"/> halvings.</summary>
+ /// <see cref="ShadowConvergeM"/> along the ray, at most <see cref="ShadowConvergeSteps"/> halvings. With
+ /// <paramref name="heightShare"/> under 1 the ray starts lower, at that share of the aircraft's height over the surface
+ /// under it (<see cref="ShadowHeightShare"/>), so the shadow lies nearer on the same line.</summary>
internal static void LayShadow(Transform shadow, Terrain ground, float seaY, Vector2 shadowHalf, Vector3 drawn, Vector3 forward, float bank,
- bool converge = false)
+ bool converge = false, float heightShare = 1f)
{
+ if (heightShare < 1f)
+ {
+ float under = Surface(ground, seaY, drawn);
+ drawn.y = under + heightShare * (drawn.y - under);
+ }
var ray = SunNow();
var hit = drawn;
float floor;
diff --git a/unity/Assets/Scripts/Map/Units/ShowcaseFlight.cs b/unity/Assets/Scripts/Map/Units/ShowcaseFlight.cs
index 3340de393..fe8ab78b3 100644
--- a/unity/Assets/Scripts/Map/Units/ShowcaseFlight.cs
+++ b/unity/Assets/Scripts/Map/Units/ShowcaseFlight.cs
@@ -3,26 +3,37 @@ using UnityEngine;
namespace Statecraft.Game.Map.Units
{
- /// <summary>Flies its object round a horizontal circle, banked into the turn, nose along the path; turns the propeller.
- /// With a still phase it holds that point (and the propeller its angle), so screenshots repeat exactly.</summary>
+ /// <summary>Flies its object round a horizontal circle, banked into the turn, nose along the path; turns the propeller;
+ /// lays its soft shadow on the ground, when it has one, as the Egyptian Spitfire's (SpitfireLoop.LayShadow, from
+ /// SpitfireLoop.ShadowHeightShare of its height). With a still phase it holds that point (and the propeller its angle), so
+ /// screenshots repeat exactly.</summary>
public sealed class ShowcaseFlight : MonoBehaviour
{
Vector3 centre; float radius, altitude, seconds, bank; Transform? propeller; float? still;
+ Transform? shadow; Terrain? ground; float seaY; Vector2 shadowHalf;
- public void Configure(Vector3 centre, float radius, float altitude, float seconds, float bank, Transform? propeller, float? stillPhase)
+ /// <summary><paramref name="shadow"/>, a child of this object, is laid on <paramref name="ground"/> or the sea's surface
+ /// <paramref name="seaY"/>, <paramref name="shadowHalf"/> across and along the heading (m), when both are given.</summary>
+ public void Configure(Vector3 centre, float radius, float altitude, float seconds, float bank, Transform? propeller, float? stillPhase,
+ Transform? shadow = null, Terrain? ground = null, float seaY = float.NegativeInfinity, Vector2 shadowHalf = default)
{
this.centre = centre; this.radius = radius; this.altitude = altitude; this.seconds = seconds; this.bank = bank;
this.propeller = propeller; still = stillPhase;
+ this.shadow = shadow; this.ground = ground; this.seaY = seaY; this.shadowHalf = shadowHalf;
Place(still ?? 0f);
}
public float? StillPhase => still;
+ /// <summary>The animation clock, Time.time. Test seam, as SpitfireLoop.Clock: an EditMode test has no frame clock.</summary>
+ internal static System.Func<float> Clock = () => Time.time;
+
void Update()
{
if (still.HasValue) return;
- Place(Time.time / seconds % 1f);
- if (propeller != null) propeller.localRotation = Quaternion.Euler(0, 0, -Mathf.Repeat(Time.time * 1500f, 360f));
+ float now = Clock();
+ Place(now / seconds % 1f);
+ if (propeller != null) propeller.localRotation = Quaternion.Euler(0, 0, -Mathf.Repeat(now * 1500f, 360f));
}
/// <summary>Puts the aircraft at phase <paramref name="t"/> (0..1) of the loop, flying anticlockwise seen from above.</summary>
@@ -32,6 +43,14 @@ namespace Statecraft.Game.Map.Units
var pos = centre + new Vector3(Mathf.Cos(a), 0, Mathf.Sin(a)) * radius; pos.y = altitude;
var forward = new Vector3(-Mathf.Sin(a), 0, Mathf.Cos(a));
transform.SetPositionAndRotation(pos, Quaternion.LookRotation(forward, Vector3.up) * Quaternion.Euler(0, 0, bank));
+ if (shadow != null && ground != null)
+ {
+ // Converging: the 101 Squadron's coast rises inland (SpitfireLoop.LayShadow). The shadow is this object's child,
+ // and this object's scale is uniform, so its world size is LayShadow's over that scale.
+ Collection.SpitfireLoop.LayShadow(shadow, ground, seaY, shadowHalf, pos, forward, bank, converge: true,
+ heightShare: Collection.SpitfireLoop.ShadowHeightShare);
+ shadow.localScale /= transform.lossyScale.x;
+ }
}
}
}
diff --git a/unity/Assets/Scripts/Map/Units/UnitLayer.cs b/unity/Assets/Scripts/Map/Units/UnitLayer.cs
index 1f09d2310..8a7d1c9e9 100644
--- a/unity/Assets/Scripts/Map/Units/UnitLayer.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitLayer.cs
@@ -639,6 +639,15 @@ namespace Statecraft.Game.Map.Units
static Func<double, double, Vector2> XZ(MapScene map) => (lon, lat) => { var w = map.Frame.ToWorld(lon, lat, 0); return new Vector2(w.x, w.z); };
+ Material? aircraftPaint, aircraftBlur;
+ Mesh? aircraftBlurMesh, aircraftShadowMesh;
+
+ /// <summary>The code-built Spitfire's glossy copy of the units' paint (UnitShowcase.Glossy), one for the layer.</summary>
+ Material AircraftPaint() => aircraftPaint ??= assets.Own(UnitShowcase.Glossy(paint));
+
+ /// <summary>The Spitfire's blur and shadow material (UnitShowcase.BlurMaterial), one for the layer.</summary>
+ Material AircraftBlur() => aircraftBlur ??= assets.Own(UnitShowcase.BlurMaterial());
+
Mesh MeshFor(string key, Func<Mesh> build)
{
if (!meshes.TryGetValue(key, out var mesh))
@@ -983,21 +992,33 @@ namespace Statecraft.Game.Map.Units
bool spitfire = t.ArtType == UnitShowcase.SpitfireType;
Func<Mesh> airframe = spitfire ? (Func<Mesh>)(() => UnitModels.Spitfire(t.ArtType))
: () => UnitModels.AviaS199(t.ArtType);
- UnitShowcase.Piece(plane.transform, "Airframe", t.ArtType, () => MeshFor(t.ArtType, airframe), paint, Vector3.zero, Quaternion.identity, 1f, out bool authored);
- Transform? prop = null;
+ // The code-built Spitfire's satin paint (UnitShowcase.AircraftSmoothness); the S-199 keeps the units' paint.
+ var mat = spitfire ? AircraftPaint() : paint;
+ var airframeGo = UnitShowcase.Piece(plane.transform, "Airframe", t.ArtType, () => MeshFor(t.ArtType, airframe), mat, Vector3.zero, Quaternion.identity, 1f, out bool authored);
+ Transform? prop = null, shadow = null;
+ Vector2 shadowHalf = default;
if (!authored)
{
var propKey = spitfire ? "spitfire-propeller" : "avia-s199-propeller";
var propMesh = MeshFor(propKey, spitfire ? (Func<Mesh>)(() => UnitModels.SpitfirePropeller(propKey)) : () => UnitModels.S199Propeller(propKey));
- prop = UnitShowcase.Piece(plane.transform, "Propeller", propMesh, paint, Vector3.zero, Quaternion.identity, 1f).transform;
+ prop = UnitShowcase.Piece(plane.transform, "Propeller", propMesh, mat, Vector3.zero, Quaternion.identity, 1f).transform;
prop.localPosition = spitfire ? UnitModels.SpitfirePropellerHub : UnitModels.S199PropellerHub;
}
+ // A flying Spitfire's light propeller blur, soft ground shadow and no cast shadow, whichever model draws it (an
+ // authored one brings its own propeller, UnitShowcase.AuthoredPropellerName).
+ if (spitfire && t.Flying)
+ {
+ prop = UnitShowcase.FlyingSpitfire(plane.transform, airframeGo, prop, aircraftBlurMesh ??= assets.Own(UnitShowcase.PropellerBlurMesh()), AircraftBlur(),
+ aircraftShadowMesh ??= assets.Own(Collection.SeaAirCollection.SpitfireShadowDisc()), out var laid, out shadowHalf);
+ shadow = laid;
+ }
plane.transform.localScale = Vector3.one * UnitShowcase.AircraftScale;
if (t.Flying)
{
var flight = plane.AddComponent<ShowcaseFlight>();
flight.Configure(baseCentre, UnitShowcase.LoopRadiusM, UnitShowcase.LoopFloor(map, baseCentre, UnitShowcase.LoopRadiusM) + UnitShowcase.AltitudeM,
- UnitShowcase.LoopSeconds, UnitShowcase.BankDegrees, prop, still ? UnitShowcase.StillPhase : (float?)null);
+ UnitShowcase.LoopSeconds, UnitShowcase.BankDegrees, prop, still ? UnitShowcase.StillPhase : (float?)null,
+ shadow, map.Terrain, UnitShowcase.SeaLevelY(map), shadowHalf);
}
else
plane.transform.SetPositionAndRotation(baseCentre + Vector3.up * ParkedHeightM * UnitShowcase.AircraftScale,
diff --git a/unity/Assets/Scripts/Map/Units/UnitShowcase.cs b/unity/Assets/Scripts/Map/Units/UnitShowcase.cs
index 248a46f79..94b169293 100644
--- a/unity/Assets/Scripts/Map/Units/UnitShowcase.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitShowcase.cs
@@ -31,6 +31,142 @@ namespace Statecraft.Game.Map.Units
/// <summary>A figure's height over <see cref="ReferenceHouseM"/>: about 1.8, as T29.</summary>
public const float HouseRatio = UnitBadge.FigureHeightM * FigureScale / ReferenceHouseM;
public const float AircraftScale = 420f; // span 11.2 m x 420 = 4.7 km: wider than a man is tall
+
+ /// <summary>DESIGN VALUE (agent-chosen, coordinator-approved plan, 5 November 2026; checked in captures): the aircraft's
+ /// paint smoothness (URP Lit), a satin sheen in the map's sun. The Egyptian Spitfire's streamed model is fully matte
+ /// (0) and the units' shared paint 0.18; only the code-built 101 Squadron Spitfire and the Egyptian one take it. 0.4 read
+ /// as still mostly matte at 31 km in e21's AFTER captures (5 November 2026).</summary>
+ public const float AircraftSmoothness = 0.5f;
+
+ /// <summary>The URP Lit smoothness property.</summary>
+ internal const string SmoothnessProperty = "_Smoothness";
+
+ /// <summary>DESIGN VALUE: the 101 Squadron Spitfire's propeller blur radius in the aircraft's frame: the blades' reach
+ /// (UnitModels.SpitfirePropeller, 1.6) and a little more.</summary>
+ public const float PropellerBlurRadius = 1.65f;
+
+ /// <summary>DESIGN VALUE: the 101 Squadron Spitfire's haze over the Egyptian one's opacity, in one layer: at the same
+ /// opacity in two layers it read as a near-opaque white plate under its dark rods (e21's AFTER captures of #2728).</summary>
+ public const float PropellerBlurOpacity = 0.65f;
+
+ /// <summary>The names of the 101 Squadron Spitfire's propeller blur (a child of its propeller) and ground shadow (a child
+ /// of the aircraft), and of an authored model's propeller (a child of its prefab's root, turned by ShowcaseFlight).</summary>
+ public const string PropellerBlurName = "PropellerBlur", ShadowName = "Shadow", AuthoredPropellerName = "Propeller";
+
+ /// <summary>A copy of <paramref name="source"/> (same shader, maps and colours) with <see cref="AircraftSmoothness"/>.
+ /// The caller owns it.</summary>
+ internal static Material Glossy(Material source)
+ {
+ var m = new Material(source) { name = source.name + " (glossy)" };
+ m.SetFloat(SmoothnessProperty, AircraftSmoothness);
+ return m;
+ }
+
+ /// <summary>The blurs' and the shadow's material: alpha-blended, unlit, both faces, its colour the meshes' vertex colours
+ /// (HexMaterials' shipped under-attack border template, so a player build keeps the shader's variant), as the Egyptian
+ /// Spitfire's (SeaAirCollection). The caller owns it.</summary>
+ internal static Material BlurMaterial() => Statecraft.HexTiles.HexMaterials.New(Statecraft.HexTiles.HexMaterials.AttackBorder);
+
+ /// <summary>DESIGN VALUES: the 101 Squadron Spitfire's propeller blur, the Egyptian Spitfire's light haze
+ /// (SeaAirCollection.PropBlurColour, PropBlurAlpha) for its four blades (UnitModels.SpitfirePropeller: every 90 degrees
+ /// from 20, which this disc, turned to face along +z, sees at 70 degrees and every 90 after), clear at the spinner,
+ /// fading out at the rim, one layer through the blades' hub, at <see cref="PropellerBlurOpacity"/>. Uploaded; the caller owns it.</summary>
+ internal static Mesh PropellerBlurMesh() => Collection.SeaAirCollection.Disc("SpitfirePropellerBlur101", 48, new[] { 0.15f, 0.4f, 0.7f, 0.9f, 1f },
+ new[] { 0f }, Collection.SeaAirCollection.PropBlurColour,
+ (r, deg) => r >= 1f ? 0f : PropellerBlurOpacity * Mathf.Min(1f, r / 0.4f) * Collection.SeaAirCollection.PropBlurAlpha(deg, 90f, 70f));
+
+ /// <summary>Puts the light blur <paramref name="mesh"/> on the propeller <paramref name="prop"/> (it turns about +z), so it
+ /// turns with it: the disc (made in XZ) turned to face along +z, <paramref name="radius"/> across.</summary>
+ internal static Transform PropellerBlur(Transform prop, Mesh mesh, Material blur, float radius = PropellerBlurRadius)
+ {
+ var go = new GameObject(PropellerBlurName);
+ go.transform.SetParent(prop, false);
+ go.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
+ go.transform.localScale = Vector3.one * radius;
+ go.AddComponent<MeshFilter>().sharedMesh = mesh;
+ var r = go.AddComponent<MeshRenderer>();
+ r.sharedMaterial = blur; r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; r.receiveShadows = false;
+ return go.transform;
+ }
+
+ /// <summary>The flying 101 Squadron Spitfire's soft ground shadow (the Egyptian Spitfire's disc, SeaAirCollection.ShadowDisc),
+ /// a child of <paramref name="plane"/> that ShowcaseFlight lays on the ground each frame, so it goes with the aircraft.</summary>
+ internal static Transform GroundShadow(Transform plane, Mesh mesh, Material blur)
+ {
+ var go = new GameObject(ShadowName);
+ go.transform.SetParent(plane, false);
+ go.AddComponent<MeshFilter>().sharedMesh = mesh;
+ var r = go.AddComponent<MeshRenderer>();
+ r.sharedMaterial = blur; r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; r.receiveShadows = false;
+ return go.transform;
+ }
+
+ /// <summary>A flying Spitfire's look, whichever model draws it (the code-built one, or an authored model in
+ /// <see cref="AuthoredFolder"/>, coordinator, 5 November 2026): its propeller (<paramref name="codeProp"/>, or the authored
+ /// prefab's child named <see cref="AuthoredPropellerName"/>) carries the light blur, sized to the propeller's own mesh;
+ /// a soft shadow, sized to the airframe as drawn, lies on the ground (ShowcaseFlight lays it); and the aircraft casts
+ /// no shadow of its own (<see cref="CastNoShadow"/>). Returns the propeller for ShowcaseFlight to turn (null when
+ /// there is none) and the shadow and its half size across and along the heading (m). Call before the aircraft is
+ /// placed or turned: the size is measured in its own frame.</summary>
+ internal static Transform? FlyingSpitfire(Transform plane, GameObject airframe, Transform? codeProp, Mesh blurMesh, Material blur,
+ Mesh shadowMesh, out Transform shadow, out Vector2 shadowHalf)
+ {
+ var size = SizeInFrame(plane); // before the blur and the shadow are added
+ shadowHalf = 0.5f * Collection.SeaAirCollection.ShadowShare * AircraftScale * new Vector2(size.x, size.z);
+ var prop = codeProp != null ? codeProp : airframe.transform.Find(AuthoredPropellerName);
+ if (prop != null)
+ {
+ // The code-built blades reach 1.6 (UnitModels.SpitfirePropeller); the blur reaches a little beyond any blades.
+ float reach = codeProp != null ? 1.6f : PropellerReach(prop);
+ PropellerBlur(prop, blurMesh, blur, reach > 0f ? reach * PropellerBlurRadius / 1.6f : PropellerBlurRadius);
+ }
+ shadow = GroundShadow(plane, shadowMesh, blur);
+ CastNoShadow(plane);
+ return prop;
+ }
+
+ /// <summary>The meshes under <paramref name="plane"/> measured in its own frame, in the model's units (metres for a
+ /// model to scale: the frame's own scale is taken out), so a code-built and an authored airframe size their shadow alike.</summary>
+ static Vector3 SizeInFrame(Transform plane)
+ {
+ Bounds? box = null;
+ foreach (var p in Corners(plane, plane))
+ if (box is Bounds b) { b.Encapsulate(p); box = b; } else box = new Bounds(p, Vector3.zero);
+ return box?.size ?? Vector3.zero;
+ }
+
+ /// <summary>How far an authored propeller's blades reach from its hub in its turning plane (its local X and Y), in its
+ /// own units: the largest of its meshes' extents along either axis (a bounding box's corner would overstate a
+ /// blade by up to the square root of 2). 0 when it has no mesh.</summary>
+ static float PropellerReach(Transform prop)
+ {
+ float reach = 0f;
+ foreach (var p in Corners(prop, prop)) reach = Mathf.Max(reach, Mathf.Abs(p.x), Mathf.Abs(p.y));
+ return reach;
+ }
+
+ /// <summary>The corners of every mesh's bounds under <paramref name="root"/>, in <paramref name="frame"/>'s local space.</summary>
+ static IEnumerable<Vector3> Corners(Transform root, Transform frame)
+ {
+ foreach (var f in root.GetComponentsInChildren<MeshFilter>(true))
+ {
+ if (f.sharedMesh == null) continue;
+ var m = frame.worldToLocalMatrix * f.transform.localToWorldMatrix;
+ var b = f.sharedMesh.bounds;
+ for (int c = 0; c < 8; c++)
+ yield return m.MultiplyPoint3x4(new Vector3((c & 1) == 0 ? b.min.x : b.max.x, (c & 2) == 0 ? b.min.y : b.max.y, (c & 4) == 0 ? b.min.z : b.max.z));
+ }
+ }
+
+ /// <summary>A flying code-built Spitfire casts no shadow of its own: its soft disc (<see cref="GroundShadow"/>) is its
+ /// shadow, and a cast one would lie about 7 km off at its drawn height (e21's AFTER captures of #2728).</summary>
+ internal static void CastNoShadow(Transform plane)
+ {
+ foreach (var r in plane.GetComponentsInChildren<Renderer>(true)) r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
+ }
+
+ /// <summary>The sea's surface (world y), as KitGround has it: the heightmap's 0 m.</summary>
+ internal static float SeaLevelY(MapScene map) => map.Terrain.transform.position.y - map.ElevMinM * MapBuilder.VerticalExaggeration;
public const float ShipScale = 95f; // 63.4 m x 95 = 6.0 km: about a hex, like the promo's boats
/// <summary>Trio spacing and the ring, as fractions of the hex circumradius. <see cref="TrioSpread"/> is the spacing
/// the placer checks a token's spot with (UnitGround), kept so no spot moved.</summary>
@@ -132,6 +268,7 @@ namespace Statecraft.Game.Map.Units
var palette = assets.Own(UnitPalette.MakeTexture(readable: false));
var paint = assets.Own(new Material(template) { name = "UnitMiniature (palette)" });
paint.SetTexture("_BaseMap", palette);
+ var aircraftPaint = assets.Own(Glossy(paint));
Mesh Built(Mesh m) { assets.Own(m); return UnitPlinth.Upload(m); } // no CPU copy kept in players
float hex = map.Hexes.hex_size_km * 1000f;
@@ -159,18 +296,22 @@ namespace Statecraft.Game.Map.Units
// The aircraft and, when code-built, its propeller.
var plane = new GameObject("Spitfire1948");
plane.transform.SetParent(root.transform, false);
- Piece(plane.transform, "Airframe", SpitfireType, () => Built(UnitModels.Spitfire("Spitfire1948")), paint,
+ var airframe = Piece(plane.transform, "Airframe", SpitfireType, () => Built(UnitModels.Spitfire("Spitfire1948")), aircraftPaint,
Vector3.zero, Quaternion.identity, 1f, out bool authoredAircraft);
- Transform? prop = null;
+ Transform? codeProp = null;
if (!authoredAircraft)
{
- prop = Piece(plane.transform, "Propeller", Built(UnitModels.SpitfirePropeller("SpitfirePropeller")), paint, Vector3.zero, Quaternion.identity, 1f).transform;
- prop.localPosition = UnitModels.SpitfirePropellerHub;
+ codeProp = Piece(plane.transform, "Propeller", Built(UnitModels.SpitfirePropeller("SpitfirePropeller")), aircraftPaint, Vector3.zero, Quaternion.identity, 1f).transform;
+ codeProp.localPosition = UnitModels.SpitfirePropellerHub;
}
+ // Its blur, shadow and no cast shadow, whichever model draws it (an authored one brings its own propeller).
+ var prop = FlyingSpitfire(plane.transform, airframe, codeProp, assets.Own(PropellerBlurMesh()), assets.Own(BlurMaterial()),
+ assets.Own(Collection.SeaAirCollection.SpitfireShadowDisc()), out var shadow, out var shadowHalf);
plane.transform.localScale = Vector3.one * AircraftScale;
var loopCentre = map.Frame.ToWorld(LoopCentre.lon, LoopCentre.lat, 0);
var flight = plane.AddComponent<ShowcaseFlight>();
- flight.Configure(loopCentre, LoopRadiusM, LoopFloor(map, loopCentre, LoopRadiusM) + AltitudeM, LoopSeconds, BankDegrees, prop, still ? StillPhase : (float?)null);
+ flight.Configure(loopCentre, LoopRadiusM, LoopFloor(map, loopCentre, LoopRadiusM) + AltitudeM, LoopSeconds, BankDegrees, prop, still ? StillPhase : (float?)null,
+ shadow, map.Terrain, SeaLevelY(map), shadowHalf);
// The corvette, at the sea surface.
var ship = Ground(map, map.Frame.ToWorld(ShipAt.lon, ShipAt.lat, 0));
diff --git a/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs b/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs
index 620bf7f62..06f166c8e 100644
--- a/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs
+++ b/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs
@@ -1288,6 +1288,11 @@ public class SeaAirCollectionTests
var prop = airframe.transform.Find(SeaAirCollection.SpitfirePropellerName);
Assert.IsNotNull(prop, "a propeller disc, a child of the aircraft's mesh");
Assert.AreEqual(ShadowCastingMode.Off, prop.GetComponent<MeshRenderer>().shadowCastingMode, "a blur casts no shadow");
+ // The coordinator-approved plan, step 1 (5 November 2026): a light haze, not the dark disc it was.
+ var colours = prop.GetComponent<MeshFilter>().sharedMesh.colors32;
+ Assert.IsTrue(colours.All(c => c.r > 180 && c.g > 180 && c.b > 180), "a light blur");
+ Assert.That(colours.Max(c => c.a) / 255f, Is.InRange(0.3f, 0.6f), "see-through");
+ Assert.AreEqual(0, colours.Min(c => c.a), "clear at its rim");
float span = SeaAirCollection.SizeOf(SeaAirCollection.Spitfire);
loop.Place(0f);
var nose = plane.TransformDirection(Vector3.down); // the mesh's -y, as the in-flight test reads it
@@ -1343,11 +1348,36 @@ public class SeaAirCollectionTests
finally { SpitfireLoop.Clock = clock; Object.DestroyImmediate(flying); }
}
+ /// <summary>The coordinator-approved Spitfire plan, step 2 (5 November 2026): the streamed model is fully matte, so the
+ /// layer gives it a glossy copy of its material (the same shader and map, smoothness UnitShowcase.AircraftSmoothness), and
+ /// leaves the streamed material itself as it was.</summary>
+ [Test]
+ public void TheSpitfireWearsAGlossyCopyOfItsMatteMaterial()
+ {
+ var map = OpenMap();
+ var (_, plane, _, _) = DrawnSpitfire(map);
+ var airframe = plane.GetComponentInChildren<MeshFilter>().GetComponent<MeshRenderer>();
+ var gloss = airframe.sharedMaterial;
+ Assert.IsTrue(gloss.name.EndsWith(" (glossy)"), "a copy, not the streamed material");
+ Assert.AreEqual(Statecraft.Game.Map.Units.UnitShowcase.AircraftSmoothness, gloss.GetFloat("_Smoothness"), 1e-6f);
+ var name = gloss.name.Substring(0, gloss.name.Length - " (glossy)".Length);
+ var sources = Resources.FindObjectsOfTypeAll<Material>().Where(m => m.name == name).ToList();
+ Assert.IsNotEmpty(sources, "the streamed material it copies");
+ foreach (var source in sources)
+ {
+ Assert.AreEqual(0f, source.GetFloat("_Smoothness"), 1e-6f, "the streamed material stays matte");
+ Assert.AreSame(source.shader, gloss.shader);
+ Assert.AreSame(source.GetTexture("_BaseMap"), gloss.GetTexture("_BaseMap"), "the same map");
+ }
+ }
+
/// <summary>The owner's report: "it doesnt look fliying". The aircraft flies well clear of the ground at every point of its
/// loop (UnitShowcase.AltitudeM over the highest ground under the loop), and a soft dark disc, as long and as wide as the
/// aircraft seen from above and fading to nothing at its rim, lies on the ground where the map's sun (MapLighting) casts
/// it: on the sun's ray through the aircraft, east-south-east of it, turned with its heading, a little over the ground
- /// under it and inside the board.</summary>
+ /// under it and inside the board. The ray starts at SpitfireLoop.ShadowHeightShare of the aircraft's height over the
+ /// surface under it, so the shadow lies near enough to read as the aircraft's (e21's captures, 5 November 2026: about
+ /// 7.5 km away at the full height).</summary>
[Test]
public void TheSpitfireFliesHighOverTheGroundAndItsSoftShadowLiesDownSunOnTheBoard()
{
@@ -1363,14 +1393,23 @@ public class SeaAirCollectionTests
var (layer, plane, loop, centre) = DrawnSpitfire(map);
var shadow = Marks(layer, SeaAirCollection.SpitfireShadowName);
Assert.IsNotNull(shadow, "a ground shadow beside the aircraft");
+ Assert.IsTrue(plane.GetComponentsInChildren<Renderer>(true).All(x => x.shadowCastingMode == ShadowCastingMode.Off),
+ "its only shadow: the aircraft casts none (one would lie about 7.7 km off at its drawn height, e21's AFTER captures)");
var renderer = shadow!.GetComponent<MeshRenderer>();
Assert.AreEqual(ShadowCastingMode.Off, renderer.shadowCastingMode); Assert.IsFalse(renderer.receiveShadows);
var alpha = shadow.GetComponent<MeshFilter>().sharedMesh.colors32.Select(c => c.a / 255f).ToList();
Assert.That(alpha.Max(), Is.InRange(0.2f, 0.8f), "dark but see-through at its middle");
+ // e21's AFTER captures of #2728: the Dakotas' disc read too faint as the Spitfire's only shadow; its own is darker.
+ var dakota = SeaAirCollection.ShadowDisc();
+ try { Assert.Greater(alpha.Max(), dakota.colors32.Max(c => c.a) / 255f + 0.1f, "darker than the Dakotas' disc"); }
+ finally { Object.DestroyImmediate(dakota); }
Assert.AreEqual(0f, alpha.Min(), 1e-3f, "nothing at its rim: a soft edge");
var ground = PlacementLayer.CampGround(map);
float span = SeaAirCollection.SizeOf(SeaAirCollection.Spitfire), y0 = map.Terrain.transform.position.y;
float Height(Vector3 p) => map.Terrain.SampleHeight(p) + y0;
+ // Where the shadow's ray starts: ShadowHeightShare of the way up from the surface (land or sea) under the aircraft.
+ Vector3 Low(Vector3 drawn) { float u = Mathf.Max(Height(drawn), ground.SeaLevelY); drawn.y = u + SpitfireLoop.ShadowHeightShare * (drawn.y - u); return drawn; }
+ Assert.That(SpitfireLoop.ShadowHeightShare, Is.InRange(0.1f, 0.5f), "lower than the drawn height, still well over the ground");
var sunFlat = new Vector2(SpitfireLoop.SunRay.x, SpitfireLoop.SunRay.z).normalized;
for (int i = 0; i < 40; i++)
{
@@ -1382,9 +1421,11 @@ public class SeaAirCollectionTests
var at = SeaAirCollection.LoopOffset(t); var drawn = centre + new Vector3(at.x, 0f, at.y);
var s = shadow.position; float g = Height(s);
Assert.That(s.y - g, Is.InRange(0f, SpitfireLoop.ShadowLiftM + 400f), $"on the ground under it at {t:0.0} s");
- var cast = drawn + SpitfireLoop.SunRay * ((drawn.y - g) / -SpitfireLoop.SunRay.y);
- Assert.Less(new Vector2(s.x - cast.x, s.z - cast.z).magnitude, 0.03f * (drawn.y - g), $"on the sun's ray through the aircraft at {t:0.0} s");
- Assert.Greater(Vector2.Dot(new Vector2(s.x - drawn.x, s.z - drawn.z), sunFlat), 0.9f * (drawn.y - g), "down-sun of it");
+ var low = Low(drawn);
+ var cast = low + SpitfireLoop.SunRay * ((low.y - g) / -SpitfireLoop.SunRay.y);
+ Assert.Less(new Vector2(s.x - cast.x, s.z - cast.z).magnitude, 0.03f * (low.y - g), $"on the sun's ray through the aircraft, from its lowered height, at {t:0.0} s");
+ Assert.Greater(Vector2.Dot(new Vector2(s.x - drawn.x, s.z - drawn.z), sunFlat), 0.9f * (low.y - g), "down-sun of it");
+ Assert.Less(new Vector2(s.x - drawn.x, s.z - drawn.z).magnitude, 0.6f * (drawn.y - g) / Mathf.Tan(MapLighting.SunElevation * Mathf.Deg2Rad), "nearer than the full height's ray would lay it");
var heading = SeaAirCollection.LoopHeading(t);
Assert.Greater(Vector3.Dot(shadow.forward, new Vector3(heading.x, 0f, heading.y)), 0.999f, "turned with its heading");
Assert.That(shadow.lossyScale.z / span, Is.InRange(0.3f, 0.6f), "half as long as the aircraft, about");
@@ -1397,7 +1438,7 @@ public class SeaAirCollectionTests
// higher sun from the south-west puts it north-east of the aircraft, nearer.
sun.transform.rotation = Quaternion.Euler(48f, 215f - 180f, 0f);
loop.Place(0f);
- var high = centre + new Vector3(SeaAirCollection.LoopOffset(0f).x, 0f, SeaAirCollection.LoopOffset(0f).y);
+ var high = Low(centre + new Vector3(SeaAirCollection.LoopOffset(0f).x, 0f, SeaAirCollection.LoopOffset(0f).y));
var landed = shadow.position; float under0 = Height(landed);
var cast0 = high + sun.transform.forward * ((high.y - under0) / -sun.transform.forward.y);
Assert.Less(new Vector2(landed.x - cast0.x, landed.z - cast0.z).magnitude, 0.03f * (high.y - under0), "on the scene sun's ray, not a fixed one");
@@ -1466,8 +1507,10 @@ public class SeaAirCollectionTests
/// 15 October 2026). The Spitfire flies the same flag, cloth and colours, but as the owner ruled on #2260 (2 November
/// 2026, "Smaller flag, no pole": "a small Egyptian flag pennant floating just above the tail (no pole through the
/// plane)"): the cloth alone, smaller than the tokens' flag, floating over the aircraft's tail. In every pose of the loop
- /// and facing every way it stays upright, behind the aircraft's middle, wholly above the aircraft's box (so it never
- /// meets the airframe, banked or not), and inside the box the labels keep clear of.</summary>
+ /// and facing every way it stays upright, behind the aircraft's middle, clear above every part of the airframe under it
+ /// (so it never meets the airframe, banked or not), just above the tail (not over the raised wingtip's height: from
+ /// there the map's camera drew it over the cockpit, e21's captures, 5 November 2026), and inside the box the labels keep
+ /// clear of.</summary>
[Test]
public void TheSpitfireFliesEgyptsFlagAsTheEgyptianTokensDo()
{
@@ -1489,7 +1532,9 @@ public class SeaAirCollectionTests
float tokens = Statecraft.Game.Map.Units.UnitBadge.FigureHeightM * Statecraft.Game.Map.Units.UnitShowcase.FigureScale;
Assert.Less(flag.lossyScale.y, 0.75f * tokens, "clearly smaller than the tokens' flag");
Assert.AreEqual(ShadowCastingMode.Off, flag.GetComponent<MeshRenderer>().shadowCastingMode, "only the aircraft's own shadow on the ground");
- var airframe = plane.GetComponentInChildren<MeshFilter>().GetComponent<Renderer>();
+ var airframeMesh = plane.GetComponentInChildren<MeshFilter>();
+ var local = airframeMesh.sharedMesh.vertices; // the streamed model is readable (the propeller test reads it too)
+ float span = SeaAirCollection.SizeOf(SeaAirCollection.Spitfire);
var keep = layer.KeepClear.Single(k => k[0].Contains(centre))[0];
for (int i = 0; i < 32; i++)
{
@@ -1497,16 +1542,26 @@ public class SeaAirCollectionTests
loop.Place(t);
var at = SeaAirCollection.LoopOffset(t); var heading = SeaAirCollection.LoopHeading(t);
var drawn = centre + new Vector3(at.x, 0f, at.y);
- var body = airframe.bounds;
- Assert.Less(Vector3.Dot(flag.position - drawn, new Vector3(heading.x, 0f, heading.y)), -0.3f * SeaAirCollection.SizeOf(SeaAirCollection.Spitfire),
- $"over the tail, behind the aircraft's middle, at {t:0.0} s");
+ var forward = new Vector3(heading.x, 0f, heading.y);
+ var verts = local.Select(airframeMesh.transform.TransformPoint).ToArray();
+ // The tail: the airframe behind 0.3 of the span back from its middle (the wing's root is well forward of it).
+ float tailTop = verts.Where(v => Vector3.Dot(v - drawn, forward) < -0.3f * span).Max(v => v.y);
+ Assert.Less(Vector3.Dot(flag.position - drawn, forward), -0.3f * span, $"over the tail, behind the aircraft's middle, at {t:0.0} s");
+ // Clear above every part of the airframe the cloth could be over, whichever way it turns: every vertex within the
+ // cloth's whole reach about its middle (it turns about its vertical) and a margin of a tenth of the span, which is
+ // wider than the airframe's triangles there, lies under the cloth's lower edge.
+ var clothMesh = flag.GetComponent<MeshFilter>().sharedMesh.bounds;
+ float reach = new Vector2(clothMesh.extents.x, clothMesh.extents.z).magnitude * flag.lossyScale.x + 0.1f * span;
+ float lower = flag.position.y - clothMesh.extents.y * flag.lossyScale.y;
+ var near = verts.Where(v => new Vector2(v.x - flag.position.x, v.z - flag.position.z).magnitude < reach).ToArray();
+ if (near.Length > 0) Assert.Greater(lower, near.Max(v => v.y), $"clear above every part of the airframe the cloth could be over at {t:0.0} s");
foreach (var look in new[] { Vector3.forward, Vector3.back, Vector3.left, Vector3.right, new Vector3(1f, 0f, 1f).normalized })
{
Statecraft.Game.Map.Units.UnitFlagFacing.Face(flag, flag.position + look * 50000f);
Assert.Greater(Vector3.Dot(flag.up, Vector3.up), 0.999f, $"upright at {t:0.0} s");
var fb = flag.GetComponent<Renderer>().bounds;
- Assert.Greater(fb.min.y, body.max.y, $"wholly above the aircraft's box, clear of the airframe, at {t:0.0} s");
- Assert.Less(fb.min.y - body.max.y, 0.25f * SeaAirCollection.SizeOf(SeaAirCollection.Spitfire), $"just above it, at {t:0.0} s");
+ Assert.Greater(fb.min.y, tailTop, $"above the tail at {t:0.0} s");
+ Assert.Less(fb.min.y - tailTop, 0.2f * span, $"just above the tail, not up at the raised wingtip's height, at {t:0.0} s");
Assert.IsTrue(keep.Contains(fb.min) && keep.Contains(fb.max), $"inside the labels' keep-clear box at {t:0.0} s");
}
}
@@ -1539,7 +1594,8 @@ public class SeaAirCollectionTests
}
/// <summary>Review of #2260: drawing, dropping and drawing the Spitfire again (its dates end and come back, the layer
- /// redraws) makes no new propeller, shadow or flag meshes or materials past the first: the layer makes them once. When
+ /// redraws) makes no new propeller, shadow or flag meshes or materials (its glossy paint included) past the first: the
+ /// layer makes them once. When
/// its dates end under residency, the aircraft and its shadow-and-flag object both go, and the labels keep clear of
/// exactly the craft left.</summary>
[Test]
@@ -1549,7 +1605,7 @@ public class SeaAirCollectionTests
int Meshes() => Resources.FindObjectsOfTypeAll<Mesh>().Count(m => m.name == "SpitfirePropellerBlur" || m.name == "SpitfireShadow"
|| m.name == Statecraft.Game.Map.Units.UnitFlags.MeshName(Statecraft.Game.Map.Units.UnitFlags.Egypt));
int Materials() => Resources.FindObjectsOfTypeAll<Material>().Count(m => m.name.StartsWith("UnitFlag (egypt", StringComparison.Ordinal)
- || m.name == Statecraft.HexTiles.HexMaterials.AttackBorder);
+ || m.name == Statecraft.HexTiles.HexMaterials.AttackBorder || m.name.EndsWith(" (glossy)", StringComparison.Ordinal));
SeaAirCollection Show(DateTime date) { var l = CollectionGeometryFixture.Craft(map, date, Array.Empty<Placement>(), C)!; AnswerAll(); return l; }
var layer = Show(new DateTime(1948, 6, 15));
Assert.IsNotNull(layer.transform.Find("el-arish-spitfire"));
diff --git a/unity/Assets/Tests/EditMode/UnitShowcaseTests.cs b/unity/Assets/Tests/EditMode/UnitShowcaseTests.cs
index c74d45e23..def1d6d95 100644
--- a/unity/Assets/Tests/EditMode/UnitShowcaseTests.cs
+++ b/unity/Assets/Tests/EditMode/UnitShowcaseTests.cs
@@ -9,6 +9,12 @@ using UnityEngine;
public class UnitShowcaseTests
{
+ // These tests are about the code-built models. An authored model in Resources/Units/Authored (#2734's Spitfire) would
+ // replace one in every Spawn, so each test starts with none; the authored tests set their own (AuthoredModel is a seam).
+ System.Func<string, GameObject> realAuthoredModel;
+ [SetUp] public void CodeBuiltModels() { realAuthoredModel = UnitShowcase.AuthoredModel; UnitShowcase.AuthoredModel = _ => null; }
+ [TearDown] public void RestoreAuthoredModels() { if (realAuthoredModel != null) UnitShowcase.AuthoredModel = realAuthoredModel; }
+
static Mesh[] AllMeshes() => new[]
{
UnitModels.Rifleman(UnitModels.Headgear.SlouchHat, UnitModels.RiflePose.Ready, false, "a"),
@@ -171,13 +177,16 @@ public class UnitShowcaseTests
return map;
}
- /// <summary>Everything a spawn made that must be freed with it: meshes, the palette material and its texture.</summary>
+ /// <summary>Everything a spawn made that must be freed with it: meshes, the palette material and its texture, and the
+ /// aircraft's glossy paint and its blur and shadow material.</summary>
static List<Object> SpawnedAssets(GameObject root)
{
var list = new List<Object>();
foreach (var f in root.GetComponentsInChildren<MeshFilter>(true)) list.Add(f.sharedMesh);
var paint = root.transform.Find("Rifleman0").GetComponent<MeshRenderer>().sharedMaterial;
list.Add(paint); list.Add(paint.GetTexture("_BaseMap"));
+ list.Add(root.transform.Find("Spitfire1948/Airframe").GetComponent<MeshRenderer>().sharedMaterial);
+ list.Add(root.transform.Find("Spitfire1948/" + UnitShowcase.ShadowName).GetComponent<MeshRenderer>().sharedMaterial);
Assert.IsTrue(list.All(o => o != null));
return list;
}
@@ -292,6 +301,11 @@ public class UnitShowcaseTests
var map = BuildMap(); // first: a new scene would destroy the stand-in models
var helmet = new GameObject("authored-helmet"); new GameObject("AuthoredMarker").transform.SetParent(helmet.transform);
var spitfire = new GameObject("authored-spitfire"); new GameObject("AuthoredMarker").transform.SetParent(spitfire.transform);
+ // An authored model's own propeller: a child named UnitShowcase.AuthoredPropellerName, turning about its local +z.
+ var bladesMesh = UnitModels.SpitfirePropeller("authored-blades");
+ var blades = new GameObject(UnitShowcase.AuthoredPropellerName);
+ blades.transform.SetParent(spitfire.transform, false);
+ blades.AddComponent<MeshFilter>().sharedMesh = bladesMesh; blades.AddComponent<MeshRenderer>();
var saved = UnitShowcase.AuthoredModel;
UnitShowcase.AuthoredModel = type => type == UnitShowcase.RiflemanHelmetType ? helmet : type == UnitShowcase.SpitfireType ? spitfire : null;
try
@@ -303,13 +317,186 @@ public class UnitShowcaseTests
Assert.AreEqual(UnitShowcase.FigureScale, root.transform.Find("Rifleman1").localScale.x, 1e-3f, "placed and scaled as the code-built one");
Assert.IsNotNull(root.transform.Find("Spitfire1948/Airframe/AuthoredMarker"));
Assert.IsNull(root.transform.Find("Spitfire1948/Propeller"), "an authored aircraft brings its own propeller");
+ Assert.IsFalse(root.transform.Find("Spitfire1948/Airframe").GetComponentsInChildren<Renderer>(true)
+ .Any(r => r.sharedMaterial != null && r.sharedMaterial.name.EndsWith(" (glossy)")), "nor the code-built glossy paint: it brings its own materials");
+ // The flight's look applies to it all the same: its own propeller turns and carries the blur, sized to its blades,
+ // and a soft shadow lies on the ground while it casts none.
+ var ownProp = root.transform.Find("Spitfire1948/Airframe/" + UnitShowcase.AuthoredPropellerName);
+ Assert.IsNotNull(ownProp, "fixture: the authored propeller");
+ var flight = root.GetComponentInChildren<ShowcaseFlight>();
+ Assert.AreSame(ownProp, typeof(ShowcaseFlight).GetField("propeller", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.GetValue(flight),
+ "the flight turns the authored propeller");
+ var blur = ownProp.Find(UnitShowcase.PropellerBlurName);
+ Assert.IsNotNull(blur, "the blur on the authored propeller");
+ Assert.That(blur.localScale.x, Is.InRange(1.4f, 1.9f), "sized to its blades (the code-built blades here, reaching about 1.6)");
+ Assert.IsNotNull(flight.transform.Find(UnitShowcase.ShadowName), "the soft shadow under an authored aircraft too");
+ Assert.IsTrue(flight.GetComponentsInChildren<Renderer>(true).All(r => r.shadowCastingMode == UnityEngine.Rendering.ShadowCastingMode.Off),
+ "and it casts no shadow of its own");
Assert.IsNotNull(root.transform.Find("Corvette1948").GetComponent<MeshFilter>());
}
finally
{
UnitShowcase.AuthoredModel = saved;
- Object.DestroyImmediate(map.gameObject); Object.DestroyImmediate(helmet); Object.DestroyImmediate(spitfire);
+ Object.DestroyImmediate(map.gameObject); Object.DestroyImmediate(helmet); Object.DestroyImmediate(spitfire); Object.DestroyImmediate(bladesMesh);
+ }
+ }
+
+ /// <summary>The coordinator-approved Spitfire plan, step 1 (5 November 2026): the code-built 101 Squadron Spitfire's
+ /// propeller carries a light, see-through blur that turns with it: pale, clear at the rim, at most about half opaque,
+ /// brighter at its four blades than between them, casting and taking no shadow.</summary>
+ [Test]
+ public void TheCodeBuiltSpitfiresPropellerCarriesALightBlur()
+ {
+ bool readable = UnitPlinth.KeepMeshesReadable; UnitPlinth.KeepMeshesReadable = true; // the blur's colours are read below
+ var map = BuildMap();
+ try
+ {
+ var root = UnitShowcase.Spawn(map, still: true);
+ var prop = root.transform.Find("Spitfire1948/Propeller");
+ var blur = prop.Find(UnitShowcase.PropellerBlurName);
+ Assert.IsNotNull(blur, "a blur, a child of the turning propeller, so it turns with it");
+ var r = blur.GetComponent<MeshRenderer>();
+ Assert.AreEqual(UnityEngine.Rendering.ShadowCastingMode.Off, r.shadowCastingMode); Assert.IsFalse(r.receiveShadows);
+ Assert.AreNotSame(root.transform.Find("Rifleman0").GetComponent<MeshRenderer>().sharedMaterial, r.sharedMaterial, "a see-through material, not the paint");
+ Assert.Greater(Mathf.Abs(Vector3.Dot(blur.up, prop.forward)), 0.999f, "the disc faces along the propeller's axis (+z)");
+ var colours = blur.GetComponent<MeshFilter>().sharedMesh.colors32;
+ Assert.IsTrue(colours.All(c => c.r > 180 && c.g > 180 && c.b > 180), "light, not the dark rods' colour");
+ float max = colours.Max(c => c.a) / 255f;
+ Assert.That(max, Is.InRange(0.3f, 0.6f), "see-through");
+ // e21's AFTER captures of #2728: two layers read as a near-opaque plate under the dark rods. One layer, lighter
+ // than the Egyptian Spitfire's haze at the same angle.
+ var positions = blur.GetComponent<MeshFilter>().sharedMesh.vertices;
+ Assert.IsTrue(positions.All(v => Mathf.Abs(v.y - positions[0].y) < 1e-5f), "one layer");
+ Assert.Less(max, Statecraft.Game.Map.Collection.SeaAirCollection.PropBlurAlpha(0f, 90f, 0f) - 0.1f, "lighter than the Egyptian haze at a blade");
+ Assert.AreEqual(0, colours.Min(c => c.a), "clear at its rim");
+ Assert.Greater(max - colours.Where(c => c.a > 0).Min(c => c.a) / 255f, 0.15f, "brighter at the blades: streaked, not a flat disc");
+ // The streaks sit at the four rods (UnitModels.SpitfirePropeller: up turned 90 b + 20 degrees about +z, so at 110 +
+ // 90 b from +x) and trail them: the propeller turns clockwise seen from behind (ShowcaseFlight, -z), so just behind a
+ // rod is a little more angle. Read in the propeller's own frame.
+ var verts = blur.GetComponent<MeshFilter>().sharedMesh.vertices;
+ float near = 0f, far = 0f; int nearN = 0, farN = 0;
+ for (int i = 0; i < verts.Length; i++)
+ {
+ var p = prop.InverseTransformPoint(blur.TransformPoint(verts[i]));
+ if (new Vector2(p.x, p.y).magnitude < 0.5f * UnitShowcase.PropellerBlurRadius || colours[i].a == 0) continue; // the outer rings
+ float behind = Mathf.Repeat(Mathf.Atan2(p.y, p.x) * Mathf.Rad2Deg - 110f, 90f);
+ if (behind < 15f) { near += colours[i].a; nearN++; } else if (behind > 45f && behind < 75f) { far += colours[i].a; farN++; }
+ }
+ Assert.Greater(nearN, 0); Assert.Greater(farN, 0);
+ Assert.Greater(near / nearN - far / farN, 0.1f * 255f, "brighter just behind each of the four rods than between them");
+ }
+ finally { UnitPlinth.KeepMeshesReadable = readable; Object.DestroyImmediate(map.gameObject); }
+ }
+
+ /// <summary>The coordinator-approved Spitfire plan, step 2: the code-built Spitfire wears a glossy copy of the units' paint
+ /// (the same palette, smoothness UnitShowcase.AircraftSmoothness), its own: the riflemen and the corvette keep theirs.</summary>
+ [Test]
+ public void TheCodeBuiltSpitfireWearsAGlossyCopyOfTheUnitsPaint()
+ {
+ var map = BuildMap();
+ try
+ {
+ var root = UnitShowcase.Spawn(map, still: true);
+ var paint = root.transform.Find("Rifleman0").GetComponent<MeshRenderer>().sharedMaterial;
+ var gloss = root.transform.Find("Spitfire1948/Airframe").GetComponent<MeshRenderer>().sharedMaterial;
+ Assert.AreNotSame(paint, gloss, "its own material");
+ Assert.AreSame(gloss, root.transform.Find("Spitfire1948/Propeller").GetComponent<MeshRenderer>().sharedMaterial, "the propeller too");
+ Assert.AreSame(paint, root.transform.Find("Corvette1948").GetComponent<MeshRenderer>().sharedMaterial, "the corvette keeps the units' paint");
+ Assert.AreEqual(UnitShowcase.AircraftSmoothness, gloss.GetFloat("_Smoothness"), 1e-6f);
+ Assert.Greater(gloss.GetFloat("_Smoothness"), paint.GetFloat("_Smoothness"), "glossier than the units' paint");
+ Assert.AreSame(paint.shader, gloss.shader); Assert.AreSame(paint.GetTexture("_BaseMap"), gloss.GetTexture("_BaseMap"), "the same palette");
+ Assert.AreEqual(paint.GetFloat("_Metallic"), gloss.GetFloat("_Metallic"), "painted, not bare metal");
+ }
+ finally { Object.DestroyImmediate(map.gameObject); }
+ }
+
+ /// <summary>The coordinator-approved Spitfire plan, step 3: the flying code-built Spitfire casts a soft shadow on the ground,
+ /// as the Egyptian Spitfire does: on the map sun's ray from SpitfireLoop.ShadowHeightShare of its height, a little over the
+ /// ground there, turned with its heading, about as long and as wide as the aircraft seen from above, going with it.</summary>
+ [Test]
+ public void TheFlyingCodeBuiltSpitfireCastsASoftShadowOnTheGround()
+ {
+ var map = BuildMap();
+ var sun = new GameObject("TEST ONLY sun").AddComponent<Light>();
+ var sunWas = RenderSettings.sun;
+ try
+ {
+ sun.type = LightType.Directional; MapLighting.Apply(sun);
+ var root = UnitShowcase.Spawn(map, still: true);
+ var flight = root.GetComponentInChildren<ShowcaseFlight>();
+ var shadow = flight.transform.Find(UnitShowcase.ShadowName);
+ Assert.IsNotNull(shadow, "a shadow, a child of the aircraft, so it goes with it");
+ Assert.IsTrue(flight.GetComponentsInChildren<Renderer>(true).All(x => x.shadowCastingMode == UnityEngine.Rendering.ShadowCastingMode.Off),
+ "its only shadow: the aircraft casts none (one would lie about 7 km off at its drawn height)");
+ var r = shadow.GetComponent<MeshRenderer>();
+ Assert.AreEqual(UnityEngine.Rendering.ShadowCastingMode.Off, r.shadowCastingMode); Assert.IsFalse(r.receiveShadows);
+ var model = UnitModels.Spitfire("span"); float span = model.bounds.size.x * UnitShowcase.AircraftScale; Object.DestroyImmediate(model);
+ float y0 = map.Terrain.transform.position.y, sea = UnitShowcase.SeaLevelY(map);
+ float Surface(Vector3 p) => Mathf.Max(map.Terrain.SampleHeight(p) + y0, sea);
+ var ray = sun.transform.forward;
+ for (int i = 0; i < 12; i++)
+ {
+ flight.Place(i / 12f);
+ var drawn = flight.transform.position; var s = shadow.position;
+ Assert.That(s.y - Surface(s), Is.InRange(0f, Statecraft.Game.Map.Collection.SpitfireLoop.ShadowLiftM + 400f), $"on the ground at phase {i}/12");
+ float under = Surface(drawn);
+ var low = new Vector3(drawn.x, under + Statecraft.Game.Map.Collection.SpitfireLoop.ShadowHeightShare * (drawn.y - under), drawn.z);
+ var cast = low + ray * ((low.y - Surface(s)) / -ray.y);
+ Assert.Less(new Vector2(s.x - cast.x, s.z - cast.z).magnitude, 50f + 0.03f * (low.y - Surface(s)), $"on the sun's ray from its lowered height at phase {i}/12");
+ Assert.Greater(Vector3.Dot(shadow.forward, Vector3.ProjectOnPlane(flight.transform.forward, Vector3.up).normalized), 0.999f, "turned with its heading");
+ Assert.That(shadow.lossyScale.x / span, Is.InRange(0.4f, 0.6f), "about half the span across (a little narrowed in the bank)");
+ Assert.That(shadow.lossyScale.z / span, Is.InRange(0.3f, 0.6f), "about half its length along");
+ }
}
+ finally { RenderSettings.sun = sunWas; Object.DestroyImmediate(sun.gameObject); Object.DestroyImmediate(map.gameObject); }
+ }
+
+ /// <summary>The authored 101 Squadron Spitfire (#2734), once it is in Resources/Units/Authored: the prefab the game loads
+ /// for the type has a DIRECT child named UnitShowcase.AuthoredPropellerName (UnitShowcase.FlyingSpitfire finds it under
+ /// the root Piece renames "Airframe"), with a mesh, its pivot on the centre line ahead of the airframe, at rest
+ /// (identity rotation, as ShowcaseFlight overwrites it), so the flight turns it and its blur fits its blades. Ignored
+ /// until the model lands.</summary>
+ [Test]
+ public void TheAuthoredSpitfireHasADirectPropellerChildTheFlightCanTurn()
+ {
+ var prefab = Resources.Load<GameObject>(UnitShowcase.AuthoredFolder + UnitShowcase.SpitfireType);
+ if (prefab == null) Assert.Ignore("no authored Spitfire in Resources yet (#2734)");
+ var prop = prefab.transform.Find(UnitShowcase.AuthoredPropellerName);
+ Assert.IsNotNull(prop, $"a direct child named {UnitShowcase.AuthoredPropellerName}");
+ Assert.IsNotNull(prop.GetComponentInChildren<MeshFilter>()?.sharedMesh, "its blades are a mesh");
+ Assert.AreEqual(Quaternion.identity, prop.localRotation, "at rest: ShowcaseFlight sets its turn about local +z");
+ Assert.AreEqual(Vector3.one, prop.localScale);
+ Assert.AreEqual(0f, prop.localPosition.x, 0.01f, "the hub on the centre line");
+ var others = prefab.GetComponentsInChildren<MeshFilter>(true).Where(f => !f.transform.IsChildOf(prop)).Select(f => f.sharedMesh.bounds).ToList();
+ Assert.IsNotEmpty(others, "an airframe besides the propeller");
+ Assert.Greater(prop.localPosition.z, others.Max(b => b.center.z), "the propeller is at the nose (+z)");
+
+ // And through the real showcase: the flight turns that propeller and it carries the blur.
+ UnitShowcase.AuthoredModel = realAuthoredModel;
+ var map = BuildMap();
+ try
+ {
+ var root = UnitShowcase.Spawn(map, still: true);
+ var spawned = root.transform.Find("Spitfire1948/Airframe/" + UnitShowcase.AuthoredPropellerName);
+ Assert.IsNotNull(spawned, "Airframe/Propeller after Piece renames the prefab's root");
+ var flight = root.GetComponentInChildren<ShowcaseFlight>();
+ Assert.AreSame(spawned, typeof(ShowcaseFlight).GetField("propeller", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.GetValue(flight));
+ Assert.IsNotNull(spawned.Find(UnitShowcase.PropellerBlurName), "the blur on it");
+ Assert.IsNotNull(flight.transform.Find(UnitShowcase.ShadowName), "the soft shadow");
+ // And the flight really turns it about its local +z, 1500 degrees a second, once it flies (not held still).
+ typeof(ShowcaseFlight).GetField("still", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.SetValue(flight, null);
+ var update = typeof(ShowcaseFlight).GetMethod("Update", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!;
+ var clock = ShowcaseFlight.Clock;
+ try
+ {
+ ShowcaseFlight.Clock = () => 0f; update.Invoke(flight, null); var q0 = spawned.localRotation;
+ ShowcaseFlight.Clock = () => 0.01f; update.Invoke(flight, null);
+ Assert.AreEqual(15f, Quaternion.Angle(q0, spawned.localRotation), 0.1f, "15 degrees in a hundredth of a second");
+ Assert.Greater(Mathf.Abs(Vector3.Dot(spawned.localRotation * Vector3.forward, Vector3.forward)), 0.999f, "about its local +z");
+ }
+ finally { ShowcaseFlight.Clock = clock; }
+ }
+ finally { Object.DestroyImmediate(map.gameObject); }
}
static Material Load(string name) => AssetDatabase.LoadAssetAtPath<Material>($"Assets/Materials/{name}.mat");