Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce read-only global transform #1460

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl LightRaw {
};

let proj = perspective.get_projection_matrix() * global_transform.compute_matrix();
let (x, y, z) = global_transform.translation.into();
let (x, y, z) = global_transform.translation().into();
LightRaw {
proj: proj.to_cols_array_2d(),
pos: [x, y, z, 1.0],
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/camera/visible_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub fn visible_entities_system(
camera_query.iter_mut()
{
visible_entities.value.clear();
let camera_position = camera_global_transform.translation;
let camera_position = camera_global_transform.translation();
let camera_mask = maybe_camera_mask.copied().unwrap_or_default();

let mut no_transform_order = 0.0;
Expand All @@ -227,7 +227,7 @@ pub fn visible_entities_system(
}

let order = if let Ok(global_transform) = visible_transform_query.get(entity) {
let position = global_transform.translation;
let position = global_transform.translation();
// smaller distances are sorted to lower indices by using the distance from the camera
FloatOrd(match camera.depth_calculation {
DepthCalculation::ZDifference => camera_position.z - position.z,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_text/src/text2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn draw_text2d_system(
let (width, height) = (calculated_size.size.width, calculated_size.size.height);

if let Some(text_glyphs) = text_pipeline.get_glyphs(&entity) {
let position = global_transform.translation
let position = global_transform.translation()
+ match text.alignment.vertical {
VerticalAlign::Top => Vec3::zero(),
VerticalAlign::Center => Vec3::new(0.0, -height * 0.5, 0.0),
Expand Down
21 changes: 18 additions & 3 deletions crates/bevy_transform/src/components/global_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use std::ops::Mul;
#[derive(Debug, PartialEq, Clone, Copy, Reflect)]
#[reflect(Component)]
pub struct GlobalTransform {
pub translation: Vec3,
pub rotation: Quat,
pub scale: Vec3,
translation: Vec3,
rotation: Quat,
scale: Vec3,
}

impl GlobalTransform {
Expand Down Expand Up @@ -142,6 +142,21 @@ impl GlobalTransform {
let up = forward.cross(right);
self.rotation = Quat::from_rotation_mat3(&Mat3::from_cols(right, up, forward));
}

#[inline]
pub fn translation(&self) -> Vec3 {
self.translation
}

#[inline]
pub fn rotation(&self) -> Quat {
self.rotation
}

#[inline]
pub fn scale(&self) -> Vec3 {
self.scale
}
}

impl Default for GlobalTransform {
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ impl Default for Transform {
impl From<GlobalTransform> for Transform {
fn from(transform: GlobalTransform) -> Self {
Self {
translation: transform.translation,
rotation: transform.rotation,
scale: transform.scale,
translation: transform.translation(),
rotation: transform.rotation(),
scale: transform.scale(),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ pub mod prelude {
}

use bevy_app::{prelude::*, startup_stage};
use bevy_ecs::IntoSystem;
use bevy_ecs::ParallelSystemDescriptorCoercion;
use bevy_ecs::{IntoSystem, ParallelSystemDescriptorCoercion};
use bevy_reflect::RegisterTypeBuilder;
use prelude::{parent_update_system, Children, GlobalTransform, Parent, PreviousParent, Transform};

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn ui_focus_system(
.iter_mut()
.filter_map(
|(entity, node, global_transform, interaction, focus_policy)| {
let position = global_transform.translation;
let position = global_transform.translation();
let ui_position = position.truncate();
let extents = node.size / 2.0;
let min = ui_position - extents;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn draw_text_system(
}

if let Some(text_glyphs) = text_pipeline.get_glyphs(&entity) {
let position = global_transform.translation - (node.size / 2.0).extend(0.0);
let position = global_transform.translation() - (node.size / 2.0).extend(0.0);

let mut drawable_text = DrawableText {
render_resource_bindings: &mut render_resource_bindings,
Expand Down