Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/3d/label_3d.cpp
20837 views
1
/**************************************************************************/
2
/* label_3d.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "label_3d.h"
32
33
#include "scene/main/window.h"
34
#include "scene/resources/mesh.h"
35
#include "scene/resources/theme.h"
36
#include "scene/theme/theme_db.h"
37
38
void Label3D::_bind_methods() {
39
ClassDB::bind_method(D_METHOD("set_horizontal_alignment", "alignment"), &Label3D::set_horizontal_alignment);
40
ClassDB::bind_method(D_METHOD("get_horizontal_alignment"), &Label3D::get_horizontal_alignment);
41
42
ClassDB::bind_method(D_METHOD("set_vertical_alignment", "alignment"), &Label3D::set_vertical_alignment);
43
ClassDB::bind_method(D_METHOD("get_vertical_alignment"), &Label3D::get_vertical_alignment);
44
45
ClassDB::bind_method(D_METHOD("set_modulate", "modulate"), &Label3D::set_modulate);
46
ClassDB::bind_method(D_METHOD("get_modulate"), &Label3D::get_modulate);
47
48
ClassDB::bind_method(D_METHOD("set_outline_modulate", "modulate"), &Label3D::set_outline_modulate);
49
ClassDB::bind_method(D_METHOD("get_outline_modulate"), &Label3D::get_outline_modulate);
50
51
ClassDB::bind_method(D_METHOD("set_text", "text"), &Label3D::set_text);
52
ClassDB::bind_method(D_METHOD("get_text"), &Label3D::get_text);
53
54
ClassDB::bind_method(D_METHOD("set_text_direction", "direction"), &Label3D::set_text_direction);
55
ClassDB::bind_method(D_METHOD("get_text_direction"), &Label3D::get_text_direction);
56
57
ClassDB::bind_method(D_METHOD("set_language", "language"), &Label3D::set_language);
58
ClassDB::bind_method(D_METHOD("get_language"), &Label3D::get_language);
59
60
ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override", "parser"), &Label3D::set_structured_text_bidi_override);
61
ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override"), &Label3D::get_structured_text_bidi_override);
62
63
ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override_options", "args"), &Label3D::set_structured_text_bidi_override_options);
64
ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override_options"), &Label3D::get_structured_text_bidi_override_options);
65
66
ClassDB::bind_method(D_METHOD("set_uppercase", "enable"), &Label3D::set_uppercase);
67
ClassDB::bind_method(D_METHOD("is_uppercase"), &Label3D::is_uppercase);
68
69
ClassDB::bind_method(D_METHOD("set_render_priority", "priority"), &Label3D::set_render_priority);
70
ClassDB::bind_method(D_METHOD("get_render_priority"), &Label3D::get_render_priority);
71
72
ClassDB::bind_method(D_METHOD("set_outline_render_priority", "priority"), &Label3D::set_outline_render_priority);
73
ClassDB::bind_method(D_METHOD("get_outline_render_priority"), &Label3D::get_outline_render_priority);
74
75
ClassDB::bind_method(D_METHOD("set_font", "font"), &Label3D::set_font);
76
ClassDB::bind_method(D_METHOD("get_font"), &Label3D::get_font);
77
78
ClassDB::bind_method(D_METHOD("set_font_size", "size"), &Label3D::set_font_size);
79
ClassDB::bind_method(D_METHOD("get_font_size"), &Label3D::get_font_size);
80
81
ClassDB::bind_method(D_METHOD("set_outline_size", "outline_size"), &Label3D::set_outline_size);
82
ClassDB::bind_method(D_METHOD("get_outline_size"), &Label3D::get_outline_size);
83
84
ClassDB::bind_method(D_METHOD("set_line_spacing", "line_spacing"), &Label3D::set_line_spacing);
85
ClassDB::bind_method(D_METHOD("get_line_spacing"), &Label3D::get_line_spacing);
86
87
ClassDB::bind_method(D_METHOD("set_autowrap_mode", "autowrap_mode"), &Label3D::set_autowrap_mode);
88
ClassDB::bind_method(D_METHOD("get_autowrap_mode"), &Label3D::get_autowrap_mode);
89
90
ClassDB::bind_method(D_METHOD("set_autowrap_trim_flags", "autowrap_trim_flags"), &Label3D::set_autowrap_trim_flags);
91
ClassDB::bind_method(D_METHOD("get_autowrap_trim_flags"), &Label3D::get_autowrap_trim_flags);
92
93
ClassDB::bind_method(D_METHOD("set_justification_flags", "justification_flags"), &Label3D::set_justification_flags);
94
ClassDB::bind_method(D_METHOD("get_justification_flags"), &Label3D::get_justification_flags);
95
96
ClassDB::bind_method(D_METHOD("set_width", "width"), &Label3D::set_width);
97
ClassDB::bind_method(D_METHOD("get_width"), &Label3D::get_width);
98
99
ClassDB::bind_method(D_METHOD("set_pixel_size", "pixel_size"), &Label3D::set_pixel_size);
100
ClassDB::bind_method(D_METHOD("get_pixel_size"), &Label3D::get_pixel_size);
101
102
ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Label3D::set_offset);
103
ClassDB::bind_method(D_METHOD("get_offset"), &Label3D::get_offset);
104
105
ClassDB::bind_method(D_METHOD("set_draw_flag", "flag", "enabled"), &Label3D::set_draw_flag);
106
ClassDB::bind_method(D_METHOD("get_draw_flag", "flag"), &Label3D::get_draw_flag);
107
108
ClassDB::bind_method(D_METHOD("set_billboard_mode", "mode"), &Label3D::set_billboard_mode);
109
ClassDB::bind_method(D_METHOD("get_billboard_mode"), &Label3D::get_billboard_mode);
110
111
ClassDB::bind_method(D_METHOD("set_alpha_cut_mode", "mode"), &Label3D::set_alpha_cut_mode);
112
ClassDB::bind_method(D_METHOD("get_alpha_cut_mode"), &Label3D::get_alpha_cut_mode);
113
114
ClassDB::bind_method(D_METHOD("set_alpha_scissor_threshold", "threshold"), &Label3D::set_alpha_scissor_threshold);
115
ClassDB::bind_method(D_METHOD("get_alpha_scissor_threshold"), &Label3D::get_alpha_scissor_threshold);
116
117
ClassDB::bind_method(D_METHOD("set_alpha_hash_scale", "threshold"), &Label3D::set_alpha_hash_scale);
118
ClassDB::bind_method(D_METHOD("get_alpha_hash_scale"), &Label3D::get_alpha_hash_scale);
119
120
ClassDB::bind_method(D_METHOD("set_alpha_antialiasing", "alpha_aa"), &Label3D::set_alpha_antialiasing);
121
ClassDB::bind_method(D_METHOD("get_alpha_antialiasing"), &Label3D::get_alpha_antialiasing);
122
123
ClassDB::bind_method(D_METHOD("set_alpha_antialiasing_edge", "edge"), &Label3D::set_alpha_antialiasing_edge);
124
ClassDB::bind_method(D_METHOD("get_alpha_antialiasing_edge"), &Label3D::get_alpha_antialiasing_edge);
125
126
ClassDB::bind_method(D_METHOD("set_texture_filter", "mode"), &Label3D::set_texture_filter);
127
ClassDB::bind_method(D_METHOD("get_texture_filter"), &Label3D::get_texture_filter);
128
129
ClassDB::bind_method(D_METHOD("generate_triangle_mesh"), &Label3D::generate_triangle_mesh);
130
131
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pixel_size", PROPERTY_HINT_RANGE, "0.0001,128,0.0001,suffix:m"), "set_pixel_size", "get_pixel_size");
132
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset", PROPERTY_HINT_NONE, "suffix:px"), "set_offset", "get_offset");
133
134
ADD_GROUP("Flags", "");
135
ADD_PROPERTY(PropertyInfo(Variant::INT, "billboard", PROPERTY_HINT_ENUM, "Disabled,Enabled,Y-Billboard"), "set_billboard_mode", "get_billboard_mode");
136
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "shaded"), "set_draw_flag", "get_draw_flag", FLAG_SHADED);
137
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "double_sided"), "set_draw_flag", "get_draw_flag", FLAG_DOUBLE_SIDED);
138
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "no_depth_test"), "set_draw_flag", "get_draw_flag", FLAG_DISABLE_DEPTH_TEST);
139
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "fixed_size"), "set_draw_flag", "get_draw_flag", FLAG_FIXED_SIZE);
140
ADD_PROPERTY(PropertyInfo(Variant::INT, "alpha_cut", PROPERTY_HINT_ENUM, "Disabled,Discard,Opaque Pre-Pass,Alpha Hash"), "set_alpha_cut_mode", "get_alpha_cut_mode");
141
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "alpha_scissor_threshold", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_alpha_scissor_threshold", "get_alpha_scissor_threshold");
142
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "alpha_hash_scale", PROPERTY_HINT_RANGE, "0,2,0.01"), "set_alpha_hash_scale", "get_alpha_hash_scale");
143
ADD_PROPERTY(PropertyInfo(Variant::INT, "alpha_antialiasing_mode", PROPERTY_HINT_ENUM, "Disabled,Alpha Edge Blend,Alpha Edge Clip"), "set_alpha_antialiasing", "get_alpha_antialiasing");
144
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "alpha_antialiasing_edge", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_alpha_antialiasing_edge", "get_alpha_antialiasing_edge");
145
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Nearest Mipmap,Linear Mipmap,Nearest Mipmap Anisotropic,Linear Mipmap Anisotropic"), "set_texture_filter", "get_texture_filter");
146
ADD_PROPERTY(PropertyInfo(Variant::INT, "render_priority", PROPERTY_HINT_RANGE, itos(RS::MATERIAL_RENDER_PRIORITY_MIN) + "," + itos(RS::MATERIAL_RENDER_PRIORITY_MAX) + ",1"), "set_render_priority", "get_render_priority");
147
ADD_PROPERTY(PropertyInfo(Variant::INT, "outline_render_priority", PROPERTY_HINT_RANGE, itos(RS::MATERIAL_RENDER_PRIORITY_MIN) + "," + itos(RS::MATERIAL_RENDER_PRIORITY_MAX) + ",1"), "set_outline_render_priority", "get_outline_render_priority");
148
149
ADD_GROUP("Text", "");
150
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate");
151
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "outline_modulate"), "set_outline_modulate", "get_outline_modulate");
152
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, ""), "set_text", "get_text");
153
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "font", PROPERTY_HINT_RESOURCE_TYPE, Font::get_class_static()), "set_font", "get_font");
154
ADD_PROPERTY(PropertyInfo(Variant::INT, "font_size", PROPERTY_HINT_RANGE, "1,256,1,or_greater,suffix:px"), "set_font_size", "get_font_size");
155
ADD_PROPERTY(PropertyInfo(Variant::INT, "outline_size", PROPERTY_HINT_RANGE, "0,127,1,suffix:px"), "set_outline_size", "get_outline_size");
156
ADD_PROPERTY(PropertyInfo(Variant::INT, "horizontal_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_horizontal_alignment", "get_horizontal_alignment");
157
ADD_PROPERTY(PropertyInfo(Variant::INT, "vertical_alignment", PROPERTY_HINT_ENUM, "Top,Center,Bottom"), "set_vertical_alignment", "get_vertical_alignment");
158
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uppercase"), "set_uppercase", "is_uppercase");
159
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "line_spacing", PROPERTY_HINT_NONE, "suffix:px"), "set_line_spacing", "get_line_spacing");
160
ADD_PROPERTY(PropertyInfo(Variant::INT, "autowrap_mode", PROPERTY_HINT_ENUM, "Off,Arbitrary,Word,Word (Smart)"), "set_autowrap_mode", "get_autowrap_mode");
161
ADD_PROPERTY(PropertyInfo(Variant::INT, "autowrap_trim_flags", PROPERTY_HINT_FLAGS, vformat("Trim Spaces After Break:%d,Trim Spaces Before Break:%d", TextServer::BREAK_TRIM_START_EDGE_SPACES, TextServer::BREAK_TRIM_END_EDGE_SPACES)), "set_autowrap_trim_flags", "get_autowrap_trim_flags");
162
ADD_PROPERTY(PropertyInfo(Variant::INT, "justification_flags", PROPERTY_HINT_FLAGS, "Kashida Justification:1,Word Justification:2,Justify Only After Last Tab:8,Skip Last Line:32,Skip Last Line With Visible Characters:64,Do Not Skip Single Line:128"), "set_justification_flags", "get_justification_flags");
163
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "width", PROPERTY_HINT_NONE, "suffix:px"), "set_width", "get_width");
164
165
ADD_GROUP("BiDi", "");
166
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left"), "set_text_direction", "get_text_direction");
167
ADD_PROPERTY(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "set_language", "get_language");
168
ADD_PROPERTY(PropertyInfo(Variant::INT, "structured_text_bidi_override", PROPERTY_HINT_ENUM, "Default,URI,File,Email,List,None,Custom"), "set_structured_text_bidi_override", "get_structured_text_bidi_override");
169
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "structured_text_bidi_override_options"), "set_structured_text_bidi_override_options", "get_structured_text_bidi_override_options");
170
171
BIND_ENUM_CONSTANT(FLAG_SHADED);
172
BIND_ENUM_CONSTANT(FLAG_DOUBLE_SIDED);
173
BIND_ENUM_CONSTANT(FLAG_DISABLE_DEPTH_TEST);
174
BIND_ENUM_CONSTANT(FLAG_FIXED_SIZE);
175
BIND_ENUM_CONSTANT(FLAG_MAX);
176
177
BIND_ENUM_CONSTANT(ALPHA_CUT_DISABLED);
178
BIND_ENUM_CONSTANT(ALPHA_CUT_DISCARD);
179
BIND_ENUM_CONSTANT(ALPHA_CUT_OPAQUE_PREPASS);
180
BIND_ENUM_CONSTANT(ALPHA_CUT_HASH);
181
}
182
183
void Label3D::_validate_property(PropertyInfo &p_property) const {
184
if (!Engine::get_singleton()->is_editor_hint()) {
185
return;
186
}
187
if (
188
p_property.name == "material_override" ||
189
p_property.name == "material_overlay" ||
190
p_property.name == "lod_bias" ||
191
p_property.name == "gi_mode" ||
192
p_property.name == "gi_lightmap_scale") {
193
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
194
}
195
196
if (p_property.name == "cast_shadow" && alpha_cut == ALPHA_CUT_DISABLED) {
197
// Alpha-blended materials can't cast shadows.
198
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
199
}
200
}
201
202
void Label3D::_notification(int p_what) {
203
switch (p_what) {
204
case NOTIFICATION_ENTER_TREE: {
205
if (!pending_update) {
206
_im_update();
207
}
208
Window *window = get_window();
209
ERR_FAIL_NULL(window);
210
window->connect("size_changed", callable_mp(this, &Label3D::_font_changed));
211
} break;
212
case NOTIFICATION_EXIT_TREE: {
213
Window *window = get_window();
214
ERR_FAIL_NULL(window);
215
window->disconnect("size_changed", callable_mp(this, &Label3D::_font_changed));
216
} break;
217
case NOTIFICATION_TRANSLATION_CHANGED: {
218
// Language update might change the appearance of some characters.
219
xl_text = atr(text);
220
dirty_text = true;
221
_queue_update();
222
} break;
223
}
224
}
225
226
void Label3D::_im_update() {
227
_shape();
228
229
triangle_mesh.unref();
230
update_gizmos();
231
232
pending_update = false;
233
}
234
235
void Label3D::_queue_update() {
236
if (pending_update) {
237
return;
238
}
239
240
pending_update = true;
241
callable_mp(this, &Label3D::_im_update).call_deferred();
242
}
243
244
AABB Label3D::get_aabb() const {
245
return aabb;
246
}
247
248
Ref<TriangleMesh> Label3D::generate_triangle_mesh() const {
249
if (triangle_mesh.is_valid()) {
250
return triangle_mesh;
251
}
252
253
Ref<Font> font = _get_font_or_default();
254
if (font.is_null()) {
255
return Ref<TriangleMesh>();
256
}
257
258
Vector<Vector3> faces;
259
faces.resize(6);
260
Vector3 *facesw = faces.ptrw();
261
262
float total_h = 0.0;
263
float max_line_w = 0.0;
264
for (int i = 0; i < lines_rid.size(); i++) {
265
total_h += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing;
266
max_line_w = MAX(max_line_w, TS->shaped_text_get_width(lines_rid[i]));
267
}
268
269
float vbegin = 0;
270
switch (vertical_alignment) {
271
case VERTICAL_ALIGNMENT_FILL:
272
case VERTICAL_ALIGNMENT_TOP: {
273
// Nothing.
274
} break;
275
case VERTICAL_ALIGNMENT_CENTER: {
276
vbegin = (total_h - line_spacing) / 2.0;
277
} break;
278
case VERTICAL_ALIGNMENT_BOTTOM: {
279
vbegin = (total_h - line_spacing);
280
} break;
281
}
282
283
Vector2 offset = Vector2(0, vbegin);
284
switch (horizontal_alignment) {
285
case HORIZONTAL_ALIGNMENT_LEFT:
286
break;
287
case HORIZONTAL_ALIGNMENT_FILL:
288
case HORIZONTAL_ALIGNMENT_CENTER: {
289
offset.x = -max_line_w / 2.0;
290
} break;
291
case HORIZONTAL_ALIGNMENT_RIGHT: {
292
offset.x = -max_line_w;
293
} break;
294
}
295
296
Rect2 final_rect = Rect2(offset + lbl_offset, Size2(max_line_w, total_h));
297
298
if (final_rect.size.x == 0 || final_rect.size.y == 0) {
299
return Ref<TriangleMesh>();
300
}
301
302
real_t px_size = get_pixel_size();
303
304
Vector2 vertices[4] = {
305
306
(final_rect.position + Vector2(0, -final_rect.size.y)) * px_size,
307
(final_rect.position + Vector2(final_rect.size.x, -final_rect.size.y)) * px_size,
308
(final_rect.position + Vector2(final_rect.size.x, 0)) * px_size,
309
final_rect.position * px_size,
310
311
};
312
313
static const int indices[6] = {
314
0, 1, 2,
315
0, 2, 3
316
};
317
318
for (int j = 0; j < 6; j++) {
319
int i = indices[j];
320
Vector3 vtx;
321
vtx[0] = vertices[i][0];
322
vtx[1] = vertices[i][1];
323
facesw[j] = vtx;
324
}
325
326
triangle_mesh.instantiate();
327
triangle_mesh->create(faces);
328
329
return triangle_mesh;
330
}
331
332
void Label3D::_generate_glyph_surfaces(const Glyph &p_glyph, Vector2 &r_offset, const Color &p_modulate, int p_priority, int p_outline_size) {
333
if (p_glyph.index == 0) {
334
r_offset.x += p_glyph.advance * pixel_size * p_glyph.repeat; // Non visual character, skip.
335
return;
336
}
337
338
Vector2 gl_of;
339
Vector2 gl_sz;
340
Rect2 gl_uv;
341
Size2 texs;
342
RID tex;
343
344
if (p_glyph.font_rid.is_valid()) {
345
tex = TS->font_get_glyph_texture_rid(p_glyph.font_rid, Vector2i(p_glyph.font_size, p_outline_size), p_glyph.index);
346
if (tex.is_valid()) {
347
gl_of = (TS->font_get_glyph_offset(p_glyph.font_rid, Vector2i(p_glyph.font_size, p_outline_size), p_glyph.index) + Vector2(p_glyph.x_off, p_glyph.y_off)) * pixel_size;
348
gl_sz = TS->font_get_glyph_size(p_glyph.font_rid, Vector2i(p_glyph.font_size, p_outline_size), p_glyph.index) * pixel_size;
349
gl_uv = TS->font_get_glyph_uv_rect(p_glyph.font_rid, Vector2i(p_glyph.font_size, p_outline_size), p_glyph.index);
350
texs = TS->font_get_glyph_texture_size(p_glyph.font_rid, Vector2i(p_glyph.font_size, p_outline_size), p_glyph.index);
351
}
352
} else if (((p_glyph.flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) && ((p_glyph.flags & TextServer::GRAPHEME_IS_EMBEDDED_OBJECT) != TextServer::GRAPHEME_IS_EMBEDDED_OBJECT)) {
353
gl_sz = TS->get_hex_code_box_size(p_glyph.font_size, p_glyph.index) * pixel_size;
354
gl_of = Vector2(0, -gl_sz.y);
355
}
356
357
if (gl_uv.size.x <= 2 || gl_uv.size.y <= 2) {
358
r_offset.x += p_glyph.advance * pixel_size * p_glyph.repeat; // Nothing to draw.
359
return;
360
}
361
362
bool msdf = TS->font_is_multichannel_signed_distance_field(p_glyph.font_rid);
363
364
for (int j = 0; j < p_glyph.repeat; j++) {
365
SurfaceKey key = SurfaceKey(tex.get_id(), p_priority, p_outline_size);
366
if (!surfaces.has(key)) {
367
SurfaceData surf;
368
surf.material = RenderingServer::get_singleton()->material_create();
369
// Set defaults for material, names need to match up those in StandardMaterial3D
370
RS::get_singleton()->material_set_param(surf.material, "albedo", Color(1, 1, 1, 1));
371
RS::get_singleton()->material_set_param(surf.material, "specular", 0.5);
372
RS::get_singleton()->material_set_param(surf.material, "metallic", 0.0);
373
RS::get_singleton()->material_set_param(surf.material, "roughness", 1.0);
374
RS::get_singleton()->material_set_param(surf.material, "uv1_offset", Vector3(0, 0, 0));
375
RS::get_singleton()->material_set_param(surf.material, "uv1_scale", Vector3(1, 1, 1));
376
RS::get_singleton()->material_set_param(surf.material, "uv2_offset", Vector3(0, 0, 0));
377
RS::get_singleton()->material_set_param(surf.material, "uv2_scale", Vector3(1, 1, 1));
378
RS::get_singleton()->material_set_param(surf.material, "alpha_scissor_threshold", alpha_scissor_threshold);
379
RS::get_singleton()->material_set_param(surf.material, "alpha_hash_scale", alpha_hash_scale);
380
RS::get_singleton()->material_set_param(surf.material, "alpha_antialiasing_edge", alpha_antialiasing_edge);
381
if (msdf) {
382
RS::get_singleton()->material_set_param(surf.material, "msdf_pixel_range", TS->font_get_msdf_pixel_range(p_glyph.font_rid));
383
RS::get_singleton()->material_set_param(surf.material, "msdf_outline_size", p_outline_size);
384
}
385
386
BaseMaterial3D::Transparency mat_transparency = BaseMaterial3D::Transparency::TRANSPARENCY_ALPHA;
387
if (get_alpha_cut_mode() == ALPHA_CUT_DISCARD) {
388
mat_transparency = BaseMaterial3D::Transparency::TRANSPARENCY_ALPHA_SCISSOR;
389
} else if (get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS) {
390
mat_transparency = BaseMaterial3D::Transparency::TRANSPARENCY_ALPHA_DEPTH_PRE_PASS;
391
} else if (get_alpha_cut_mode() == ALPHA_CUT_HASH) {
392
mat_transparency = BaseMaterial3D::Transparency::TRANSPARENCY_ALPHA_HASH;
393
}
394
395
RID shader_rid;
396
StandardMaterial3D::get_material_for_2d(get_draw_flag(FLAG_SHADED), mat_transparency, get_draw_flag(FLAG_DOUBLE_SIDED), get_billboard_mode() == StandardMaterial3D::BILLBOARD_ENABLED, get_billboard_mode() == StandardMaterial3D::BILLBOARD_FIXED_Y, msdf, get_draw_flag(FLAG_DISABLE_DEPTH_TEST), get_draw_flag(FLAG_FIXED_SIZE), texture_filter, alpha_antialiasing_mode, false, &shader_rid);
397
398
RS::get_singleton()->material_set_shader(surf.material, shader_rid);
399
RS::get_singleton()->material_set_param(surf.material, "texture_albedo", tex);
400
RS::get_singleton()->material_set_param(surf.material, "albedo_texture_size", texs);
401
if (get_alpha_cut_mode() == ALPHA_CUT_DISABLED) {
402
RS::get_singleton()->material_set_render_priority(surf.material, p_priority);
403
} else {
404
surf.z_shift = p_priority * pixel_size;
405
}
406
407
surfaces[key] = surf;
408
}
409
SurfaceData &s = surfaces[key];
410
411
s.mesh_vertices.resize((s.offset + 1) * 4);
412
s.mesh_normals.resize((s.offset + 1) * 4);
413
s.mesh_tangents.resize((s.offset + 1) * 16);
414
s.mesh_colors.resize((s.offset + 1) * 4);
415
s.mesh_uvs.resize((s.offset + 1) * 4);
416
417
s.mesh_vertices.write[(s.offset * 4) + 3] = Vector3(r_offset.x + gl_of.x, r_offset.y - gl_of.y - gl_sz.y, s.z_shift);
418
s.mesh_vertices.write[(s.offset * 4) + 2] = Vector3(r_offset.x + gl_of.x + gl_sz.x, r_offset.y - gl_of.y - gl_sz.y, s.z_shift);
419
s.mesh_vertices.write[(s.offset * 4) + 1] = Vector3(r_offset.x + gl_of.x + gl_sz.x, r_offset.y - gl_of.y, s.z_shift);
420
s.mesh_vertices.write[(s.offset * 4) + 0] = Vector3(r_offset.x + gl_of.x, r_offset.y - gl_of.y, s.z_shift);
421
422
for (int i = 0; i < 4; i++) {
423
s.mesh_normals.write[(s.offset * 4) + i] = Vector3(0.0, 0.0, 1.0);
424
s.mesh_tangents.write[(s.offset * 16) + (i * 4) + 0] = 1.0;
425
s.mesh_tangents.write[(s.offset * 16) + (i * 4) + 1] = 0.0;
426
s.mesh_tangents.write[(s.offset * 16) + (i * 4) + 2] = 0.0;
427
s.mesh_tangents.write[(s.offset * 16) + (i * 4) + 3] = 1.0;
428
s.mesh_colors.write[(s.offset * 4) + i] = p_modulate;
429
s.mesh_uvs.write[(s.offset * 4) + i] = Vector2();
430
}
431
432
if (tex.is_valid()) {
433
s.mesh_uvs.write[(s.offset * 4) + 3] = Vector2(gl_uv.position.x / texs.x, (gl_uv.position.y + gl_uv.size.y) / texs.y);
434
s.mesh_uvs.write[(s.offset * 4) + 2] = Vector2((gl_uv.position.x + gl_uv.size.x) / texs.x, (gl_uv.position.y + gl_uv.size.y) / texs.y);
435
s.mesh_uvs.write[(s.offset * 4) + 1] = Vector2((gl_uv.position.x + gl_uv.size.x) / texs.x, gl_uv.position.y / texs.y);
436
s.mesh_uvs.write[(s.offset * 4) + 0] = Vector2(gl_uv.position.x / texs.x, gl_uv.position.y / texs.y);
437
}
438
439
s.indices.resize((s.offset + 1) * 6);
440
s.indices.write[(s.offset * 6) + 0] = (s.offset * 4) + 0;
441
s.indices.write[(s.offset * 6) + 1] = (s.offset * 4) + 1;
442
s.indices.write[(s.offset * 6) + 2] = (s.offset * 4) + 2;
443
s.indices.write[(s.offset * 6) + 3] = (s.offset * 4) + 0;
444
s.indices.write[(s.offset * 6) + 4] = (s.offset * 4) + 2;
445
s.indices.write[(s.offset * 6) + 5] = (s.offset * 4) + 3;
446
447
s.offset++;
448
r_offset.x += p_glyph.advance * pixel_size;
449
}
450
}
451
452
void Label3D::_shape() {
453
// When a shaped text is invalidated by an external source, we want to reshape it.
454
if (!TS->shaped_text_is_ready(text_rid)) {
455
dirty_text = true;
456
}
457
458
for (const RID &line_rid : lines_rid) {
459
if (!TS->shaped_text_is_ready(line_rid)) {
460
dirty_lines = true;
461
break;
462
}
463
}
464
465
// Clear mesh.
466
RS::get_singleton()->mesh_clear(mesh);
467
aabb = AABB();
468
469
// Clear materials.
470
for (const KeyValue<SurfaceKey, SurfaceData> &E : surfaces) {
471
RenderingServer::get_singleton()->free_rid(E.value.material);
472
}
473
surfaces.clear();
474
475
Ref<Font> font = _get_font_or_default();
476
ERR_FAIL_COND(font.is_null());
477
478
// Update text buffer.
479
if (dirty_text) {
480
TS->shaped_text_clear(text_rid);
481
TS->shaped_text_set_direction(text_rid, text_direction);
482
483
const String &lang = language.is_empty() ? _get_locale() : language;
484
String txt = uppercase ? TS->string_to_upper(xl_text, lang) : xl_text;
485
TS->shaped_text_add_string(text_rid, txt, font->get_rids(), font_size, font->get_opentype_features(), lang);
486
487
TypedArray<Vector3i> stt;
488
if (st_parser == TextServer::STRUCTURED_TEXT_CUSTOM) {
489
GDVIRTUAL_CALL(_structured_text_parser, st_args, txt, stt);
490
} else {
491
stt = TS->parse_structured_text(st_parser, st_args, txt);
492
}
493
TS->shaped_text_set_bidi_override(text_rid, stt);
494
495
dirty_text = false;
496
dirty_font = false;
497
dirty_lines = true;
498
} else if (dirty_font) {
499
int spans = TS->shaped_get_span_count(text_rid);
500
for (int i = 0; i < spans; i++) {
501
TS->shaped_set_span_update_font(text_rid, i, font->get_rids(), font_size, font->get_opentype_features());
502
}
503
504
dirty_font = false;
505
dirty_lines = true;
506
}
507
508
if (dirty_lines) {
509
for (int i = 0; i < lines_rid.size(); i++) {
510
TS->free_rid(lines_rid[i]);
511
}
512
lines_rid.clear();
513
514
BitField<TextServer::LineBreakFlag> autowrap_flags = TextServer::BREAK_MANDATORY;
515
switch (autowrap_mode) {
516
case TextServer::AUTOWRAP_WORD_SMART:
517
autowrap_flags = TextServer::BREAK_WORD_BOUND | TextServer::BREAK_ADAPTIVE | TextServer::BREAK_MANDATORY;
518
break;
519
case TextServer::AUTOWRAP_WORD:
520
autowrap_flags = TextServer::BREAK_WORD_BOUND | TextServer::BREAK_MANDATORY;
521
break;
522
case TextServer::AUTOWRAP_ARBITRARY:
523
autowrap_flags = TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_MANDATORY;
524
break;
525
case TextServer::AUTOWRAP_OFF:
526
break;
527
}
528
autowrap_flags = autowrap_flags | autowrap_flags_trim;
529
530
PackedInt32Array line_breaks = TS->shaped_text_get_line_breaks(text_rid, width, 0, autowrap_flags);
531
float max_line_w = 0.0;
532
for (int i = 0; i < line_breaks.size(); i = i + 2) {
533
RID line = TS->shaped_text_substr(text_rid, line_breaks[i], line_breaks[i + 1] - line_breaks[i]);
534
max_line_w = MAX(max_line_w, TS->shaped_text_get_width(line));
535
lines_rid.push_back(line);
536
}
537
538
if (horizontal_alignment == HORIZONTAL_ALIGNMENT_FILL) {
539
int jst_to_line = lines_rid.size();
540
if (lines_rid.size() == 1 && jst_flags.has_flag(TextServer::JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE)) {
541
jst_to_line = lines_rid.size();
542
} else {
543
if (jst_flags.has_flag(TextServer::JUSTIFICATION_SKIP_LAST_LINE)) {
544
jst_to_line = lines_rid.size() - 1;
545
}
546
if (jst_flags.has_flag(TextServer::JUSTIFICATION_SKIP_LAST_LINE_WITH_VISIBLE_CHARS)) {
547
for (int i = lines_rid.size() - 1; i >= 0; i--) {
548
if (TS->shaped_text_has_visible_chars(lines_rid[i])) {
549
jst_to_line = i;
550
break;
551
}
552
}
553
}
554
}
555
for (int i = 0; i < jst_to_line; i++) {
556
TS->shaped_text_fit_to_width(lines_rid[i], (width > 0) ? width : max_line_w, jst_flags);
557
}
558
}
559
dirty_lines = false;
560
}
561
562
// Generate surfaces and materials.
563
float total_h = 0.0;
564
for (int i = 0; i < lines_rid.size(); i++) {
565
total_h += (TS->shaped_text_get_size(lines_rid[i]).y + line_spacing) * pixel_size;
566
}
567
568
float vbegin = 0.0;
569
switch (vertical_alignment) {
570
case VERTICAL_ALIGNMENT_FILL:
571
case VERTICAL_ALIGNMENT_TOP: {
572
// Nothing.
573
} break;
574
case VERTICAL_ALIGNMENT_CENTER: {
575
vbegin = (total_h - line_spacing * pixel_size) / 2.0;
576
} break;
577
case VERTICAL_ALIGNMENT_BOTTOM: {
578
vbegin = (total_h - line_spacing * pixel_size);
579
} break;
580
}
581
582
Vector2 offset = Vector2(0, vbegin + lbl_offset.y * pixel_size);
583
for (int i = 0; i < lines_rid.size(); i++) {
584
const Glyph *glyphs = TS->shaped_text_get_glyphs(lines_rid[i]);
585
int gl_size = TS->shaped_text_get_glyph_count(lines_rid[i]);
586
float line_width = TS->shaped_text_get_width(lines_rid[i]) * pixel_size;
587
588
switch (horizontal_alignment) {
589
case HORIZONTAL_ALIGNMENT_LEFT:
590
offset.x = 0.0;
591
break;
592
case HORIZONTAL_ALIGNMENT_FILL:
593
case HORIZONTAL_ALIGNMENT_CENTER: {
594
offset.x = -line_width / 2.0;
595
} break;
596
case HORIZONTAL_ALIGNMENT_RIGHT: {
597
offset.x = -line_width;
598
} break;
599
}
600
offset.x += lbl_offset.x * pixel_size;
601
if (aabb == AABB()) {
602
aabb.position = Vector3(offset.x, offset.y, 0);
603
aabb.expand_to(Vector3(offset.x + line_width, offset.y - (TS->shaped_text_get_size(lines_rid[i]).y + line_spacing) * pixel_size, 0));
604
} else {
605
aabb.expand_to(Vector3(offset.x, offset.y, 0));
606
aabb.expand_to(Vector3(offset.x + line_width, offset.y - (TS->shaped_text_get_size(lines_rid[i]).y + line_spacing) * pixel_size, 0));
607
}
608
offset.y -= TS->shaped_text_get_ascent(lines_rid[i]) * pixel_size;
609
610
if (outline_modulate.a != 0.0 && outline_size > 0) {
611
// Outline surfaces.
612
Vector2 ol_offset = offset;
613
for (int j = 0; j < gl_size; j++) {
614
_generate_glyph_surfaces(glyphs[j], ol_offset, outline_modulate, outline_render_priority, outline_size);
615
}
616
}
617
618
// Main text surfaces.
619
for (int j = 0; j < gl_size; j++) {
620
_generate_glyph_surfaces(glyphs[j], offset, modulate, render_priority);
621
}
622
offset.y -= (TS->shaped_text_get_descent(lines_rid[i]) + line_spacing) * pixel_size;
623
}
624
625
switch (get_billboard_mode()) {
626
case StandardMaterial3D::BILLBOARD_ENABLED: {
627
real_t size_new = MAX(Math::abs(aabb.position.x), (aabb.position.x + aabb.size.x));
628
size_new = MAX(size_new, MAX(Math::abs(aabb.position.y), (aabb.position.y + aabb.size.y)));
629
aabb.position = Vector3(-size_new, -size_new, -size_new);
630
aabb.size = Vector3(size_new * 2.0, size_new * 2.0, size_new * 2.0);
631
} break;
632
case StandardMaterial3D::BILLBOARD_FIXED_Y: {
633
real_t size_new = MAX(Math::abs(aabb.position.x), (aabb.position.x + aabb.size.x));
634
aabb.position.x = -size_new;
635
aabb.position.z = -size_new;
636
aabb.size.x = size_new * 2.0;
637
aabb.size.z = size_new * 2.0;
638
} break;
639
default:
640
break;
641
}
642
643
for (const KeyValue<SurfaceKey, SurfaceData> &E : surfaces) {
644
Array mesh_array;
645
mesh_array.resize(RS::ARRAY_MAX);
646
mesh_array[RS::ARRAY_VERTEX] = E.value.mesh_vertices;
647
mesh_array[RS::ARRAY_NORMAL] = E.value.mesh_normals;
648
mesh_array[RS::ARRAY_TANGENT] = E.value.mesh_tangents;
649
mesh_array[RS::ARRAY_COLOR] = E.value.mesh_colors;
650
mesh_array[RS::ARRAY_TEX_UV] = E.value.mesh_uvs;
651
mesh_array[RS::ARRAY_INDEX] = E.value.indices;
652
653
RS::SurfaceData sd;
654
RS::get_singleton()->mesh_create_surface_data_from_arrays(&sd, RS::PRIMITIVE_TRIANGLES, mesh_array);
655
656
sd.material = E.value.material;
657
658
RS::get_singleton()->mesh_add_surface(mesh, sd);
659
}
660
}
661
662
void Label3D::set_text(const String &p_string) {
663
if (text == p_string) {
664
return;
665
}
666
667
text = p_string;
668
xl_text = atr(p_string);
669
dirty_text = true;
670
_queue_update();
671
}
672
673
String Label3D::get_text() const {
674
return text;
675
}
676
677
void Label3D::set_horizontal_alignment(HorizontalAlignment p_alignment) {
678
ERR_FAIL_INDEX((int)p_alignment, 4);
679
if (horizontal_alignment != p_alignment) {
680
if (horizontal_alignment == HORIZONTAL_ALIGNMENT_FILL || p_alignment == HORIZONTAL_ALIGNMENT_FILL) {
681
dirty_lines = true; // Reshape lines.
682
}
683
horizontal_alignment = p_alignment;
684
_queue_update();
685
}
686
}
687
688
HorizontalAlignment Label3D::get_horizontal_alignment() const {
689
return horizontal_alignment;
690
}
691
692
void Label3D::set_vertical_alignment(VerticalAlignment p_alignment) {
693
ERR_FAIL_INDEX((int)p_alignment, 4);
694
if (vertical_alignment != p_alignment) {
695
vertical_alignment = p_alignment;
696
_queue_update();
697
}
698
}
699
700
VerticalAlignment Label3D::get_vertical_alignment() const {
701
return vertical_alignment;
702
}
703
704
void Label3D::set_text_direction(TextServer::Direction p_text_direction) {
705
ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
706
if (text_direction != p_text_direction) {
707
text_direction = p_text_direction;
708
dirty_text = true;
709
_queue_update();
710
}
711
}
712
713
TextServer::Direction Label3D::get_text_direction() const {
714
return text_direction;
715
}
716
717
void Label3D::set_language(const String &p_language) {
718
if (language != p_language) {
719
language = p_language;
720
dirty_text = true;
721
_queue_update();
722
}
723
}
724
725
String Label3D::get_language() const {
726
return language;
727
}
728
729
void Label3D::set_structured_text_bidi_override(TextServer::StructuredTextParser p_parser) {
730
if (st_parser != p_parser) {
731
st_parser = p_parser;
732
dirty_text = true;
733
_queue_update();
734
}
735
}
736
737
TextServer::StructuredTextParser Label3D::get_structured_text_bidi_override() const {
738
return st_parser;
739
}
740
741
void Label3D::set_structured_text_bidi_override_options(const Array &p_args) {
742
if (st_args != p_args) {
743
st_args = Array(p_args);
744
dirty_text = true;
745
_queue_update();
746
}
747
}
748
749
Array Label3D::get_structured_text_bidi_override_options() const {
750
return Array(st_args);
751
}
752
753
void Label3D::set_uppercase(bool p_uppercase) {
754
if (uppercase != p_uppercase) {
755
uppercase = p_uppercase;
756
dirty_text = true;
757
_queue_update();
758
}
759
}
760
761
bool Label3D::is_uppercase() const {
762
return uppercase;
763
}
764
765
void Label3D::set_render_priority(int p_priority) {
766
ERR_FAIL_COND(p_priority < RS::MATERIAL_RENDER_PRIORITY_MIN || p_priority > RS::MATERIAL_RENDER_PRIORITY_MAX);
767
if (render_priority != p_priority) {
768
render_priority = p_priority;
769
_queue_update();
770
}
771
}
772
773
int Label3D::get_render_priority() const {
774
return render_priority;
775
}
776
777
void Label3D::set_outline_render_priority(int p_priority) {
778
ERR_FAIL_COND(p_priority < RS::MATERIAL_RENDER_PRIORITY_MIN || p_priority > RS::MATERIAL_RENDER_PRIORITY_MAX);
779
if (outline_render_priority != p_priority) {
780
outline_render_priority = p_priority;
781
_queue_update();
782
}
783
}
784
785
int Label3D::get_outline_render_priority() const {
786
return outline_render_priority;
787
}
788
789
void Label3D::_font_changed() {
790
dirty_font = true;
791
_queue_update();
792
}
793
794
void Label3D::set_font(const Ref<Font> &p_font) {
795
if (font_override != p_font) {
796
if (font_override.is_valid()) {
797
font_override->disconnect_changed(callable_mp(this, &Label3D::_font_changed));
798
}
799
font_override = p_font;
800
dirty_font = true;
801
if (font_override.is_valid()) {
802
font_override->connect_changed(callable_mp(this, &Label3D::_font_changed));
803
}
804
_queue_update();
805
}
806
}
807
808
Ref<Font> Label3D::get_font() const {
809
return font_override;
810
}
811
812
Ref<Font> Label3D::_get_font_or_default() const {
813
// Similar code taken from `FontVariation::_get_base_font_or_default`.
814
815
if (theme_font.is_valid()) {
816
theme_font->disconnect_changed(callable_mp(const_cast<Label3D *>(this), &Label3D::_font_changed));
817
theme_font.unref();
818
}
819
820
if (font_override.is_valid()) {
821
return font_override;
822
}
823
824
const StringName theme_name = SceneStringName(font);
825
Vector<StringName> theme_types;
826
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), theme_types);
827
828
ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
829
Vector<Ref<Theme>> themes = global_context->get_themes();
830
if (Engine::get_singleton()->is_editor_hint()) {
831
themes.insert(0, ThemeDB::get_singleton()->get_project_theme());
832
}
833
834
for (const Ref<Theme> &theme : themes) {
835
if (theme.is_null()) {
836
continue;
837
}
838
839
for (const StringName &E : theme_types) {
840
if (!theme->has_font(theme_name, E)) {
841
continue;
842
}
843
844
Ref<Font> f = theme->get_font(theme_name, E);
845
if (f.is_valid()) {
846
theme_font = f;
847
theme_font->connect_changed(callable_mp(const_cast<Label3D *>(this), &Label3D::_font_changed));
848
}
849
return f;
850
}
851
}
852
853
Ref<Font> f = global_context->get_fallback_theme()->get_font(theme_name, StringName());
854
if (f.is_valid()) {
855
theme_font = f;
856
theme_font->connect_changed(callable_mp(const_cast<Label3D *>(this), &Label3D::_font_changed));
857
}
858
return f;
859
}
860
861
void Label3D::set_font_size(int p_size) {
862
if (font_size != p_size) {
863
font_size = p_size;
864
dirty_font = true;
865
_queue_update();
866
}
867
}
868
869
int Label3D::get_font_size() const {
870
return font_size;
871
}
872
873
void Label3D::set_outline_size(int p_size) {
874
if (outline_size != p_size) {
875
outline_size = p_size;
876
_queue_update();
877
}
878
}
879
880
int Label3D::get_outline_size() const {
881
return outline_size;
882
}
883
884
void Label3D::set_modulate(const Color &p_color) {
885
if (modulate != p_color) {
886
modulate = p_color;
887
_queue_update();
888
}
889
}
890
891
Color Label3D::get_modulate() const {
892
return modulate;
893
}
894
895
void Label3D::set_outline_modulate(const Color &p_color) {
896
if (outline_modulate != p_color) {
897
outline_modulate = p_color;
898
_queue_update();
899
}
900
}
901
902
Color Label3D::get_outline_modulate() const {
903
return outline_modulate;
904
}
905
906
void Label3D::set_autowrap_mode(TextServer::AutowrapMode p_mode) {
907
if (autowrap_mode != p_mode) {
908
autowrap_mode = p_mode;
909
dirty_lines = true;
910
_queue_update();
911
}
912
}
913
914
TextServer::AutowrapMode Label3D::get_autowrap_mode() const {
915
return autowrap_mode;
916
}
917
918
void Label3D::set_autowrap_trim_flags(BitField<TextServer::LineBreakFlag> p_flags) {
919
if (autowrap_flags_trim != (p_flags & TextServer::BREAK_TRIM_MASK)) {
920
autowrap_flags_trim = (p_flags & TextServer::BREAK_TRIM_MASK);
921
dirty_lines = true;
922
_queue_update();
923
}
924
}
925
926
BitField<TextServer::LineBreakFlag> Label3D::get_autowrap_trim_flags() const {
927
return autowrap_flags_trim;
928
}
929
930
void Label3D::set_justification_flags(BitField<TextServer::JustificationFlag> p_flags) {
931
if (jst_flags != p_flags) {
932
jst_flags = p_flags;
933
dirty_lines = true;
934
_queue_update();
935
}
936
}
937
938
BitField<TextServer::JustificationFlag> Label3D::get_justification_flags() const {
939
return jst_flags;
940
}
941
942
void Label3D::set_width(float p_width) {
943
if (width != p_width) {
944
width = p_width;
945
dirty_lines = true;
946
_queue_update();
947
}
948
}
949
950
float Label3D::get_width() const {
951
return width;
952
}
953
954
void Label3D::set_pixel_size(real_t p_amount) {
955
if (pixel_size != p_amount) {
956
pixel_size = p_amount;
957
_queue_update();
958
}
959
}
960
961
real_t Label3D::get_pixel_size() const {
962
return pixel_size;
963
}
964
965
void Label3D::set_offset(const Point2 &p_offset) {
966
if (lbl_offset != p_offset) {
967
lbl_offset = p_offset;
968
_queue_update();
969
}
970
}
971
972
Point2 Label3D::get_offset() const {
973
return lbl_offset;
974
}
975
976
void Label3D::set_line_spacing(float p_line_spacing) {
977
if (line_spacing != p_line_spacing) {
978
line_spacing = p_line_spacing;
979
_queue_update();
980
}
981
}
982
983
float Label3D::get_line_spacing() const {
984
return line_spacing;
985
}
986
987
void Label3D::set_draw_flag(DrawFlags p_flag, bool p_enable) {
988
ERR_FAIL_INDEX(p_flag, FLAG_MAX);
989
if (flags[p_flag] != p_enable) {
990
flags[p_flag] = p_enable;
991
_queue_update();
992
}
993
}
994
995
bool Label3D::get_draw_flag(DrawFlags p_flag) const {
996
ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
997
return flags[p_flag];
998
}
999
1000
void Label3D::set_billboard_mode(StandardMaterial3D::BillboardMode p_mode) {
1001
ERR_FAIL_INDEX(p_mode, 3);
1002
if (billboard_mode != p_mode) {
1003
billboard_mode = p_mode;
1004
_queue_update();
1005
}
1006
}
1007
1008
StandardMaterial3D::BillboardMode Label3D::get_billboard_mode() const {
1009
return billboard_mode;
1010
}
1011
1012
void Label3D::set_alpha_cut_mode(AlphaCutMode p_mode) {
1013
ERR_FAIL_INDEX(p_mode, ALPHA_CUT_MAX);
1014
if (alpha_cut != p_mode) {
1015
alpha_cut = p_mode;
1016
_queue_update();
1017
notify_property_list_changed();
1018
}
1019
}
1020
1021
void Label3D::set_texture_filter(StandardMaterial3D::TextureFilter p_filter) {
1022
if (texture_filter != p_filter) {
1023
texture_filter = p_filter;
1024
_queue_update();
1025
}
1026
}
1027
1028
StandardMaterial3D::TextureFilter Label3D::get_texture_filter() const {
1029
return texture_filter;
1030
}
1031
1032
Label3D::AlphaCutMode Label3D::get_alpha_cut_mode() const {
1033
return alpha_cut;
1034
}
1035
1036
void Label3D::set_alpha_hash_scale(float p_hash_scale) {
1037
if (alpha_hash_scale != p_hash_scale) {
1038
alpha_hash_scale = p_hash_scale;
1039
_queue_update();
1040
}
1041
}
1042
1043
float Label3D::get_alpha_hash_scale() const {
1044
return alpha_hash_scale;
1045
}
1046
1047
void Label3D::set_alpha_scissor_threshold(float p_threshold) {
1048
if (alpha_scissor_threshold != p_threshold) {
1049
alpha_scissor_threshold = p_threshold;
1050
_queue_update();
1051
}
1052
}
1053
1054
float Label3D::get_alpha_scissor_threshold() const {
1055
return alpha_scissor_threshold;
1056
}
1057
1058
void Label3D::set_alpha_antialiasing(BaseMaterial3D::AlphaAntiAliasing p_alpha_aa) {
1059
if (alpha_antialiasing_mode != p_alpha_aa) {
1060
alpha_antialiasing_mode = p_alpha_aa;
1061
_queue_update();
1062
}
1063
}
1064
1065
BaseMaterial3D::AlphaAntiAliasing Label3D::get_alpha_antialiasing() const {
1066
return alpha_antialiasing_mode;
1067
}
1068
1069
void Label3D::set_alpha_antialiasing_edge(float p_edge) {
1070
if (alpha_antialiasing_edge != p_edge) {
1071
alpha_antialiasing_edge = p_edge;
1072
_queue_update();
1073
}
1074
}
1075
1076
float Label3D::get_alpha_antialiasing_edge() const {
1077
return alpha_antialiasing_edge;
1078
}
1079
1080
Label3D::Label3D() {
1081
for (int i = 0; i < FLAG_MAX; i++) {
1082
flags[i] = (i == FLAG_DOUBLE_SIDED);
1083
}
1084
1085
text_rid = TS->create_shaped_text();
1086
1087
mesh = RenderingServer::get_singleton()->mesh_create();
1088
1089
// Disable shadow casting by default to improve performance and avoid unintended visual artifacts.
1090
set_cast_shadows_setting(SHADOW_CASTING_SETTING_OFF);
1091
1092
// Label3D can't contribute to GI in any way, so disable it to improve performance.
1093
set_gi_mode(GI_MODE_DISABLED);
1094
1095
set_base(mesh);
1096
}
1097
1098
Label3D::~Label3D() {
1099
for (int i = 0; i < lines_rid.size(); i++) {
1100
TS->free_rid(lines_rid[i]);
1101
}
1102
lines_rid.clear();
1103
1104
TS->free_rid(text_rid);
1105
1106
ERR_FAIL_NULL(RenderingServer::get_singleton());
1107
RenderingServer::get_singleton()->free_rid(mesh);
1108
for (KeyValue<SurfaceKey, SurfaceData> E : surfaces) {
1109
RenderingServer::get_singleton()->free_rid(E.value.material);
1110
}
1111
surfaces.clear();
1112
}
1113
1114