Skip to content

UWAL / MSDFText

Classes

MSDFText

Utility class to write some text onto a GPUBuffer and then use a GPUTexture to output it to a canvas. Note: This class will probably get deprecated once HTML in Canvas is widely adopted.

See

MSDF Text and Curtains examples for reference.

Constructors

Constructor
ts
new MSDFText(label?): MSDFText;
Parameters
ParameterTypeDefault valueDescription
label?string"MSDFText"Name of the text
Returns

MSDFText

Methods

CreateRenderPipeline()
ts
CreateRenderPipeline(Renderer, descriptor?): Promise<RenderPipelineInstance>;

Create an internal pipeline to render text.

Parameters
ParameterTypeDescription
RendererRenderStageRenderer instance to create the pipeline
descriptor?BasePipelineDescriptor & RenderPipelineState & Record<"renderBundleDescriptor", RenderBundleDescriptor | undefined> & Record<"colorTargets", GPUColorTargetState | GPUColorTargetState[] | undefined>Additional pipeline settings
Returns

Promise<RenderPipelineInstance>

LoadFont()
ts
LoadFont(
   url, 
   generated?, 
requestOptions?): Promise<MSDFFont>;

Load and use an MSDFFont.

Parameters
ParameterTypeDefault valueDescription
urlstringundefinedURL to load the font from
generated?booleanfalseWhether the font was generated with this tool
requestOptions?RequestInitundefinedOptional fetch request options
Returns

Promise<MSDFFont>

See

https://github.com/UstymUkhman/uwal/issues/9

Write()
ts
Write(
   string, 
   color?, 
   scale?, 
   centered?): GPUBuffer;

Write a text string to a GPUBuffer.

Parameters
ParameterTypeDefault valueDescription
stringstringundefinedString to write
color?ColorValue0x000000Text color
scale?number0.01Text scale
centered?booleanfalseSet to true to center the text
Returns

GPUBuffer

SetTranslation()
ts
SetTranslation(translation, textBuffer): void;

Set the text translation matrix.

Parameters
ParameterTypeDescription
translationFloat32Array<ArrayBufferLike>Translation matrix
textBufferGPUBufferText buffer to update
Returns

void

SetColor()
ts
SetColor(color, textBuffer): void;

Set the text color.

Parameters
ParameterTypeDescription
colorColorValueColor value
textBufferGPUBufferText buffer to update
Returns

void

SetScale()
ts
SetScale(scale, textBuffer): void;

Set the text scale.

Parameters
ParameterTypeDescription
scalenumberScale value
textBufferGPUBufferText buffer to update
Returns

void

Clear()
ts
Clear(textBuffer?): void;

Destroy the text buffer and reset its color and scale. Remove the pipeline's bind groups and reset its render bundles.

Parameters
ParameterTypeDescription
textBuffer?GPUBufferText buffer to remove
Returns

void

Destroy()
ts
Destroy(): void;

Remove the rendering pipeline, destroy the font, and reset the internal state. Only unlinking is performed; the Destroy method on the removed pipeline is not called.

Returns

void

Accessors

CameraMatrixBuffer
Set Signature
ts
set CameraMatrixBuffer(cameraBuffer): void;

Set a PrerspectiveCamera buffer to render the text.

See

https://github.com/UstymUkhman/uwal/issues/9

Parameters
ParameterTypeDescription
cameraBufferGPUBufferCamera buffer
Returns

void

Pipeline
Get Signature
ts
get Pipeline(): RenderPipelineInstance | undefined;
Returns

RenderPipelineInstance | undefined

Pipeline used for text rendering.

Font
Get Signature
ts
get Font(): MSDFFont | undefined;
Returns

MSDFFont | undefined

MSDFFont instance.

Set Signature
ts
set Font(font): void;

Dynamically set the text font. Called internaly by the LoadFont method.

Parameters
ParameterTypeDescription
fontMSDFFontMSDFFont to use
Returns

void

Released under the MIT License.