viewport.toolbox
This package holds more than this page lists. See all of its files in its world.
README.md
labels
Where every world-space label lands on screen, and which ones overlap.
A capture shows the picture, but a picture of thirty signs does not say which two touch, which one a screen edge cuts off, or how many pixels tall a line of text is drawn. This answers those as data, for one camera at the size the engine is drawing:
labels: every label with any part on screen, nearest first, each with its pixelrectand on-screencorners, itsdepth, the pixellineHeightof one of its lines, the screen edges thatcutit or that it comes withinmarginof (nearEdge), and whether the camera sees it from behind (mirrored).overlaps: every pair whose quads overlap (or stand closer thangappixels), naming the one nearer the camera, which draws over the other.keepOut: the labels that reach a HUD widget (by UI element id) or a pixel rect you name.unseen: the labels the camera does not show, and why (behind,offscreen,hidden,layer).smallestLine: the label whose line is drawn smallest.
A label is a Text3D, a UiPanel in 3d mode, or an instance of any
component you list in components that publishes getWorldQuad(eye). Each
is projected the way it is drawn: a billboard Text3D is turned toward the
camera's position the way its shader turns it, its right edge level with the
world, so a label off to one side of the view stands at an angle to the screen
and its rect is the one the frame shows.
Every rect is in the viewport's pixels, top-left origin: the space
worldToScreen, viewport.size and a capture of the viewport use. The
default camera is the one on screen (camera.active()): the editor
fly-camera in edit mode, the player's camera in play. Name another with
camera.
Checking a layout at a phone's shape
In one execute, so the size is held while the report is read:
local viewport = require("@builtin::tools.viewport.setSize")
local labels = require("@builtin::tools.viewport.labels")
viewport.setSize(390, 844) -- an upright phone
local upright = labels.labels({ margin = 8, gap = 2, keepOut = { "hud-health" } })
viewport.setSize(844, 390) -- the same phone turned
local turned = labels.labels({ margin = 8, gap = 2, keepOut = { "hud-health" } })
return { upright = upright.overlaps, uprightCut = upright.cut, turned = turned.overlaps }
From bash: zero viewport labels '{"margin": 8}'.
A component of your own (a name plate, a sign board) joins the report by
publishing getWorldQuad(eye), returning { corners, anchor, lines?, text?, drawnBy? }: the four world-space corners bottom-left, bottom-right,
top-right, top-left as its text reads, the line count of its text, and the
entity that draws it when that is not the component's own.