Skip to content

GlobalTransform Rework #5125

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

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
11 changes: 0 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1277,17 +1277,6 @@ description = "A simple way to view glTF models with Bevy. Just run `cargo run -
category = "Tools"
wasm = true

# Transforms
[[example]]
name = "global_vs_local_translation"
path = "examples/transforms/global_vs_local_translation.rs"

[package.metadata.example.global_vs_local_translation]
name = "Global / Local Translation"
description = "Illustrates the difference between direction of a translation in respect to local object or global object Transform"
category = "Transforms"
wasm = true

[[example]]
name = "3d_rotation"
path = "examples/transforms/3d_rotation.rs"
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bevy_render::{
renderer::RenderDevice,
view::{ComputedVisibility, RenderLayers, Visibility, VisibleEntities},
};
use bevy_transform::components::GlobalTransform;
use bevy_transform::components::{GlobalTransform, Transform};
use bevy_utils::tracing::warn;

use crate::{
Expand Down Expand Up @@ -1201,7 +1201,7 @@ pub fn update_point_light_frusta(
Mat4::perspective_infinite_reverse_rh(std::f32::consts::FRAC_PI_2, 1.0, POINT_LIGHT_NEAR_Z);
let view_rotations = CUBE_MAP_FACES
.iter()
.map(|CubeMapFace { target, up }| GlobalTransform::identity().looking_at(*target, *up))
.map(|CubeMapFace { target, up }| Transform::identity().looking_at(*target, *up))
.collect::<Vec<_>>();

for (entity, transform, point_light, mut cubemap_frusta) in views.iter_mut() {
Expand All @@ -1217,7 +1217,7 @@ pub fn update_point_light_frusta(
// ignore scale because we don't want to effectively scale light radius and range
// by applying those as a view transform to shadow map rendering of objects
// and ignore rotation because we want the shadow map projections to align with the axes
let view_translation = GlobalTransform::from_translation(transform.translation);
let view_translation = Transform::from_translation(transform.translation);
let view_backward = transform.back();

for (view_rotation, frustum) in view_rotations.iter().zip(cubemap_frusta.iter_mut()) {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use bevy_render::{
ExtractedView, ViewUniform, ViewUniformOffset, ViewUniforms, Visibility, VisibleEntities,
},
};
use bevy_transform::components::GlobalTransform;
use bevy_transform::components::{GlobalTransform, Transform};
use bevy_utils::FloatOrd;
use bevy_utils::{
tracing::{error, warn},
Expand All @@ -52,7 +52,7 @@ pub struct ExtractedPointLight {
intensity: f32,
range: f32,
radius: f32,
transform: GlobalTransform,
transform: Transform,
shadows_enabled: bool,
shadow_depth_bias: f32,
shadow_normal_bias: f32,
Expand Down Expand Up @@ -446,7 +446,7 @@ pub fn extract_lights(
intensity: point_light.intensity / (4.0 * std::f32::consts::PI),
range: point_light.range,
radius: point_light.radius,
transform: *transform,
transform: transform.into_inner(),
shadows_enabled: point_light.shadows_enabled,
shadow_depth_bias: point_light.shadow_depth_bias,
// The factor of SQRT_2 is for the worst-case diagonal offset
Expand Down Expand Up @@ -668,7 +668,7 @@ pub fn prepare_lights(
Mat4::perspective_infinite_reverse_rh(std::f32::consts::FRAC_PI_2, 1.0, POINT_LIGHT_NEAR_Z);
let cube_face_rotations = CUBE_MAP_FACES
.iter()
.map(|CubeMapFace { target, up }| GlobalTransform::identity().looking_at(*target, *up))
.map(|CubeMapFace { target, up }| Transform::identity().looking_at(*target, *up))
.collect::<Vec<_>>();

global_light_meta.entity_to_index.clear();
Expand Down Expand Up @@ -807,7 +807,7 @@ pub fn prepare_lights(
// ignore scale because we don't want to effectively scale light radius and range
// by applying those as a view transform to shadow map rendering of objects
// and ignore rotation because we want the shadow map projections to align with the axes
let view_translation = GlobalTransform::from_translation(light.transform.translation);
let view_translation = Transform::from_translation(light.transform.translation);

for (face_index, view_rotation) in cube_face_rotations.iter().enumerate() {
let depth_texture_view =
Expand Down Expand Up @@ -921,7 +921,7 @@ pub fn prepare_lights(
ExtractedView {
width: directional_light_shadow_map.size as u32,
height: directional_light_shadow_map.size as u32,
transform: GlobalTransform::from_matrix(view.inverse()),
transform: Transform::from_matrix(view.inverse()),
projection,
},
RenderPhase::<Shadow>::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ pub fn extract_cameras(
},
ExtractedView {
projection: camera.projection_matrix(),
transform: *transform,
transform: transform.into_inner(),
width: viewport_size.x,
height: viewport_size.y,
},
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
use bevy_math::{Mat4, Vec3};
use bevy_transform::components::GlobalTransform;
use bevy_transform::components::Transform;
use bevy_utils::HashMap;

pub struct ViewPlugin;
Expand Down Expand Up @@ -76,7 +76,7 @@ impl Default for Msaa {
#[derive(Component)]
pub struct ExtractedView {
pub projection: Mat4,
pub transform: GlobalTransform,
pub transform: Transform,
pub width: u32,
pub height: u32,
}
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use bevy_render::{
view::{Msaa, ViewUniform, ViewUniformOffset, ViewUniforms, Visibility},
RenderWorld,
};
use bevy_transform::components::GlobalTransform;
use bevy_transform::components::{GlobalTransform, Transform};
use bevy_utils::FloatOrd;
use bevy_utils::HashMap;
use bytemuck::{Pod, Zeroable};
Expand Down Expand Up @@ -173,7 +173,7 @@ impl SpecializedRenderPipeline for SpritePipeline {

#[derive(Component, Clone, Copy)]
pub struct ExtractedSprite {
pub transform: GlobalTransform,
pub transform: Transform,
pub color: Color,
/// Select an area of the texture
pub rect: Option<Rect>,
Expand Down Expand Up @@ -241,7 +241,7 @@ pub fn extract_sprites(
// PERF: we don't check in this function that the `Image` asset is ready, since it should be in most cases and hashing the handle is expensive
extracted_sprites.sprites.alloc().init(ExtractedSprite {
color: sprite.color,
transform: *transform,
transform: transform.into_inner(),
// Use the full texture
rect: None,
// Pass the custom size
Expand All @@ -260,7 +260,7 @@ pub fn extract_sprites(
let rect = Some(texture_atlas.textures[atlas_sprite.index as usize]);
extracted_sprites.sprites.alloc().init(ExtractedSprite {
color: atlas_sprite.color,
transform: *transform,
transform: transform.into_inner(),
// Select the area in the texture atlas
rect,
// Pass the custom size
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 extract_text2d_sprite(
HorizontalAlign::Right => Vec3::new(-width, 0.0, 0.0),
};

let mut text_transform = *transform;
let mut text_transform = transform.into_inner();
text_transform.scale /= scale_factor;

for text_glyph in text_glyphs {
Expand Down
Loading