acdream/tests/AcDream.App.Tests/Rendering/ChargenPreviewCameraTests.cs
Erik 55bfd9ca82 feat(chargen): Campaign CC slice CC6a — index→ObjDesc factory + preview renderer foundation
Delivers the CC6a foundation half of the chargen 3D preview: the missing
index->ObjDesc appearance factory the campaign plan's acdream-seams
section named, plus a static-pose offscreen renderer following
PrivateEntityViewportRenderer's proven paperdoll/appraisal architecture.
Page mount, spin/color-wheel controls, and rotate/zoom behavior stay out
of scope per the CC4-parallel worktree contract (CC6b, after CC4 merges).

Core (src/AcDream.Core/CharGen/, pure, no Chorizite on public surfaces):
ChargenAppearanceFactory.TryCompose ports gmCG3DView::Update @0x004EE9D0's
ObjDesc rebuild in its exact decompiled order - base body, hair style,
clothing in retail's own Headgear/Trousers/Shirt/Footwear order (not the
UI tab order or the wire's field order, both of which differ), eyes
(bald-aware), nose, mouth, then the unconditional skin subpalette, hair
color, eye color. ChargenPalSetMath ports PalSet::GetPaletteID's
shade-to-index formula, cross-checked three ways (decomp control flow,
ACE's PaletteSet.GetPaletteID "Taken from acclient.c" citation, ACViewer's
identical slider math). ChargenPalSet/ChargenClothingTable are pure
projections behind IChargenPalSetSource/IChargenClothingTableSource so the
factory itself never touches a dat.

Content (src/AcDream.Content/CharGen/): ChargenAppearanceCatalog is the
cached dat-backed implementation of those two source interfaces, mirroring
ChargenTableReader's no-leak discipline.

App (src/AcDream.App/Rendering/): ChargenPreviewRenderer is a third facade
over PrivateEntityViewportRenderer beside PaperdollViewportRenderer and
CreatureAppraisalViewportRenderer - no existing rendering file touched.
ChargenPreviewCamera carries the four retail-verbatim per-heritage eye
profiles from gmCGAppearancePage::Update @0x0047E8F0 (cross-checked
against ZoomIn/ZoomOut's identical literals) plus the recovered rotation
(3.0 s/revolution) and zoom-tween (0.6 s, reconstructed from the
decompiler's garbled float literals - the plan's own "measure if it
matters" note is resolved, not garbled beyond recovery). Rotation applies
to the character model, not the camera, per gmCGAppearancePage::DoRotation.
ChargenPreviewEntityBuilder resolves Setup/GfxObj/Surface/Animation itself
(there is no live entity yet), reusing DatLiveEntityProjectionMaterializer's
surface-override algorithm and RetailPaperdollPoseApplicator's held-pose
technique, generalized to chargen's per-heritage rest-pose DID.

Two register rows filed: TS-83 (the plan-named CC6a static-pose-vs-retail-
idle-loop staging, CC6b to retire) and TS-82 (measured, not assumed - the
un-ported clothing Setup-substitution fallback chain costs nothing for the
9 standard heritages with clothing UI, but Undead's default gear choices
genuinely lack ClothingBaseEffects coverage for Undead's own body Setup).

Tests: ChargenPalSetMathTests, ChargenAppearanceFactoryTests (hand-built
fixtures), ChargenAppearanceCatalogInstalledDatTests (installed-DAT sweep,
all 26 heritage/gender combinations, zero missing PalSet/ClothingTable
ids), ChargenPreviewCameraTests, ChargenPreviewEntityBuilderTests
(installed-DAT-gated, proves a real 34-part Aluvian mesh resolves).
Core.Tests 4767/1 skip, Content.Tests 146/0, App.Tests 5121/6 skips - all
pre-existing skips, zero failures, full solution Release build green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-15 17:22:06 +02:00

110 lines
4.6 KiB
C#

using System.Numerics;
using AcDream.App.Rendering;
using AcDream.Core.CharGen;
using Xunit;
namespace AcDream.App.Tests.Rendering;
/// <summary>
/// Pins <see cref="ChargenPreviewCamera"/>'s retail-verbatim per-heritage
/// eye positions (<c>gmCGAppearancePage::Update @ 0x0047E8F0</c>,
/// cross-checked against the identical literals in <c>ZoomIn</c>/<c>ZoomOut
/// @ 0x0047CF00</c>/<c>0x0047D050</c>) and the zero-yaw/zero-pitch look
/// convention DollCameraTests already established for the shared private
/// viewport.
/// </summary>
public class ChargenPreviewCameraTests
{
[Theory]
[InlineData((uint)ChargenHeritageGroup.Aluvian, 0f, -0.550000012f, 1.64999998f)]
[InlineData((uint)ChargenHeritageGroup.Gharundim, 0f, -0.550000012f, 1.64999998f)]
[InlineData((uint)ChargenHeritageGroup.Gearknight, 0f, -0.550000012f, 1.64999998f)]
[InlineData((uint)ChargenHeritageGroup.Undead, 0f, -0.550000012f, 1.64999998f)]
[InlineData((uint)ChargenHeritageGroup.Tumerok, 0f, -0.850000024f, 1.64999998f)]
[InlineData((uint)ChargenHeritageGroup.Olthoi, 0f, -1.85000002f, 1.85000002f)]
[InlineData((uint)ChargenHeritageGroup.OlthoiAcid, 0f, -3.04999995f, 2.75f)]
public void ResolveDefaultEye_MatchesRetailPerHeritageLiterals(uint heritageId, float x, float y, float z)
{
Vector3 eye = ChargenPreviewCamera.ResolveDefaultEye(heritageId);
Assert.Equal(x, eye.X, 4);
Assert.Equal(y, eye.Y, 4);
Assert.Equal(z, eye.Z, 4);
}
[Theory]
[InlineData((uint)ChargenHeritageGroup.Aluvian, 0f, -2.5f, 0.95f)]
[InlineData((uint)ChargenHeritageGroup.Tumerok, 0f, -2.5f, 0.95f)] // ZoomOut has NO Tumerok special case, unlike the zoomed-in default.
[InlineData((uint)ChargenHeritageGroup.Olthoi, 0f, -3.79999995f, 1.14999998f)]
[InlineData((uint)ChargenHeritageGroup.OlthoiAcid, 0f, -5.69999981f, 1.64999998f)]
public void ResolveZoomedOutEye_MatchesRetailPerHeritageLiterals(uint heritageId, float x, float y, float z)
{
Vector3 eye = ChargenPreviewCamera.ResolveZoomedOutEye(heritageId);
Assert.Equal(x, eye.X, 4);
Assert.Equal(y, eye.Y, 4);
Assert.Equal(z, eye.Z, 4);
}
[Fact]
public void Constructor_DefaultsToStandardHeritageEye_ForUnknownHeritageId()
{
var cam = new ChargenPreviewCamera(heritageId: 0u);
Assert.Equal(ChargenPreviewCamera.ResolveDefaultEye(0u), cam.Eye);
}
[Fact]
public void SetHeritage_UpdatesEyeToTheNewHeritagesProfile()
{
var cam = new ChargenPreviewCamera((uint)ChargenHeritageGroup.Aluvian);
cam.SetHeritage((uint)ChargenHeritageGroup.Olthoi);
Assert.Equal(ChargenPreviewCamera.ResolveDefaultEye((uint)ChargenHeritageGroup.Olthoi), cam.Eye);
}
[Fact]
public void View_LooksStraightDownPlusY_ZeroYawZeroPitch()
{
// Same identity-direction convention DollCameraTests pins for the paperdoll:
// retail SetCameraDirection(0,0,0) resets the view frame to IDENTITY.
var cam = new ChargenPreviewCamera((uint)ChargenHeritageGroup.Aluvian) { Aspect = 1f };
var forward = -new Vector3(cam.View.M13, cam.View.M23, cam.View.M33);
Assert.Equal(0f, forward.X, 4);
Assert.Equal(1f, forward.Y, 4);
Assert.Equal(0f, forward.Z, 4);
}
[Fact]
public void Eye_RoundTripsThroughViewMatrixInversion()
{
var cam = new ChargenPreviewCamera((uint)ChargenHeritageGroup.Olthoi) { Aspect = 1f };
Assert.True(Matrix4x4.Invert(cam.View, out var inv));
Vector3 eye = inv.Translation;
Assert.Equal(cam.Eye.X, eye.X, 3);
Assert.Equal(cam.Eye.Y, eye.Y, 3);
Assert.Equal(cam.Eye.Z, eye.Z, 3);
}
[Fact]
public void Projection_IsFiniteAndUsesAspect()
{
var cam = new ChargenPreviewCamera { Aspect = 1.5f };
Assert.True(float.IsFinite(cam.Projection.M11));
Assert.NotEqual(0f, cam.Projection.M34);
}
[Fact]
public void RotationSecondsPerRevolution_IsExactlyThreeSeconds()
{
// Raw double bits low32=0x00000000, high32=0x40080000 — no
// reconstruction needed, the decompiler shows this one cleanly.
Assert.Equal(3.0f, ChargenPreviewCamera.RotationSecondsPerRevolution);
}
[Fact]
public void ZoomTweenDurationSeconds_IsExactlyZeroPointSix()
{
// Recovered by reinterpreting the decompiler's garbled float literal
// as the raw low-32-bit store and pairing it with the (clean) high
// dword; cross-confirmed via the -0.1 sentinel in ZoomIn/ZoomOut
// reconstructing to the well-known IEEE-754 bit pattern for -0.1.
Assert.Equal(0.6f, ChargenPreviewCamera.ZoomTweenDurationSeconds);
}
}