Skip to content

Commit e861074

Browse files
committed
Eliminate GlobalTransform -> TRS conversions and add warning
1 parent 5ce99d1 commit e861074

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

crates/bevy_text/src/text2d.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn extract_text2d_sprite(
6868
text2d_query: Extract<Query<(Entity, &Visibility, &Text, &GlobalTransform, &Text2dSize)>>,
6969
) {
7070
let scale_factor = windows.scale_factor(WindowId::primary()) as f32;
71-
for (entity, visibility, text, transform, calculated_size) in text2d_query.iter() {
71+
for (entity, visibility, text, text_transform, calculated_size) in text2d_query.iter() {
7272
if !visibility.is_visible {
7373
continue;
7474
}
@@ -86,9 +86,6 @@ pub fn extract_text2d_sprite(
8686
HorizontalAlign::Right => Vec3::new(-width, 0.0, 0.0),
8787
};
8888

89-
let mut text_transform = Transform::from(*transform);
90-
text_transform.scale /= scale_factor;
91-
9289
for text_glyph in text_glyphs {
9390
let color = text.sections[text_glyph.section_index]
9491
.style
@@ -104,11 +101,13 @@ pub fn extract_text2d_sprite(
104101
let glyph_transform = Transform::from_translation(
105102
alignment_offset * scale_factor + text_glyph.position.extend(0.),
106103
);
107-
108-
let transform = text_transform.mul_transform(glyph_transform);
104+
// NOTE: Should match `bevy_ui::render::extract_text_uinodes`
105+
let transform = *text_transform
106+
* GlobalTransform::from_scale(Vec3::splat(scale_factor.recip()))
107+
* glyph_transform;
109108

110109
extracted_sprites.sprites.push(ExtractedSprite {
111-
transform: transform.into(),
110+
transform,
112111
color,
113112
rect,
114113
custom_size: None,

crates/bevy_transform/src/components/transform.rs

+2
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ impl Default for Transform {
339339
}
340340
}
341341

342+
/// The transform is expected to be non-degenerate and without shearing, or the output
343+
/// will be invalid.
342344
impl From<GlobalTransform> for Transform {
343345
fn from(transform: GlobalTransform) -> Self {
344346
transform.compute_transform()

crates/bevy_ui/src/render/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,9 @@ pub fn extract_text_uinodes(
305305
let rect = atlas.textures[index];
306306
let atlas_size = Some(atlas.size);
307307

308-
let (scale, rotation, translation) =
309-
global_transform.to_scale_rotation_translation();
310-
let extracted_transform = Mat4::from_rotation_translation(rotation, translation)
311-
* Mat4::from_scale(scale / scale_factor)
308+
// NOTE: Should match `bevy_text::text2d::extract_text2d_sprite`
309+
let extracted_transform = global_transform.compute_matrix()
310+
* Mat4::from_scale(Vec3::splat(scale_factor.recip()))
312311
* Mat4::from_translation(
313312
alignment_offset * scale_factor + text_glyph.position.extend(0.),
314313
);

0 commit comments

Comments
 (0)