Aetheria/tests/Aetheria.Shared.Tests/ShipEmitterExhaustTests.cs
soul 28666e3550 A directional thruster's emitter is one-sided, and the catalog refuses one that fires along its push
The exhaust is born along each triangle's normal of the emitter mesh, and every Nakovalnya, Wren and starter emitter was
a thin closed box, so it fired both ways along the thruster axis. The generator now writes one side: hull_source keeps
of a hull source's emit mesh only the triangles facing its anchor's yaw (the exhaust), and the starter's thruster boxes
carry a single exhaust face. ShipModCatalog.Bind, which Compose and ship-authoring validate both run, reads the emitter
geometry from the GLB (world transform included) and refuses a directional thruster whose emitter has any face or vertex
normal with a non-negative dot with the push, naming the anchor. The rule is the directional class's alone; a ring
thruster would bring its own. The Nakovalnya and Wren ship.glb are regenerated through Build + Package and the starter;
ship.cc, anchors, node indices and every non-emitter node are unchanged. Blender smokes and the test GLBs now give
thrusters an exhaust-facing emitter and a matching Rotation.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-19 20:47:05 +01:00

70 lines
3.2 KiB
C#

using System;
using System.IO;
using System.Linq;
using Xunit;
// A directional thruster's emitter mesh is the surface its exhaust is born from, along each triangle's normal, so every
// normal must face the exhaust, opposite the push (ShipModCatalog.BindExhaust). A closed box fires both ways: the operator
// saw the same thrusters firing whichever way the ship strafed. A ring thruster is a class of its own with its own rule and
// is not exercised here.
public sealed class ShipEmitterExhaustTests : IDisposable
{
private readonly TempDirectory _directory = new TempDirectory();
public void Dispose() => _directory.Dispose();
private string Thruster => Path.Combine(_directory.Path, "mod.skiff", "ship.cc");
// The fixture thruster's hardpoint Rotation is None, so its exhaust leaves toward glTF's +Z; its emitter, one quad
// wound to face +Z, is the one-sided emitter the generator writes.
private void Write(Action<ShipParts> tweak = null, string from = null, string to = null)
{
ShipFixture.WritePackage(_directory.Path, "mod.skiff", tweak: tweak);
if (from == null) return;
var json = ShipFixture.GlbJson(ShipFixture.Nodes);
Assert.Contains(from, json);
File.WriteAllBytes(Path.Combine(_directory.Path, "mod.skiff", "skiff.glb"), ShipFixture.Glb(json.Replace(from, to), ShipFixture.MeshBytes()));
}
private static void Reversed(ShipParts ship) => ship.Hull.Hardpoints.Single(hardpoint => hardpoint.Transform == "thruster.port").Rotation = ItemRotation.Reversed;
[Fact]
public void AOneSidedEmitterFacingItsExhaustIsAccepted()
{
Write();
Assert.Equal("mod.skiff", ShipModCatalog.ReadPackage(Thruster).Visual.Id);
}
[Fact]
public void AClosedBoxEmitterIsRefusedNamingItsAnchor()
{
Write(from: @"""name"":""thruster-port"",""mesh"":1", to: @"""name"":""thruster-port"",""mesh"":0");
var message = Assert.Throws<InvalidOperationException>(() => ShipModCatalog.ReadPackage(Thruster)).Message;
Assert.Contains("thruster emitter thruster.port", message);
Assert.Contains("one-sided", message);
}
[Fact]
public void AnEmitterFacingTheWrongWayIsRefused()
{
// The same quad toward +Z under a thruster that now faces aft: its exhaust would leave along the push.
Write(Reversed);
Assert.Contains("thruster emitter thruster.port", Assert.Throws<InvalidOperationException>(() => ShipModCatalog.ReadPackage(Thruster)).Message);
}
[Fact]
public void TheNodesTurnDecidesWhichWayTheEmitterFaces()
{
// Turned half a circle about Y, the quad's +Z becomes -Z: the exhaust of an aft-facing thruster.
Write(Reversed, from: @"""name"":""thruster-port"",""mesh"":1", to: @"""name"":""thruster-port"",""mesh"":1,""rotation"":[0,1,0,0]");
Assert.Equal("mod.skiff", ShipModCatalog.ReadPackage(Thruster).Visual.Id);
}
[Fact]
public void TheShippedAndFixturePackagesPass()
{
var root = RunStartTests.FindRepoRoot();
foreach (var ship in new[] { Path.Combine("GameData", "Mods", "aetheria.nakovalnya"), Path.Combine("tests", "fixtures", "mods", "aetheria.wren") })
Assert.NotNull(ShipModCatalog.ReadPackage(Path.Combine(root, ship, "ship.cc")));
}
}