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

@ -1661,16 +1661,36 @@ namespace AcDream.App.Rendering.Wb
var renderData = UploadGfxObjMeshData(meshData);
if (renderData == null)
{
// 0-vertex mesh: every polygon was gated out at extraction. #119
// (2026-06-11) dat-verified this is LEGITIMATE for all-no-draw
// models (all polys NoPos + Base1Solid surfaces — retail's
// skipNoTexture never draws them either; 0x010002B4/0x010008A8
// are this class, Issue119UpNullGfxObjDumpTests). The empty
// cache is the correct terminal state for those. 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 as one).
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)");
// 0-vertex mesh: every polygon was gated out at extraction.
// #119 (2026-06-11) ORIGINALLY reasoned this is LEGITIMATE
// for every all-NoPos+Base1Solid ("all-no-draw") model,
// claiming retail's skipNoTexture never draws untextured
// subsets at all. #426 (2026-08-23, the Holtburg windmill
// axle 0x010010CE) corrected that: retail's skipNoTexture
// only suppresses untextured subsets on a BUILDING SHELL
// (RenderDeviceD3D::DrawBuilding @0x0059f2a0 sets
// ObjBuildingOrBuildingPart=1) or inside an EnvCell
// 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();
}

View file

@ -1183,6 +1183,15 @@ public sealed partial class WbDrawDispatcher
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++;
if (!DirectionalShadowPreparedDraws.TryClassifyMaterial(
batch.Translucency,

View file

@ -631,6 +631,14 @@ public sealed unsafe partial class WbDrawDispatcher
{
ObjectRenderBatch batch =
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;
if (opacity < 1f && IsOpaque(translucency))
translucency = TranslucencyKind.AlphaBlend;

View file

@ -3421,6 +3421,15 @@ public sealed partial class WbDrawDispatcher : IDisposable
{
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;
// #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;
// Handle Positive Surface
if (!poly.Stippling.HasFlag(StipplingType.NoPos)) {
AddSurfaceToBatch(poly, poly.PosSurface, false);
}
// #426 (2026-08-23, Holtburg windmill axle 0x010010CE): NoPos
// ("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
// Some objects use Clockwise CullMode to indicate negative surface data is present
@ -376,7 +387,13 @@ public sealed class MeshExtractor {
TextureFormat textureFormat;
UploadPixelFormat? uploadPixelFormat = 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);
uint paletteId = 0;
bool isDxt3or5 = false;
@ -710,6 +727,20 @@ public sealed class MeshExtractor {
// GL cull enum: 0 = pos, 1 = pos twice with reversed winding,
// 2 = pos + neg surface. The DAT-side NoPos/NoNeg flags still
// 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 hasNeg = !poly.Stippling.HasFlag(StipplingType.NoNeg);
@ -745,7 +776,13 @@ public sealed class MeshExtractor {
TextureFormat textureFormat;
UploadPixelFormat? uploadPixelFormat = 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);
uint paletteId = 0;
bool isDxt3or5 = false;

View file

@ -22,9 +22,15 @@ public static class PakFormat {
/// version 3 embeds exact render-pass translucency in each texture batch
/// so production never rebuilds surface metadata from live DAT. Version 4
/// 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>
public const uint CurrentBakeToolVersion = 4;
public const uint CurrentBakeToolVersion = 5;
}
/// <summary>

View file

@ -41,7 +41,19 @@ public static class CellMesh
if (poly.VertexIds.Count < 3)
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))
continue;

View file

@ -28,8 +28,16 @@ public static class GfxObjMesh
/// The rule for emitting a polygon side:
/// </para>
/// <list type="bullet">
/// <item><b>Pos side:</b> emit whenever <c>!Stippling.NoPos</c> and
/// <c>PosSurface</c> is a valid index.</item>
/// <item><b>Pos side:</b> emit whenever <c>PosSurface</c> is a valid
/// 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
/// <c>Stippling.Negative</c>, <c>Stippling.Both</c>, or
/// <c>(!Stippling.NoNeg &amp;&amp; SidesType == CullMode.Clockwise)</c>.
@ -69,9 +77,10 @@ public static class GfxObjMesh
continue; // degenerate — can't form a triangle
// --- Positive side ---
bool hasPos = !poly.Stippling.HasFlag(StipplingType.NoPos);
if (hasPos)
EmitSide(poly, poly.PosSurface, isNeg: false);
// #426: always emit — NoPos only means "no positive UVs", not
// "no positive face" (see the class doc). EmitSide's own
// surfaceIdx-validity guard is the only real gate.
EmitSide(poly, poly.PosSurface, isNeg: false);
// --- Negative side ---
// 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>
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()
{