p5.tree/visibility

Knowing what the camera can see.

Ask whether a point, a sphere or a box is in view before drawing it. visibility() answers VISIBLE, SEMIVISIBLE or INVISIBLE for the current camera; bounds() captures the six planes of another camera's view so the same question can be asked from its point of view; and distanceToBound() measures how far a point is from one of those planes.

Reach for it to skip drawing what is off-screen, or to show what a second camera is looking at.

p5

visibility(opts)

Test whether a point, a sphere or an axis-aligned box is inside, crossing or outside the current camera's view frustum, returning VISIBLE, SEMIVISIBLE or INVISIBLE (see the sphere example). Give a point as center, a sphere as center plus radius, and a box as its two corners; mat4Model places local-space bounds in the world (see the AABB example), and bounds tests against another camera's planes from bounds(). Needs a WEBGL canvas.

ParameterTypeDefaultDescription
opts { corner1?: Float32Array | ArrayLike | p5.Vector, corner2?: Float32Array | ArrayLike | p5.Vector, center?: Float32Array | ArrayLike | p5.Vector, radius?: number, bounds?: object, mat4Model?: Float32Array | ArrayLike | p5.Matrix, }

Returns number p5.Tree.VISIBLE | SEMIVISIBLE | INVISIBLE

Sphere test against the current camera: edge-crossers flagged, culled ones skipped
Local-space AABB under mat4Model

bounds([opts])

Compute the six planes of a camera's view frustum as a keyed object — the current camera, or one given as mat4Eye — to pass as the bounds option of visibility() and distanceToBound() (see the second-camera example). Needs a WEBGL canvas.

ParameterTypeDefaultDescription
opts optional { mat4Eye?: Float32Array | ArrayLike | p5.Matrix }

Returns object

Cull against a second camera's frustum

distanceToBound(point, key, [bounds])

Signed distance from a point to one frustum plane. Positive → outside (invisible side).

ParameterTypeDefaultDescription
point ArrayLike|p5.Vector
key number|string p5.Tree plane constant (LEFT, RIGHT, NEAR, FAR, TOP, BOTTOM).
bounds optional object Planes from bounds(). Defaults to the current camera's view.

Returns number

Signed distance to the RIGHT plane: negative inside, positive outside