Skip to content

@orillusion/core


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

readonly static DEFAULT_TEXT_OPTS: Required<TextOptions>

Defined in: src/util/UIUtil.ts:17

Text rendering options. Missing fields fall back to sensible defaults.

Methods

measureText()

static measureText(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?

TextOptions

Returns

object

width

width: number

height

height: number


textToTexture()

static textToTexture(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

Context3D

opts?

TextOptions

Returns

Promise<BitmapTexture2D>


updateTextTexture()

static updateTextTexture(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

BitmapTexture2D

text

string

opts?

TextOptions

Returns

Promise<void>