Only Draw What The Map Says You Can See
PVS culling driven by the BSP's own compiled cluster graph, with a debug command that prints exactly how much it threw away.
Reading The Map's Own Visibility
PVSCuller registers meshes against the cluster graph compiled into the BSP file, then decides visibility from the camera position. The map is not asked where the walls are. The map is asked what it already knows about what is visible.
Commands: pvs on|off|status|cluster|debug.
The Optimisations Are the Interesting Part
- Meshes are assigned to every cluster their bounding box intersects, sampled at
15 points — eight corners, the centre, six face centres.
- Cached
hasPVSlookups. - Tuple-based sampling to avoid allocating a
Vector3per test. - Cached stats;
isVisibleonly written when it changes. - Hooked into
scene.onBeforeRenderObservablerather than its own
requestAnimationFrame loop.
- A reverse
Map<cluster, meshes[]>instead of scanning meshes per cluster.
What pvs debug Prints
Current cluster. Visible and total clusters. Visible and total meshes. Culled percentage. Update time in milliseconds.
The update-time figure is the point of the command. Culling that costs more than it saves is a common outcome when it is added by hand, and the only way to know is to print the number.