fix #426: extract solid-colour (NO_POS_UVS) faces; skip untextured subsets only on building shells and cells like retail

The Holtburg windmill axle (GfxObj 0x010010CE, 8 polygons, all
Stippling.NoPos + SurfaceType.Base1Solid) extracted to a 0-vertex mesh.
NoPos ("NO_POS_UVS", acclient.h:7380-7388) means "this side has no
texture coordinates" — true of every solid-colour polygon, since
nothing samples them — not "there is no positive face". Extraction read
it as the latter and dropped the polygon entirely, client-wide, for
every untextured polygon on every object.

Retail's D3DPolyRender::DrawMesh (@0x0059d4a0, named-retail decomp
~line 426048) draws an untextured subset on an ordinary object exactly
like a textured one; the only retail cases that skip an untextured
subset are a building shell (RenderDeviceD3D::DrawBuilding @0x0059f2a0
sets ObjBuildingOrBuildingPart=1) or an EnvCell interior
(RenderDeviceD3D::DrawEnvCell @0x0059f170, arg4=1). The #119
investigation's "retail's skipNoTexture never draws them either"
conclusion was itself wrong as a general rule.

- MeshExtractor.PrepareGfxObjMeshData / GfxObjMesh.Build: emit the
  positive side whenever PosSurface is a valid index, regardless of
  NoPos; the existing UV-index-0 fallback already produces zero
  texcoords for a NoPos polygon with no UVs on the wire.
- RetailUntexturedSurfacePolicy.IsUntextured(SurfaceType): the one
  place that answers "is this surface textured"
  ((type & (Base1Image|Base1ClipMap)) == 0), replacing the old
  `isSolid = NoPos || Base1Solid` (which also mis-classified a NEG-side
  batch by the POS-side's NoPos flag).
- RetailUntexturedSubsetPolicy.Draws(isBuildingShell, isUntextured):
  the shared draw-time gate wired into WbDrawDispatcher.ClassifyBatches,
  .PackedOracle.ClassifyPackedBatches, and
  .DirectionalShadows.AddDirectionalShadowBatches — one predicate so the
  three walks cannot drift (Campaign VM VM6 lesson).
- CellMesh.cs / MeshExtractor.PrepareCellStructMeshData deliberately
  KEEP their NoPos-gated skip for cell-wall geometry — retail's
  DrawEnvCell really does skip untextured subsets there; register row
  AP-234 documents the NoPos-vs-Surface.Type approximation.
- PakFormat.CurrentBakeToolVersion 4->5 (LauncherInstallRecordStore in
  lockstep): a pak baked by an older tool is missing every untextured
  face. No bake was run as part of this commit.

Also fixed: WorldBuilder's own upstream ObjectMeshManager.cs has the
identical NoPos bug (ObjectMeshManager.cs:959,984) — our port had
faithfully carried it over, and our own conformance test
(Build_NoPosFlag_OnlyEmitsNegSide) asserted the bug as correct WB
conformance. Renamed/reworded to Build_NoPosFlag_EmitsBothPosAndNegSide
with a citation for why retail decomp overrides WB here.

Issue119UpNullGfxObjDumpTests re-run against the installed DAT:
#119's own two objects (0x010002B4 9/9 polys, 0x010008A8 1/1 poly) now
gate DRAWS on every polygon instead of extracting to nothing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-23 11:20:24 +02:00
parent 51a5fe99ef
commit 517d17b4b3
18 changed files with 755 additions and 40 deletions

View file

@ -24,6 +24,74 @@ What does NOT go here:
- Every session: scan OPEN issues at start; promote/close anything we touched during the session before ending. - Every session: scan OPEN issues at start; promote/close anything we touched during the session before ending.
- Promoting to a Phase: mark as `DONE (promoted to Phase X)` + commit SHA where the Phase entry landed. - Promoting to a Phase: mark as `DONE (promoted to Phase X)` + commit SHA where the Phase entry landed.
## #426 — Every solid-colour (untextured) polygon on every object client-wide was invisible: mesh extraction misread NO_POS_UVS as "no positive face"
**Status:** ✅ FIXED 2026-08-23 (found on the Holtburg windmill axle, GfxObj
0x010010CE, 30.4N 28.2E).
**Component:** content extraction (`MeshExtractor`/`GfxObjMesh`) + draw-time
classification (`WbDrawDispatcher`)
**Symptom:** the windmill axle's 8 polygons (all `Stippling.NoPos` +
`SurfaceType.Base1Solid`) extracted to a 0-vertex mesh —
`[up-null] 0x010010CE produced a 0-vertex mesh`. Not an isolated case: EVERY
flat-coloured (untextured) polygon on EVERY GfxObj client-wide extracted to
nothing, because `PrepareGfxObjMeshData`/`GfxObjMesh.Build` gated emission of
a polygon's positive side on `!Stippling.HasFlag(StipplingType.NoPos)`.
**Root cause:** `StipplingType.NoPos` (`NO_POS_UVS = 0x4`,
`docs/research/named-retail/acclient.h:7380-7388`) means "this side has no
texture coordinates" — true of every solid-colour polygon, since nothing
samples them — NOT "there is no positive face". The extraction code read it
as the latter and silently dropped the polygon entirely. Retail's
`D3DPolyRender::DrawMesh` (@0x0059d4a0,
`docs/research/named-retail/acclient_2013_pseudo_c.txt` ~line 426048) draws
an untextured subset (`(surface->type & 6) == 0`, i.e. neither
`BASE1_IMAGE` nor `BASE1_CLIPMAP`) on an ORDINARY object exactly like a
textured one; the ONLY retail cases that skip an untextured subset are a
BUILDING SHELL (`RenderDeviceD3D::DrawBuilding` @0x0059f2a0 sets
`ObjBuildingOrBuildingPart = 1`) and an EnvCell interior
(`RenderDeviceD3D::DrawEnvCell` @0x0059f170, `arg4 = 1`). The earlier #119
investigation's "retail's skipNoTexture never draws them either" conclusion
was itself wrong — that only happened to hold for #119's two specific
GfxObjs because retail's per-model draw call passes `arg4` from the caller's
own context, not because untextured subsets are universally skipped (see the
#119 amendment below).
**Fix:** `MeshExtractor.PrepareGfxObjMeshData` and `GfxObjMesh.Build` now
emit a polygon's positive side whenever `PosSurface` is a valid index,
regardless of NoPos; a NoPos polygon with no UVs on the wire falls back to
UV index 0 / zero texcoords (the pre-existing fallback path, unchanged).
`RetailUntexturedSurfacePolicy.IsUntextured(SurfaceType)`
(`src/AcDream.Core/Meshing/RetailUntexturedSurfacePolicy.cs`) is the ONE
place that now answers "is this surface textured", built from the surface's
own `Type` flags (`Base1Image`/`Base1ClipMap`) instead of the polygon's
Stippling — `MeshExtractor`'s `isSolid`/`TextureKey.IsSolid` now uses it
(previously `isSolid = NoPos || Base1Solid`, which also mis-classified a
NEG-side batch by the POS-side's NoPos flag). `RetailUntexturedSubsetPolicy
.Draws(isBuildingShell, isUntextured)` in the same file is the shared
draw-time predicate wired into `WbDrawDispatcher.ClassifyBatches`,
`.PackedOracle.ClassifyPackedBatches`, and
`.DirectionalShadows.AddDirectionalShadowBatches` — the ONE thing that
still skips an untextured subset is a building-shell entity, matching
retail's `DrawBuilding` gate; the shadow caster and receiver agree by
construction. `CellMesh.cs` and `MeshExtractor.PrepareCellStructMeshData`
(EnvCell/cell-wall geometry) deliberately KEEP their existing NoPos-gated
skip — retail's `DrawEnvCell` really does skip untextured cell subsets, and
the NoPos flag remains an approximation of that rule rather than a bug (see
register row AP-234).
**Verification:** `Issue119UpNullGfxObjDumpTests` (Lane=InstalledDat) reran
against the installed DAT post-fix: #119's own two objects (0x010002B4, 9/9
polygons; 0x010008A8, 1/1 polygon — both all-NoPos+Base1Solid) now gate
`DRAWS` on every polygon instead of producing a 0-vertex mesh.
**Pak version:** `PakFormat.CurrentBakeToolVersion` 4→5 (also
`LauncherInstallRecordStore.CurrentBakeToolVersion`, kept in lockstep) — a
pak baked by an older tool is missing every untextured face and MUST be
regenerated; no bake was run as part of this fix (out of scope for a code
commit — the next scheduled bake picks it up via the version bump forcing a
rebuild).
## #425 — Options Apply "Atmospheric rendering" fell back to the default path and stayed locked out: Low's 64 MiB resident budget did not scale with resolution ## #425 — Options Apply "Atmospheric rendering" fell back to the default path and stayed locked out: Low's 64 MiB resident budget did not scale with resolution
**Status:** ✅ FIXED 2026-08-23 (found at the owner's VM3/VM6 gate launch). **Status:** ✅ FIXED 2026-08-23 (found at the owner's VM3/VM6 gate launch).
@ -16763,6 +16831,18 @@ failing step pins which candidate fires.
**Filed:** 2026-06-11 (T5 comprehensive gate, user items 9+13) **Filed:** 2026-06-11 (T5 comprehensive gate, user items 9+13)
**Component:** render — mesh upload / content inclusion **Component:** render — mesh upload / content inclusion
**AMENDED 2026-08-23 (#426):** the "Retail's skipNoTexture never draws them
either" conclusion below is WRONG as a general rule — retail only skips an
untextured (solid-colour) subset on a BUILDING SHELL or inside an EnvCell;
an ORDINARY object's untextured polygons DO draw, and the extraction was
dropping every one of them client-wide via a NoPos misread (fixed by #426).
Post-fix, `Issue119UpNullGfxObjDumpTests` shows BOTH of this entry's
GfxObjs now gate DRAWS on every polygon instead of extracting to nothing —
whether that geometry is actually visible on screen (i.e. whether either
object is a building-shell part, which would still skip it at draw time)
is unverified and NOT the same question as the extraction-level "no draw"
claim this entry made in 2026-06-12.
**RESOLUTION (2026-06-12) — three root causes, fixed in sequence, each **RESOLUTION (2026-06-12) — three root causes, fixed in sequence, each
pinned by the ACDREAM_DUMP_ENTITY decisive probe (`3cf6bcc`):** pinned by the ACDREAM_DUMP_ENTITY decisive probe (`3cf6bcc`):**
1. **`2163308` — Tier-1 cross-entity batch serving** (the broken stairs + 1. **`2163308` — Tier-1 cross-entity batch serving** (the broken stairs +

File diff suppressed because one or more lines are too long

View file

@ -1661,16 +1661,36 @@ namespace AcDream.App.Rendering.Wb
var renderData = UploadGfxObjMeshData(meshData); var renderData = UploadGfxObjMeshData(meshData);
if (renderData == null) if (renderData == null)
{ {
// 0-vertex mesh: every polygon was gated out at extraction. #119 // 0-vertex mesh: every polygon was gated out at extraction.
// (2026-06-11) dat-verified this is LEGITIMATE for all-no-draw // #119 (2026-06-11) ORIGINALLY reasoned this is LEGITIMATE
// models (all polys NoPos + Base1Solid surfaces — retail's // for every all-NoPos+Base1Solid ("all-no-draw") model,
// skipNoTexture never draws them either; 0x010002B4/0x010008A8 // claiming retail's skipNoTexture never draws untextured
// are this class, Issue119UpNullGfxObjDumpTests). The empty // subsets at all. #426 (2026-08-23, the Holtburg windmill
// cache is the correct terminal state for those. The line stays // axle 0x010010CE) corrected that: retail's skipNoTexture
// as a tripwire for the OTHER way to get here (extraction // only suppresses untextured subsets on a BUILDING SHELL
// dropped textured polys — a real defect; dat-verify with the // (RenderDeviceD3D::DrawBuilding @0x0059f2a0 sets
// dump test before treating as one). // ObjBuildingOrBuildingPart=1) or inside an EnvCell
Console.WriteLine($"[up-null] 0x{meshData.ObjectId:X10} produced a 0-vertex mesh — caching empty render data (legitimate for all-no-draw models; dat-verify via Issue119UpNullGfxObjDumpTests)"); // interior (DrawEnvCell @0x0059f170, arg4=1) — an
// ORDINARY object's untextured (solid-colour) polygons DO
// draw (D3DPolyRender::DrawMesh(..., arg4=0)). Extraction
// now emits the positive side for every polygon with a
// valid PosSurface regardless of NoPos, so a 0-vertex
// mesh here is legitimate ONLY for a model whose every
// polygon is degenerate (fewer than 3 vertices) or
// references no valid Surface index at all.
// Issue119UpNullGfxObjDumpTests' own dump against the
// installed DAT confirms #119's original two objects
// (0x010002B4, 9 polys; 0x010008A8, 1 poly — both
// all-NoPos+Base1Solid) now gate DRAWS on every polygon
// and are NOT examples of the legitimate 0-vertex case
// any more; they were never actually all-degenerate or
// all-invalid-surface, they were all-solid, which #426
// now extracts. The line stays as a tripwire for the
// OTHER way to get here (extraction dropped textured
// polys — a real defect;
// dat-verify with the dump test before treating a hit as
// legitimate).
Console.WriteLine($"[up-null] 0x{meshData.ObjectId:X10} produced a 0-vertex mesh — caching empty render data (legitimate only for degenerate/no-valid-surface models post-#426; dat-verify via Issue119UpNullGfxObjDumpTests)");
renderData = new ObjectRenderData(); renderData = new ObjectRenderData();
} }

View file

@ -1183,6 +1183,15 @@ public sealed partial class WbDrawDispatcher
batchIndex++) batchIndex++)
{ {
ObjectRenderBatch batch = renderData.Batches[batchIndex]; ObjectRenderBatch batch = renderData.Batches[batchIndex];
// #426: a batch retail never draws for this entity casts no
// shadow either — same gate as ClassifyBatches/
// ClassifyPackedBatches (RetailUntexturedSubsetPolicy), so the
// caster and receiver agree by construction (mirrors the
// FoliageWindClassification comment below).
if (!RetailUntexturedSubsetPolicy.Draws(candidate.IsBuildingShell, batch.Key.IsSolid))
continue;
sourceBatches++; sourceBatches++;
if (!DirectionalShadowPreparedDraws.TryClassifyMaterial( if (!DirectionalShadowPreparedDraws.TryClassifyMaterial(
batch.Translucency, batch.Translucency,

View file

@ -631,6 +631,14 @@ public sealed unsafe partial class WbDrawDispatcher
{ {
ObjectRenderBatch batch = ObjectRenderBatch batch =
renderData.Batches[batchIndex]; renderData.Batches[batchIndex];
// #426: mirrors the classic ClassifyBatches gate exactly — see
// RetailUntexturedSubsetPolicy for the retail citation. ONE
// shared predicate so the classic and packed classifiers cannot
// drift (Campaign VM VM6).
if (!RetailUntexturedSubsetPolicy.Draws(entity.IsBuildingShell, batch.Key.IsSolid))
continue;
TranslucencyKind translucency = batch.Translucency; TranslucencyKind translucency = batch.Translucency;
if (opacity < 1f && IsOpaque(translucency)) if (opacity < 1f && IsOpaque(translucency))
translucency = TranslucencyKind.AlphaBlend; translucency = TranslucencyKind.AlphaBlend;

View file

@ -3421,6 +3421,15 @@ public sealed partial class WbDrawDispatcher : IDisposable
{ {
var batch = renderData.Batches[batchIdx]; var batch = renderData.Batches[batchIdx];
// #426: retail's D3DPolyRender::DrawMesh skips an UNTEXTURED
// (solid-colour) subset only on a BUILDING SHELL
// (RenderDeviceD3D::DrawBuilding sets ObjBuildingOrBuildingPart);
// ordinary statics/scenery/creatures/items draw it same as any
// textured subset. ONE shared predicate with ClassifyPackedBatches
// and AddDirectionalShadowBatches — see RetailUntexturedSubsetPolicy.
if (!RetailUntexturedSubsetPolicy.Draws(entity.IsBuildingShell, batch.Key.IsSolid))
continue;
TranslucencyKind translucency = batch.Translucency; TranslucencyKind translucency = batch.Translucency;
// #188: a mid-fade instance whose surface is otherwise Opaque/ClipMap // #188: a mid-fade instance whose surface is otherwise Opaque/ClipMap

View file

@ -347,9 +347,20 @@ public sealed class MeshExtractor {
if (poly.VertexIds.Count < 3) continue; if (poly.VertexIds.Count < 3) continue;
// Handle Positive Surface // Handle Positive Surface
if (!poly.Stippling.HasFlag(StipplingType.NoPos)) { // #426 (2026-08-23, Holtburg windmill axle 0x010010CE): NoPos
AddSurfaceToBatch(poly, poly.PosSurface, false); // ("NO_POS_UVS", acclient.h:7386) means "this side has no texture
} // coordinates" — that's true of every SOLID-COLOUR polygon, not
// "there is no positive face". Retail's D3DPolyRender::DrawMesh
// draws untextured (solid) subsets on ordinary objects same as
// textured ones (see RetailUntexturedSurfacePolicy); only a
// building shell or an EnvCell interior skips them, and that is
// a DRAW-time decision (RetailUntexturedSubsetPolicy, applied in
// WbDrawDispatcher), not an extraction-time one. So the positive
// side is always emitted when PosSurface is a valid index;
// AddSurfaceToBatch already falls back to UV index 0 / zero
// texcoords (via BuildPolygonIndices) when NoPos leaves no UVs to
// read.
AddSurfaceToBatch(poly, poly.PosSurface, false);
// Handle Negative Surface // Handle Negative Surface
// Some objects use Clockwise CullMode to indicate negative surface data is present // Some objects use Clockwise CullMode to indicate negative surface data is present
@ -376,7 +387,13 @@ public sealed class MeshExtractor {
TextureFormat textureFormat; TextureFormat textureFormat;
UploadPixelFormat? uploadPixelFormat = null; UploadPixelFormat? uploadPixelFormat = null;
UploadPixelType? uploadPixelType = null; UploadPixelType? uploadPixelType = null;
bool isSolid = poly.Stippling.HasFlag(StipplingType.NoPos) || surface.Type.HasFlag(SurfaceType.Base1Solid); // #426: "solid" (untextured) is a SURFACE fact, not a
// polygon-stippling fact — see RetailUntexturedSurfacePolicy.
// The old `NoPos ||` term conflated "this polygon's positive
// side has no UVs" with "this surface is untextured"; it also
// wrongly classified a NEG-side batch by the POS-side's NoPos
// flag, since this method is shared by both sides.
bool isSolid = RetailUntexturedSurfacePolicy.IsUntextured(surface.Type);
bool isClipMap = surface.Type.HasFlag(SurfaceType.Base1ClipMap); bool isClipMap = surface.Type.HasFlag(SurfaceType.Base1ClipMap);
uint paletteId = 0; uint paletteId = 0;
bool isDxt3or5 = false; bool isDxt3or5 = false;
@ -710,6 +727,20 @@ public sealed class MeshExtractor {
// GL cull enum: 0 = pos, 1 = pos twice with reversed winding, // GL cull enum: 0 = pos, 1 = pos twice with reversed winding,
// 2 = pos + neg surface. The DAT-side NoPos/NoNeg flags still // 2 = pos + neg surface. The DAT-side NoPos/NoNeg flags still
// suppress hidden portal/cap faces before they reach our mesh. // suppress hidden portal/cap faces before they reach our mesh.
//
// #426: unlike PrepareGfxObjMeshData (ordinary objects — fixed to
// emit every NoPos-flagged positive side, since NoPos means "no
// UVs", not "no face"), this NoPos gate is INTENTIONALLY kept.
// Cell-wall geometry draws through retail's
// RenderDeviceD3D::DrawEnvCell (@0x0059f170), which calls
// D3DPolyRender::DrawMesh with arg4=1 and skips every UNTEXTURED
// subset — approximated here by the polygon's own NoPos flag
// rather than by resolving Surface.Type
// (Base1Image/Base1ClipMap, see RetailUntexturedSurfacePolicy)
// before this decision is made. See
// docs/architecture/retail-divergence-register.md AP-234. Do NOT
// remove this gate to mirror the GfxObj fix — that would draw
// solid-colour cell-wall faces retail never shows.
bool hasPos = !poly.Stippling.HasFlag(StipplingType.NoPos); bool hasPos = !poly.Stippling.HasFlag(StipplingType.NoPos);
bool hasNeg = !poly.Stippling.HasFlag(StipplingType.NoNeg); bool hasNeg = !poly.Stippling.HasFlag(StipplingType.NoNeg);
@ -745,7 +776,13 @@ public sealed class MeshExtractor {
TextureFormat textureFormat; TextureFormat textureFormat;
UploadPixelFormat? uploadPixelFormat = null; UploadPixelFormat? uploadPixelFormat = null;
UploadPixelType? uploadPixelType = null; UploadPixelType? uploadPixelType = null;
bool isSolid = poly.Stippling.HasFlag(StipplingType.NoPos) || surface.Type.HasFlag(SurfaceType.Base1Solid); // #426: "solid" (untextured) is a SURFACE fact, not a
// polygon-stippling fact — see RetailUntexturedSurfacePolicy.
// The old `NoPos ||` term conflated "this polygon's positive
// side has no UVs" with "this surface is untextured"; it also
// wrongly classified a NEG-side batch by the POS-side's NoPos
// flag, since this method is shared by both sides.
bool isSolid = RetailUntexturedSurfacePolicy.IsUntextured(surface.Type);
bool isClipMap = surface.Type.HasFlag(SurfaceType.Base1ClipMap); bool isClipMap = surface.Type.HasFlag(SurfaceType.Base1ClipMap);
uint paletteId = 0; uint paletteId = 0;
bool isDxt3or5 = false; bool isDxt3or5 = false;

View file

@ -22,9 +22,15 @@ public static class PakFormat {
/// version 3 embeds exact render-pass translucency in each texture batch /// version 3 embeds exact render-pass translucency in each texture batch
/// so production never rebuilds surface metadata from live DAT. Version 4 /// so production never rebuilds surface metadata from live DAT. Version 4
/// adds complete immutable flat collision and EnvCell-topology payloads. /// adds complete immutable flat collision and EnvCell-topology payloads.
/// The binary format remains version 1. /// Version 5 (#426, 2026-08-23) extracts untextured (solid-colour)
/// positive faces that versions &lt;=4 dropped — every GfxObj polygon
/// whose Stippling carries NoPos (NO_POS_UVS) previously extracted to
/// zero vertices on its positive side, so any pak baked by an older tool
/// is missing those faces (e.g. the Holtburg windmill axle 0x010010CE,
/// 8 polygons all NoPos + Base1Solid, extracted to a 0-vertex mesh). The
/// binary format remains version 1.
/// </summary> /// </summary>
public const uint CurrentBakeToolVersion = 4; public const uint CurrentBakeToolVersion = 5;
} }
/// <summary> /// <summary>

View file

@ -41,7 +41,19 @@ public static class CellMesh
if (poly.VertexIds.Count < 3) if (poly.VertexIds.Count < 3)
continue; // degenerate polygon continue; // degenerate polygon
// Skip if NoPos stippling is set (polygon has no positive surface geometry). // Retail's RenderDeviceD3D::DrawEnvCell (@0x0059f170) calls
// D3DPolyRender::DrawMesh with arg4=1, which skips every
// UNTEXTURED subset inside an EnvCell interior — unlike ordinary
// objects, which draw them (see RetailUntexturedSurfacePolicy /
// RetailUntexturedSubsetPolicy, #426). We approximate
// "untextured" here with the polygon's own NoPos stippling flag
// rather than resolving the Surface's own Type
// (Base1Image/Base1ClipMap) before this per-polygon decision —
// see docs/architecture/retail-divergence-register.md AP-234. Do
// NOT remove this gate the way #426 removed the matching gate in
// GfxObjMesh.Build/MeshExtractor.PrepareGfxObjMeshData — retail
// genuinely skips untextured cell geometry, unlike ordinary
// objects.
if (poly.Stippling.HasFlag(DatReaderWriter.Enums.StipplingType.NoPos)) if (poly.Stippling.HasFlag(DatReaderWriter.Enums.StipplingType.NoPos))
continue; continue;

View file

@ -28,8 +28,16 @@ public static class GfxObjMesh
/// The rule for emitting a polygon side: /// The rule for emitting a polygon side:
/// </para> /// </para>
/// <list type="bullet"> /// <list type="bullet">
/// <item><b>Pos side:</b> emit whenever <c>!Stippling.NoPos</c> and /// <item><b>Pos side:</b> emit whenever <c>PosSurface</c> is a valid
/// <c>PosSurface</c> is a valid index.</item> /// index, REGARDLESS of <c>Stippling.NoPos</c>. #426
/// (2026-08-23): NoPos ("NO_POS_UVS", acclient.h:7386) means
/// "this side has no texture coordinates" — every solid-colour
/// polygon carries it, since it has no UVs to carry — not "there
/// is no positive face". Retail's <c>D3DPolyRender::DrawMesh</c>
/// draws untextured (solid) subsets on ordinary objects the same
/// as textured ones (see <see cref="RetailUntexturedSurfacePolicy"/>);
/// a NoPos polygon with no UVs to read falls back to UV index 0 /
/// zero texcoords below.</item>
/// <item><b>Neg side:</b> emit when /// <item><b>Neg side:</b> emit when
/// <c>Stippling.Negative</c>, <c>Stippling.Both</c>, or /// <c>Stippling.Negative</c>, <c>Stippling.Both</c>, or
/// <c>(!Stippling.NoNeg &amp;&amp; SidesType == CullMode.Clockwise)</c>. /// <c>(!Stippling.NoNeg &amp;&amp; SidesType == CullMode.Clockwise)</c>.
@ -69,9 +77,10 @@ public static class GfxObjMesh
continue; // degenerate — can't form a triangle continue; // degenerate — can't form a triangle
// --- Positive side --- // --- Positive side ---
bool hasPos = !poly.Stippling.HasFlag(StipplingType.NoPos); // #426: always emit — NoPos only means "no positive UVs", not
if (hasPos) // "no positive face" (see the class doc). EmitSide's own
EmitSide(poly, poly.PosSurface, isNeg: false); // surfaceIdx-validity guard is the only real gate.
EmitSide(poly, poly.PosSurface, isNeg: false);
// --- Negative side --- // --- Negative side ---
// Three ways AC flags a polygon as double-sided: // Three ways AC flags a polygon as double-sided:

View file

@ -0,0 +1,76 @@
using DatReaderWriter.Enums;
namespace AcDream.Core.Meshing;
/// <summary>
/// Retail's textured-vs-untextured surface classification, ported from
/// <c>D3DPolyRender::DrawMesh</c> @0x0059d4a0 (named-retail decomp,
/// docs/research/named-retail/acclient_2013_pseudo_c.txt ~line 426048): a
/// surface subset is TEXTURED — and therefore never subject to either of
/// retail's "skip untextured" gates (see
/// <see cref="RetailUntexturedSubsetPolicy"/>) — when
/// <c>(surface-&gt;type &amp; 6) != 0</c>, i.e. when
/// <see cref="SurfaceType.Base1Image"/> (<c>BASE1_IMAGE</c>, 0x2) or
/// <see cref="SurfaceType.Base1ClipMap"/> (<c>BASE1_CLIPMAP</c>, 0x4) is set
/// (docs/research/named-retail/acclient.h:5822-5824). Every other surface —
/// including <see cref="SurfaceType.Base1Solid"/> and any surface whose type
/// carries neither bit — is UNTEXTURED: a flat-colour ("solid") subset filled
/// from <c>Surface.ColorValue</c> rather than a decoded texture.
/// </summary>
/// <remarks>
/// #426 (2026-08-23, the Holtburg windmill axle 0x010010CE): the polygon-side
/// <c>StipplingType.NoPos</c> flag ("this side has no texture coordinates",
/// acclient.h:7386) is NOT the same fact as "this surface is untextured" —
/// every solid-colour polygon carries NoPos (it has no UVs to carry), but
/// NoPos says nothing about whether the surface itself is textured. The old
/// extraction conflated the two (<c>isSolid = NoPos || Base1Solid</c>) and,
/// worse, used NoPos to decide whether to emit the polygon's positive side AT
/// ALL — dropping every solid-colour polygon on every object. This type is
/// the ONE place that answers "is this surface textured", built from the
/// Surface's own Type flags so extraction (isSolid / TextureKey.IsSolid) and
/// draw-time skip policy agree by construction.
/// </remarks>
public static class RetailUntexturedSurfacePolicy
{
public static bool IsUntextured(SurfaceType type) =>
(type & (SurfaceType.Base1Image | SurfaceType.Base1ClipMap)) == 0;
}
/// <summary>
/// Retail's draw-time policy for an UNTEXTURED (solid-colour) mesh subset on
/// an ordinary <see cref="AcDream.Core.World.WorldEntity"/>, ported from the
/// same <c>D3DPolyRender::DrawMesh</c> untextured branch: the subset draws
/// unless <c>skipNoTexture != 0 &amp;&amp;
/// RenderDeviceD3D::ObjBuildingOrBuildingPart != 0</c>. <c>skipNoTexture</c>
/// @0x00820e30 is a global initialised to 1 and never cleared, so in
/// practice the gate reduces to
/// <c>RenderDeviceD3D::ObjBuildingOrBuildingPart == 0</c>.
/// <c>RenderDeviceD3D::DrawBuilding</c> (@0x0059f2a0) sets that flag around
/// the building-shell draw, so a building shell's own untextured subsets are
/// the ONE case where an ordinary WorldEntity skips them — statics, scenery,
/// creatures, and items (<c>DrawMeshInternal</c> @0x0059f360 →
/// <c>DrawMesh(gfxobj, mesh, arg4: 0)</c>) always draw their untextured
/// subsets.
/// </summary>
/// <remarks>
/// EnvCell interiors are retail's OTHER "skip untextured" case
/// (<c>RenderDeviceD3D::DrawEnvCell</c> @0x0059f170 calls
/// <c>DrawMesh(..., arg4: 1)</c>), but EnvCell/CellStruct geometry never
/// reaches this predicate — it draws through <c>EnvCellRenderer</c> /
/// <c>MeshExtractor.PrepareCellStructMeshData</c>, which keeps its own
/// NoPos-based approximation of the same rule (see
/// <c>docs/architecture/retail-divergence-register.md</c> AP-234 and
/// <c>CellMesh.cs</c>'s matching gate).
/// <para>
/// ONE shared predicate for <c>WbDrawDispatcher</c>'s classic classifier
/// (<c>ClassifyBatches</c>), packed classifier (<c>ClassifyPackedBatches</c>),
/// and the directional-shadow caster walk (<c>AddDirectionalShadowBatches</c>)
/// — Campaign VM VM6 showed that two hand-maintained classifiers computing
/// the "same" fact independently drift apart.
/// </para>
/// </remarks>
public static class RetailUntexturedSubsetPolicy
{
public static bool Draws(bool isBuildingShell, bool isUntextured) =>
!isUntextured || !isBuildingShell;
}

View file

@ -29,7 +29,10 @@ public sealed record InstallRecordVerification(
/// </summary> /// </summary>
public sealed class LauncherInstallRecordStore public sealed class LauncherInstallRecordStore
{ {
public const uint CurrentBakeToolVersion = 4; // Kept in lockstep with AcDream.Content.Pak.PakFormat.CurrentBakeToolVersion
// (#426, 2026-08-23: version 5 extracts untextured/solid-colour positive
// faces that versions <=4 dropped).
public const uint CurrentBakeToolVersion = 5;
private static readonly JsonSerializerOptions SerializerOptions = new() private static readonly JsonSerializerOptions SerializerOptions = new()
{ {

View file

@ -0,0 +1,294 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Numerics;
using AcDream.Content;
using DatReaderWriter;
using DatReaderWriter.DBObjs;
using DatReaderWriter.Enums;
using DatReaderWriter.Lib.IO;
using DatReaderWriter.Types;
using Microsoft.Extensions.Logging.Abstractions;
namespace AcDream.Content.Tests;
/// <summary>
/// #426 (2026-08-23, the Holtburg windmill axle 0x010010CE, 8 polygons all
/// NoPos + Base1Solid): MeshExtractor.PrepareGfxObjMeshData used to gate the
/// positive side on <c>!Stippling.NoPos</c>, dropping every solid-colour
/// polygon on every object client-wide (NoPos means "no positive UVs" —
/// acclient.h:7386 — not "no positive face"). These tests exercise the fix
/// through the PUBLIC PrepareMeshData entry point against a synthetic,
/// entirely in-memory dat graph (no installed DAT directory required — this
/// lane stays hermetic), using a hand-rolled <see cref="IDatReaderWriter"/> /
/// <see cref="IDatDatabase"/> pair in the same shape as
/// DatResolutionPrecedenceTests' ResolutionSource/StubDatabase.
/// </summary>
public sealed class MeshExtractorSolidFaceExtractionTests
{
private const uint GfxObjId = 0x01000001u;
private const uint SolidSurfaceId = 0x08000001u;
private const uint TexturedSurfaceId = 0x08000002u;
private const uint SurfaceTextureId = 0x05000001u;
private const uint RenderSurfaceId = 0x06000001u;
/// <summary>
/// One quad polygon, NoPos + Base1Solid: the exact shape of the windmill
/// axle's own polygons. Must now extract to 4 vertices / 6 indices in a
/// single batch flagged solid, instead of the pre-#426 0-vertex mesh.
/// </summary>
[Fact]
public void PrepareMeshData_NoPosSolidQuad_EmitsSolidBatchWithFourVerticesAndSixIndices()
{
var dats = new FakeMeshExtractorDats();
dats.RegisterRootGfxObj(GfxObjId, BuildQuadGfxObj(SolidSurfaceId, noPos: true));
var color = new ColorARGB { Alpha = 255, Red = 12, Green = 34, Blue = 56 };
dats.Register(SolidSurfaceId, new Surface
{
Type = SurfaceType.Base1Solid,
ColorValue = color,
});
var extractor = new MeshExtractor(dats, NullLogger.Instance, sideStagedSink: null);
ObjectMeshData? mesh = extractor.PrepareMeshData(GfxObjId, isSetup: false);
Assert.NotNull(mesh);
Assert.Equal(4, mesh!.Vertices.Length);
List<TextureBatchData> batches = mesh.TextureBatches.Values.Single();
TextureBatchData batch = Assert.Single(batches);
Assert.Equal(6, batch.Indices.Count);
Assert.True(batch.Key.IsSolid);
// GetOrCreateSolidColorTexture bakes the surface's own ColorValue.
Assert.Equal((byte)color.Red, batch.TextureData[0]);
Assert.Equal((byte)color.Green, batch.TextureData[1]);
Assert.Equal((byte)color.Blue, batch.TextureData[2]);
Assert.Equal((byte)color.Alpha, batch.TextureData[3]);
}
/// <summary>
/// Same NoPos quad, but the positive surface is TEXTURED
/// (Base1Image) rather than solid. NoPos still means "no UVs on this
/// polygon's wire data" regardless of what the surface is — the emitted
/// vertices fall back to UV (0,0), and the batch must be classified
/// non-solid (IsSolid == false) so it decodes the real texture instead
/// of baking a flat colour fill.
/// </summary>
[Fact]
public void PrepareMeshData_NoPosTexturedQuad_EmitsWithZeroUVsAndIsSolidFalse()
{
var dats = new FakeMeshExtractorDats();
dats.RegisterRootGfxObj(GfxObjId, BuildQuadGfxObj(TexturedSurfaceId, noPos: true));
dats.Register(TexturedSurfaceId, new Surface
{
Type = SurfaceType.Base1Image,
OrigTextureId = SurfaceTextureId,
});
dats.Register(SurfaceTextureId, new SurfaceTexture
{
Textures = new List<QualifiedDataId<RenderSurface>> { RenderSurfaceId },
});
dats.Register(RenderSurfaceId, new RenderSurface
{
Width = 1,
Height = 1,
Format = PixelFormat.PFID_A8R8G8B8,
SourceData = new byte[] { 10, 20, 30, 255 },
});
var extractor = new MeshExtractor(dats, NullLogger.Instance, sideStagedSink: null);
ObjectMeshData? mesh = extractor.PrepareMeshData(GfxObjId, isSetup: false);
Assert.NotNull(mesh);
Assert.Equal(4, mesh!.Vertices.Length);
Assert.All(mesh.Vertices, v => Assert.Equal(Vector2.Zero, v.UV));
List<TextureBatchData> batches = mesh.TextureBatches.Values.Single();
TextureBatchData batch = Assert.Single(batches);
Assert.Equal(6, batch.Indices.Count);
Assert.False(batch.Key.IsSolid);
}
/// <summary>One quad (4 verts), single polygon, PosSurface referencing <paramref name="surfaceId"/>.</summary>
private static GfxObj BuildQuadGfxObj(uint surfaceId, bool noPos)
{
return new GfxObj
{
Surfaces = { surfaceId },
VertexArray = new VertexArray
{
Vertices =
{
// No UVs at all — matches a real NoPos polygon's vertices,
// which carry no UV entries because nothing samples them.
[0] = new SWVertex { Origin = new Vector3(0, 0, 0), Normal = Vector3.UnitZ },
[1] = new SWVertex { Origin = new Vector3(1, 0, 0), Normal = Vector3.UnitZ },
[2] = new SWVertex { Origin = new Vector3(1, 1, 0), Normal = Vector3.UnitZ },
[3] = new SWVertex { Origin = new Vector3(0, 1, 0), Normal = Vector3.UnitZ },
},
},
Polygons =
{
[0] = new Polygon
{
Stippling = noPos ? StipplingType.NoPos : default,
PosSurface = 0,
NegSurface = -1,
VertexIds = { 0, 1, 2, 3 },
},
},
};
}
/// <summary>
/// Minimal in-memory <see cref="IDatReaderWriter"/> for MeshExtractor:
/// resolves exactly one "root" GfxObj through Portal (the only path
/// PrepareMeshData needs for TryResolvePreferred's default
/// implementation), plus arbitrary typed lookups (Surface,
/// SurfaceTexture, RenderSurface) also through Portal.
/// </summary>
private sealed class FakeMeshExtractorDats : IDatReaderWriter
{
private readonly Dictionary<uint, IDBObj> _portalObjects = new();
private uint _rootId;
public FakeMeshExtractorDats() => Portal = new FakeDatDatabase(_portalObjects);
public void RegisterRootGfxObj(uint id, GfxObj gfxObj)
{
_rootId = id;
_portalObjects[id] = gfxObj;
}
public void Register<T>(uint id, T obj) where T : IDBObj => _portalObjects[id] = obj;
public string SourceDirectory => string.Empty;
public IDatDatabase Portal { get; }
public IDatDatabase Cell => EmptyDatDatabase.Instance;
public ReadOnlyDictionary<uint, IDatDatabase> CellRegions { get; } =
new(new Dictionary<uint, IDatDatabase>());
public IDatDatabase HighRes => EmptyDatDatabase.Instance;
public IDatDatabase Language => EmptyDatDatabase.Instance;
public IDatDatabase Local => EmptyDatDatabase.Instance;
public ReadOnlyDictionary<uint, uint> RegionFileMap { get; } =
new(new Dictionary<uint, uint>());
public int PortalIteration => 0;
public int CellIteration => 0;
public int HighResIteration => 0;
public int LanguageIteration => 0;
public bool TryGetFileBytes(uint regionId, uint fileId, ref byte[] bytes, out int bytesRead)
{
bytesRead = 0;
return false;
}
public IEnumerable<uint> GetAllIdsOfType<T>() where T : IDBObj => Array.Empty<uint>();
public IEnumerable<IDatReaderWriter.IdResolution> ResolveId(uint id) =>
id == _rootId
? new[] { new IDatReaderWriter.IdResolution(Portal, DBObjType.GfxObj) }
: Array.Empty<IDatReaderWriter.IdResolution>();
public bool TrySave<T>(T obj, int iteration = 0) where T : IDBObj =>
throw new NotSupportedException();
public bool TrySave<T>(uint regionId, T obj, int iteration = 0) where T : IDBObj =>
throw new NotSupportedException();
[return: MaybeNull]
public T Get<T>(uint fileId) where T : IDBObj =>
Portal.TryGet<T>(fileId, out var value) ? value : default;
public bool TryGet<T>(uint fileId, [MaybeNullWhen(false)] out T value) where T : IDBObj =>
Portal.TryGet(fileId, out value);
public void Dispose()
{
}
}
private sealed class FakeDatDatabase : IDatDatabase
{
private readonly Dictionary<uint, IDBObj> _objects;
public FakeDatDatabase(Dictionary<uint, IDBObj> objects) => _objects = objects;
// Never dereferenced by MeshExtractor's own code paths (only
// RetailPhysicsScriptLoader's ctor reads it, into a NULLABLE field
// it never touches unless a physics-script emitter is loaded, which
// these tests never trigger).
public DatDatabase Db => null!;
public int Iteration => 0;
public IEnumerable<uint> GetAllIdsOfType<T>() where T : IDBObj => Array.Empty<uint>();
public bool TryGet<T>(uint fileId, [MaybeNullWhen(false)] out T value) where T : IDBObj
{
if (_objects.TryGetValue(fileId, out IDBObj? obj) && obj is T typed)
{
value = typed;
return true;
}
value = default;
return false;
}
public bool TryGetFileBytes(uint fileId, [MaybeNullWhen(false)] out byte[] value)
{
value = null;
return false;
}
public bool TryGetFileBytes(uint fileId, ref byte[] bytes, out int bytesRead)
{
bytesRead = 0;
return false;
}
public bool TrySave<T>(T obj, int iteration = 0) where T : IDBObj =>
throw new NotSupportedException();
public void Dispose()
{
}
}
private sealed class EmptyDatDatabase : IDatDatabase
{
public static readonly EmptyDatDatabase Instance = new();
public DatDatabase Db => null!;
public int Iteration => 0;
public IEnumerable<uint> GetAllIdsOfType<T>() where T : IDBObj => Array.Empty<uint>();
public bool TryGet<T>(uint fileId, [MaybeNullWhen(false)] out T value) where T : IDBObj
{
value = default;
return false;
}
public bool TryGetFileBytes(uint fileId, [MaybeNullWhen(false)] out byte[] value)
{
value = null;
return false;
}
public bool TryGetFileBytes(uint fileId, ref byte[] bytes, out int bytesRead)
{
bytesRead = 0;
return false;
}
public bool TrySave<T>(T obj, int iteration = 0) where T : IDBObj =>
throw new NotSupportedException();
public void Dispose()
{
}
}
}

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using AcDream.Core.Meshing;
using DatReaderWriter; using DatReaderWriter;
using DatReaderWriter.DBObjs; using DatReaderWriter.DBObjs;
using DatReaderWriter.Enums; using DatReaderWriter.Enums;
@ -22,6 +23,22 @@ namespace AcDream.Core.Tests.Conformance;
/// and replicates MeshExtractor.PrepareGfxObjMeshData's gates (moved from /// and replicates MeshExtractor.PrepareGfxObjMeshData's gates (moved from
/// ObjectMeshManager in MP1a) /// ObjectMeshManager in MP1a)
/// so the zeroing gate reads directly off the output. /// so the zeroing gate reads directly off the output.
///
/// #426 (2026-08-23) UPDATE: the gate replica below now mirrors the FIXED
/// extraction rule — the positive side is added whenever PosSurface is a
/// valid index, regardless of Stippling.NoPos (NoPos means "no positive
/// UVs", not "no positive face"; see RetailUntexturedSurfacePolicy). Run
/// against the installed DAT, both of #119's original objects now gate
/// DRAWS on every single polygon (0x010002B4: 9/9 polys; 0x010008A8: 1/1
/// poly — both all-NoPos+Base1Solid, wouldAddPos == polygon count) — they
/// are NEITHER all-degenerate NOR all-invalid-surface-index; they were
/// dropped for being all-solid, and #426 now extracts that geometry. The
/// #119 filing's "retail never draws untextured subsets" conclusion was
/// simply wrong (see #426's ISSUES.md entry) — it never held for these two
/// objects specifically. Whether their solid faces end up VISIBLE on
/// screen (vs. skipped again at draw time by RetailUntexturedSubsetPolicy,
/// if either object turns out to be a building-shell part) is a separate,
/// unverified question this dump does not answer.
/// </summary> /// </summary>
[Trait("Lane", "InstalledDat")] [Trait("Lane", "InstalledDat")]
public sealed class Issue119UpNullGfxObjDumpTests public sealed class Issue119UpNullGfxObjDumpTests
@ -57,7 +74,10 @@ public sealed class Issue119UpNullGfxObjDumpTests
} }
// Replicate the extraction gates (PrepareGfxObjMeshData): // Replicate the extraction gates (PrepareGfxObjMeshData):
// pos added when !NoPos // pos added whenever PosSurface is a valid index — #426
// (2026-08-23): NoPos means "no positive UVs", not "no positive
// face"; ordinary objects draw untextured (solid) subsets the same
// as textured ones (RetailUntexturedSurfacePolicy).
// neg added when Negative || Both || (!NoNeg && SidesType==Clockwise) // neg added when Negative || Both || (!NoNeg && SidesType==Clockwise)
// surface index must be in [0, Surfaces.Count) // surface index must be in [0, Surfaces.Count)
int wouldAddPos = 0, wouldAddNeg = 0, degenerate = 0; int wouldAddPos = 0, wouldAddNeg = 0, degenerate = 0;
@ -68,8 +88,7 @@ public sealed class Issue119UpNullGfxObjDumpTests
if (poly.VertexIds.Count < 3) { degenerate++; gate = "degenerate(<3 verts)"; } if (poly.VertexIds.Count < 3) { degenerate++; gate = "degenerate(<3 verts)"; }
else else
{ {
bool pos = !poly.Stippling.HasFlag(StipplingType.NoPos) bool pos = poly.PosSurface >= 0 && poly.PosSurface < gfx.Surfaces.Count;
&& poly.PosSurface >= 0 && poly.PosSurface < gfx.Surfaces.Count;
bool neg = (poly.Stippling.HasFlag(StipplingType.Negative) bool neg = (poly.Stippling.HasFlag(StipplingType.Negative)
|| poly.Stippling.HasFlag(StipplingType.Both) || poly.Stippling.HasFlag(StipplingType.Both)
|| (!poly.Stippling.HasFlag(StipplingType.NoNeg) && poly.SidesType == CullMode.Clockwise)) || (!poly.Stippling.HasFlag(StipplingType.NoNeg) && poly.SidesType == CullMode.Clockwise))
@ -96,6 +115,18 @@ public sealed class Issue119UpNullGfxObjDumpTests
/// are "regular shell polys" — render digest user axiom). A non-zero /// are "regular shell polys" — render digest user axiom). A non-zero
/// "DROPPED but textured" count names the extraction as the stairs-miss /// "DROPPED but textured" count names the extraction as the stairs-miss
/// mechanism; zero exonerates the per-poly gates. /// mechanism; zero exonerates the per-poly gates.
///
/// #426 (2026-08-23) UPDATE: post-fix, the POS side can only be dropped
/// when PosSurface itself is out of range — a textured pos-side surface
/// with a valid index is now ALWAYS emitted (that's the whole point of
/// #426). So this test's remaining bite is almost entirely the NEG-side
/// gate (unchanged by #426 — a textured NEG surface can still legitimately
/// be dropped when none of the three double-sided conditions hold). Kept
/// under its original name/assertion (zero textured drops) because that
/// invariant is still exactly what we want to hold; `SurfaceIsTextured`
/// now calls the shared RetailUntexturedSurfacePolicy predicate instead of
/// a bare Base1Solid check, so this test and the extraction it's checking
/// literally cannot drift on what "textured" means.
/// </summary> /// </summary>
[Theory] [Theory]
[InlineData(0x010014C3u)] [InlineData(0x010014C3u)]
@ -112,7 +143,7 @@ public sealed class Issue119UpNullGfxObjDumpTests
{ {
if (idx < 0 || idx >= gfx!.Surfaces.Count) return false; if (idx < 0 || idx >= gfx!.Surfaces.Count) return false;
if (!dats.Portal.TryGet<Surface>(gfx.Surfaces[idx], out var surf) || surf is null) return false; if (!dats.Portal.TryGet<Surface>(gfx.Surfaces[idx], out var surf) || surf is null) return false;
return !surf.Type.HasFlag(SurfaceType.Base1Solid); return !RetailUntexturedSurfacePolicy.IsUntextured(surf.Type);
} }
int draws = 0; int draws = 0;
@ -120,8 +151,7 @@ public sealed class Issue119UpNullGfxObjDumpTests
foreach (var (pid, poly) in gfx!.Polygons.OrderBy(kv => kv.Key)) foreach (var (pid, poly) in gfx!.Polygons.OrderBy(kv => kv.Key))
{ {
if (poly.VertexIds.Count < 3) continue; if (poly.VertexIds.Count < 3) continue;
bool pos = !poly.Stippling.HasFlag(StipplingType.NoPos) bool pos = poly.PosSurface >= 0 && poly.PosSurface < gfx.Surfaces.Count;
&& poly.PosSurface >= 0 && poly.PosSurface < gfx.Surfaces.Count;
bool neg = (poly.Stippling.HasFlag(StipplingType.Negative) bool neg = (poly.Stippling.HasFlag(StipplingType.Negative)
|| poly.Stippling.HasFlag(StipplingType.Both) || poly.Stippling.HasFlag(StipplingType.Both)
|| (!poly.Stippling.HasFlag(StipplingType.NoNeg) && poly.SidesType == CullMode.Clockwise)) || (!poly.Stippling.HasFlag(StipplingType.NoNeg) && poly.SidesType == CullMode.Clockwise))

View file

@ -247,4 +247,56 @@ public class GfxObjMeshTests
Assert.Empty(subs); // no valid polygons → no sub-meshes Assert.Empty(subs); // no valid polygons → no sub-meshes
} }
/// <summary>
/// #426 (2026-08-23, Holtburg windmill axle 0x010010CE): a NoPos-flagged
/// polygon ("this side has no texture coordinates", acclient.h:7386) is
/// NOT "no positive face" — every solid-colour polygon carries NoPos.
/// Before the fix, <c>hasPos = !Stippling.NoPos</c> dropped this quad
/// entirely, producing zero vertices. GfxObjMesh.Build doesn't branch on
/// Surface.Type at all (that classification — "is this untextured" —
/// lives in RetailUntexturedSurfacePolicy and is consumed by
/// MeshExtractor, which is what actually decides solid-vs-textured
/// rendering), so a NoPos polygon over a "solid" surface and a NoPos
/// polygon over a "textured" surface are IDENTICAL from this method's
/// point of view — both are proven by this one case.
/// </summary>
[Fact]
public void Build_NoPosQuad_StillEmitsPositiveSideVerticesAndIndices()
{
var gfx = new GfxObj
{
Surfaces = { 0x08000000u },
VertexArray = new VertexArray
{
Vertices =
{
// No UVs at all — matches a real solid-colour polygon's
// vertices, which carry no UV entries because nothing
// ever samples them.
[0] = new SWVertex { Origin = new(0, 0, 0) },
[1] = new SWVertex { Origin = new(1, 0, 0) },
[2] = new SWVertex { Origin = new(1, 1, 0) },
[3] = new SWVertex { Origin = new(0, 1, 0) },
},
},
Polygons =
{
[0] = new Polygon
{
Stippling = StipplingType.NoPos,
PosSurface = 0,
NegSurface = -1,
VertexIds = { 0, 1, 2, 3 },
// No PosUVIndices — NoPos means there ARE none on the wire.
},
},
};
var sub = GfxObjMesh.Build(gfx).Single();
Assert.Equal(4, sub.Vertices.Length);
Assert.Equal(6, sub.Indices.Length); // fan-triangulated quad, 2 triangles
Assert.All(sub.Vertices, v => Assert.Equal(Vector2.Zero, v.TexCoord));
}
} }

View file

@ -0,0 +1,42 @@
using AcDream.Core.Meshing;
using DatReaderWriter.Enums;
namespace AcDream.Core.Tests.Meshing;
/// <summary>
/// #426 (2026-08-23, the Holtburg windmill axle 0x010010CE): pins the two
/// predicates that replaced the buggy <c>isSolid = NoPos || Base1Solid</c>
/// extraction rule and the "retail never draws untextured subsets" #119
/// misconception. See RetailUntexturedSurfacePolicy.cs for the full retail
/// citations (D3DPolyRender::DrawMesh / DrawBuilding / DrawEnvCell).
/// </summary>
public sealed class RetailUntexturedSurfacePolicyTests
{
[Theory]
[InlineData(SurfaceType.Base1Solid, true)] // solid-colour — untextured
[InlineData((SurfaceType)0, true)] // neither bit set — untextured
[InlineData(SurfaceType.Base1Image, false)] // BASE1_IMAGE (0x2) — textured
[InlineData(SurfaceType.Base1ClipMap, false)] // BASE1_CLIPMAP (0x4) — textured
[InlineData(SurfaceType.Base1Image | SurfaceType.Base1Solid, false)] // both bits — retail's literal (type & 6) != 0 still calls this textured
[InlineData(SurfaceType.Base1Image | SurfaceType.Additive, false)] // unrelated flags alongside a textured bit stay textured
public void IsUntextured_MatchesRetailBitmask(SurfaceType type, bool expected)
{
Assert.Equal(expected, RetailUntexturedSurfacePolicy.IsUntextured(type));
}
[Theory]
// (isBuildingShell, isUntextured) -> draws
[InlineData(false, true, true)] // ordinary object, solid subset — retail draws it (#426's own bug)
[InlineData(true, true, false)] // building shell, solid subset — retail's DrawBuilding skips it
[InlineData(false, false, true)] // ordinary object, textured subset — always drawn
[InlineData(true, false, true)] // building shell, textured subset — the shell gate only touches untextured subsets
public void Draws_MatchesRetailBuildingShellGate(
bool isBuildingShell,
bool isUntextured,
bool expectedDraws)
{
Assert.Equal(
expectedDraws,
RetailUntexturedSubsetPolicy.Draws(isBuildingShell, isUntextured));
}
}

View file

@ -18,6 +18,23 @@ namespace AcDream.Core.Tests.Rendering.Wb;
/// If this test fails, either our port has drifted or the WB code has /// If this test fails, either our port has drifted or the WB code has
/// changed upstream — investigate which, do not "fix" the test. /// changed upstream — investigate which, do not "fix" the test.
/// </para> /// </para>
///
/// <para>
/// ONE DOCUMENTED EXCEPTION (#426, 2026-08-23):
/// <see cref="Build_NoPosFlag_EmitsBothPosAndNegSide"/> below intentionally
/// diverges from WorldBuilder's own upstream
/// <c>ObjectMeshManager.cs:959</c> (<c>if
/// (!poly.Stippling.HasFlag(StipplingType.NoPos))</c>), which has the exact
/// same bug our port faithfully carried over: gating the polygon's positive
/// side on <c>!NoPos</c>, silently dropping every solid-colour polygon.
/// Named-retail decomp (<c>D3DPolyRender::DrawMesh</c> @0x0059d4a0) proves
/// <c>NoPos</c> ("this side has no texture coordinates",
/// acclient.h:7380-7388) does not gate whether retail draws the positive
/// side at all — see #426 in docs/ISSUES.md for the full citation. This is
/// the one case in this file where the retail decomp — not WB — is the
/// oracle; see the acdream-wide rule in CLAUDE.md ("the decompiled code is
/// ground truth ... if they disagree, the decompiled code wins").
/// </para>
/// </summary> /// </summary>
public sealed class MeshExtractionConformanceTests public sealed class MeshExtractionConformanceTests
{ {
@ -66,8 +83,18 @@ public sealed class MeshExtractionConformanceTests
Assert.Equal(2, ours.Count); Assert.Equal(2, ours.Count);
} }
/// <summary>
/// #426 (2026-08-23): renamed from <c>Build_NoPosFlag_OnlyEmitsNegSide</c>,
/// which asserted <c>Assert.Single(ours)</c> — the OLD bug's own
/// behavior (NoPos silently dropped the positive side). NoPos means "no
/// positive UVs" (acclient.h:7386), not "no positive face"; retail draws
/// an ordinary object's untextured positive side same as a textured one
/// (D3DPolyRender::DrawMesh @0x0059d4a0). See the class doc's "ONE
/// DOCUMENTED EXCEPTION" note for why this test intentionally diverges
/// from WorldBuilder's own (equally buggy) upstream algorithm.
/// </summary>
[Fact] [Fact]
public void Build_NoPosFlag_OnlyEmitsNegSide() public void Build_NoPosFlag_EmitsBothPosAndNegSide()
{ {
var gfxObj = MakeUnitQuadGfxObj(); var gfxObj = MakeUnitQuadGfxObj();
var poly = gfxObj.Polygons[0]; var poly = gfxObj.Polygons[0];
@ -77,7 +104,7 @@ public sealed class MeshExtractionConformanceTests
var ours = GfxObjMesh.Build(gfxObj, dats: null); var ours = GfxObjMesh.Build(gfxObj, dats: null);
Assert.Single(ours); Assert.Equal(2, ours.Count);
} }
/// <summary> /// <summary>

View file

@ -51,12 +51,12 @@ public sealed class LauncherInstallerTests : IDisposable
await File.WriteAllTextAsync(request.OutputPath, "complete prepared package"); await File.WriteAllTextAsync(request.OutputPath, "complete prepared package");
long bytes = new FileInfo(request.OutputPath).Length; long bytes = new FileInfo(request.OutputPath).Length;
output("acdream-bake human header\n{\"v\":1,\"e\":\"star"); output("acdream-bake human header\n{\"v\":1,\"e\":\"star");
output("ted\",\"bakeToolVersion\":4,\"outputPath\":\"pak\"}\n"); output($"ted\",\"bakeToolVersion\":{LauncherInstallRecordStore.CurrentBakeToolVersion},\"outputPath\":\"pak\"}}\n");
output("{\"v\":1,\"e\":\"progress\",\"phase\":\"mesh\"," output("{\"v\":1,\"e\":\"progress\",\"phase\":\"mesh\","
+ "\"completed\":25,\"total\":100,\"failures\":0," + "\"completed\":25,\"total\":100,\"failures\":0,"
+ "\"elapsedSeconds\":5,\"etaSeconds\":15}\n"); + "\"elapsedSeconds\":5,\"etaSeconds\":15}\n");
output("{\"v\":1,\"e\":\"newMetric\",\"value\":1}\n"); output("{\"v\":1,\"e\":\"newMetric\",\"value\":1}\n");
output($"{{\"v\":1,\"e\":\"completed\",\"bakeToolVersion\":4," output($"{{\"v\":1,\"e\":\"completed\",\"bakeToolVersion\":{LauncherInstallRecordStore.CurrentBakeToolVersion},"
+ $"\"outputBytes\":{bytes},\"failures\":0}}\n"); + $"\"outputBytes\":{bytes},\"failures\":0}}\n");
return new BakeProcessResult(0, string.Empty); return new BakeProcessResult(0, string.Empty);
}); });
@ -153,7 +153,7 @@ public sealed class LauncherInstallerTests : IDisposable
async (request, output, _) => async (request, output, _) =>
{ {
await File.WriteAllTextAsync(request.OutputPath, "partial replacement"); await File.WriteAllTextAsync(request.OutputPath, "partial replacement");
output("{\"v\":1,\"e\":\"started\",\"bakeToolVersion\":4}\n"); output($"{{\"v\":1,\"e\":\"started\",\"bakeToolVersion\":{LauncherInstallRecordStore.CurrentBakeToolVersion}}}\n");
output("{\"v\":1,\"e\":\"error\",\"message\":\"fixture failed\"}\n"); output("{\"v\":1,\"e\":\"error\",\"message\":\"fixture failed\"}\n");
return new BakeProcessResult(9, "human failure detail"); return new BakeProcessResult(9, "human failure detail");
}, },
@ -186,9 +186,9 @@ public sealed class LauncherInstallerTests : IDisposable
{ {
await File.WriteAllTextAsync(request.OutputPath, "contradictory output"); await File.WriteAllTextAsync(request.OutputPath, "contradictory output");
long bytes = new FileInfo(request.OutputPath).Length; long bytes = new FileInfo(request.OutputPath).Length;
output("{\"v\":1,\"e\":\"started\",\"bakeToolVersion\":4}\n"); output($"{{\"v\":1,\"e\":\"started\",\"bakeToolVersion\":{LauncherInstallRecordStore.CurrentBakeToolVersion}}}\n");
output("{\"v\":1,\"e\":\"error\",\"message\":\"first failure\"}\n"); output("{\"v\":1,\"e\":\"error\",\"message\":\"first failure\"}\n");
output($"{{\"v\":1,\"e\":\"completed\",\"bakeToolVersion\":4," output($"{{\"v\":1,\"e\":\"completed\",\"bakeToolVersion\":{LauncherInstallRecordStore.CurrentBakeToolVersion},"
+ $"\"outputBytes\":{bytes},\"failures\":0}}\n"); + $"\"outputBytes\":{bytes},\"failures\":0}}\n");
return new BakeProcessResult(0, string.Empty); return new BakeProcessResult(0, string.Empty);
}); });
@ -275,8 +275,8 @@ public sealed class LauncherInstallerTests : IDisposable
Directory.CreateDirectory(Path.GetDirectoryName(request.OutputPath)!); Directory.CreateDirectory(Path.GetDirectoryName(request.OutputPath)!);
await File.WriteAllTextAsync(request.OutputPath, "complete but unverified"); await File.WriteAllTextAsync(request.OutputPath, "complete but unverified");
long bytes = new FileInfo(request.OutputPath).Length; long bytes = new FileInfo(request.OutputPath).Length;
output("{\"v\":1,\"e\":\"started\",\"bakeToolVersion\":4}\n"); output($"{{\"v\":1,\"e\":\"started\",\"bakeToolVersion\":{LauncherInstallRecordStore.CurrentBakeToolVersion}}}\n");
output($"{{\"v\":1,\"e\":\"completed\",\"bakeToolVersion\":4," output($"{{\"v\":1,\"e\":\"completed\",\"bakeToolVersion\":{LauncherInstallRecordStore.CurrentBakeToolVersion},"
+ $"\"outputBytes\":{bytes},\"failures\":0}}\n"); + $"\"outputBytes\":{bytes},\"failures\":0}}\n");
return new BakeProcessResult(0, string.Empty); return new BakeProcessResult(0, string.Empty);
}); });