Back to API Reference
Class

UniTextMeshGenerator

Converts positioned glyphs into Unity mesh data for text rendering.

Remarks

This is the final stage of the text processing pipeline. It takes PositionedGlyph data from TextProcessor and generates vertex, UV, color, and triangle data suitable for Unity's mesh system. Key features: Groups glyphs by rendering target to minimize draw calls: one segment per font (Texture2DArray atlas) Uses pooled buffers from UniTextArrayPool<T> for zero allocations Provides callbacks for text modifiers to inject custom processing Typical usage: generator.SetRectOffset(rect); generator.GenerateMeshDataOnly(positionedGlyphs); var renderData = generator.CollectRenderData(); // Use renderData to render each segment generator.ReturnInstanceBuffers();
public int SdfVertexCount{ get }

Number of vertices in the SDF segment.

public int SdfTriangleCount{ get }

Number of triangle indices in the SDF segment.

public int EmojiVertexCount{ get }

Number of vertices in the emoji segment.

public int EmojiTriangleCount{ get }

Number of triangle indices in the emoji segment.

public int CurrentSegmentVertexStart{ get }

Starting vertex index for the current segment. Used to compute relative triangle indices.

public float FontSize{ get; set }

Gets or sets the font size in points for mesh generation.

public UniTextRenderMode RenderMode{ get; set }

Gets or sets the atlas mode (SDF or MSDF) for glyph lookup and material selection.

public bool HasGeneratedData{ get }

Gets a value indicating whether mesh data has been generated and is available.

public Vector3[] Vertices{ get }

Gets the vertex position buffer (X, Y, Z coordinates).

public Vector4[] Uvs0{ get }

Gets the primary UV buffer (texture coordinates and scale in W component).

public Color32[] Colors{ get }

Gets the vertex color buffer.

public int[] Triangles{ get }

Gets the triangle index buffer.

public Vector4[] Uvs1{ get }

Gets the UV1 buffer: x = aspect (glyphW/glyphH), y = face dilate.

public Vector4[] Uvs2{ get }

Gets the UV2 buffer containing layer 2 (underlay/shadow) parameters.

public Vector4[] Uvs3{ get }

Gets the UV3 buffer containing layer 3 (underlay/shadow) parameters.

public bool TrackGlyphKey()

Tracks a glyph key for atlas ref counting. Deduplicates automatically. Use for modifier glyphs that don't need cached entry data.

[ctor]public UniTextMeshGenerator(UniTextFontProvider fontProvider, UniTextBuffers uniTextBuffers)

Initializes a new instance of the UniTextMeshGenerator class.

public static void ScaleGlyphQuad(float pivotX)

Scales a glyph quad (4 vertices) around the cursor position and baseline. Used by SizeModifier, SmallCapsModifier, ScriptPositionModifier.

public void EnsureUvBuffer(int channel)

Allocates and zero-clears a UV effect buffer (channel 2 or 3) if not already allocated.

public void ReturnInstanceBuffers()

Returns all instance buffers to the pool and clears the generated data flag.

public void Dispose()

Releases all pooled resources. Call when the generator is no longer needed.

public void EnsureCapacity(int additionalVertices, int additionalTriangles)

Ensures the vertex and triangle buffers have capacity for additional data.

public void QueueEffectTriangle()

Queues the 6 triangle indices for an effect duplicate quad starting at destBaseIdx into the shared pre- or post-face buffer.

public void RequestBandUpgradeIfNeeded()

Requests an atlas band upgrade for the current glyph if any effect modifier asked for SDF padding wider than the current tile's computed band. Re-rasterizes the glyph at a larger tile so subsequent frames have room for the requested outline / shadow extent.

public void ExpandQuad(int baseIdx, float delta)

Expands a 4-vertex glyph quad outward on all sides by delta (UV-space). Updates both positions and UV0 consistently so the atlas sample stays aligned.

public void SetRectOffset(Rect rect)

Sets the layout rectangle for text positioning.

public void GenerateMeshDataOnly()

Generates mesh data (vertices, UVs, colors, triangles) from positioned glyphs. Groups by rendering target: SDF fonts in one segment (Texture2DArray), emoji separately.

public List<UniTextRenderData> CollectRenderData()

Collects raw render data (vertex/UV/triangle array slices + material/order metadata) for every segment produced by the latest mesh generation. Does not build Unity Mesh objects — consumers (canvas UpdateSubMeshes, world batcher) decide what to do with the raw data.

public void AssignAutoMaterials()

Ensures atlas subscription for auto-material management. Must be called on the main thread (creates materials lazily).

public static const float DefaultSdfPadding

Base UV-space padding (normalized by glyph height) allocated around every face quad. Face and effect modifiers that expand the quad must subtract this baseline from their requested extent when computing the expansion delta.

public int currentCluster

The cluster index of the glyph currently being processed.

public float height

Height of the current glyph including padding.

public float baselineY

Y coordinate of the text baseline for the current glyph.

public float cursorX

X coordinate of the cursor position (pen position) for the current glyph.

public float scale

Current font scale factor (FontSize / font.UnitsPerEm).

public float fontMetricFactor

FontSize * FontScale — converts normalized glyph metrics to UI-space units. Constant per font.

public Color32 defaultColor

Default vertex color applied to all glyphs.

public float paddingPixels

Atlas padding in pixels from font settings.

public float padding

Padding in font units.

public float padding2

Double padding for width/height calculations.

public float invAtlasSize

Inverse atlas size for UV calculations: 1 / atlasSize.

public UniTextFont font

Current font being processed.

public float offsetX

X offset from the rect origin.

public float offsetY

Y offset from the rect origin.

public int vertexCount

Current number of vertices in the mesh buffers.

public int triangleCount

Current number of triangle indices in the mesh buffers.

public int faceBaseIdx

Index of the first vertex of the face quad of the glyph currently being processed. Stable across all onGlyph invocations for a single glyph, even when modifiers append additional geometry that grows vertexCount.

public Action onMainPassComplete

Invoked after the main glyph loop completes, before any finalization phase. Subscribers may emit additional quads into the open vertex stream; if they call onGlyph for each emitted quad with isVirtualGlyph set, per-glyph modifiers (color, gradient, bold) and effect modifiers (outline, shadow, extrude) pick up the new quads through the standard pipeline.

public Action onMainPassFinalize

Finalization phase for the main glyph pass (SDF). Runs after onMainPassComplete and before the emoji segment is processed.

public Action onGlyph

Invoked for each glyph during mesh generation.

public Action onRebuildEnd

Invoked after all mesh generation is complete.

public Action onRebuildStart

Invoked before mesh generation starts.

public Action<List<UniTextRenderData>> onCollectSubMeshes

Invoked by CollectRenderData after base SDF/emoji segments are written to the result buffer, but before the buffer is sorted and returned. Subscribers append their own UniTextRenderData entries (each with a custom materialOverride, atlasOverride, order and sortIndex) to the provided list.

public float currentMaxGlyphExtent

Maximum UV-space padding requested for the current glyph by any modifier. Reset to 0 before each onGlyph invocation. Subscribers accumulate via max. Read after onGlyph to decide atlas band upgrades.

public bool isVirtualGlyph

True when the currently processed glyph is virtual (injected by a modifier — list marker, ellipsis dot — and has no ShapedGlyph behind it).

public EffectPass currentEffectPass

Determines where EffectModifier duplicate quads (outline, shadow, extrude) land in the index buffer for the currently processed glyph.

public int postFaceInsertPoint

Triangle-buffer index where PostFace triangles are inserted during finalization. Negative means "append to the tail".

See Also