#119: entity bounds from dat vertex data - works for every case, not just multi-part

The 1ca412d part-offset expansion fixed the staircase but still rested
on the 5 m promise one level down: a SINGLE part whose mesh extends
more than 5 m from its own origin (offset 0 -> box +-5 m) keeps the
gaze-dependent vanish. Per the user's mandate ("it must work for every
case"), the bound now derives from the dat VERTEX data - the same
vertices that get drawn - so no synthetic containment promise remains.

Oracle context (read this session): retail has NO whole-entity
visibility volume - CPhysicsPart::Draw (0x0050d7a0) viewcone-checks
each part's dat-authored CGfxObj.drawing_sphere at the part's own
world position (RenderDeviceD3D::DrawMesh 0x005a0860). Retail's bound
IS data; ours was a promise. Our per-ENTITY granularity stays (a
deliberate batching-era choice, WB-owned per the inventory) but the
volume is now data-derived and conservative: visually identical by
construction, never culls what retail would draw.

- GfxObjBounds: per-GfxObj vertex AABB, cached by id (parts repeat
  heavily); LocalBoundsAccumulator: union of part-transformed AABB
  corners (conservative-correct under any affine transform).
- WorldEntity.SetLocalBounds + RefreshAabb preferred path: rotate the
  root-local bounds' 8 corners into world axes + DefaultAabbRadius
  margin (absorbs animated-pose drift vs the rest-pose bounds; keeps
  small objects at their historical box size). Offset heuristic stays
  as the fallback for boundless fixtures.
- All four hydration sites wired (outdoor stabs, scenery incl. baked
  scale, interior cell statics, server live spawns).

Tests: tall-single-part coverage (the case 1ca412d could not see),
rotation-following, accumulator union. Suites: App 246+1skip / Core
1434+2skip / UI 420 / Net 294.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-11 22:39:05 +02:00
parent 1ca412d07b
commit 6a9b529113
4 changed files with 248 additions and 13 deletions

View file

@ -111,6 +111,26 @@ public sealed class WorldEntity
public Vector3 AabbMax { get; private set; }
public bool AabbDirty { get; private set; } = true;
/// <summary>
/// Root-local geometry bounds: the union over MeshRefs of each part's dat
/// vertex AABB transformed by its part transform (see
/// <c>Meshing.LocalBoundsAccumulator</c>). Set at hydration from the same
/// vertex data that gets drawn — the every-case fix for the "#119 bounds
/// must cover the mesh" class. When absent (HasLocalBounds false), the
/// part-offset heuristic below is the fallback.
/// </summary>
public Vector3 LocalBoundMin { get; private set; }
public Vector3 LocalBoundMax { get; private set; }
public bool HasLocalBounds { get; private set; }
public void SetLocalBounds(Vector3 min, Vector3 max)
{
LocalBoundMin = min;
LocalBoundMax = max;
HasLocalBounds = true;
AabbDirty = true;
}
private const float DefaultAabbRadius = 5.0f;
public void RefreshAabb()
@ -118,18 +138,48 @@ public sealed class WorldEntity
var p = Position;
// #119 follow-up (2026-06-11): the box must cover the MESH, not just the
// anchor. A multi-part Setup's parts sit at root-relative offsets — the
// AAB3 tower's spiral staircase spans 15 m ABOVE its anchor — and BOTH
// visibility gates derive from this box: the dispatcher's per-entity
// frustum cull (WbDrawDispatcher.WalkEntitiesInto) and the viewcone
// sphere (RetailPViewRenderer.EntitySphere = this box's bounding
// sphere). A fixed ±5 m anchor box dropped the staircase whenever the
// gaze left the anchor's neighborhood: stairs visible looking down the
// spiral (anchor in view), gone looking up (anchor culled) — the
// user-reported direction/angle asymmetry. Expand by the largest part
// offset; using the offset MAGNITUDE keeps the box rotation-invariant,
// so entity.Rotation needs no handling here. Identity-part entities
// (1-part Setups, GfxObjs, scenery) get offset 0 — behavior unchanged.
// anchor. BOTH visibility gates derive from this box: the dispatcher's
// per-entity frustum cull (WbDrawDispatcher.WalkEntitiesInto) and the
// viewcone sphere (RetailPViewRenderer.EntitySphere = this box's
// bounding sphere). The original fixed ±5 m anchor box dropped the AAB3
// tower staircase (parts spiralling 15 m above the anchor) whenever the
// gaze left the anchor's neighborhood — stairs visible looking down,
// gone looking up.
//
// Preferred path: dat-vertex-derived root-local bounds (SetLocalBounds
// at hydration), rotated into world axes — re-boxing the 8 rotated
// corners contains the rotated contents, so this is correct for EVERY
// shape including a single tall part at identity transform (which the
// offset heuristic below cannot see). DefaultAabbRadius stays as a
// margin: it absorbs animated-pose drift (MeshRefs are swapped per
// frame for animated entities while local bounds are rest-pose) and
// keeps small objects at their historical box size.
if (HasLocalBounds)
{
Vector3 lo = LocalBoundMin, hi = LocalBoundMax;
var rot = Rotation;
Vector3 min = default, max = default;
for (int c = 0; c < 8; c++)
{
var corner = new Vector3(
(c & 1) == 0 ? lo.X : hi.X,
(c & 2) == 0 ? lo.Y : hi.Y,
(c & 4) == 0 ? lo.Z : hi.Z);
var t = Vector3.Transform(corner, rot);
if (c == 0) { min = max = t; }
else { min = Vector3.Min(min, t); max = Vector3.Max(max, t); }
}
AabbMin = p + min - new Vector3(DefaultAabbRadius);
AabbMax = p + max + new Vector3(DefaultAabbRadius);
AabbDirty = false;
return;
}
// Fallback (no hydration bounds — e.g. tests, minimal fixtures): anchor
// box expanded by the largest part-translation magnitude. Rotation-
// invariant; covers multi-part spreads but NOT a single part whose mesh
// extends >5 m from its own origin — which is why hydrated entities use
// the vertex-derived path above.
float radius = DefaultAabbRadius;
var refs = MeshRefs;
if (refs is not null)