Class: UIUtil
Defined in: src/util/UIUtil.ts:15
Utility helpers for building sprite textures from Canvas2D output — primarily textToTexture for rendering labels (name tags, HP text, damage numbers) that live in the 3D world via SpriteRenderer.
Designed for static / low-frequency updates (fewer than ~10 Hz, fewer than ~50 simultaneous text elements). For high-frequency animated text, build a dedicated atlas.
Constructors
Constructor
new UIUtil():
UIUtil
Returns
UIUtil
Properties
DEFAULT_TEXT_OPTS
readonlystaticDEFAULT_TEXT_OPTS:Required<TextOptions>
Defined in: src/util/UIUtil.ts:17
Text rendering options. Missing fields fall back to sensible defaults.
Methods
measureText()
staticmeasureText(text,opts?):object
Defined in: src/util/UIUtil.ts:33
Measure the CSS-pixel size needed to render text with the given options.
Parameters
text
string
opts?
Returns
object
width
width:
number
height
height:
number
textToTexture()
statictextToTexture(text,ctx,opts?):Promise<BitmapTexture2D>
Defined in: src/util/UIUtil.ts:55
Render text to a new GPU texture. Returns a BitmapTexture2D bound to ctx. The texture format is rgba8unorm with premultiplied alpha — suitable for SpriteMaterial.baseMap.
Parameters
text
string
ctx
opts?
Returns
Promise<BitmapTexture2D>
updateTextTexture()
staticupdateTextTexture(texture,text,opts?):Promise<void>
Defined in: src/util/UIUtil.ts:69
Re-render text into an existing texture's backing store. Requires the texture's width/height to match the new size — if they differ, the texture is recreated under the hood via the standard source setter.
Parameters
texture
text
string
opts?
Returns
Promise<void>

