TextMesh

继承: PrimitiveMesh < Mesh < Resource < RefCounted < Object

根据文本生成 PrimitiveMesh

描述

根据文本生成 PrimitiveMesh

使用了矢量字形轮廓的动态字体才能用于生成 TextMesh。不支持位图字体(包括 TrueType/OpenType 容器中的位图数据,例如彩色 Emoji 字体)。

UV 布局由 4 个横条组成,从上到下依次为:正面占 40% 高度,背面占 40% 的高度,外面占 10% 的高度,内侧面占 10% 的高度。

教程

属性

AutowrapMode

autowrap_mode

0

float

curve_step

0.5

float

depth

0.05

Font

font

int

font_size

16

HorizontalAlignment

horizontal_alignment

1

BitField[JustificationFlag]

justification_flags

163

String

language

""

float

line_spacing

0.0

Vector2

offset

Vector2(0, 0)

float

pixel_size

0.01

StructuredTextParser

structured_text_bidi_override

0

Array

structured_text_bidi_override_options

[]

String

text

""

Direction

text_direction

0

bool

uppercase

false

VerticalAlignment

vertical_alignment

1

float

width

500.0


属性说明

AutowrapMode autowrap_mode = 0 🔗

如果设置为 TextServer.AUTOWRAP_OFF 以外的值,则文本将在节点的边界矩形内自动换行。如果你调整节点大小,就会自动更改其高度,从而显示所有文本。


float curve_step = 0.5 🔗

  • void set_curve_step(value: float)

  • float get_curve_step()

Step (in pixels) used to approximate Bézier curves. Lower values result in smoother curves, but is slower to generate and render. Consider adjusting this according to the font size and the typical viewing distance.

Note: Changing this property will regenerate the mesh, which is a slow operation, especially with large font sizes and long texts.


float depth = 0.05 🔗

生成的网格的深度,设为 0.0 时只有正面,此时的 UV 布局会变为让正面占据整张纹理。


Font font 🔗

  • void set_font(value: Font)

  • Font get_font()

用于显示文本的字体配置。


int font_size = 16 🔗

  • void set_font_size(value: int)

  • int get_font_size()

Font size of the TextMesh's text. This property works in tandem with pixel_size. Higher values will result in a more detailed font, regardless of curve_step and pixel_size. Consider keeping this value below 63 (inclusive) for good performance, and adjust pixel_size as needed to enlarge text.

Note: Changing this property will regenerate the mesh, which is a slow operation, especially with large font sizes and long texts. To change the text's size in real-time efficiently, change the node's Node3D.scale instead.


HorizontalAlignment horizontal_alignment = 1 🔗

控制文本的水平对齐方式。支持左对齐、居中对齐、右对齐、填充(即两端对齐)。


BitField[JustificationFlag] justification_flags = 163 🔗

行填充对齐规则。


String language = "" 🔗

Language code used for line-breaking and text shaping algorithms. If left empty, the current locale is used instead.


float line_spacing = 0.0 🔗

  • void set_line_spacing(value: float)

  • float get_line_spacing()

行与行之间的额外纵向留白(单位为像素),留白会被添加到行的降部。该值可以为负数。


Vector2 offset = Vector2(0, 0) 🔗

The text drawing offset (in pixels).

Note: Changing this property will regenerate the mesh, which is a slow operation. To change the text's position in real-time efficiently, change the node's Node3D.position instead.


float pixel_size = 0.01 🔗

  • void set_pixel_size(value: float)

  • float get_pixel_size()

The size of one pixel's width on the text to scale it in 3D. This property works in tandem with font_size.

Note: Changing this property will regenerate the mesh, which is a slow operation, especially with large font sizes and long texts. To change the text's size in real-time efficiently, change the node's Node3D.scale instead.


StructuredTextParser structured_text_bidi_override = 0 🔗

为结构化文本设置 BiDi 算法覆盖。


Array structured_text_bidi_override_options = [] 🔗

  • void set_structured_text_bidi_override_options(value: Array)

  • Array get_structured_text_bidi_override_options()

设置 BiDi 覆盖的附加选项。


String text = "" 🔗

要从中生成网格的文本。

注意:由于是 Resource,所以它并不遵循 Node.auto_translate_mode 的规则。如果需要禁用翻译,则应使用 Object.set_message_translation() 手动完成。


Direction text_direction = 0 🔗

基础文本书写方向。


bool uppercase = false 🔗

  • void set_uppercase(value: bool)

  • bool is_uppercase()

如果为 true,所有文本都将显示为大写。


VerticalAlignment vertical_alignment = 1 🔗

控制文本的垂直对齐方式。支持顶部对齐、居中对齐、底部对齐。


float width = 500.0 🔗

文本宽度(单位为像素),用于填充对齐。