From 9e927587e0470510a3506e024a39908941595e24 Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Thu, 10 Jun 2021 18:48:02 +0200 Subject: [PATCH 01/12] Add TransformBundle --- crates/bevy_transform/src/lib.rs | 86 +++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index f255c613db814..087f84b61871d 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -4,13 +4,95 @@ pub mod transform_propagate_system; pub mod prelude { #[doc(hidden)] - pub use crate::{components::*, hierarchy::*, TransformPlugin}; + pub use crate::{components::*, hierarchy::*, TransformBundle, TransformPlugin}; } use bevy_app::prelude::*; -use bevy_ecs::schedule::{ParallelSystemDescriptorCoercion, SystemLabel}; +use bevy_ecs::{ + bundle::Bundle, + schedule::{ParallelSystemDescriptorCoercion, SystemLabel}, +}; +use bevy_math::{Mat4, Quat, Vec3}; use prelude::{parent_update_system, Children, GlobalTransform, Parent, PreviousParent, Transform}; +#[derive(Default, Bundle, Clone, Debug)] +pub struct TransformBundle { + pub transform: Transform, + pub global_transform: GlobalTransform, +} + +impl TransformBundle { + /// Creates a new [`TransformBundle`] at the position `(x, y, z)`. In 2d, the `z` component + /// is used for z-ordering elements: higher `z`-value will be in front of lower + /// `z`-value. + #[inline] + pub fn from_xyz(x: f32, y: f32, z: f32) -> Self { + TransformBundle { + transform: Transform::from_xyz(x, y, z), + ..Default::default() + } + } + + /// Creates a new identity [`TransformBundle`], with no translation, rotation, and a scale of 1 + /// on all axes. + #[inline] + pub const fn identity() -> Self { + TransformBundle { + transform: Transform::identity(), + global_transform: GlobalTransform::identity(), + } + } + + /// Extracts the translation, rotation, and scale from `matrix`. It must be a 3d affine + /// transformation matrix. + #[inline] + pub fn from_matrix(matrix: Mat4) -> Self { + TransformBundle { + transform: Transform::from_matrix(matrix), + ..Default::default() + } + } + + /// Creates a new [`TransformBundle`], with `translation`. Rotation will be 0 and scale 1 on + /// all axes. + #[inline] + pub fn from_translation(translation: Vec3) -> Self { + TransformBundle { + transform: Transform::from_translation(translation), + ..Default::default() + } + } + + /// Creates a new [`TransformBundle`], with `rotation`. Translation will be 0 and scale 1 on + /// all axes. + #[inline] + pub fn from_rotation(rotation: Quat) -> Self { + TransformBundle { + transform: Transform::from_rotation(rotation), + ..Default::default() + } + } + + /// Creates a new [`TransformBundle`], with `scale`. Translation will be 0 and rotation 0 on + /// all axes. + #[inline] + pub fn from_scale(scale: Vec3) -> Self { + TransformBundle { + transform: Transform::from_scale(scale), + ..Default::default() + } + } +} + +impl From for TransformBundle { + fn from(transform: Transform) -> Self { + TransformBundle { + transform, + ..Default::default() + } + } +} + #[derive(Default)] pub struct TransformPlugin; From b02184b22c2cf4e28de608a5178912569c8dd097 Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Thu, 10 Jun 2021 18:59:23 +0200 Subject: [PATCH 02/12] Make Bundles use TransformBundle --- crates/bevy_pbr/src/entity.rs | 11 ++++----- crates/bevy_render/src/entity.rs | 21 +++++++--------- crates/bevy_sprite/src/entity.rs | 12 ++++------ crates/bevy_text/src/text2d.rs | 9 ++++--- crates/bevy_ui/src/entity.rs | 29 ++++++++++------------- examples/2d/contributors.rs | 5 ++-- examples/2d/many_sprites.rs | 3 ++- examples/2d/sprite_sheet.rs | 2 +- examples/2d/texture_atlas.rs | 5 ++-- examples/3d/3d_scene.rs | 8 ++++--- examples/3d/load_gltf.rs | 6 +++-- examples/3d/msaa.rs | 6 +++-- examples/3d/orthographic.rs | 14 ++++++----- examples/3d/parenting.rs | 10 ++++---- examples/3d/pbr.rs | 11 +++++---- examples/3d/render_to_texture.rs | 13 ++++++---- examples/3d/spawner.rs | 8 ++++--- examples/3d/texture.rs | 13 ++++++---- examples/3d/update_gltf_scene.rs | 5 ++-- examples/3d/wireframe.rs | 8 ++++--- examples/3d/z_sort_debug.rs | 10 ++++---- examples/android/android.rs | 8 ++++--- examples/asset/asset_loading.rs | 12 ++++++---- examples/asset/hot_asset_reloading.rs | 6 +++-- examples/async_tasks/async_compute.rs | 9 +++---- examples/ecs/hierarchy.rs | 11 +++++---- examples/ecs/iter_combinations.rs | 12 +++++----- examples/ecs/parallel_query.rs | 2 +- examples/game/alien_cake_addict.rs | 5 ++-- examples/game/breakout.rs | 14 +++++------ examples/ios/src/lib.rs | 10 ++++---- examples/shader/animate_shader.rs | 6 +++-- examples/shader/array_texture.rs | 4 +++- examples/shader/hot_shader_reloading.rs | 6 +++-- examples/shader/mesh_custom_attribute.rs | 6 +++-- examples/shader/shader_custom_material.rs | 6 +++-- examples/shader/shader_defs.rs | 8 ++++--- examples/tools/bevymark.rs | 3 ++- examples/window/multiple_windows.rs | 10 +++++--- 39 files changed, 195 insertions(+), 152 deletions(-) diff --git a/crates/bevy_pbr/src/entity.rs b/crates/bevy_pbr/src/entity.rs index 9b1d3c6314743..45ca2f12dc19e 100644 --- a/crates/bevy_pbr/src/entity.rs +++ b/crates/bevy_pbr/src/entity.rs @@ -8,7 +8,7 @@ use bevy_render::{ prelude::Visible, render_graph::base::MainPass, }; -use bevy_transform::prelude::{GlobalTransform, Transform}; +use bevy_transform::prelude::TransformBundle; /// A component bundle for "pbr mesh" entities #[derive(Bundle)] @@ -19,8 +19,8 @@ pub struct PbrBundle { pub draw: Draw, pub visible: Visible, pub render_pipelines: RenderPipelines, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } impl Default for PbrBundle { @@ -35,7 +35,6 @@ impl Default for PbrBundle { main_pass: Default::default(), draw: Default::default(), transform: Default::default(), - global_transform: Default::default(), } } } @@ -44,6 +43,6 @@ impl Default for PbrBundle { #[derive(Debug, Bundle, Default)] pub struct PointLightBundle { pub point_light: PointLight, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } diff --git a/crates/bevy_render/src/entity.rs b/crates/bevy_render/src/entity.rs index 7c6d4df1a93f0..b3e654e124994 100644 --- a/crates/bevy_render/src/entity.rs +++ b/crates/bevy_render/src/entity.rs @@ -11,7 +11,7 @@ use crate::{ use base::MainPass; use bevy_asset::Handle; use bevy_ecs::bundle::Bundle; -use bevy_transform::components::{GlobalTransform, Transform}; +use bevy_transform::TransformBundle; /// A component bundle for "mesh" entities #[derive(Bundle, Default)] @@ -21,8 +21,8 @@ pub struct MeshBundle { pub visible: Visible, pub render_pipelines: RenderPipelines, pub main_pass: MainPass, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } /// Component bundle for camera entities with perspective projection @@ -33,8 +33,8 @@ pub struct PerspectiveCameraBundle { pub camera: Camera, pub perspective_projection: PerspectiveProjection, pub visible_entities: VisibleEntities, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } impl PerspectiveCameraBundle { @@ -51,7 +51,6 @@ impl PerspectiveCameraBundle { perspective_projection: Default::default(), visible_entities: Default::default(), transform: Default::default(), - global_transform: Default::default(), } } } @@ -66,7 +65,6 @@ impl Default for PerspectiveCameraBundle { perspective_projection: Default::default(), visible_entities: Default::default(), transform: Default::default(), - global_transform: Default::default(), } } } @@ -79,8 +77,8 @@ pub struct OrthographicCameraBundle { pub camera: Camera, pub orthographic_projection: OrthographicProjection, pub visible_entities: VisibleEntities, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } impl OrthographicCameraBundle { @@ -99,8 +97,7 @@ impl OrthographicCameraBundle { ..Default::default() }, visible_entities: Default::default(), - transform: Transform::from_xyz(0.0, 0.0, far - 0.1), - global_transform: Default::default(), + transform: TransformBundle::from_xyz(0.0, 0.0, far - 0.1), } } @@ -117,7 +114,6 @@ impl OrthographicCameraBundle { }, visible_entities: Default::default(), transform: Default::default(), - global_transform: Default::default(), } } @@ -130,7 +126,6 @@ impl OrthographicCameraBundle { orthographic_projection: Default::default(), visible_entities: Default::default(), transform: Default::default(), - global_transform: Default::default(), } } } diff --git a/crates/bevy_sprite/src/entity.rs b/crates/bevy_sprite/src/entity.rs index 70fd8d5699640..9e3750c41ac9b 100644 --- a/crates/bevy_sprite/src/entity.rs +++ b/crates/bevy_sprite/src/entity.rs @@ -10,7 +10,7 @@ use bevy_render::{ prelude::{Draw, Visible}, render_graph::base::MainPass, }; -use bevy_transform::prelude::{GlobalTransform, Transform}; +use bevy_transform::TransformBundle; #[derive(Bundle, Clone)] pub struct SpriteBundle { @@ -21,8 +21,8 @@ pub struct SpriteBundle { pub draw: Draw, pub visible: Visible, pub render_pipelines: RenderPipelines, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } impl Default for SpriteBundle { @@ -41,7 +41,6 @@ impl Default for SpriteBundle { sprite: Default::default(), material: Default::default(), transform: Default::default(), - global_transform: Default::default(), } } } @@ -60,8 +59,8 @@ pub struct SpriteSheetBundle { pub render_pipelines: RenderPipelines, pub main_pass: MainPass, pub mesh: Handle, // TODO: maybe abstract this out - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } impl Default for SpriteSheetBundle { @@ -80,7 +79,6 @@ impl Default for SpriteSheetBundle { sprite: Default::default(), texture_atlas: Default::default(), transform: Default::default(), - global_transform: Default::default(), } } } diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 88dc89575c381..75ce75d3cedb7 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -14,7 +14,7 @@ use bevy_render::{ renderer::RenderResourceBindings, }; use bevy_sprite::{TextureAtlas, QUAD_HANDLE}; -use bevy_transform::prelude::{GlobalTransform, Transform}; +use bevy_transform::prelude::{GlobalTransform, TransformBundle}; use bevy_window::Windows; use glyph_brush_layout::{HorizontalAlign, VerticalAlign}; @@ -27,10 +27,10 @@ pub struct Text2dBundle { pub draw: Draw, pub visible: Visible, pub text: Text, - pub transform: Transform, - pub global_transform: GlobalTransform, pub main_pass: MainPass, pub text_2d_size: Text2dSize, + #[bundle] + pub transform: TransformBundle, } impl Default for Text2dBundle { @@ -44,12 +44,11 @@ impl Default for Text2dBundle { ..Default::default() }, text: Default::default(), - transform: Default::default(), - global_transform: Default::default(), main_pass: MainPass {}, text_2d_size: Text2dSize { size: Size::default(), }, + transform: Default::default(), } } } diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index d7312b4baf10a..cdf71591d07b9 100644 --- a/crates/bevy_ui/src/entity.rs +++ b/crates/bevy_ui/src/entity.rs @@ -15,7 +15,7 @@ use bevy_render::{ }; use bevy_sprite::{ColorMaterial, QUAD_HANDLE}; use bevy_text::Text; -use bevy_transform::prelude::{GlobalTransform, Transform}; +use bevy_transform::TransformBundle; #[derive(Bundle, Clone, Debug)] pub struct NodeBundle { @@ -26,8 +26,8 @@ pub struct NodeBundle { pub draw: Draw, pub visible: Visible, pub render_pipelines: RenderPipelines, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } impl Default for NodeBundle { @@ -46,7 +46,6 @@ impl Default for NodeBundle { material: Default::default(), draw: Default::default(), transform: Default::default(), - global_transform: Default::default(), } } } @@ -62,8 +61,8 @@ pub struct ImageBundle { pub draw: Draw, pub visible: Visible, pub render_pipelines: RenderPipelines, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } impl Default for ImageBundle { @@ -84,7 +83,6 @@ impl Default for ImageBundle { ..Default::default() }, transform: Default::default(), - global_transform: Default::default(), } } } @@ -98,8 +96,8 @@ pub struct TextBundle { pub text: Text, pub calculated_size: CalculatedSize, pub focus_policy: FocusPolicy, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } impl Default for TextBundle { @@ -118,7 +116,6 @@ impl Default for TextBundle { calculated_size: Default::default(), style: Default::default(), transform: Default::default(), - global_transform: Default::default(), } } } @@ -135,8 +132,8 @@ pub struct ButtonBundle { pub draw: Draw, pub visible: Visible, pub render_pipelines: RenderPipelines, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } impl Default for ButtonBundle { @@ -158,7 +155,6 @@ impl Default for ButtonBundle { ..Default::default() }, transform: Default::default(), - global_transform: Default::default(), } } } @@ -168,8 +164,8 @@ pub struct UiCameraBundle { pub camera: Camera, pub orthographic_projection: OrthographicProjection, pub visible_entities: VisibleEntities, - pub transform: Transform, - pub global_transform: GlobalTransform, + #[bundle] + pub transform: TransformBundle, } impl Default for UiCameraBundle { @@ -189,8 +185,7 @@ impl Default for UiCameraBundle { ..Default::default() }, visible_entities: Default::default(), - transform: Transform::from_xyz(0.0, 0.0, far - 0.1), - global_transform: Default::default(), + transform: TransformBundle::from_xyz(0.0, 0.0, far - 0.1), } } } diff --git a/examples/2d/contributors.rs b/examples/2d/contributors.rs index 6186bb78dd5fe..5ef2e42e270e5 100644 --- a/examples/2d/contributors.rs +++ b/examples/2d/contributors.rs @@ -68,7 +68,8 @@ fn setup( let mut rnd = rand::thread_rng(); for name in contribs { - let pos = (rnd.gen_range(-400.0..400.0), rnd.gen_range(0.0..400.0)); + let transform = + TransformBundle::from_xyz(rnd.gen_range(-400.0..400.0), rnd.gen_range(0.0..400.0), 0.0); let dir = rnd.gen_range(-1.0..1.0); let velocity = Vec3::new(dir * 500.0, 0.0, 0.0); let hue = rnd.gen_range(0.0..=360.0); @@ -76,8 +77,6 @@ fn setup( // some sprites should be flipped let flipped = rnd.gen_bool(0.5); - let transform = Transform::from_xyz(pos.0, pos.1, 0.0); - let e = commands .spawn() .insert_bundle(( diff --git a/examples/2d/many_sprites.rs b/examples/2d/many_sprites.rs index 203efe376488f..2ce60ae2827b2 100644 --- a/examples/2d/many_sprites.rs +++ b/examples/2d/many_sprites.rs @@ -65,7 +65,8 @@ fn setup( translation, rotation, scale, - }, + } + .into(), sprite: Sprite::new(tile_size), ..Default::default() }); diff --git a/examples/2d/sprite_sheet.rs b/examples/2d/sprite_sheet.rs index 678e4cb6b3903..6046272b32bf6 100644 --- a/examples/2d/sprite_sheet.rs +++ b/examples/2d/sprite_sheet.rs @@ -34,7 +34,7 @@ fn setup( commands .spawn_bundle(SpriteSheetBundle { texture_atlas: texture_atlas_handle, - transform: Transform::from_scale(Vec3::splat(6.0)), + transform: TransformBundle::from_scale(Vec3::splat(6.0)), ..Default::default() }) .insert(Timer::from_seconds(0.1, true)); diff --git a/examples/2d/texture_atlas.rs b/examples/2d/texture_atlas.rs index 5bae1b57fddb0..56ca1aec8441a 100644 --- a/examples/2d/texture_atlas.rs +++ b/examples/2d/texture_atlas.rs @@ -68,7 +68,8 @@ fn setup( translation: Vec3::new(150.0, 0.0, 0.0), scale: Vec3::splat(4.0), ..Default::default() - }, + } + .into(), sprite: TextureAtlasSprite::new(vendor_index as u32), texture_atlas: atlas_handle, ..Default::default() @@ -76,7 +77,7 @@ fn setup( // draw the atlas itself commands.spawn_bundle(SpriteBundle { material: materials.add(texture_atlas_texture.into()), - transform: Transform::from_xyz(-300.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(-300.0, 0.0, 0.0), ..Default::default() }); } diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index 7bbe026d2b206..a25e366cdf22e 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -24,17 +24,19 @@ fn setup( commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: Transform::from_xyz(0.0, 0.5, 0.0), + transform: TransformBundle::from_xyz(0.0, 0.5, 0.0), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), + transform: TransformBundle::from_xyz(4.0, 8.0, 4.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(-2.0, 2.5, 5.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/3d/load_gltf.rs b/examples/3d/load_gltf.rs index 280c8172bc929..f0650a3279158 100644 --- a/examples/3d/load_gltf.rs +++ b/examples/3d/load_gltf.rs @@ -16,12 +16,14 @@ fn main() { fn setup(mut commands: Commands, asset_server: Res) { commands.spawn_scene(asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0")); commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(0.7, 0.7, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y), + transform: Transform::from_xyz(0.7, 0.7, 1.0) + .looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y) + .into(), ..Default::default() }); commands .spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(3.0, 5.0, 3.0), + transform: TransformBundle::from_xyz(3.0, 5.0, 3.0), ..Default::default() }) .insert(Rotates); diff --git a/examples/3d/msaa.rs b/examples/3d/msaa.rs index 8878da9f0273b..c2759b2d63af1 100644 --- a/examples/3d/msaa.rs +++ b/examples/3d/msaa.rs @@ -26,12 +26,14 @@ fn setup( }); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), + transform: TransformBundle::from_xyz(4.0, 8.0, 4.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(-3.0, 3.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(-3.0, 3.0, 5.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/3d/orthographic.rs b/examples/3d/orthographic.rs index ec8a1d296bef6..7ea0ddb1226b3 100644 --- a/examples/3d/orthographic.rs +++ b/examples/3d/orthographic.rs @@ -17,7 +17,9 @@ fn setup( // set up the camera let mut camera = OrthographicCameraBundle::new_3d(); camera.orthographic_projection.scale = 3.0; - camera.transform = Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y); + camera.transform = Transform::from_xyz(5.0, 5.0, 5.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(); // camera commands.spawn_bundle(camera); @@ -32,30 +34,30 @@ fn setup( commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: Transform::from_xyz(1.5, 0.5, 1.5), + transform: TransformBundle::from_xyz(1.5, 0.5, 1.5), ..Default::default() }); commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: Transform::from_xyz(1.5, 0.5, -1.5), + transform: TransformBundle::from_xyz(1.5, 0.5, -1.5), ..Default::default() }); commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: Transform::from_xyz(-1.5, 0.5, 1.5), + transform: TransformBundle::from_xyz(-1.5, 0.5, 1.5), ..Default::default() }); commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: Transform::from_xyz(-1.5, 0.5, -1.5), + transform: TransformBundle::from_xyz(-1.5, 0.5, -1.5), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(3.0, 8.0, 5.0), + transform: TransformBundle::from_xyz(3.0, 8.0, 5.0), ..Default::default() }); } diff --git a/examples/3d/parenting.rs b/examples/3d/parenting.rs index 4d54464a8c8fa..689ebd5940f4f 100644 --- a/examples/3d/parenting.rs +++ b/examples/3d/parenting.rs @@ -38,7 +38,7 @@ fn setup( .spawn_bundle(PbrBundle { mesh: cube_handle.clone(), material: cube_material_handle.clone(), - transform: Transform::from_xyz(0.0, 0.0, 1.0), + transform: TransformBundle::from_xyz(0.0, 0.0, 1.0), ..Default::default() }) .insert(Rotator) @@ -47,18 +47,20 @@ fn setup( parent.spawn_bundle(PbrBundle { mesh: cube_handle, material: cube_material_handle, - transform: Transform::from_xyz(0.0, 0.0, 3.0), + transform: TransformBundle::from_xyz(0.0, 0.0, 3.0), ..Default::default() }); }); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 5.0, -4.0), + transform: TransformBundle::from_xyz(4.0, 5.0, -4.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(5.0, 10.0, 10.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/3d/pbr.rs b/examples/3d/pbr.rs index 0bd93545aa60e..220b5d54b940e 100644 --- a/examples/3d/pbr.rs +++ b/examples/3d/pbr.rs @@ -33,7 +33,7 @@ fn setup( roughness: x01, ..Default::default() }), - transform: Transform::from_xyz(x as f32, y as f32 + 0.5, 0.0), + transform: TransformBundle::from_xyz(x as f32, y as f32 + 0.5, 0.0), ..Default::default() }); } @@ -50,12 +50,12 @@ fn setup( unlit: true, ..Default::default() }), - transform: Transform::from_xyz(-5.0, -2.5, 0.0), + transform: TransformBundle::from_xyz(-5.0, -2.5, 0.0), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_translation(Vec3::new(50.0, 50.0, 50.0)), + transform: TransformBundle::from_xyz(50.0, 50.0, 50.0), point_light: PointLight { intensity: 50000., range: 100., @@ -65,8 +65,9 @@ fn setup( }); // camera commands.spawn_bundle(OrthographicCameraBundle { - transform: Transform::from_translation(Vec3::new(0.0, 0.0, 8.0)) - .looking_at(Vec3::default(), Vec3::Y), + transform: Transform::from_xyz(0.0, 0.0, 8.0) + .looking_at(Vec3::default(), Vec3::Y) + .into(), orthographic_projection: bevy::render::camera::OrthographicProjection { scale: 0.01, ..Default::default() diff --git a/examples/3d/render_to_texture.rs b/examples/3d/render_to_texture.rs index 1cb34f27faa32..e06868cdc6517 100644 --- a/examples/3d/render_to_texture.rs +++ b/examples/3d/render_to_texture.rs @@ -151,7 +151,7 @@ fn setup( .spawn_bundle(PbrBundle { mesh: cube_handle, material: cube_material_handle, - transform: Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)), + transform: TransformBundle::from_xyz(0.0, 0.0, 1.0), ..Default::default() }) .insert(FirstPassCube) @@ -161,7 +161,7 @@ fn setup( // light // note: currently lights are shared between passes! commands.spawn_bundle(PointLightBundle { - transform: Transform::from_translation(Vec3::new(0.0, 0.0, 10.0)), + transform: TransformBundle::from_xyz(0.0, 0.0, 10.0), ..Default::default() }); @@ -174,7 +174,8 @@ fn setup( ..Default::default() }, transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0)) - .looking_at(Vec3::default(), Vec3::Y), + .looking_at(Vec3::default(), Vec3::Y) + .into(), ..Default::default() }; active_cameras.add(FIRST_PASS_CAMERA); @@ -207,7 +208,8 @@ fn setup( translation: Vec3::new(0.0, 0.0, 1.5), rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0), ..Default::default() - }, + } + .into(), visible: Visible { is_transparent: true, ..Default::default() @@ -218,7 +220,8 @@ fn setup( commands.spawn_bundle(PerspectiveCameraBundle { transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0)) - .looking_at(Vec3::default(), Vec3::Y), + .looking_at(Vec3::default(), Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/3d/spawner.rs b/examples/3d/spawner.rs index 60e52d163d528..2c0af90b41922 100644 --- a/examples/3d/spawner.rs +++ b/examples/3d/spawner.rs @@ -42,12 +42,14 @@ fn setup( ) { // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, -4.0, 5.0), + transform: TransformBundle::from_xyz(4.0, -4.0, 5.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(0.0, 15.0, 150.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(0.0, 15.0, 150.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); @@ -64,7 +66,7 @@ fn setup( ), ..Default::default() }), - transform: Transform::from_xyz( + transform: TransformBundle::from_xyz( rng.gen_range(-50.0..50.0), rng.gen_range(-50.0..50.0), 0.0, diff --git a/examples/3d/texture.rs b/examples/3d/texture.rs index 75e5f1f9cce27..6c3d43438314a 100644 --- a/examples/3d/texture.rs +++ b/examples/3d/texture.rs @@ -57,7 +57,8 @@ fn setup( translation: Vec3::new(0.0, 0.0, 1.5), rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0), ..Default::default() - }, + } + .into(), visible: Visible { is_transparent: true, ..Default::default() @@ -72,7 +73,8 @@ fn setup( translation: Vec3::new(0.0, 0.0, 0.0), rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0), ..Default::default() - }, + } + .into(), visible: Visible { is_transparent: true, ..Default::default() @@ -87,7 +89,8 @@ fn setup( translation: Vec3::new(0.0, 0.0, -1.5), rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0), ..Default::default() - }, + } + .into(), visible: Visible { is_transparent: true, ..Default::default() @@ -96,7 +99,9 @@ fn setup( }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(3.0, 5.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(3.0, 5.0, 8.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/3d/update_gltf_scene.rs b/examples/3d/update_gltf_scene.rs index 15a84a4919938..2a5eb635ad135 100644 --- a/examples/3d/update_gltf_scene.rs +++ b/examples/3d/update_gltf_scene.rs @@ -25,12 +25,13 @@ fn setup( mut scene_instance: ResMut, ) { commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 5.0, 4.0), + transform: TransformBundle::from_xyz(4.0, 5.0, 4.0), ..Default::default() }); commands.spawn_bundle(PerspectiveCameraBundle { transform: Transform::from_xyz(1.05, 0.9, 1.5) - .looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y), + .looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y) + .into(), ..Default::default() }); diff --git a/examples/3d/wireframe.rs b/examples/3d/wireframe.rs index c07483cfb25d1..49b7671c7961c 100644 --- a/examples/3d/wireframe.rs +++ b/examples/3d/wireframe.rs @@ -40,19 +40,21 @@ fn setup( .spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: Transform::from_xyz(0.0, 0.5, 0.0), + transform: TransformBundle::from_xyz(0.0, 0.5, 0.0), ..Default::default() }) // This enables wireframe drawing on this entity .insert(Wireframe); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), + transform: TransformBundle::from_xyz(4.0, 8.0, 4.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(-2.0, 2.5, 5.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/3d/z_sort_debug.rs b/examples/3d/z_sort_debug.rs index 6484fda893ef3..c71d87c934433 100644 --- a/examples/3d/z_sort_debug.rs +++ b/examples/3d/z_sort_debug.rs @@ -56,7 +56,7 @@ fn setup( unlit: true, ..Default::default() }), - transform: Transform::from_xyz(0.0, 0.0, 1.0), + transform: TransformBundle::from_xyz(0.0, 0.0, 1.0), ..Default::default() }) .insert(Rotator) @@ -68,7 +68,7 @@ fn setup( unlit: true, ..Default::default() }), - transform: Transform::from_xyz(0.0, 3.0, 0.0), + transform: TransformBundle::from_xyz(0.0, 3.0, 0.0), ..Default::default() }); parent.spawn_bundle(PbrBundle { @@ -77,13 +77,15 @@ fn setup( unlit: true, ..Default::default() }), - transform: Transform::from_xyz(0.0, -3.0, 0.0), + transform: TransformBundle::from_xyz(0.0, -3.0, 0.0), ..Default::default() }); }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(5.0, 10.0, 10.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/android/android.rs b/examples/android/android.rs index 006dd37486a04..2bb9241a8387d 100644 --- a/examples/android/android.rs +++ b/examples/android/android.rs @@ -26,17 +26,19 @@ fn setup( commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: Transform::from_xyz(0.0, 0.5, 0.0), + transform: TransformBundle::from_xyz(0.0, 0.5, 0.0), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), + transform: TransformBundle::from_xyz(4.0, 8.0, 4.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(-2.0, 2.5, 5.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/asset/asset_loading.rs b/examples/asset/asset_loading.rs index 4c0f6b926d5cd..00e1be1b4fa7b 100644 --- a/examples/asset/asset_loading.rs +++ b/examples/asset/asset_loading.rs @@ -53,31 +53,33 @@ fn setup( commands.spawn_bundle(PbrBundle { mesh: monkey_handle, material: material_handle.clone(), - transform: Transform::from_xyz(-3.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(-3.0, 0.0, 0.0), ..Default::default() }); // cube commands.spawn_bundle(PbrBundle { mesh: cube_handle, material: material_handle.clone(), - transform: Transform::from_xyz(0.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(0.0, 0.0, 0.0), ..Default::default() }); // sphere commands.spawn_bundle(PbrBundle { mesh: sphere_handle, material: material_handle, - transform: Transform::from_xyz(3.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(3.0, 0.0, 0.0), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 5.0, 4.0), + transform: TransformBundle::from_xyz(4.0, 5.0, 4.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(0.0, 3.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(0.0, 3.0, 10.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/asset/hot_asset_reloading.rs b/examples/asset/hot_asset_reloading.rs index 9216b1031100f..f29ac2a7cbe48 100644 --- a/examples/asset/hot_asset_reloading.rs +++ b/examples/asset/hot_asset_reloading.rs @@ -24,12 +24,14 @@ fn setup(mut commands: Commands, asset_server: Res) { commands.spawn_scene(scene_handle); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 5.0, 4.0), + transform: TransformBundle::from_xyz(4.0, 5.0, 4.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(2.0, 2.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(2.0, 2.0, 6.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/async_tasks/async_compute.rs b/examples/async_tasks/async_compute.rs index 9e0b50b05a3ea..74a91707402a0 100644 --- a/examples/async_tasks/async_compute.rs +++ b/examples/async_tasks/async_compute.rs @@ -86,7 +86,7 @@ fn handle_tasks( commands.entity(entity).insert_bundle(PbrBundle { mesh: box_mesh_handle.0.clone(), material: box_material_handle.0.clone(), - transform, + transform: transform.into(), ..Default::default() }); @@ -107,14 +107,15 @@ fn setup_env(mut commands: Commands) { // lights commands.spawn_bundle(PointLightBundle { - transform: Transform::from_translation(Vec3::new(4.0, 12.0, 15.0)), + transform: TransformBundle::from_xyz(4.0, 12.0, 15.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_translation(Vec3::new(offset, offset, 15.0)) - .looking_at(Vec3::new(offset, offset, 0.0), Vec3::Y), + transform: Transform::from_xyz(offset, offset, 15.0) + .looking_at(Vec3::new(offset, offset, 0.0), Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/ecs/hierarchy.rs b/examples/ecs/hierarchy.rs index 96a51f72d0e2d..21e417806f9cb 100644 --- a/examples/ecs/hierarchy.rs +++ b/examples/ecs/hierarchy.rs @@ -19,7 +19,7 @@ fn setup( // Spawn a root entity with no parent let parent = commands .spawn_bundle(SpriteBundle { - transform: Transform::from_scale(Vec3::splat(0.75)), + transform: TransformBundle::from_scale(Vec3::splat(0.75)), material: materials.add(ColorMaterial { color: Color::WHITE, texture: Some(texture.clone()), @@ -34,7 +34,8 @@ fn setup( translation: Vec3::new(250.0, 0.0, 0.0), scale: Vec3::splat(0.75), ..Default::default() - }, + } + .into(), material: materials.add(ColorMaterial { color: Color::BLUE, texture: Some(texture.clone()), @@ -55,7 +56,8 @@ fn setup( translation: Vec3::new(-250.0, 0.0, 0.0), scale: Vec3::splat(0.75), ..Default::default() - }, + } + .into(), material: materials.add(ColorMaterial { color: Color::RED, texture: Some(texture.clone()), @@ -73,7 +75,8 @@ fn setup( translation: Vec3::new(0.0, 250.0, 0.0), scale: Vec3::splat(0.75), ..Default::default() - }, + } + .into(), material: materials.add(ColorMaterial { color: Color::GREEN, texture: Some(texture), diff --git a/examples/ecs/iter_combinations.rs b/examples/ecs/iter_combinations.rs index 69e8811a6a74b..54aaae8b02262 100644 --- a/examples/ecs/iter_combinations.rs +++ b/examples/ecs/iter_combinations.rs @@ -75,7 +75,8 @@ fn generate_bodies( translation: position, scale: Vec3::splat(mass_value_cube_root * 0.1), ..Default::default() - }, + } + .into(), mesh: mesh.clone(), material: materials.add( Color::rgb_linear( @@ -104,10 +105,7 @@ fn generate_bodies( commands .spawn_bundle(BodyBundle { pbr: PbrBundle { - transform: Transform { - scale: Vec3::splat(0.5), - ..Default::default() - }, + transform: TransformBundle::from_scale(Vec3::splat(0.5)), mesh: meshes.add(Mesh::from(shape::Icosphere { radius: 1.0, subdivisions: 5, @@ -123,7 +121,9 @@ fn generate_bodies( ..Default::default() }); commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(0.0, 10.5, -20.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(0.0, 10.5, -20.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/ecs/parallel_query.rs b/examples/ecs/parallel_query.rs index 3c770f5d2bc5e..20b0b932c8952 100644 --- a/examples/ecs/parallel_query.rs +++ b/examples/ecs/parallel_query.rs @@ -15,7 +15,7 @@ fn spawn_system( commands .spawn_bundle(SpriteBundle { material: material.clone(), - transform: Transform::from_scale(Vec3::splat(0.1)), + transform: TransformBundle::from_scale(Vec3::splat(0.1)), ..Default::default() }) .insert(Velocity( diff --git a/examples/game/alien_cake_addict.rs b/examples/game/alien_cake_addict.rs index a9158614012c5..37885ba123604 100644 --- a/examples/game/alien_cake_addict.rs +++ b/examples/game/alien_cake_addict.rs @@ -88,7 +88,8 @@ fn setup_cameras(mut commands: Commands, mut game: ResMut) { 2.0 * BOARD_SIZE_J as f32 / 3.0, BOARD_SIZE_J as f32 / 2.0 - 0.5, ) - .looking_at(game.camera_is_focus, Vec3::Y), + .looking_at(game.camera_is_focus, Vec3::Y) + .into(), ..Default::default() }); commands.spawn_bundle(UiCameraBundle::default()); @@ -102,7 +103,7 @@ fn setup(mut commands: Commands, asset_server: Res, mut game: ResMu game.player.j = BOARD_SIZE_J / 2; commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 5.0, 4.0), + transform: TransformBundle::from_xyz(4.0, 5.0, 4.0), ..Default::default() }); diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index 26ef9bdcbe0c7..b5f9a032f4921 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -57,7 +57,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: materials.add(Color::rgb(0.5, 0.5, 1.0).into()), - transform: Transform::from_xyz(0.0, -215.0, 0.0), + transform: TransformBundle::from_xyz(0.0, -215.0, 0.0), sprite: Sprite::new(Vec2::new(120.0, 30.0)), ..Default::default() }) @@ -67,7 +67,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()), - transform: Transform::from_xyz(0.0, -50.0, 1.0), + transform: TransformBundle::from_xyz(0.0, -50.0, 1.0), sprite: Sprite::new(Vec2::new(30.0, 30.0)), ..Default::default() }) @@ -118,7 +118,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: wall_material.clone(), - transform: Transform::from_xyz(-bounds.x / 2.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(-bounds.x / 2.0, 0.0, 0.0), sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y + wall_thickness)), ..Default::default() }) @@ -127,7 +127,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: wall_material.clone(), - transform: Transform::from_xyz(bounds.x / 2.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(bounds.x / 2.0, 0.0, 0.0), sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y + wall_thickness)), ..Default::default() }) @@ -136,7 +136,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: wall_material.clone(), - transform: Transform::from_xyz(0.0, -bounds.y / 2.0, 0.0), + transform: TransformBundle::from_xyz(0.0, -bounds.y / 2.0, 0.0), sprite: Sprite::new(Vec2::new(bounds.x + wall_thickness, wall_thickness)), ..Default::default() }) @@ -145,7 +145,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: wall_material, - transform: Transform::from_xyz(0.0, bounds.y / 2.0, 0.0), + transform: TransformBundle::from_xyz(0.0, bounds.y / 2.0, 0.0), sprite: Sprite::new(Vec2::new(bounds.x + wall_thickness, wall_thickness)), ..Default::default() }) @@ -173,7 +173,7 @@ fn setup( .spawn_bundle(SpriteBundle { material: brick_material.clone(), sprite: Sprite::new(brick_size), - transform: Transform::from_translation(brick_position), + transform: TransformBundle::from_translation(brick_position), ..Default::default() }) .insert(Collider::Scorable); diff --git a/examples/ios/src/lib.rs b/examples/ios/src/lib.rs index 978390d1a77a8..57e4d3a7d138e 100644 --- a/examples/ios/src/lib.rs +++ b/examples/ios/src/lib.rs @@ -32,7 +32,7 @@ fn setup_scene( commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()), - transform: Transform::from_xyz(0.0, 0.5, 0.0), + transform: TransformBundle::from_xyz(0.0, 0.5, 0.0), ..Default::default() }); // sphere @@ -42,17 +42,19 @@ fn setup_scene( radius: 0.5, })), material: materials.add(Color::rgb(0.1, 0.4, 0.8).into()), - transform: Transform::from_xyz(1.5, 1.5, 1.5), + transform: TransformBundle::from_xyz(1.5, 1.5, 1.5), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), + transform: TransformBundle::from_xyz(4.0, 8.0, 4.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(-2.0, 2.5, 5.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/shader/animate_shader.rs b/examples/shader/animate_shader.rs index aff72e3e6a44f..4feada271300e 100644 --- a/examples/shader/animate_shader.rs +++ b/examples/shader/animate_shader.rs @@ -104,14 +104,16 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, )]), - transform: Transform::from_xyz(0.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(0.0, 0.0, 0.0), ..Default::default() }) .insert(TimeUniform { value: 0.0 }); // Spawn a camera. commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(0.0, 0.0, 8.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/shader/array_texture.rs b/examples/shader/array_texture.rs index fba6d5800d6f3..721d44babe06c 100644 --- a/examples/shader/array_texture.rs +++ b/examples/shader/array_texture.rs @@ -112,7 +112,9 @@ fn setup( .unwrap(); commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(2.0, 2.0, 2.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/shader/hot_shader_reloading.rs b/examples/shader/hot_shader_reloading.rs index 08fc65189a5c2..947f0cbfbdcf6 100644 --- a/examples/shader/hot_shader_reloading.rs +++ b/examples/shader/hot_shader_reloading.rs @@ -68,13 +68,15 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, )]), - transform: Transform::from_xyz(0.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(0.0, 0.0, 0.0), ..Default::default() }) .insert(material); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(3.0, 5.0, -8.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/shader/mesh_custom_attribute.rs b/examples/shader/mesh_custom_attribute.rs index c9a188aef9b5b..85ebbd0b52887 100644 --- a/examples/shader/mesh_custom_attribute.rs +++ b/examples/shader/mesh_custom_attribute.rs @@ -104,12 +104,14 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, )]), - transform: Transform::from_xyz(0.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(0.0, 0.0, 0.0), ..Default::default() }); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(3.0, 5.0, -8.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/shader/shader_custom_material.rs b/examples/shader/shader_custom_material.rs index 4be05c87fed6c..ee092feeff544 100644 --- a/examples/shader/shader_custom_material.rs +++ b/examples/shader/shader_custom_material.rs @@ -90,13 +90,15 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, )]), - transform: Transform::from_xyz(0.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(0.0, 0.0, 0.0), ..Default::default() }) .insert(material); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(3.0, 5.0, -8.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/shader/shader_defs.rs b/examples/shader/shader_defs.rs index ab9e4f8c4623e..efa1964a83135 100644 --- a/examples/shader/shader_defs.rs +++ b/examples/shader/shader_defs.rs @@ -112,7 +112,7 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle.clone(), )]), - transform: Transform::from_xyz(-2.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(-2.0, 0.0, 0.0), ..Default::default() }) .insert(green_material); @@ -123,13 +123,15 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, )]), - transform: Transform::from_xyz(2.0, 0.0, 0.0), + transform: TransformBundle::from_xyz(2.0, 0.0, 0.0), ..Default::default() }) .insert(blue_material); // camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(3.0, 5.0, -8.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); } diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index 26abaec4ff6af..6a297091df2da 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -143,7 +143,8 @@ fn mouse_handler( translation: Vec3::new(bird_x, bird_y, bird_z), scale: Vec3::splat(BIRD_SCALE), ..Default::default() - }, + } + .into(), ..Default::default() }) .insert(Bird { diff --git a/examples/window/multiple_windows.rs b/examples/window/multiple_windows.rs index 57c1e2f824e10..6b0651edf2b32 100644 --- a/examples/window/multiple_windows.rs +++ b/examples/window/multiple_windows.rs @@ -186,12 +186,14 @@ fn setup_pipeline( commands.spawn_scene(asset_server.load("models/monkey/Monkey.gltf#Scene0")); // light commands.spawn_bundle(PointLightBundle { - transform: Transform::from_xyz(4.0, 5.0, 4.0), + transform: TransformBundle::from_xyz(4.0, 5.0, 4.0), ..Default::default() }); // main camera commands.spawn_bundle(PerspectiveCameraBundle { - transform: Transform::from_xyz(0.0, 0.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(0.0, 0.0, 6.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); // second window camera @@ -201,7 +203,9 @@ fn setup_pipeline( window: window_id, ..Default::default() }, - transform: Transform::from_xyz(6.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(6.0, 0.0, 0.0) + .looking_at(Vec3::ZERO, Vec3::Y) + .into(), ..Default::default() }); From 4c8d912ab424d72541bc66d6609233321952afb0 Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Thu, 10 Jun 2021 20:27:17 +0200 Subject: [PATCH 03/12] clippy --- examples/3d/pbr.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/3d/pbr.rs b/examples/3d/pbr.rs index 220b5d54b940e..56f47611e9371 100644 --- a/examples/3d/pbr.rs +++ b/examples/3d/pbr.rs @@ -61,7 +61,6 @@ fn setup( range: 100., ..Default::default() }, - ..Default::default() }); // camera commands.spawn_bundle(OrthographicCameraBundle { From ee2c9e2300cc2f96f33801f1af51944503cce62a Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Thu, 10 Jun 2021 21:25:18 +0200 Subject: [PATCH 04/12] Rename fields --- crates/bevy_transform/src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index 087f84b61871d..0b5f40816929d 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -17,8 +17,8 @@ use prelude::{parent_update_system, Children, GlobalTransform, Parent, PreviousP #[derive(Default, Bundle, Clone, Debug)] pub struct TransformBundle { - pub transform: Transform, - pub global_transform: GlobalTransform, + pub local: Transform, + pub global: GlobalTransform, } impl TransformBundle { @@ -28,7 +28,7 @@ impl TransformBundle { #[inline] pub fn from_xyz(x: f32, y: f32, z: f32) -> Self { TransformBundle { - transform: Transform::from_xyz(x, y, z), + local: Transform::from_xyz(x, y, z), ..Default::default() } } @@ -38,8 +38,8 @@ impl TransformBundle { #[inline] pub const fn identity() -> Self { TransformBundle { - transform: Transform::identity(), - global_transform: GlobalTransform::identity(), + local: Transform::identity(), + global: GlobalTransform::identity(), } } @@ -48,7 +48,7 @@ impl TransformBundle { #[inline] pub fn from_matrix(matrix: Mat4) -> Self { TransformBundle { - transform: Transform::from_matrix(matrix), + local: Transform::from_matrix(matrix), ..Default::default() } } @@ -58,7 +58,7 @@ impl TransformBundle { #[inline] pub fn from_translation(translation: Vec3) -> Self { TransformBundle { - transform: Transform::from_translation(translation), + local: Transform::from_translation(translation), ..Default::default() } } @@ -68,7 +68,7 @@ impl TransformBundle { #[inline] pub fn from_rotation(rotation: Quat) -> Self { TransformBundle { - transform: Transform::from_rotation(rotation), + local: Transform::from_rotation(rotation), ..Default::default() } } @@ -78,7 +78,7 @@ impl TransformBundle { #[inline] pub fn from_scale(scale: Vec3) -> Self { TransformBundle { - transform: Transform::from_scale(scale), + local: Transform::from_scale(scale), ..Default::default() } } @@ -87,7 +87,7 @@ impl TransformBundle { impl From for TransformBundle { fn from(transform: Transform) -> Self { TransformBundle { - transform, + local: transform, ..Default::default() } } From 37f53b8c141a19dca8150187e62771fa131d20b8 Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Thu, 10 Jun 2021 21:34:44 +0200 Subject: [PATCH 05/12] Add documentation for TransformBundle --- .../src/components/global_transform.rs | 3 +- .../src/components/transform.rs | 3 +- crates/bevy_transform/src/lib.rs | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index ceca829bc74f6..af832ee088dd7 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -7,8 +7,9 @@ use std::ops::Mul; /// Describe the position of an entity relative to the reference frame. /// /// * To place or move an entity, you should set its [`Transform`]. -/// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. /// * To get the global position of an entity, you should get its [`GlobalTransform`]. +/// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. +/// * Use the [`TransformBundle`] to guaranty this. /// /// ## [`Transform`] and [`GlobalTransform`] /// diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index f4a538d30ecb8..1e78a70d3d15c 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -8,8 +8,9 @@ use std::ops::Mul; /// to its parent position. /// /// * To place or move an entity, you should set its [`Transform`]. -/// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. /// * To get the global position of an entity, you should get its [`GlobalTransform`]. +/// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. +/// * Use the [`TransformBundle`] to guaranty this. /// /// ## [`Transform`] and [`GlobalTransform`] /// diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index 0b5f40816929d..cf33210c94944 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -8,13 +8,46 @@ pub mod prelude { } use bevy_app::prelude::*; +// Note: Neccesary because `Component` is only used in the documentation of TransformBundle. +#[allow(unused_imports)] use bevy_ecs::{ bundle::Bundle, + component::Component, schedule::{ParallelSystemDescriptorCoercion, SystemLabel}, }; use bevy_math::{Mat4, Quat, Vec3}; use prelude::{parent_update_system, Children, GlobalTransform, Parent, PreviousParent, Transform}; +/// A [`Bundle`] of the [`Transform`] and [`GlobalTransform`] [`Component`]s, which describe the position of an entity. +/// +/// * To place or move an entity, you should set its [`Transform`]. +/// * To get the global position of an entity, you should get its [`GlobalTransform`]. +/// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. +/// * Use the [`TransformBundle`] to guaranty this. +/// +/// ## [`Transform`] and [`GlobalTransform`] +/// +/// [`Transform`] is the position of an entity relative to its parent position, or the reference +/// frame if it doesn't have a [`Parent`](super::Parent). +/// +/// [`GlobalTransform`] is the position of an entity relative to the reference frame. +/// +/// [`GlobalTransform`] is updated from [`Transform`] in the system +/// [`transform_propagate_system`](crate::transform_propagate_system::transform_propagate_system). +/// +/// In pseudo code: +/// ```ignore +/// for entity in entities_without_parent: +/// set entity.global_transform to entity.transform +/// recursively: +/// set parent to current entity +/// for child in parent.children: +/// set child.global_transform to parent.global_transform * child.transform +/// ``` +/// +/// This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you +/// update the[`Transform`] of an entity in this stage or after, you will notice a 1 frame lag +/// before the [`GlobalTransform`] is updated. #[derive(Default, Bundle, Clone, Debug)] pub struct TransformBundle { pub local: Transform, From 573bfdca600193582fb446b078c1713143d2d6db Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Fri, 11 Jun 2021 00:02:29 +0200 Subject: [PATCH 06/12] Address review comments --- .../bevy_transform/src/components/global_transform.rs | 2 +- crates/bevy_transform/src/components/transform.rs | 2 +- crates/bevy_transform/src/lib.rs | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index af832ee088dd7..a375aaf280476 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -9,7 +9,7 @@ use std::ops::Mul; /// * To place or move an entity, you should set its [`Transform`]. /// * To get the global position of an entity, you should get its [`GlobalTransform`]. /// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. -/// * Use the [`TransformBundle`] to guaranty this. +/// * You may use the [`TransformBundle`] to guaranty this. /// /// ## [`Transform`] and [`GlobalTransform`] /// diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 1e78a70d3d15c..2596f82d55017 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -10,7 +10,7 @@ use std::ops::Mul; /// * To place or move an entity, you should set its [`Transform`]. /// * To get the global position of an entity, you should get its [`GlobalTransform`]. /// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. -/// * Use the [`TransformBundle`] to guaranty this. +/// * You may use the [`TransformBundle`] to guaranty this. /// /// ## [`Transform`] and [`GlobalTransform`] /// diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index cf33210c94944..630dbe0a681b9 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -8,27 +8,24 @@ pub mod prelude { } use bevy_app::prelude::*; -// Note: Neccesary because `Component` is only used in the documentation of TransformBundle. -#[allow(unused_imports)] use bevy_ecs::{ bundle::Bundle, - component::Component, schedule::{ParallelSystemDescriptorCoercion, SystemLabel}, }; use bevy_math::{Mat4, Quat, Vec3}; use prelude::{parent_update_system, Children, GlobalTransform, Parent, PreviousParent, Transform}; -/// A [`Bundle`] of the [`Transform`] and [`GlobalTransform`] [`Component`]s, which describe the position of an entity. +/// A [`Bundle`] of the [`Transform`] and [`GlobalTransform`] [`Component`](bevy_ecs::component::Component)s, which describe the position of an entity. /// /// * To place or move an entity, you should set its [`Transform`]. /// * To get the global position of an entity, you should get its [`GlobalTransform`]. /// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. -/// * Use the [`TransformBundle`] to guaranty this. +/// * You may use the [`TransformBundle`] to guaranty this. /// /// ## [`Transform`] and [`GlobalTransform`] /// /// [`Transform`] is the position of an entity relative to its parent position, or the reference -/// frame if it doesn't have a [`Parent`](super::Parent). +/// frame if it doesn't have a [`Parent`](Parent). /// /// [`GlobalTransform`] is the position of an entity relative to the reference frame. /// @@ -72,6 +69,7 @@ impl TransformBundle { pub const fn identity() -> Self { TransformBundle { local: Transform::identity(), + // Note: `..Default::default()` cannot be used here, because it isn't const global: GlobalTransform::identity(), } } From 4be9681e3d2ddc517b253761c6ed28e7fdd55dfc Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Sat, 12 Jun 2021 15:02:40 +0200 Subject: [PATCH 07/12] Only construct TransformBundle from Transform --- crates/bevy_gltf/src/loader.rs | 8 +-- crates/bevy_render/src/entity.rs | 4 +- crates/bevy_transform/src/lib.rs | 63 ++++--------------- .../src/transform_propagate_system.rs | 56 ++++++++--------- crates/bevy_ui/src/entity.rs | 4 +- examples/2d/contributors.rs | 3 +- examples/2d/sprite_sheet.rs | 2 +- examples/2d/texture_atlas.rs | 2 +- examples/3d/3d_scene.rs | 4 +- examples/3d/load_gltf.rs | 2 +- examples/3d/msaa.rs | 2 +- examples/3d/orthographic.rs | 10 +-- examples/3d/parenting.rs | 6 +- examples/3d/pbr.rs | 6 +- examples/3d/render_to_texture.rs | 4 +- examples/3d/spawner.rs | 7 ++- examples/3d/update_gltf_scene.rs | 9 ++- examples/3d/wireframe.rs | 4 +- examples/3d/z_sort_debug.rs | 6 +- examples/android/android.rs | 4 +- examples/asset/asset_loading.rs | 8 +-- examples/asset/hot_asset_reloading.rs | 2 +- examples/async_tasks/async_compute.rs | 2 +- examples/ecs/hierarchy.rs | 2 +- examples/ecs/iter_combinations.rs | 2 +- examples/ecs/parallel_query.rs | 2 +- examples/game/alien_cake_addict.rs | 48 +++++++------- examples/game/breakout.rs | 14 ++--- examples/ios/src/lib.rs | 6 +- examples/shader/animate_shader.rs | 2 +- examples/shader/hot_shader_reloading.rs | 2 +- examples/shader/mesh_custom_attribute.rs | 2 +- examples/shader/shader_custom_material.rs | 2 +- examples/shader/shader_defs.rs | 4 +- examples/window/multiple_windows.rs | 2 +- 35 files changed, 130 insertions(+), 176 deletions(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 9c68cd996230f..016d4ffbbf7f8 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -20,7 +20,8 @@ use bevy_render::{ use bevy_scene::Scene; use bevy_transform::{ hierarchy::{BuildWorldChildren, WorldChildBuilder}, - prelude::{GlobalTransform, Transform}, + prelude::Transform, + TransformBundle, }; use gltf::{ mesh::Mode, @@ -280,7 +281,7 @@ async fn load_gltf<'a, 'b>( let mut world = World::default(); world .spawn() - .insert_bundle((Transform::identity(), GlobalTransform::identity())) + .insert_bundle(TransformBundle::default()) .with_children(|parent| { for node in scene.nodes() { let result = load_node(&node, parent, load_context, &buffer_data); @@ -450,9 +451,8 @@ fn load_node( ) -> Result<(), GltfError> { let transform = gltf_node.transform(); let mut gltf_error = None; - let mut node = world_builder.spawn_bundle(( + let mut node = world_builder.spawn_bundle(TransformBundle::from_transform( Transform::from_matrix(Mat4::from_cols_array_2d(&transform.matrix())), - GlobalTransform::identity(), )); if let Some(name) = gltf_node.name() { diff --git a/crates/bevy_render/src/entity.rs b/crates/bevy_render/src/entity.rs index b3e654e124994..ca63a450906aa 100644 --- a/crates/bevy_render/src/entity.rs +++ b/crates/bevy_render/src/entity.rs @@ -11,7 +11,7 @@ use crate::{ use base::MainPass; use bevy_asset::Handle; use bevy_ecs::bundle::Bundle; -use bevy_transform::TransformBundle; +use bevy_transform::{components::Transform, TransformBundle}; /// A component bundle for "mesh" entities #[derive(Bundle, Default)] @@ -97,7 +97,7 @@ impl OrthographicCameraBundle { ..Default::default() }, visible_entities: Default::default(), - transform: TransformBundle::from_xyz(0.0, 0.0, far - 0.1), + transform: Transform::from_xyz(0.0, 0.0, far - 0.1).into(), } } diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index 630dbe0a681b9..10641133756b7 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -12,10 +12,10 @@ use bevy_ecs::{ bundle::Bundle, schedule::{ParallelSystemDescriptorCoercion, SystemLabel}, }; -use bevy_math::{Mat4, Quat, Vec3}; use prelude::{parent_update_system, Children, GlobalTransform, Parent, PreviousParent, Transform}; -/// A [`Bundle`] of the [`Transform`] and [`GlobalTransform`] [`Component`](bevy_ecs::component::Component)s, which describe the position of an entity. +/// A [`Bundle`] of the [`Transform`] and [`GlobalTransform`] +/// [`Component`](bevy_ecs::component::Component)s, which describe the position of an entity. /// /// * To place or move an entity, you should set its [`Transform`]. /// * To get the global position of an entity, you should get its [`GlobalTransform`]. @@ -52,13 +52,17 @@ pub struct TransformBundle { } impl TransformBundle { - /// Creates a new [`TransformBundle`] at the position `(x, y, z)`. In 2d, the `z` component - /// is used for z-ordering elements: higher `z`-value will be in front of lower - /// `z`-value. + /// Creates a new [`TransformBundle`] from a [`Transform`] and a [`GlobalTransform`]. + pub fn new(local: Transform, global: GlobalTransform) -> Self { + TransformBundle { local, global } + } + + /// Creates a new [`TransformBundle`] from a [`Transform`] and leaving [`GlobalTransform`] with + /// no translation, rotation, and a scale of 1 on all axes. #[inline] - pub fn from_xyz(x: f32, y: f32, z: f32) -> Self { + pub fn from_transform(transform: Transform) -> Self { TransformBundle { - local: Transform::from_xyz(x, y, z), + local: transform, ..Default::default() } } @@ -73,54 +77,11 @@ impl TransformBundle { global: GlobalTransform::identity(), } } - - /// Extracts the translation, rotation, and scale from `matrix`. It must be a 3d affine - /// transformation matrix. - #[inline] - pub fn from_matrix(matrix: Mat4) -> Self { - TransformBundle { - local: Transform::from_matrix(matrix), - ..Default::default() - } - } - - /// Creates a new [`TransformBundle`], with `translation`. Rotation will be 0 and scale 1 on - /// all axes. - #[inline] - pub fn from_translation(translation: Vec3) -> Self { - TransformBundle { - local: Transform::from_translation(translation), - ..Default::default() - } - } - - /// Creates a new [`TransformBundle`], with `rotation`. Translation will be 0 and scale 1 on - /// all axes. - #[inline] - pub fn from_rotation(rotation: Quat) -> Self { - TransformBundle { - local: Transform::from_rotation(rotation), - ..Default::default() - } - } - - /// Creates a new [`TransformBundle`], with `scale`. Translation will be 0 and rotation 0 on - /// all axes. - #[inline] - pub fn from_scale(scale: Vec3) -> Self { - TransformBundle { - local: Transform::from_scale(scale), - ..Default::default() - } - } } impl From for TransformBundle { fn from(transform: Transform) -> Self { - TransformBundle { - local: transform, - ..Default::default() - } + Self::from_transform(transform) } } diff --git a/crates/bevy_transform/src/transform_propagate_system.rs b/crates/bevy_transform/src/transform_propagate_system.rs index a4ab7aadcdf89..7992e39b76eae 100644 --- a/crates/bevy_transform/src/transform_propagate_system.rs +++ b/crates/bevy_transform/src/transform_propagate_system.rs @@ -82,7 +82,10 @@ mod test { }; use super::*; - use crate::hierarchy::{parent_update_system, BuildChildren, BuildWorldChildren}; + use crate::{ + hierarchy::{parent_update_system, BuildChildren, BuildWorldChildren}, + TransformBundle, + }; #[test] fn did_propagate() { @@ -96,33 +99,31 @@ mod test { schedule.add_stage("update", update_stage); // Root entity - world.spawn().insert_bundle(( - Transform::from_xyz(1.0, 0.0, 0.0), - GlobalTransform::identity(), - )); + world + .spawn() + .insert_bundle(TransformBundle::from_transform(Transform::from_xyz( + 1.0, 0.0, 0.0, + ))); let mut children = Vec::new(); world .spawn() - .insert_bundle(( - Transform::from_xyz(1.0, 0.0, 0.0), - GlobalTransform::identity(), - )) + .insert_bundle(TransformBundle::from_transform(Transform::from_xyz( + 1.0, 0.0, 0.0, + ))) .with_children(|parent| { children.push( parent - .spawn_bundle(( - Transform::from_xyz(0.0, 2.0, 0.), - GlobalTransform::identity(), - )) + .spawn_bundle(TransformBundle::from_transform(Transform::from_xyz( + 0.0, 2.0, 0., + ))) .id(), ); children.push( parent - .spawn_bundle(( - Transform::from_xyz(0.0, 0.0, 3.), - GlobalTransform::identity(), - )) + .spawn_bundle(TransformBundle::from_transform(Transform::from_xyz( + 0.0, 0.0, 3., + ))) .id(), ); }); @@ -155,25 +156,22 @@ mod test { let mut commands = Commands::new(&mut queue, &world); let mut children = Vec::new(); commands - .spawn_bundle(( - Transform::from_xyz(1.0, 0.0, 0.0), - GlobalTransform::identity(), - )) + .spawn_bundle(TransformBundle::from_transform(Transform::from_xyz( + 1.0, 0.0, 0.0, + ))) .with_children(|parent| { children.push( parent - .spawn_bundle(( - Transform::from_xyz(0.0, 2.0, 0.0), - GlobalTransform::identity(), - )) + .spawn_bundle(TransformBundle::from_transform(Transform::from_xyz( + 0.0, 2.0, 0.0, + ))) .id(), ); children.push( parent - .spawn_bundle(( - Transform::from_xyz(0.0, 0.0, 3.0), - GlobalTransform::identity(), - )) + .spawn_bundle(TransformBundle::from_transform(Transform::from_xyz( + 0.0, 0.0, 3.0, + ))) .id(), ); }); diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index cdf71591d07b9..f0bdde04c1bca 100644 --- a/crates/bevy_ui/src/entity.rs +++ b/crates/bevy_ui/src/entity.rs @@ -15,7 +15,7 @@ use bevy_render::{ }; use bevy_sprite::{ColorMaterial, QUAD_HANDLE}; use bevy_text::Text; -use bevy_transform::TransformBundle; +use bevy_transform::{components::Transform, TransformBundle}; #[derive(Bundle, Clone, Debug)] pub struct NodeBundle { @@ -185,7 +185,7 @@ impl Default for UiCameraBundle { ..Default::default() }, visible_entities: Default::default(), - transform: TransformBundle::from_xyz(0.0, 0.0, far - 0.1), + transform: Transform::from_xyz(0.0, 0.0, far - 0.1).into(), } } } diff --git a/examples/2d/contributors.rs b/examples/2d/contributors.rs index 5ef2e42e270e5..2ee3fdb6a8bdb 100644 --- a/examples/2d/contributors.rs +++ b/examples/2d/contributors.rs @@ -69,7 +69,8 @@ fn setup( for name in contribs { let transform = - TransformBundle::from_xyz(rnd.gen_range(-400.0..400.0), rnd.gen_range(0.0..400.0), 0.0); + Transform::from_xyz(rnd.gen_range(-400.0..400.0), rnd.gen_range(0.0..400.0), 0.0) + .into(); let dir = rnd.gen_range(-1.0..1.0); let velocity = Vec3::new(dir * 500.0, 0.0, 0.0); let hue = rnd.gen_range(0.0..=360.0); diff --git a/examples/2d/sprite_sheet.rs b/examples/2d/sprite_sheet.rs index 6046272b32bf6..e24d96d9a2553 100644 --- a/examples/2d/sprite_sheet.rs +++ b/examples/2d/sprite_sheet.rs @@ -34,7 +34,7 @@ fn setup( commands .spawn_bundle(SpriteSheetBundle { texture_atlas: texture_atlas_handle, - transform: TransformBundle::from_scale(Vec3::splat(6.0)), + transform: Transform::from_scale(Vec3::splat(6.0)).into(), ..Default::default() }) .insert(Timer::from_seconds(0.1, true)); diff --git a/examples/2d/texture_atlas.rs b/examples/2d/texture_atlas.rs index 56ca1aec8441a..d70ca4b9118ce 100644 --- a/examples/2d/texture_atlas.rs +++ b/examples/2d/texture_atlas.rs @@ -77,7 +77,7 @@ fn setup( // draw the atlas itself commands.spawn_bundle(SpriteBundle { material: materials.add(texture_atlas_texture.into()), - transform: TransformBundle::from_xyz(-300.0, 0.0, 0.0), + transform: Transform::from_xyz(-300.0, 0.0, 0.0).into(), ..Default::default() }); } diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index a25e366cdf22e..091b277235ac9 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -24,12 +24,12 @@ fn setup( commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: TransformBundle::from_xyz(0.0, 0.5, 0.0), + transform: Transform::from_xyz(0.0, 0.5, 0.0).into(), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 8.0, 4.0), + transform: Transform::from_xyz(4.0, 8.0, 4.0).into(), ..Default::default() }); // camera diff --git a/examples/3d/load_gltf.rs b/examples/3d/load_gltf.rs index f0650a3279158..8d627f43a1432 100644 --- a/examples/3d/load_gltf.rs +++ b/examples/3d/load_gltf.rs @@ -23,7 +23,7 @@ fn setup(mut commands: Commands, asset_server: Res) { }); commands .spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(3.0, 5.0, 3.0), + transform: Transform::from_xyz(3.0, 5.0, 3.0).into(), ..Default::default() }) .insert(Rotates); diff --git a/examples/3d/msaa.rs b/examples/3d/msaa.rs index c2759b2d63af1..a19845a94d7c7 100644 --- a/examples/3d/msaa.rs +++ b/examples/3d/msaa.rs @@ -26,7 +26,7 @@ fn setup( }); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 8.0, 4.0), + transform: Transform::from_xyz(4.0, 8.0, 4.0).into(), ..Default::default() }); // camera diff --git a/examples/3d/orthographic.rs b/examples/3d/orthographic.rs index 7ea0ddb1226b3..1682f5ca87cf1 100644 --- a/examples/3d/orthographic.rs +++ b/examples/3d/orthographic.rs @@ -34,30 +34,30 @@ fn setup( commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: TransformBundle::from_xyz(1.5, 0.5, 1.5), + transform: Transform::from_xyz(1.5, 0.5, 1.5).into(), ..Default::default() }); commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: TransformBundle::from_xyz(1.5, 0.5, -1.5), + transform: Transform::from_xyz(1.5, 0.5, -1.5).into(), ..Default::default() }); commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: TransformBundle::from_xyz(-1.5, 0.5, 1.5), + transform: Transform::from_xyz(-1.5, 0.5, 1.5).into(), ..Default::default() }); commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: TransformBundle::from_xyz(-1.5, 0.5, -1.5), + transform: Transform::from_xyz(-1.5, 0.5, -1.5).into(), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(3.0, 8.0, 5.0), + transform: Transform::from_xyz(3.0, 8.0, 5.0).into(), ..Default::default() }); } diff --git a/examples/3d/parenting.rs b/examples/3d/parenting.rs index 689ebd5940f4f..22b7e4cfa1a82 100644 --- a/examples/3d/parenting.rs +++ b/examples/3d/parenting.rs @@ -38,7 +38,7 @@ fn setup( .spawn_bundle(PbrBundle { mesh: cube_handle.clone(), material: cube_material_handle.clone(), - transform: TransformBundle::from_xyz(0.0, 0.0, 1.0), + transform: Transform::from_xyz(0.0, 0.0, 1.0).into(), ..Default::default() }) .insert(Rotator) @@ -47,13 +47,13 @@ fn setup( parent.spawn_bundle(PbrBundle { mesh: cube_handle, material: cube_material_handle, - transform: TransformBundle::from_xyz(0.0, 0.0, 3.0), + transform: Transform::from_xyz(0.0, 0.0, 3.0).into(), ..Default::default() }); }); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 5.0, -4.0), + transform: Transform::from_xyz(4.0, 5.0, -4.0).into(), ..Default::default() }); // camera diff --git a/examples/3d/pbr.rs b/examples/3d/pbr.rs index 56f47611e9371..160e8619c2ade 100644 --- a/examples/3d/pbr.rs +++ b/examples/3d/pbr.rs @@ -33,7 +33,7 @@ fn setup( roughness: x01, ..Default::default() }), - transform: TransformBundle::from_xyz(x as f32, y as f32 + 0.5, 0.0), + transform: Transform::from_xyz(x as f32, y as f32 + 0.5, 0.0).into(), ..Default::default() }); } @@ -50,12 +50,12 @@ fn setup( unlit: true, ..Default::default() }), - transform: TransformBundle::from_xyz(-5.0, -2.5, 0.0), + transform: Transform::from_xyz(-5.0, -2.5, 0.0).into(), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(50.0, 50.0, 50.0), + transform: Transform::from_xyz(50.0, 50.0, 50.0).into(), point_light: PointLight { intensity: 50000., range: 100., diff --git a/examples/3d/render_to_texture.rs b/examples/3d/render_to_texture.rs index e06868cdc6517..e29c9d938269a 100644 --- a/examples/3d/render_to_texture.rs +++ b/examples/3d/render_to_texture.rs @@ -151,7 +151,7 @@ fn setup( .spawn_bundle(PbrBundle { mesh: cube_handle, material: cube_material_handle, - transform: TransformBundle::from_xyz(0.0, 0.0, 1.0), + transform: Transform::from_xyz(0.0, 0.0, 1.0).into(), ..Default::default() }) .insert(FirstPassCube) @@ -161,7 +161,7 @@ fn setup( // light // note: currently lights are shared between passes! commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(0.0, 0.0, 10.0), + transform: Transform::from_xyz(0.0, 0.0, 10.0).into(), ..Default::default() }); diff --git a/examples/3d/spawner.rs b/examples/3d/spawner.rs index 2c0af90b41922..1316b6de3437f 100644 --- a/examples/3d/spawner.rs +++ b/examples/3d/spawner.rs @@ -42,7 +42,7 @@ fn setup( ) { // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, -4.0, 5.0), + transform: Transform::from_xyz(4.0, -4.0, 5.0).into(), ..Default::default() }); // camera @@ -66,11 +66,12 @@ fn setup( ), ..Default::default() }), - transform: TransformBundle::from_xyz( + transform: Transform::from_xyz( rng.gen_range(-50.0..50.0), rng.gen_range(-50.0..50.0), 0.0, - ), + ) + .into(), ..Default::default() }); } diff --git a/examples/3d/update_gltf_scene.rs b/examples/3d/update_gltf_scene.rs index 2a5eb635ad135..43fd7eddd1329 100644 --- a/examples/3d/update_gltf_scene.rs +++ b/examples/3d/update_gltf_scene.rs @@ -25,7 +25,7 @@ fn setup( mut scene_instance: ResMut, ) { commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 5.0, 4.0), + transform: Transform::from_xyz(4.0, 5.0, 4.0).into(), ..Default::default() }); commands.spawn_bundle(PerspectiveCameraBundle { @@ -38,10 +38,9 @@ fn setup( // Spawn the scene as a child of another entity. This first scene will be translated backward // with its parent commands - .spawn_bundle(( - Transform::from_xyz(0.0, 0.0, -1.0), - GlobalTransform::identity(), - )) + .spawn_bundle(TransformBundle::from_transform(Transform::from_xyz( + 0.0, 0.0, -1.0, + ))) .with_children(|parent| { parent.spawn_scene(asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0")); }); diff --git a/examples/3d/wireframe.rs b/examples/3d/wireframe.rs index 49b7671c7961c..795a0351fb4bb 100644 --- a/examples/3d/wireframe.rs +++ b/examples/3d/wireframe.rs @@ -40,14 +40,14 @@ fn setup( .spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: TransformBundle::from_xyz(0.0, 0.5, 0.0), + transform: Transform::from_xyz(0.0, 0.5, 0.0).into(), ..Default::default() }) // This enables wireframe drawing on this entity .insert(Wireframe); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 8.0, 4.0), + transform: Transform::from_xyz(4.0, 8.0, 4.0).into(), ..Default::default() }); // camera diff --git a/examples/3d/z_sort_debug.rs b/examples/3d/z_sort_debug.rs index c71d87c934433..010d3dcc85b6b 100644 --- a/examples/3d/z_sort_debug.rs +++ b/examples/3d/z_sort_debug.rs @@ -56,7 +56,7 @@ fn setup( unlit: true, ..Default::default() }), - transform: TransformBundle::from_xyz(0.0, 0.0, 1.0), + transform: Transform::from_xyz(0.0, 0.0, 1.0).into(), ..Default::default() }) .insert(Rotator) @@ -68,7 +68,7 @@ fn setup( unlit: true, ..Default::default() }), - transform: TransformBundle::from_xyz(0.0, 3.0, 0.0), + transform: Transform::from_xyz(0.0, 3.0, 0.0).into(), ..Default::default() }); parent.spawn_bundle(PbrBundle { @@ -77,7 +77,7 @@ fn setup( unlit: true, ..Default::default() }), - transform: TransformBundle::from_xyz(0.0, -3.0, 0.0), + transform: Transform::from_xyz(0.0, -3.0, 0.0).into(), ..Default::default() }); }); diff --git a/examples/android/android.rs b/examples/android/android.rs index 2bb9241a8387d..d293526251f35 100644 --- a/examples/android/android.rs +++ b/examples/android/android.rs @@ -26,12 +26,12 @@ fn setup( commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: TransformBundle::from_xyz(0.0, 0.5, 0.0), + transform: Transform::from_xyz(0.0, 0.5, 0.0).into(), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 8.0, 4.0), + transform: Transform::from_xyz(4.0, 8.0, 4.0).into(), ..Default::default() }); // camera diff --git a/examples/asset/asset_loading.rs b/examples/asset/asset_loading.rs index 00e1be1b4fa7b..eb744aa638136 100644 --- a/examples/asset/asset_loading.rs +++ b/examples/asset/asset_loading.rs @@ -53,26 +53,26 @@ fn setup( commands.spawn_bundle(PbrBundle { mesh: monkey_handle, material: material_handle.clone(), - transform: TransformBundle::from_xyz(-3.0, 0.0, 0.0), + transform: Transform::from_xyz(-3.0, 0.0, 0.0).into(), ..Default::default() }); // cube commands.spawn_bundle(PbrBundle { mesh: cube_handle, material: material_handle.clone(), - transform: TransformBundle::from_xyz(0.0, 0.0, 0.0), + transform: Transform::from_xyz(0.0, 0.0, 0.0).into(), ..Default::default() }); // sphere commands.spawn_bundle(PbrBundle { mesh: sphere_handle, material: material_handle, - transform: TransformBundle::from_xyz(3.0, 0.0, 0.0), + transform: Transform::from_xyz(3.0, 0.0, 0.0).into(), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 5.0, 4.0), + transform: Transform::from_xyz(4.0, 5.0, 4.0).into(), ..Default::default() }); // camera diff --git a/examples/asset/hot_asset_reloading.rs b/examples/asset/hot_asset_reloading.rs index f29ac2a7cbe48..668146228b386 100644 --- a/examples/asset/hot_asset_reloading.rs +++ b/examples/asset/hot_asset_reloading.rs @@ -24,7 +24,7 @@ fn setup(mut commands: Commands, asset_server: Res) { commands.spawn_scene(scene_handle); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 5.0, 4.0), + transform: Transform::from_xyz(4.0, 5.0, 4.0).into(), ..Default::default() }); // camera diff --git a/examples/async_tasks/async_compute.rs b/examples/async_tasks/async_compute.rs index 74a91707402a0..3f66f08a08043 100644 --- a/examples/async_tasks/async_compute.rs +++ b/examples/async_tasks/async_compute.rs @@ -107,7 +107,7 @@ fn setup_env(mut commands: Commands) { // lights commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 12.0, 15.0), + transform: Transform::from_xyz(4.0, 12.0, 15.0).into(), ..Default::default() }); diff --git a/examples/ecs/hierarchy.rs b/examples/ecs/hierarchy.rs index 21e417806f9cb..4a4e0fce38d1f 100644 --- a/examples/ecs/hierarchy.rs +++ b/examples/ecs/hierarchy.rs @@ -19,7 +19,7 @@ fn setup( // Spawn a root entity with no parent let parent = commands .spawn_bundle(SpriteBundle { - transform: TransformBundle::from_scale(Vec3::splat(0.75)), + transform: Transform::from_scale(Vec3::splat(0.75)).into(), material: materials.add(ColorMaterial { color: Color::WHITE, texture: Some(texture.clone()), diff --git a/examples/ecs/iter_combinations.rs b/examples/ecs/iter_combinations.rs index 54aaae8b02262..4aabaf6db6541 100644 --- a/examples/ecs/iter_combinations.rs +++ b/examples/ecs/iter_combinations.rs @@ -105,7 +105,7 @@ fn generate_bodies( commands .spawn_bundle(BodyBundle { pbr: PbrBundle { - transform: TransformBundle::from_scale(Vec3::splat(0.5)), + transform: Transform::from_scale(Vec3::splat(0.5)).into(), mesh: meshes.add(Mesh::from(shape::Icosphere { radius: 1.0, subdivisions: 5, diff --git a/examples/ecs/parallel_query.rs b/examples/ecs/parallel_query.rs index 20b0b932c8952..49a392e450b96 100644 --- a/examples/ecs/parallel_query.rs +++ b/examples/ecs/parallel_query.rs @@ -15,7 +15,7 @@ fn spawn_system( commands .spawn_bundle(SpriteBundle { material: material.clone(), - transform: TransformBundle::from_scale(Vec3::splat(0.1)), + transform: Transform::from_scale(Vec3::splat(0.1)).into(), ..Default::default() }) .insert(Velocity( diff --git a/examples/game/alien_cake_addict.rs b/examples/game/alien_cake_addict.rs index 37885ba123604..9ef4a3bbef66f 100644 --- a/examples/game/alien_cake_addict.rs +++ b/examples/game/alien_cake_addict.rs @@ -103,7 +103,7 @@ fn setup(mut commands: Commands, asset_server: Res, mut game: ResMu game.player.j = BOARD_SIZE_J / 2; commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 5.0, 4.0), + transform: Transform::from_xyz(4.0, 5.0, 4.0).into(), ..Default::default() }); @@ -115,10 +115,11 @@ fn setup(mut commands: Commands, asset_server: Res, mut game: ResMu .map(|i| { let height = rand::thread_rng().gen_range(-0.1..0.1); commands - .spawn_bundle(( - Transform::from_xyz(i as f32, height - 0.2, j as f32), - GlobalTransform::identity(), - )) + .spawn_bundle(TransformBundle::from_transform(Transform::from_xyz( + i as f32, + height - 0.2, + j as f32, + ))) .with_children(|cell| { cell.spawn_scene(cell_scene.clone()); }); @@ -131,18 +132,15 @@ fn setup(mut commands: Commands, asset_server: Res, mut game: ResMu // spawn the game character game.player.entity = Some( commands - .spawn_bundle(( - Transform { - translation: Vec3::new( - game.player.i as f32, - game.board[game.player.j][game.player.i].height, - game.player.j as f32, - ), - rotation: Quat::from_rotation_y(-std::f32::consts::FRAC_PI_2), - ..Default::default() - }, - GlobalTransform::identity(), - )) + .spawn_bundle(TransformBundle::from_transform(Transform { + translation: Vec3::new( + game.player.i as f32, + game.board[game.player.j][game.player.i].height, + game.player.j as f32, + ), + rotation: Quat::from_rotation_y(-std::f32::consts::FRAC_PI_2), + ..Default::default() + })) .with_children(|cell| { cell.spawn_scene(asset_server.load("models/AlienCake/alien.glb#Scene0")); }) @@ -321,16 +319,12 @@ fn spawn_bonus( } game.bonus.entity = Some( commands - .spawn_bundle(( - Transform { - translation: Vec3::new( - game.bonus.i as f32, - game.board[game.bonus.j][game.bonus.i].height + 0.2, - game.bonus.j as f32, - ), - ..Default::default() - }, - GlobalTransform::identity(), + .spawn_bundle(TransformBundle::from_transform( + Transform::from_translation(Vec3::new( + game.bonus.i as f32, + game.board[game.bonus.j][game.bonus.i].height + 0.2, + game.bonus.j as f32, + )), )) .with_children(|cell| { cell.spawn_scene(game.bonus.handle.clone()); diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index b5f9a032f4921..7c74f2ea25b2d 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -57,7 +57,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: materials.add(Color::rgb(0.5, 0.5, 1.0).into()), - transform: TransformBundle::from_xyz(0.0, -215.0, 0.0), + transform: Transform::from_xyz(0.0, -215.0, 0.0).into(), sprite: Sprite::new(Vec2::new(120.0, 30.0)), ..Default::default() }) @@ -67,7 +67,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()), - transform: TransformBundle::from_xyz(0.0, -50.0, 1.0), + transform: Transform::from_xyz(0.0, -50.0, 1.0).into(), sprite: Sprite::new(Vec2::new(30.0, 30.0)), ..Default::default() }) @@ -118,7 +118,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: wall_material.clone(), - transform: TransformBundle::from_xyz(-bounds.x / 2.0, 0.0, 0.0), + transform: Transform::from_xyz(-bounds.x / 2.0, 0.0, 0.0).into(), sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y + wall_thickness)), ..Default::default() }) @@ -127,7 +127,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: wall_material.clone(), - transform: TransformBundle::from_xyz(bounds.x / 2.0, 0.0, 0.0), + transform: Transform::from_xyz(bounds.x / 2.0, 0.0, 0.0).into(), sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y + wall_thickness)), ..Default::default() }) @@ -136,7 +136,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: wall_material.clone(), - transform: TransformBundle::from_xyz(0.0, -bounds.y / 2.0, 0.0), + transform: Transform::from_xyz(0.0, -bounds.y / 2.0, 0.0).into(), sprite: Sprite::new(Vec2::new(bounds.x + wall_thickness, wall_thickness)), ..Default::default() }) @@ -145,7 +145,7 @@ fn setup( commands .spawn_bundle(SpriteBundle { material: wall_material, - transform: TransformBundle::from_xyz(0.0, bounds.y / 2.0, 0.0), + transform: Transform::from_xyz(0.0, bounds.y / 2.0, 0.0).into(), sprite: Sprite::new(Vec2::new(bounds.x + wall_thickness, wall_thickness)), ..Default::default() }) @@ -173,7 +173,7 @@ fn setup( .spawn_bundle(SpriteBundle { material: brick_material.clone(), sprite: Sprite::new(brick_size), - transform: TransformBundle::from_translation(brick_position), + transform: Transform::from_translation(brick_position).into(), ..Default::default() }) .insert(Collider::Scorable); diff --git a/examples/ios/src/lib.rs b/examples/ios/src/lib.rs index 57e4d3a7d138e..d053acb00f737 100644 --- a/examples/ios/src/lib.rs +++ b/examples/ios/src/lib.rs @@ -32,7 +32,7 @@ fn setup_scene( commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()), - transform: TransformBundle::from_xyz(0.0, 0.5, 0.0), + transform: Transform::from_xyz(0.0, 0.5, 0.0).into(), ..Default::default() }); // sphere @@ -42,12 +42,12 @@ fn setup_scene( radius: 0.5, })), material: materials.add(Color::rgb(0.1, 0.4, 0.8).into()), - transform: TransformBundle::from_xyz(1.5, 1.5, 1.5), + transform: Transform::from_xyz(1.5, 1.5, 1.5).into(), ..Default::default() }); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 8.0, 4.0), + transform: Transform::from_xyz(4.0, 8.0, 4.0).into(), ..Default::default() }); // camera diff --git a/examples/shader/animate_shader.rs b/examples/shader/animate_shader.rs index 4feada271300e..18ccf4f8babd4 100644 --- a/examples/shader/animate_shader.rs +++ b/examples/shader/animate_shader.rs @@ -104,7 +104,7 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, )]), - transform: TransformBundle::from_xyz(0.0, 0.0, 0.0), + transform: Transform::from_xyz(0.0, 0.0, 0.0).into(), ..Default::default() }) .insert(TimeUniform { value: 0.0 }); diff --git a/examples/shader/hot_shader_reloading.rs b/examples/shader/hot_shader_reloading.rs index 947f0cbfbdcf6..d6d7ce48b6758 100644 --- a/examples/shader/hot_shader_reloading.rs +++ b/examples/shader/hot_shader_reloading.rs @@ -68,7 +68,7 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, )]), - transform: TransformBundle::from_xyz(0.0, 0.0, 0.0), + transform: Transform::from_xyz(0.0, 0.0, 0.0).into(), ..Default::default() }) .insert(material); diff --git a/examples/shader/mesh_custom_attribute.rs b/examples/shader/mesh_custom_attribute.rs index 85ebbd0b52887..7ab891cf32ea7 100644 --- a/examples/shader/mesh_custom_attribute.rs +++ b/examples/shader/mesh_custom_attribute.rs @@ -104,7 +104,7 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, )]), - transform: TransformBundle::from_xyz(0.0, 0.0, 0.0), + transform: Transform::from_xyz(0.0, 0.0, 0.0).into(), ..Default::default() }); // camera diff --git a/examples/shader/shader_custom_material.rs b/examples/shader/shader_custom_material.rs index ee092feeff544..a245de1706819 100644 --- a/examples/shader/shader_custom_material.rs +++ b/examples/shader/shader_custom_material.rs @@ -90,7 +90,7 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, )]), - transform: TransformBundle::from_xyz(0.0, 0.0, 0.0), + transform: Transform::from_xyz(0.0, 0.0, 0.0).into(), ..Default::default() }) .insert(material); diff --git a/examples/shader/shader_defs.rs b/examples/shader/shader_defs.rs index efa1964a83135..a196c73d0077b 100644 --- a/examples/shader/shader_defs.rs +++ b/examples/shader/shader_defs.rs @@ -112,7 +112,7 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle.clone(), )]), - transform: TransformBundle::from_xyz(-2.0, 0.0, 0.0), + transform: Transform::from_xyz(-2.0, 0.0, 0.0).into(), ..Default::default() }) .insert(green_material); @@ -123,7 +123,7 @@ fn setup( render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, )]), - transform: TransformBundle::from_xyz(2.0, 0.0, 0.0), + transform: Transform::from_xyz(2.0, 0.0, 0.0).into(), ..Default::default() }) .insert(blue_material); diff --git a/examples/window/multiple_windows.rs b/examples/window/multiple_windows.rs index 6b0651edf2b32..7a38f99e39c74 100644 --- a/examples/window/multiple_windows.rs +++ b/examples/window/multiple_windows.rs @@ -186,7 +186,7 @@ fn setup_pipeline( commands.spawn_scene(asset_server.load("models/monkey/Monkey.gltf#Scene0")); // light commands.spawn_bundle(PointLightBundle { - transform: TransformBundle::from_xyz(4.0, 5.0, 4.0), + transform: Transform::from_xyz(4.0, 5.0, 4.0).into(), ..Default::default() }); // main camera From 63a649ee20959788cdf409e8f3698c7cadc66576 Mon Sep 17 00:00:00 2001 From: MinerSebas <66798382+MinerSebas@users.noreply.github.com> Date: Tue, 15 Jun 2021 00:39:48 +0200 Subject: [PATCH 08/12] Apply suggestions from code review Co-authored-by: Nathan Ward <43621845+NathanSWard@users.noreply.github.com> --- crates/bevy_transform/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index 10641133756b7..6366dc3e18318 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -53,6 +53,7 @@ pub struct TransformBundle { impl TransformBundle { /// Creates a new [`TransformBundle`] from a [`Transform`] and a [`GlobalTransform`]. + #[inline] pub fn new(local: Transform, global: GlobalTransform) -> Self { TransformBundle { local, global } } @@ -80,6 +81,7 @@ impl TransformBundle { } impl From for TransformBundle { + #[inline] fn from(transform: Transform) -> Self { Self::from_transform(transform) } From f86bbf6e3b888581f0d44fbe458382582d26dd4a Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Tue, 15 Jun 2021 16:02:51 +0200 Subject: [PATCH 09/12] Remove pseudo code in documentation --- .../bevy_transform/src/components/global_transform.rs | 10 ---------- crates/bevy_transform/src/components/transform.rs | 10 ---------- crates/bevy_transform/src/lib.rs | 10 ---------- 3 files changed, 30 deletions(-) diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index a375aaf280476..387eb9df3a78c 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -21,16 +21,6 @@ use std::ops::Mul; /// [`GlobalTransform`] is updated from [`Transform`] in the system /// [`transform_propagate_system`](crate::transform_propagate_system::transform_propagate_system). /// -/// In pseudo code: -/// ```ignore -/// for entity in entities_without_parent: -/// set entity.global_transform to entity.transform -/// recursively: -/// set parent to current entity -/// for child in parent.children: -/// set child.global_transform to parent.global_transform * child.transform -/// ``` -/// /// This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you /// update the[`Transform`] of an entity in this stage or after, you will notice a 1 frame lag /// before the [`GlobalTransform`] is updated. diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 2596f82d55017..8ac26a7a22bd0 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -22,16 +22,6 @@ use std::ops::Mul; /// [`GlobalTransform`] is updated from [`Transform`] in the system /// [`transform_propagate_system`](crate::transform_propagate_system::transform_propagate_system). /// -/// In pseudo code: -/// ```ignore -/// for entity in entities_without_parent: -/// set entity.global_transform to entity.transform -/// recursively: -/// set parent to current entity -/// for child in parent.children: -/// set child.global_transform to parent.global_transform * child.transform -/// ``` -/// /// This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you /// update the[`Transform`] of an entity in this stage or after, you will notice a 1 frame lag /// before the [`GlobalTransform`] is updated. diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index 6366dc3e18318..189de9b3848d6 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -32,16 +32,6 @@ use prelude::{parent_update_system, Children, GlobalTransform, Parent, PreviousP /// [`GlobalTransform`] is updated from [`Transform`] in the system /// [`transform_propagate_system`](crate::transform_propagate_system::transform_propagate_system). /// -/// In pseudo code: -/// ```ignore -/// for entity in entities_without_parent: -/// set entity.global_transform to entity.transform -/// recursively: -/// set parent to current entity -/// for child in parent.children: -/// set child.global_transform to parent.global_transform * child.transform -/// ``` -/// /// This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you /// update the[`Transform`] of an entity in this stage or after, you will notice a 1 frame lag /// before the [`GlobalTransform`] is updated. From 37f64e4e6dc41bd2ecd24ed951cfcc1c6fb6d82e Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Tue, 15 Jun 2021 16:03:14 +0200 Subject: [PATCH 10/12] Remove unnecessary new constuctor --- crates/bevy_transform/src/lib.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index 189de9b3848d6..42a3ee42f43b4 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -42,12 +42,6 @@ pub struct TransformBundle { } impl TransformBundle { - /// Creates a new [`TransformBundle`] from a [`Transform`] and a [`GlobalTransform`]. - #[inline] - pub fn new(local: Transform, global: GlobalTransform) -> Self { - TransformBundle { local, global } - } - /// Creates a new [`TransformBundle`] from a [`Transform`] and leaving [`GlobalTransform`] with /// no translation, rotation, and a scale of 1 on all axes. #[inline] From 92571c801f34e9cbc5372891efb0090ae75fb61c Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Tue, 15 Jun 2021 16:04:25 +0200 Subject: [PATCH 11/12] Use the const identity() over default() --- crates/bevy_gltf/src/loader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 016d4ffbbf7f8..59bb7fab3df9a 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -281,7 +281,7 @@ async fn load_gltf<'a, 'b>( let mut world = World::default(); world .spawn() - .insert_bundle(TransformBundle::default()) + .insert_bundle(TransformBundle::identity()) .with_children(|parent| { for node in scene.nodes() { let result = load_node(&node, parent, load_context, &buffer_data); From a0c7dddea6756cd48f39f1a0fc1d8654c561530a Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Sun, 20 Jun 2021 15:04:06 +0200 Subject: [PATCH 12/12] Replace guaranty with guarantee --- crates/bevy_transform/src/components/global_transform.rs | 2 +- crates/bevy_transform/src/components/transform.rs | 2 +- crates/bevy_transform/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index 387eb9df3a78c..80d075f7271f3 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -9,7 +9,7 @@ use std::ops::Mul; /// * To place or move an entity, you should set its [`Transform`]. /// * To get the global position of an entity, you should get its [`GlobalTransform`]. /// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. -/// * You may use the [`TransformBundle`] to guaranty this. +/// * You may use the [`TransformBundle`] to guarantee this. /// /// ## [`Transform`] and [`GlobalTransform`] /// diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 8ac26a7a22bd0..8dc853e102cda 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -10,7 +10,7 @@ use std::ops::Mul; /// * To place or move an entity, you should set its [`Transform`]. /// * To get the global position of an entity, you should get its [`GlobalTransform`]. /// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. -/// * You may use the [`TransformBundle`] to guaranty this. +/// * You may use the [`TransformBundle`] to guarantee this. /// /// ## [`Transform`] and [`GlobalTransform`] /// diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index 42a3ee42f43b4..aa03f00497328 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -20,7 +20,7 @@ use prelude::{parent_update_system, Children, GlobalTransform, Parent, PreviousP /// * To place or move an entity, you should set its [`Transform`]. /// * To get the global position of an entity, you should get its [`GlobalTransform`]. /// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. -/// * You may use the [`TransformBundle`] to guaranty this. +/// * You may use the [`TransformBundle`] to guarantee this. /// /// ## [`Transform`] and [`GlobalTransform`] ///