OcclusionSpanMap
Per horizontal band of the canvas, the merged x ranges that occluders cover across the whole band, each with the farthest depth of the occluders merged into it (conservative). An object is hidden only if one merged range covers it in every band it touches.
Constructor
new OcclusionSpanMap(
width: float,
height: float,
bandCount: integer,
): OcclusionSpanMapParameters
width(float) — canvas width in pixelsheight(float) — canvas height in pixelsbandCount(integer) — number of horizontal bands the canvas is divided into
Instance Methods
build(polygons: Array.<BGE.OccluderPolygon>): void
Rebuilds the map from this frame's occluders, replacing the previous frame's spans.
Parameters
polygons(Array.<BGE.OccluderPolygon>) — convex canvas-space occluders, nearest (lowest depth) first for the tightest map
Returns
void
getNearestDepth(): float
The nearest depth any span claims. An object reaching this near can't be hidden.
Returns
float— a very large number when the map is empty
isPointCovered(x: float, y: float, depth: float): boolean
Whether a span strictly nearer than depth covers the canvas point. An object that draws over this point no nearer than depth can only be hidden if it is.
Parameters
x(float) — canvas xy(float) — canvas ydepth(float) — the depth to compare spans against
Returns
boolean
isHidden(
minX: float,
minY: float,
maxX: float,
maxY: float,
nearestDepth: float,
): boolean
True only if the box is covered in every band it touches by one merged span whose depth is strictly nearer than nearestDepth. A box extending off the canvas is never hidden. The caller inflates the box by any safety margin first.
Parameters
minX(float) — left edge of the boxminY(float) — top edge of the boxmaxX(float) — right edge of the boxmaxY(float) — bottom edge of the boxnearestDepth(float) — depth of the nearest point of the object
Returns
boolean— true if the object is certainly hidden
getBandHeight(): float
Returns
float— the height of each band in pixels
getBandCount(): integer
Returns
integer— the number of bands
getBandSpans(band: integer): Array.<float>
Parameters
band(integer) — band index, 0 at the top
Returns
Array.<float>— the band's merged spans as a flat [left, right, depth, ...] list, for debug drawing