From e866ab4a72937eb05bc4246f06551089abd5a3ab Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:53:26 +0200 Subject: [PATCH] [Label3D] Calculate AABB from the full text rect instead of individual glyphs. --- scene/3d/label_3d.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scene/3d/label_3d.cpp b/scene/3d/label_3d.cpp index 3fb472335e4..a04ba622d8a 100644 --- a/scene/3d/label_3d.cpp +++ b/scene/3d/label_3d.cpp @@ -422,12 +422,6 @@ void Label3D::_generate_glyph_surfaces(const Glyph &p_glyph, Vector2 &r_offset, s.mesh_tangents.write[(s.offset * 16) + (i * 4) + 3] = 1.0; s.mesh_colors.write[(s.offset * 4) + i] = p_modulate; s.mesh_uvs.write[(s.offset * 4) + i] = Vector2(); - - if (aabb == AABB()) { - aabb.position = s.mesh_vertices[(s.offset * 4) + i]; - } else { - aabb.expand_to(s.mesh_vertices[(s.offset * 4) + i]); - } } if (tex.is_valid()) { @@ -598,6 +592,13 @@ void Label3D::_shape() { } break; } offset.x += lbl_offset.x * pixel_size; + if (aabb == AABB()) { + aabb.position = Vector3(offset.x, offset.y, 0); + aabb.expand_to(Vector3(offset.x + line_width, offset.y - (TS->shaped_text_get_size(lines_rid[i]).y + line_spacing) * pixel_size, 0)); + } else { + aabb.expand_to(Vector3(offset.x, offset.y, 0)); + aabb.expand_to(Vector3(offset.x + line_width, offset.y - (TS->shaped_text_get_size(lines_rid[i]).y + line_spacing) * pixel_size, 0)); + } offset.y -= TS->shaped_text_get_ascent(lines_rid[i]) * pixel_size; if (outline_modulate.a != 0.0 && outline_size > 0) {