From 5d44a143558fcfafc6e3321b760585b43f946c4c Mon Sep 17 00:00:00 2001 From: NthTensor Date: Mon, 26 May 2025 16:24:34 -0400 Subject: [PATCH 1/4] rename `Transform` to `Transform3d` --- Cargo.toml | 4 +- assets/scenes/load_scene_example.scn.ron | 2 +- crates/bevy_animation/src/animatable.rs | 4 +- crates/bevy_animation/src/animation_curves.rs | 4 +- crates/bevy_audio/src/audio.rs | 2 +- crates/bevy_audio/src/sinks.rs | 4 +- .../src/core_2d/camera_2d.rs | 4 +- crates/bevy_core_pipeline/src/skybox/mod.rs | 4 +- crates/bevy_gizmos/src/aabb.rs | 4 +- crates/bevy_gizmos/src/retained.rs | 4 +- crates/bevy_gizmos/src/rounded_box.rs | 4 +- crates/bevy_gltf/src/assets.rs | 6 +- crates/bevy_gltf/src/loader/gltf_ext/scene.rs | 8 +- crates/bevy_gltf/src/loader/mod.rs | 14 +- crates/bevy_mesh/src/mesh.rs | 16 +-- crates/bevy_pbr/src/decal/clustered.rs | 4 +- .../bevy_pbr/src/light/directional_light.rs | 2 +- crates/bevy_pbr/src/light/mod.rs | 6 +- crates/bevy_pbr/src/light/point_light.rs | 2 +- crates/bevy_pbr/src/light/spot_light.rs | 2 +- crates/bevy_pbr/src/light_probe/mod.rs | 8 +- crates/bevy_pbr/src/render/light.rs | 4 +- crates/bevy_pbr/src/volumetric_fog/mod.rs | 4 +- crates/bevy_picking/src/lib.rs | 2 +- crates/bevy_remote/src/builtin_methods.rs | 10 +- crates/bevy_render/src/camera/camera.rs | 4 +- crates/bevy_render/src/mesh/components.rs | 6 +- crates/bevy_scene/src/components.rs | 6 +- crates/bevy_sprite/src/sprite.rs | 6 +- crates/bevy_text/src/text2d.rs | 4 +- crates/bevy_transform/README.md | 2 +- crates/bevy_transform/src/commands.rs | 14 +- .../src/components/global_transform.rs | 50 +++---- .../src/components/transform.rs | 126 +++++++++--------- crates/bevy_transform/src/helper.rs | 24 ++-- crates/bevy_transform/src/plugins.rs | 4 +- crates/bevy_transform/src/systems.rs | 76 ++++++----- crates/bevy_transform/src/traits.rs | 4 +- .../src/experimental/ghost_hierarchy.rs | 2 +- crates/bevy_ui/src/layout/mod.rs | 6 +- crates/bevy_ui/src/ui_node.rs | 4 +- crates/bevy_ui/src/widget/text.rs | 2 +- errors/B0001.md | 14 +- errors/B0004.md | 14 +- errors/B0005.md | 2 +- examples/2d/2d_shapes.rs | 2 +- examples/2d/2d_viewport_to_world.rs | 4 +- examples/2d/bloom_2d.rs | 4 +- examples/2d/custom_gltf_vertex_attribute.rs | 2 +- examples/2d/mesh2d.rs | 2 +- examples/2d/mesh2d_alpha_mode.rs | 12 +- examples/2d/mesh2d_arcs.rs | 4 +- examples/2d/mesh2d_repeated_texture.rs | 14 +- examples/2d/mesh2d_vertex_color_texture.rs | 4 +- examples/2d/move_sprite.rs | 7 +- examples/2d/pixel_grid_snap.rs | 8 +- examples/2d/rotation.rs | 18 +-- examples/2d/sprite_animation.rs | 4 +- examples/2d/sprite_scale.rs | 54 ++++---- examples/2d/sprite_sheet.rs | 2 +- examples/2d/sprite_slice.rs | 4 +- examples/2d/text2d.rs | 20 +-- examples/2d/texture_atlas.rs | 8 +- examples/2d/transparency_2d.rs | 6 +- examples/2d/wireframe_2d.rs | 6 +- examples/3d/3d_scene.rs | 8 +- examples/3d/3d_shapes.rs | 10 +- examples/3d/3d_viewport_to_world.rs | 4 +- examples/3d/animated_material.rs | 4 +- examples/3d/anisotropy.rs | 10 +- examples/3d/anti_aliasing.rs | 6 +- examples/3d/atmosphere.rs | 12 +- examples/3d/atmospheric_fog.rs | 6 +- examples/3d/auto_exposure.rs | 8 +- examples/3d/blend_modes.rs | 18 +-- examples/3d/bloom_3d.rs | 6 +- examples/3d/camera_sub_view.rs | 6 +- examples/3d/clearcoat.rs | 14 +- examples/3d/clustered_decals.rs | 18 +-- examples/3d/color_grading.rs | 6 +- examples/3d/decal.rs | 10 +- examples/3d/deferred_rendering.rs | 22 +-- examples/3d/depth_of_field.rs | 2 +- examples/3d/edit_material_on_gltf.rs | 10 +- examples/3d/fog.rs | 14 +- examples/3d/fog_volumes.rs | 15 ++- examples/3d/generate_custom_mesh.rs | 4 +- examples/3d/irradiance_volumes.rs | 18 +-- examples/3d/lighting.rs | 26 ++-- examples/3d/lightmaps.rs | 2 +- examples/3d/lines.rs | 6 +- examples/3d/load_gltf.rs | 4 +- examples/3d/load_gltf_extras.rs | 2 +- examples/3d/mesh_ray_cast.rs | 6 +- examples/3d/meshlet.rs | 8 +- examples/3d/mixed_lighting.rs | 6 +- examples/3d/motion_blur.rs | 26 ++-- examples/3d/occlusion_culling.rs | 14 +- examples/3d/order_independent_transparency.rs | 22 +-- examples/3d/orthographic.rs | 12 +- examples/3d/parallax_mapping.rs | 22 +-- examples/3d/parenting.rs | 10 +- examples/3d/pbr.rs | 10 +- examples/3d/pcss.rs | 4 +- examples/3d/post_processing.rs | 6 +- examples/3d/query_gltf_primitives.rs | 4 +- examples/3d/reflection_probes.rs | 6 +- examples/3d/render_to_texture.rs | 14 +- examples/3d/rotate_environment_map.rs | 4 +- examples/3d/scrolling_fog.rs | 10 +- examples/3d/shadow_biases.rs | 8 +- examples/3d/shadow_caster_receiver.rs | 12 +- examples/3d/skybox.rs | 6 +- examples/3d/specular_tint.rs | 6 +- examples/3d/spherical_area_lights.rs | 4 +- examples/3d/split_screen.rs | 6 +- examples/3d/spotlight.rs | 14 +- examples/3d/ssao.rs | 12 +- examples/3d/ssr.rs | 12 +- examples/3d/texture.rs | 8 +- examples/3d/tonemapping.rs | 8 +- examples/3d/transmission.rs | 30 ++--- examples/3d/transparency_3d.rs | 14 +- examples/3d/two_passes.rs | 8 +- examples/3d/update_gltf_scene.rs | 8 +- examples/3d/vertex_colors.rs | 6 +- examples/3d/visibility_range.rs | 6 +- examples/3d/volumetric_fog.rs | 12 +- examples/3d/wireframe.rs | 10 +- examples/README.md | 2 +- examples/animation/animated_mesh.rs | 4 +- examples/animation/animated_mesh_control.rs | 4 +- examples/animation/animated_mesh_events.rs | 8 +- examples/animation/animated_transform.rs | 18 +-- examples/animation/animation_graph.rs | 8 +- examples/animation/animation_masks.rs | 8 +- examples/animation/color_animation.rs | 8 +- examples/animation/custom_skinned_mesh.rs | 10 +- examples/animation/eased_motion.rs | 10 +- examples/animation/easing_functions.rs | 14 +- examples/animation/gltf_skinned_mesh.rs | 6 +- examples/animation/morph_targets.rs | 4 +- examples/app/headless_renderer.rs | 8 +- examples/asset/alter_mesh.rs | 8 +- examples/asset/alter_sprite.rs | 4 +- examples/asset/asset_loading.rs | 10 +- examples/asset/asset_settings.rs | 6 +- examples/asset/hot_asset_reloading.rs | 4 +- examples/asset/multi_asset_sync.rs | 8 +- examples/asset/repeated_texture.rs | 10 +- examples/async_tasks/async_compute.rs | 9 +- .../external_source_external_thread.rs | 4 +- examples/audio/spatial_audio_2d.rs | 12 +- examples/audio/spatial_audio_3d.rs | 16 +-- examples/camera/2d_screen_shake.rs | 8 +- examples/camera/2d_top_down_camera.rs | 8 +- examples/camera/camera_orbit.rs | 8 +- examples/camera/custom_projection.rs | 8 +- examples/camera/first_person_view_model.rs | 12 +- examples/camera/projection_zoom.rs | 6 +- examples/diagnostics/log_diagnostics.rs | 8 +- examples/ecs/entity_disabling.rs | 2 +- examples/ecs/error_handling.rs | 14 +- examples/ecs/fallible_params.rs | 10 +- examples/ecs/hierarchy.rs | 10 +- examples/ecs/iter_combinations.rs | 15 ++- examples/ecs/parallel_query.rs | 6 +- examples/games/alien_cake_addict.rs | 20 +-- examples/games/breakout.rs | 22 +-- examples/games/contributors.rs | 12 +- examples/games/desk_toy.rs | 24 ++-- examples/games/loading_screen.rs | 10 +- examples/gizmos/3d_gizmos.rs | 10 +- examples/gizmos/axes.rs | 22 +-- examples/gizmos/light_gizmos.rs | 14 +- examples/helpers/camera_controller.rs | 2 +- examples/input/text_input.rs | 2 +- examples/math/bounding_2d.rs | 20 +-- examples/math/custom_primitives.rs | 20 +-- examples/math/random_sampling.rs | 12 +- examples/math/render_primitives.rs | 12 +- examples/math/sampling_primitives.rs | 18 +-- examples/mobile/src/lib.rs | 12 +- .../movement/physics_in_fixed_timestep.rs | 12 +- examples/movement/smooth_follow.rs | 14 +- examples/picking/debug_picking.rs | 10 +- examples/picking/mesh_picking.rs | 12 +- examples/picking/simple_picking.rs | 10 +- examples/picking/sprite_picking.rs | 10 +- examples/remote/client.rs | 2 +- examples/remote/server.rs | 10 +- examples/scene/scene.rs | 2 +- examples/shader/animate_shader.rs | 4 +- examples/shader/array_texture.rs | 6 +- examples/shader/automatic_instancing.rs | 6 +- .../shader/compute_shader_game_of_life.rs | 2 +- examples/shader/custom_phase_item.rs | 4 +- examples/shader/custom_post_processing.rs | 7 +- examples/shader/custom_render_phase.rs | 8 +- examples/shader/custom_shader_instancing.rs | 2 +- examples/shader/custom_vertex_attribute.rs | 4 +- examples/shader/extended_material.rs | 8 +- examples/shader/extended_material_bindless.rs | 8 +- examples/shader/fallback_image.rs | 2 +- examples/shader/shader_defs.rs | 6 +- examples/shader/shader_material.rs | 4 +- examples/shader/shader_material_2d.rs | 2 +- examples/shader/shader_material_bindless.rs | 6 +- examples/shader/shader_material_glsl.rs | 4 +- .../shader_material_screenspace_texture.rs | 8 +- examples/shader/shader_material_wesl.rs | 6 +- examples/shader/shader_prepass.rs | 14 +- examples/shader/specialized_mesh_pipeline.rs | 4 +- examples/shader/storage_buffer.rs | 4 +- examples/shader/texture_binding_array.rs | 2 +- examples/state/computed_states.rs | 2 +- examples/state/custom_transitions.rs | 2 +- examples/state/states.rs | 2 +- examples/state/sub_states.rs | 2 +- examples/stress_tests/bevymark.rs | 8 +- .../stress_tests/many_animated_sprites.rs | 6 +- examples/stress_tests/many_cameras_lights.rs | 10 +- examples/stress_tests/many_cubes.rs | 46 +++---- examples/stress_tests/many_foxes.rs | 10 +- examples/stress_tests/many_gizmos.rs | 2 +- examples/stress_tests/many_lights.rs | 8 +- examples/stress_tests/many_materials.rs | 6 +- examples/stress_tests/many_sprites.rs | 6 +- examples/stress_tests/many_text2d.rs | 8 +- examples/stress_tests/transform_hierarchy.rs | 12 +- examples/testbed/2d.rs | 14 +- examples/testbed/3d.rs | 25 ++-- examples/testbed/full_ui.rs | 2 +- examples/time/virtual_time.rs | 8 +- examples/tools/gamepad_viewer.rs | 22 +-- examples/tools/scene_viewer/main.rs | 8 +- .../tools/scene_viewer/scene_viewer_plugin.rs | 2 +- examples/transforms/3d_rotation.rs | 8 +- examples/transforms/align.rs | 20 +-- examples/transforms/scale.rs | 10 +- examples/transforms/transform.rs | 20 +-- examples/transforms/translation.rs | 8 +- examples/ui/overflow_debug.rs | 12 +- examples/ui/render_ui_to_texture.rs | 6 +- examples/ui/viewport_node.rs | 4 +- examples/window/low_power.rs | 6 +- examples/window/multiple_windows.rs | 6 +- examples/window/screenshot.rs | 6 +- tests/window/minimizing.rs | 6 +- tests/window/resizing.rs | 6 +- 250 files changed, 1215 insertions(+), 1195 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 79967b68ec9ee..d2215539bab8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1492,7 +1492,7 @@ doc-scrape-examples = true [package.metadata.example.animated_transform] name = "Animated Transform" -description = "Create and play an animation defined by code that operates on the `Transform` component" +description = "Create and play an animation defined by code that operates on the `Transform3d` component" category = "Animation" wasm = true @@ -3180,7 +3180,7 @@ doc-scrape-examples = true [package.metadata.example.align] name = "Alignment" -description = "A demonstration of Transform's axis-alignment feature" +description = "A demonstration of `Transform3d`'s axis-alignment feature" category = "Transforms" wasm = true diff --git a/assets/scenes/load_scene_example.scn.ron b/assets/scenes/load_scene_example.scn.ron index 477bee30545df..b9ce5c0dd359b 100644 --- a/assets/scenes/load_scene_example.scn.ron +++ b/assets/scenes/load_scene_example.scn.ron @@ -9,7 +9,7 @@ components: { "bevy_ecs::name::Name": "joe", "bevy_transform::components::global_transform::GlobalTransform": ((1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)), - "bevy_transform::components::transform::Transform": ( + "bevy_transform::components::transform::Transform3d": ( translation: (0.0, 0.0, 0.0), rotation: (0.0, 0.0, 0.0, 1.0), scale: (1.0, 1.0, 1.0), diff --git a/crates/bevy_animation/src/animatable.rs b/crates/bevy_animation/src/animatable.rs index a345c5fce4f0a..968af09160db3 100644 --- a/crates/bevy_animation/src/animatable.rs +++ b/crates/bevy_animation/src/animatable.rs @@ -4,7 +4,7 @@ use crate::util; use bevy_color::{Laba, LinearRgba, Oklaba, Srgba, Xyza}; use bevy_math::*; use bevy_reflect::Reflect; -use bevy_transform::prelude::Transform; +use bevy_transform::prelude::Transform3d; /// An individual input for [`Animatable::blend`]. pub struct BlendInput { @@ -130,7 +130,7 @@ impl Animatable for bool { } } -impl Animatable for Transform { +impl Animatable for Transform3d { fn interpolate(a: &Self, b: &Self, t: f32) -> Self { Self { translation: Vec3::interpolate(&a.translation, &b.translation, t), diff --git a/crates/bevy_animation/src/animation_curves.rs b/crates/bevy_animation/src/animation_curves.rs index 45fa393e05965..274a2cb7ec5ac 100644 --- a/crates/bevy_animation/src/animation_curves.rs +++ b/crates/bevy_animation/src/animation_curves.rs @@ -21,7 +21,7 @@ //! animation system. //! //! For instance, let's imagine that we want to use the `Vec3` output -//! from our curve to animate the [translation component of a `Transform`]. For this, there is +//! from our curve to animate the [translation component of a `Transform3d`]. For this, there is //! the adaptor [`AnimatableCurve`], which wraps any [`Curve`] and [`AnimatableProperty`] and turns it into an //! [`AnimationCurve`] that will use the given curve to animate the entity's property: //! @@ -78,7 +78,7 @@ //! This is the lowest-level option with the most control, but it is also the most complicated. //! //! [using a function]: bevy_math::curve::FunctionCurve -//! [translation component of a `Transform`]: bevy_transform::prelude::Transform::translation +//! [translation component of a `Transform3d`]: bevy_transform::prelude::Transform::translation //! [`AnimationClip`]: crate::AnimationClip //! [there]: AnimatableProperty //! [`animated_field`]: crate::animated_field diff --git a/crates/bevy_audio/src/audio.rs b/crates/bevy_audio/src/audio.rs index 349cf6b6a46f4..eba8ef4981824 100644 --- a/crates/bevy_audio/src/audio.rs +++ b/crates/bevy_audio/src/audio.rs @@ -140,7 +140,7 @@ impl PlaybackSettings { /// Settings for the listener for spatial audio sources. /// -/// This must be accompanied by `Transform` and `GlobalTransform`. +/// This must be accompanied by `Transform3d` and `GlobalTransform`. /// Only one entity with a `SpatialListener` should be present at any given time. #[derive(Component, Clone, Debug, Reflect)] #[reflect(Clone, Default, Component, Debug)] diff --git a/crates/bevy_audio/src/sinks.rs b/crates/bevy_audio/src/sinks.rs index 1e020d1fd8d71..a32de015540fb 100644 --- a/crates/bevy_audio/src/sinks.rs +++ b/crates/bevy_audio/src/sinks.rs @@ -1,7 +1,7 @@ use crate::Volume; use bevy_ecs::component::Component; use bevy_math::Vec3; -use bevy_transform::prelude::Transform; +use bevy_transform::prelude::Transform3d; use core::time::Duration; pub use rodio::source::SeekError; use rodio::{Sink, SpatialSink}; @@ -341,7 +341,7 @@ impl SpatialAudioSink { } /// Set the listener position, with an ear on each side separated by `gap`. - pub fn set_listener_position(&self, position: Transform, gap: f32) { + pub fn set_listener_position(&self, position: Transform3d, gap: f32) { self.set_ears_position( position.translation + position.left() * gap / 2.0, position.translation + position.right() * gap / 2.0, diff --git a/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs b/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs index d46174192be9f..a3073ba628bb6 100644 --- a/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs +++ b/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs @@ -9,7 +9,7 @@ use bevy_render::{ extract_component::ExtractComponent, primitives::Frustum, }; -use bevy_transform::prelude::{GlobalTransform, Transform}; +use bevy_transform::prelude::{GlobalTransform, Transform3d}; /// A 2D camera component. Enables the 2D render graph for a [`Camera`]. #[derive(Component, Default, Reflect, Clone, ExtractComponent)] @@ -20,7 +20,7 @@ use bevy_transform::prelude::{GlobalTransform, Transform}; DebandDither, CameraRenderGraph::new(Core2d), Projection::Orthographic(OrthographicProjection::default_2d()), - Frustum = OrthographicProjection::default_2d().compute_frustum(&GlobalTransform::from(Transform::default())), + Frustum = OrthographicProjection::default_2d().compute_frustum(&GlobalTransform::from(Transform3d::default())), Tonemapping::None, )] pub struct Camera2d; diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index ede50d6d8fce6..43b16e708f8ed 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -27,7 +27,7 @@ use bevy_render::{ view::{ExtractedView, Msaa, ViewTarget, ViewUniform, ViewUniforms}, Render, RenderApp, RenderSystems, }; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; use prepass::{SkyboxPrepassPipeline, SKYBOX_PREPASS_SHADER_HANDLE}; use crate::{core_3d::CORE_3D_DEPTH_FORMAT, prepass::PreviousViewUniforms}; @@ -128,7 +128,7 @@ impl ExtractComponent for Skybox { skybox.clone(), SkyboxUniforms { brightness: skybox.brightness * exposure, - transform: Transform::from_rotation(skybox.rotation) + transform: Transform3d::from_rotation(skybox.rotation) .compute_matrix() .inverse(), #[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu")))] diff --git a/crates/bevy_gizmos/src/aabb.rs b/crates/bevy_gizmos/src/aabb.rs index 4ac9e5f2ac456..d66784e33f311 100644 --- a/crates/bevy_gizmos/src/aabb.rs +++ b/crates/bevy_gizmos/src/aabb.rs @@ -13,7 +13,7 @@ use bevy_ecs::{ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_render::primitives::Aabb; use bevy_transform::{ - components::{GlobalTransform, Transform}, + components::{GlobalTransform, Transform3d}, TransformSystems, }; @@ -104,7 +104,7 @@ fn color_from_entity(entity: Entity) -> Color { fn aabb_transform(aabb: Aabb, transform: GlobalTransform) -> GlobalTransform { transform * GlobalTransform::from( - Transform::from_translation(aabb.center.into()) + Transform3d::from_translation(aabb.center.into()) .with_scale((aabb.half_extents * 2.).into()), ) } diff --git a/crates/bevy_gizmos/src/retained.rs b/crates/bevy_gizmos/src/retained.rs index 88610b9744203..2c302274351a7 100644 --- a/crates/bevy_gizmos/src/retained.rs +++ b/crates/bevy_gizmos/src/retained.rs @@ -5,7 +5,7 @@ use core::ops::{Deref, DerefMut}; use bevy_asset::Handle; use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; #[cfg(feature = "bevy_render")] use { @@ -74,7 +74,7 @@ impl DerefMut for GizmoAsset { /// [`Gizmos`]: crate::gizmos::Gizmos #[derive(Component, Clone, Debug, Default, Reflect)] #[reflect(Component, Clone, Default)] -#[require(Transform)] +#[require(Transform3d)] pub struct Gizmo { /// The handle to the gizmo to draw. pub handle: Handle, diff --git a/crates/bevy_gizmos/src/rounded_box.rs b/crates/bevy_gizmos/src/rounded_box.rs index 530d4f8617a54..8c3faaf4af99b 100644 --- a/crates/bevy_gizmos/src/rounded_box.rs +++ b/crates/bevy_gizmos/src/rounded_box.rs @@ -8,7 +8,7 @@ use core::f32::consts::FRAC_PI_2; use crate::{gizmos::GizmoBuffer, prelude::GizmoConfigGroup}; use bevy_color::Color; use bevy_math::{Isometry2d, Isometry3d, Quat, Vec2, Vec3}; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; /// A builder returned by [`GizmoBuffer::rounded_rect`] and [`GizmoBuffer::rounded_rect_2d`] pub struct RoundedRectBuilder<'a, Config, Clear> @@ -182,7 +182,7 @@ where // Handle cases where the rounded cuboid collapses into simpler shapes if edge_radius == 0.0 { - let transform = Transform::from_translation(config.isometry.translation.into()) + let transform = Transform3d::from_translation(config.isometry.translation.into()) .with_rotation(config.isometry.rotation) .with_scale(self.size); self.gizmos.cuboid(transform, config.color); diff --git a/crates/bevy_gltf/src/assets.rs b/crates/bevy_gltf/src/assets.rs index bfc920ebcea1f..b5e11d6faf119 100644 --- a/crates/bevy_gltf/src/assets.rs +++ b/crates/bevy_gltf/src/assets.rs @@ -91,7 +91,7 @@ impl GltfMesh { } /// A glTF node with all of its child nodes, its [`GltfMesh`], -/// [`Transform`](bevy_transform::prelude::Transform), its optional [`GltfSkin`] +/// [`Transform3d`](bevy_transform::prelude::Transform), its optional [`GltfSkin`] /// and an optional [`GltfExtras`]. /// /// See [the relevant glTF specification section](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-node). @@ -108,7 +108,7 @@ pub struct GltfNode { /// Skin of the node. pub skin: Option>, /// Local transform. - pub transform: bevy_transform::prelude::Transform, + pub transform: bevy_transform::prelude::Transform3d, /// Is this node used as an animation root #[cfg(feature = "bevy_animation")] pub is_animation_root: bool, @@ -122,7 +122,7 @@ impl GltfNode { node: &gltf::Node, children: Vec>, mesh: Option>, - transform: bevy_transform::prelude::Transform, + transform: bevy_transform::prelude::Transform3d, skin: Option>, extras: Option, ) -> Self { diff --git a/crates/bevy_gltf/src/loader/gltf_ext/scene.rs b/crates/bevy_gltf/src/loader/gltf_ext/scene.rs index 83e6778b99e37..c2973305d68f6 100644 --- a/crates/bevy_gltf/src/loader/gltf_ext/scene.rs +++ b/crates/bevy_gltf/src/loader/gltf_ext/scene.rs @@ -1,6 +1,6 @@ use bevy_ecs::name::Name; use bevy_math::{Mat4, Vec3}; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; use gltf::scene::Node; @@ -26,16 +26,16 @@ pub(crate) fn node_name(node: &Node) -> Name { /// on [`Node::transform()`](gltf::Node::transform) directly because it uses optimized glam types and /// if `libm` feature of `bevy_math` crate is enabled also handles cross /// platform determinism properly. -pub(crate) fn node_transform(node: &Node) -> Transform { +pub(crate) fn node_transform(node: &Node) -> Transform3d { match node.transform() { gltf::scene::Transform::Matrix { matrix } => { - Transform::from_matrix(Mat4::from_cols_array_2d(&matrix)) + Transform3d::from_matrix(Mat4::from_cols_array_2d(&matrix)) } gltf::scene::Transform::Decomposed { translation, rotation, scale, - } => Transform { + } => Transform3d { translation: Vec3::from(translation), rotation: bevy_math::Quat::from_array(rotation), scale: Vec3::from(scale), diff --git a/crates/bevy_gltf/src/loader/mod.rs b/crates/bevy_gltf/src/loader/mod.rs index 9bdeb23f26885..8026705d567fc 100644 --- a/crates/bevy_gltf/src/loader/mod.rs +++ b/crates/bevy_gltf/src/loader/mod.rs @@ -48,7 +48,7 @@ use bevy_render::{ use bevy_scene::Scene; #[cfg(not(target_arch = "wasm32"))] use bevy_tasks::IoTaskPool; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; use gltf::{ accessor::Iter, @@ -302,7 +302,7 @@ async fn load_gltf<'a, 'b, 'c>( { match outputs { ReadOutputs::Translations(tr) => { - let translation_property = animated_field!(Transform::translation); + let translation_property = animated_field!(Transform3d::translation); let translations: Vec = tr.map(Vec3::from).collect(); if keyframe_timestamps.len() == 1 { Some(VariableCurve::new(AnimatableCurve::new( @@ -349,7 +349,7 @@ async fn load_gltf<'a, 'b, 'c>( } } ReadOutputs::Rotations(rots) => { - let rotation_property = animated_field!(Transform::rotation); + let rotation_property = animated_field!(Transform3d::rotation); let rotations: Vec = rots.into_f32().map(Quat::from_array).collect(); if keyframe_timestamps.len() == 1 { @@ -400,7 +400,7 @@ async fn load_gltf<'a, 'b, 'c>( } } ReadOutputs::Scales(scale) => { - let scale_property = animated_field!(Transform::scale); + let scale_property = animated_field!(Transform3d::scale); let scales: Vec = scale.map(Vec3::from).collect(); if keyframe_timestamps.len() == 1 { Some(VariableCurve::new(AnimatableCurve::new( @@ -867,7 +867,7 @@ async fn load_gltf<'a, 'b, 'c>( let mut scene_load_context = load_context.begin_labeled_asset(); let world_root_id = world - .spawn((Transform::default(), Visibility::default())) + .spawn((Transform3d::default(), Visibility::default())) .with_children(|parent| { for node in scene.nodes() { let result = load_node( @@ -879,7 +879,7 @@ async fn load_gltf<'a, 'b, 'c>( &mut node_index_to_entity_map, &mut entity_to_skin_index_map, &mut active_camera_found, - &Transform::default(), + &Transform3d::default(), #[cfg(feature = "bevy_animation")] &animation_roots, #[cfg(feature = "bevy_animation")] @@ -1292,7 +1292,7 @@ fn load_node( node_index_to_entity_map: &mut HashMap, entity_to_skin_index_map: &mut EntityHashMap, active_camera_found: &mut bool, - parent_transform: &Transform, + parent_transform: &Transform3d, #[cfg(feature = "bevy_animation")] animation_roots: &HashSet, #[cfg(feature = "bevy_animation")] mut animation_context: Option, document: &Document, diff --git a/crates/bevy_mesh/src/mesh.rs b/crates/bevy_mesh/src/mesh.rs index e4868dbf6997d..056781b2d16c1 100644 --- a/crates/bevy_mesh/src/mesh.rs +++ b/crates/bevy_mesh/src/mesh.rs @@ -1,4 +1,4 @@ -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; pub use wgpu_types::PrimitiveTopology; use super::{ @@ -863,18 +863,18 @@ impl Mesh { Ok(()) } - /// Transforms the vertex positions, normals, and tangents of the mesh by the given [`Transform`]. + /// Transforms the vertex positions, normals, and tangents of the mesh by the given [`Transform3d`]. /// /// `Aabb` of entities with modified mesh are not updated automatically. - pub fn transformed_by(mut self, transform: Transform) -> Self { + pub fn transformed_by(mut self, transform: Transform3d) -> Self { self.transform_by(transform); self } - /// Transforms the vertex positions, normals, and tangents of the mesh in place by the given [`Transform`]. + /// Transforms the vertex positions, normals, and tangents of the mesh in place by the given [`Transform3d`]. /// /// `Aabb` of entities with modified mesh are not updated automatically. - pub fn transform_by(&mut self, transform: Transform) { + pub fn transform_by(&mut self, transform: Transform3d) { // Needed when transforming normals and tangents let scale_recip = 1. / transform.scale; debug_assert!( @@ -1228,7 +1228,7 @@ impl Mesh { } } -impl core::ops::Mul for Transform { +impl core::ops::Mul for Transform3d { type Output = Mesh; fn mul(self, rhs: Mesh) -> Self::Output { @@ -1252,7 +1252,7 @@ mod tests { use bevy_asset::RenderAssetUsages; use bevy_math::primitives::Triangle3d; use bevy_math::Vec3; - use bevy_transform::components::Transform; + use bevy_transform::components::Transform3d; #[test] #[should_panic] @@ -1285,7 +1285,7 @@ mod tests { .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, vec![[0., 0.], [1., 0.], [0.5, 1.]]); let mesh = mesh.transformed_by( - Transform::from_translation(Vec3::splat(-2.)).with_scale(Vec3::new(2., 0., -1.)), + Transform3d::from_translation(Vec3::splat(-2.)).with_scale(Vec3::new(2., 0., -1.)), ); if let Some(VertexAttributeValues::Float32x3(positions)) = diff --git a/crates/bevy_pbr/src/decal/clustered.rs b/crates/bevy_pbr/src/decal/clustered.rs index cadcd1b8712a9..3ff3a3b11180c 100644 --- a/crates/bevy_pbr/src/decal/clustered.rs +++ b/crates/bevy_pbr/src/decal/clustered.rs @@ -45,7 +45,7 @@ use bevy_render::{ view::{self, ViewVisibility, Visibility, VisibilityClass}, Extract, ExtractSchedule, Render, RenderApp, RenderSystems, }; -use bevy_transform::{components::GlobalTransform, prelude::Transform}; +use bevy_transform::{components::GlobalTransform, prelude::Transform3d}; use bytemuck::{Pod, Zeroable}; use crate::{ @@ -81,7 +81,7 @@ pub struct ClusteredDecalPlugin; /// with forward or deferred rendering and don't require a prepass. #[derive(Component, Debug, Clone, Reflect, ExtractComponent)] #[reflect(Component, Debug, Clone)] -#[require(Transform, Visibility, VisibilityClass)] +#[require(Transform3d, Visibility, VisibilityClass)] #[component(on_add = view::add_visibility_class::)] pub struct ClusteredDecal { /// The image that the clustered decal projects. diff --git a/crates/bevy_pbr/src/light/directional_light.rs b/crates/bevy_pbr/src/light/directional_light.rs index a5798fdde7f0f..d17efc46161c3 100644 --- a/crates/bevy_pbr/src/light/directional_light.rs +++ b/crates/bevy_pbr/src/light/directional_light.rs @@ -49,7 +49,7 @@ use super::*; CascadesFrusta, CascadeShadowConfig, CascadesVisibleEntities, - Transform, + Transform3d, Visibility, VisibilityClass )] diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index 91ea9cddd3b4c..0022a4c28f36d 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -17,7 +17,7 @@ use bevy_render::{ ViewVisibility, VisibilityClass, VisibilityRange, VisibleEntityRanges, }, }; -use bevy_transform::components::{GlobalTransform, Transform}; +use bevy_transform::components::{GlobalTransform, Transform3d}; use bevy_utils::Parallel; use crate::*; @@ -595,7 +595,7 @@ pub fn update_point_light_frusta( ) { let view_rotations = CUBE_MAP_FACES .iter() - .map(|CubeMapFace { target, up }| Transform::IDENTITY.looking_at(*target, *up)) + .map(|CubeMapFace { target, up }| Transform3d::IDENTITY.looking_at(*target, *up)) .collect::>(); for (entity, transform, point_light, mut cubemap_frusta) in &mut views { @@ -623,7 +623,7 @@ pub fn update_point_light_frusta( // ignore scale because we don't want to effectively scale light radius and range // by applying those as a view transform to shadow map rendering of objects // and ignore rotation because we want the shadow map projections to align with the axes - let view_translation = Transform::from_translation(transform.translation()); + let view_translation = Transform3d::from_translation(transform.translation()); let view_backward = transform.back(); for (view_rotation, frustum) in view_rotations.iter().zip(cubemap_frusta.iter_mut()) { diff --git a/crates/bevy_pbr/src/light/point_light.rs b/crates/bevy_pbr/src/light/point_light.rs index f2e4224d28f94..00ba99cd72101 100644 --- a/crates/bevy_pbr/src/light/point_light.rs +++ b/crates/bevy_pbr/src/light/point_light.rs @@ -30,7 +30,7 @@ use super::*; #[require( CubemapFrusta, CubemapVisibleEntities, - Transform, + Transform3d, Visibility, VisibilityClass )] diff --git a/crates/bevy_pbr/src/light/spot_light.rs b/crates/bevy_pbr/src/light/spot_light.rs index a7cfe1b817407..fff562905134e 100644 --- a/crates/bevy_pbr/src/light/spot_light.rs +++ b/crates/bevy_pbr/src/light/spot_light.rs @@ -9,7 +9,7 @@ use super::*; /// the transform, and can be specified with [`Transform::looking_at`](Transform::looking_at). #[derive(Component, Debug, Clone, Copy, Reflect)] #[reflect(Component, Default, Debug, Clone)] -#[require(Frustum, VisibleMeshEntities, Transform, Visibility, VisibilityClass)] +#[require(Frustum, VisibleMeshEntities, Transform3d, Visibility, VisibilityClass)] #[component(on_add = view::add_visibility_class::)] pub struct SpotLight { /// The color of the light. diff --git a/crates/bevy_pbr/src/light_probe/mod.rs b/crates/bevy_pbr/src/light_probe/mod.rs index d7323a1e3c9ed..dd373348176ac 100644 --- a/crates/bevy_pbr/src/light_probe/mod.rs +++ b/crates/bevy_pbr/src/light_probe/mod.rs @@ -29,7 +29,7 @@ use bevy_render::{ view::{ExtractedView, Visibility}, Extract, ExtractSchedule, Render, RenderApp, RenderSystems, }; -use bevy_transform::{components::Transform, prelude::GlobalTransform}; +use bevy_transform::{components::Transform3d, prelude::GlobalTransform}; use tracing::error; use core::{hash::Hash, ops::Deref}; @@ -74,7 +74,7 @@ pub struct LightProbePlugin; /// [`IrradianceVolume`]. /// /// The light probe range is conceptually a unit cube (1×1×1) centered on the -/// origin. The [`Transform`] applied to this entity can scale, rotate, or translate +/// origin. The [`Transform3d`] applied to this entity can scale, rotate, or translate /// that cube so that it contains all fragments that should take this light probe into account. /// /// When multiple sources of indirect illumination can be applied to a fragment, @@ -107,7 +107,7 @@ pub struct LightProbePlugin; /// with other engines should be aware of this terminology difference. #[derive(Component, Debug, Clone, Copy, Default, Reflect)] #[reflect(Component, Default, Debug, Clone)] -#[require(Transform, Visibility)] +#[require(Transform3d, Visibility)] pub struct LightProbe; /// A GPU type that stores information about a light probe. @@ -399,7 +399,7 @@ fn gather_environment_map_uniform( for (view_entity, environment_map_light) in view_query.iter() { let environment_map_uniform = if let Some(environment_map_light) = environment_map_light { EnvironmentMapUniform { - transform: Transform::from_rotation(environment_map_light.rotation) + transform: Transform3d::from_rotation(environment_map_light.rotation) .compute_matrix() .inverse(), } diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index f57ba9adf343e..6ff0729046e87 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -42,7 +42,7 @@ use bevy_render::{ mesh::allocator::SlabId, sync_world::{MainEntity, RenderEntity}, }; -use bevy_transform::{components::GlobalTransform, prelude::Transform}; +use bevy_transform::{components::GlobalTransform, prelude::Transform3d}; use bevy_utils::default; use core::{hash::Hash, marker::PhantomData, ops::Range}; #[cfg(feature = "trace")] @@ -793,7 +793,7 @@ pub fn prepare_lights( // Pre-calculate for PointLights let cube_face_rotations = CUBE_MAP_FACES .iter() - .map(|CubeMapFace { target, up }| Transform::IDENTITY.looking_at(*target, *up)) + .map(|CubeMapFace { target, up }| Transform3d::IDENTITY.looking_at(*target, *up)) .collect::>(); global_light_meta.entity_to_index.clear(); diff --git a/crates/bevy_pbr/src/volumetric_fog/mod.rs b/crates/bevy_pbr/src/volumetric_fog/mod.rs index 4af1bbb4213e5..890b433569f27 100644 --- a/crates/bevy_pbr/src/volumetric_fog/mod.rs +++ b/crates/bevy_pbr/src/volumetric_fog/mod.rs @@ -53,7 +53,7 @@ use bevy_render::{ view::Visibility, ExtractSchedule, Render, RenderApp, RenderSystems, }; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; use render::{ VolumetricFogNode, VolumetricFogPipeline, VolumetricFogUniformBuffer, CUBE_MESH, PLANE_MESH, VOLUMETRIC_FOG_HANDLE, @@ -117,7 +117,7 @@ pub struct VolumetricFog { #[derive(Clone, Component, Debug, Reflect)] #[reflect(Component, Default, Debug, Clone)] -#[require(Transform, Visibility)] +#[require(Transform3d, Visibility)] pub struct FogVolume { /// The color of the fog. /// diff --git a/crates/bevy_picking/src/lib.rs b/crates/bevy_picking/src/lib.rs index 53387e84c8d1f..9301e5743a6ff 100644 --- a/crates/bevy_picking/src/lib.rs +++ b/crates/bevy_picking/src/lib.rs @@ -53,7 +53,7 @@ //! fn setup(mut commands: Commands) { //! commands.spawn(Transform::default()) //! // Spawn your entity here, e.g. a Mesh. -//! // When dragged, mutate the `Transform` component on the dragged target entity: +//! // When dragged, mutate the `Transform3d` component on the dragged target entity: //! .observe(|trigger: Trigger>, mut transforms: Query<&mut Transform>| { //! let mut transform = transforms.get_mut(trigger.target()).unwrap(); //! let drag = trigger.event(); diff --git a/crates/bevy_remote/src/builtin_methods.rs b/crates/bevy_remote/src/builtin_methods.rs index 18c85d3eec5f3..6d828cbb27cf5 100644 --- a/crates/bevy_remote/src/builtin_methods.rs +++ b/crates/bevy_remote/src/builtin_methods.rs @@ -99,7 +99,7 @@ pub struct BrpGetParams { /// /// Note that these strings must consist of the *full* type paths: e.g. /// `bevy_transform::components::transform::Transform`, not just - /// `Transform`. + /// `Transform3d`. /// /// [full paths]: bevy_reflect::TypePath::type_path pub components: Vec, @@ -151,7 +151,7 @@ pub struct BrpSpawnParams { /// /// Note that the keys of the map must be the [full type paths]: e.g. /// `bevy_transform::components::transform::Transform`, not just - /// `Transform`. + /// `Transform3d`. /// /// [full type paths]: bevy_reflect::TypePath::type_path pub components: HashMap, @@ -179,7 +179,7 @@ pub struct BrpRemoveParams { /// /// Note that these strings must consist of the [full type paths]: e.g. /// `bevy_transform::components::transform::Transform`, not just - /// `Transform`. + /// `Transform3d`. /// /// [full type paths]: bevy_reflect::TypePath::type_path pub components: Vec, @@ -208,7 +208,7 @@ pub struct BrpInsertParams { /// /// Note that the keys of the map must be the [full type paths]: e.g. /// `bevy_transform::components::transform::Transform`, not just - /// `Transform`. + /// `Transform3d`. /// /// [full type paths]: bevy_reflect::TypePath::type_path pub components: HashMap, @@ -1287,7 +1287,7 @@ fn get_entity_mut(world: &mut World, entity: Entity) -> Result)] pub struct Mesh2d(pub Handle); @@ -98,7 +98,7 @@ impl AsAssetId for Mesh2d { /// ``` #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)] #[reflect(Component, Default, Clone, PartialEq)] -#[require(Transform, Visibility, VisibilityClass)] +#[require(Transform3d, Visibility, VisibilityClass)] #[component(on_add = view::add_visibility_class::)] pub struct Mesh3d(pub Handle); diff --git a/crates/bevy_scene/src/components.rs b/crates/bevy_scene/src/components.rs index d4d42c3a1c98c..f9a31ae1ebac4 100644 --- a/crates/bevy_scene/src/components.rs +++ b/crates/bevy_scene/src/components.rs @@ -2,7 +2,7 @@ use bevy_asset::Handle; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{component::Component, prelude::ReflectComponent}; use bevy_reflect::{prelude::ReflectDefault, Reflect}; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; use derive_more::derive::From; #[cfg(feature = "bevy_render")] @@ -14,7 +14,7 @@ use crate::{DynamicScene, Scene}; /// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component. #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)] #[reflect(Component, Default, Debug, PartialEq, Clone)] -#[require(Transform)] +#[require(Transform3d)] #[cfg_attr(feature = "bevy_render", require(Visibility))] pub struct SceneRoot(pub Handle); @@ -22,6 +22,6 @@ pub struct SceneRoot(pub Handle); /// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component. #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)] #[reflect(Component, Default, Debug, PartialEq, Clone)] -#[require(Transform)] +#[require(Transform3d)] #[cfg_attr(feature = "bevy_render", require(Visibility))] pub struct DynamicSceneRoot(pub Handle); diff --git a/crates/bevy_sprite/src/sprite.rs b/crates/bevy_sprite/src/sprite.rs index 61461ab640c44..fcb679f65fbb3 100644 --- a/crates/bevy_sprite/src/sprite.rs +++ b/crates/bevy_sprite/src/sprite.rs @@ -9,13 +9,13 @@ use bevy_render::{ sync_world::SyncToRenderWorld, view::{self, Visibility, VisibilityClass}, }; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; use crate::TextureSlicer; /// Describes a sprite to be rendered to a 2D camera #[derive(Component, Debug, Default, Clone, Reflect)] -#[require(Transform, Visibility, SyncToRenderWorld, VisibilityClass, Anchor)] +#[require(Transform3d, Visibility, SyncToRenderWorld, VisibilityClass, Anchor)] #[reflect(Component, Default, Debug, Clone)] #[component(on_add = view::add_visibility_class::)] pub struct Sprite { @@ -240,7 +240,7 @@ pub enum ScalingMode { FitEnd, } -/// Normalized (relative to its size) offset of a 2d renderable entity from its [`Transform`]. +/// Normalized (relative to its size) offset of a 2d renderable entity from its [`Transform3d`]. #[derive(Component, Debug, Clone, Copy, PartialEq, Deref, DerefMut, Reflect)] #[reflect(Component, Default, Debug, PartialEq, Clone)] #[doc(alias = "pivot")] diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 5069804df8672..c0f0c63aced48 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -29,7 +29,7 @@ use bevy_render::{ use bevy_sprite::{ Anchor, ExtractedSlice, ExtractedSlices, ExtractedSprite, ExtractedSprites, Sprite, }; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; use bevy_transform::prelude::GlobalTransform; use bevy_window::{PrimaryWindow, Window}; @@ -92,7 +92,7 @@ use bevy_window::{PrimaryWindow, Window}; Anchor, Visibility, VisibilityClass, - Transform + Transform3d )] #[component(on_add = view::add_visibility_class::)] pub struct Text2d(pub String); diff --git a/crates/bevy_transform/README.md b/crates/bevy_transform/README.md index c291b45e9b4a0..7b99172c551ca 100644 --- a/crates/bevy_transform/README.md +++ b/crates/bevy_transform/README.md @@ -6,4 +6,4 @@ [![Docs](https://docs.rs/bevy_transform/badge.svg)](https://docs.rs/bevy_transform/latest/bevy_transform/) [![Discord](https://img.shields.io/discord/691052431525675048.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/bevy) -This crate contains types and functions associated with the `Transform` component. +This crate contains types and functions associated with the `Transform3d` component. diff --git a/crates/bevy_transform/src/commands.rs b/crates/bevy_transform/src/commands.rs index aed9ea6b221eb..60f995229bf47 100644 --- a/crates/bevy_transform/src/commands.rs +++ b/crates/bevy_transform/src/commands.rs @@ -1,16 +1,16 @@ //! Extension to [`EntityCommands`] to modify [`bevy_ecs::hierarchy`] hierarchies. //! while preserving [`GlobalTransform`]. -use crate::prelude::{GlobalTransform, Transform}; +use crate::prelude::{GlobalTransform, Transform3d}; use bevy_ecs::{entity::Entity, hierarchy::ChildOf, system::EntityCommands, world::EntityWorldMut}; /// Collection of methods similar to the built-in parenting methods on [`EntityWorldMut`] and [`EntityCommands`], but preserving each /// entity's [`GlobalTransform`]. pub trait BuildChildrenTransformExt { /// Change this entity's parent while preserving this entity's [`GlobalTransform`] - /// by updating its [`Transform`]. + /// by updating its [`Transform3d`]. /// - /// Insert the [`ChildOf`] component directly if you don't want to also update the [`Transform`]. + /// Insert the [`ChildOf`] component directly if you don't want to also update the [`Transform3d`]. /// /// Note that both the hierarchy and transform updates will only execute /// the next time commands are applied @@ -18,9 +18,9 @@ pub trait BuildChildrenTransformExt { fn set_parent_in_place(&mut self, parent: Entity) -> &mut Self; /// Make this entity parentless while preserving this entity's [`GlobalTransform`] - /// by updating its [`Transform`] to be equal to its current [`GlobalTransform`]. + /// by updating its [`Transform3d`] to be equal to its current [`GlobalTransform`]. /// - /// See [`EntityWorldMut::remove::`] or [`EntityCommands::remove::`] for a method that doesn't update the [`Transform`]. + /// See [`EntityWorldMut::remove::`] or [`EntityCommands::remove::`] for a method that doesn't update the [`Transform3d`]. /// /// Note that both the hierarchy and transform updates will only execute /// the next time commands are applied @@ -52,7 +52,7 @@ impl BuildChildrenTransformExt for EntityWorldMut<'_> { let parent = *world.get_entity(parent).ok()?.get::()?; let child_global = *world.get_entity(child).ok()?.get::()?; let mut child_entity = world.get_entity_mut(child).ok()?; - let mut child = child_entity.get_mut::()?; + let mut child = child_entity.get_mut::()?; *child = child_global.reparented_to(&parent); Some(()) }; @@ -69,7 +69,7 @@ impl BuildChildrenTransformExt for EntityWorldMut<'_> { let mut update_transform = || { let child_global = *world.get_entity(child).ok()?.get::()?; let mut child_entity = world.get_entity_mut(child).ok()?; - let mut child = child_entity.get_mut::()?; + let mut child = child_entity.get_mut::()?; *child = child_global.compute_transform(); Some(()) }; diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index b10d5a9d1aba3..6e375b21291e2 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -1,6 +1,6 @@ use core::ops::Mul; -use super::Transform; +use super::Transform3d; use bevy_math::{ops, Affine3A, Dir3, Isometry3d, Mat4, Quat, Vec3, Vec3A}; use derive_more::derive::From; @@ -19,23 +19,23 @@ use { /// [`GlobalTransform`] is an affine transformation from entity-local coordinates to worldspace coordinates. /// /// You cannot directly mutate [`GlobalTransform`]; instead, you change an entity's transform by manipulating -/// its [`Transform`], which indirectly causes Bevy to update its [`GlobalTransform`]. +/// its [`Transform3d`], which indirectly causes Bevy to update its [`GlobalTransform`]. /// /// * To get the global transform of an entity, you should get its [`GlobalTransform`]. -/// * For transform hierarchies to work correctly, you must have both a [`Transform`] and a [`GlobalTransform`]. -/// [`GlobalTransform`] is automatically inserted whenever [`Transform`] is inserted. +/// * For transform hierarchies to work correctly, you must have both a [`Transform3d`] and a [`GlobalTransform`]. +/// [`GlobalTransform`] is automatically inserted whenever [`Transform3d`] is inserted. /// -/// ## [`Transform`] and [`GlobalTransform`] +/// ## [`Transform3d`] and [`GlobalTransform`] /// -/// [`Transform`] transforms an entity relative to its parent's reference frame, or relative to world space coordinates, +/// [`Transform3d`] transforms an entity relative to its parent's reference frame, or relative to world space coordinates, /// if it doesn't have a [`ChildOf`](bevy_ecs::hierarchy::ChildOf) component. /// -/// [`GlobalTransform`] is managed by Bevy; it is computed by successively applying the [`Transform`] of each ancestor +/// [`GlobalTransform`] is managed by Bevy; it is computed by successively applying the [`Transform3d`] of each ancestor /// entity which has a Transform. This is done automatically by Bevy-internal systems in the [`TransformSystems::Propagate`] /// system set. /// /// This system runs during [`PostUpdate`](bevy_app::PostUpdate). If you -/// update the [`Transform`] of an entity in this schedule or after, you will notice a 1 frame lag +/// update the [`Transform3d`] of an entity in this schedule or after, you will notice a 1 frame lag /// before the [`GlobalTransform`] is updated. /// /// [`TransformSystems::Propagate`]: crate::TransformSystems::Propagate @@ -125,14 +125,14 @@ impl GlobalTransform { self.0 } - /// Returns the transformation as a [`Transform`]. + /// Returns the transformation as a [`Transform3d`]. /// /// The transform is expected to be non-degenerate and without shearing, or the output /// will be invalid. #[inline] - pub fn compute_transform(&self) -> Transform { + pub fn compute_transform(&self) -> Transform3d { let (scale, rotation, translation) = self.0.to_scale_rotation_translation(); - Transform { + Transform3d { translation, rotation, scale, @@ -152,7 +152,7 @@ impl GlobalTransform { Isometry3d::new(translation, rotation) } - /// Returns the [`Transform`] `self` would have if it was a child of an entity + /// Returns the [`Transform3d`] `self` would have if it was a child of an entity /// with the `parent` [`GlobalTransform`]. /// /// This is useful if you want to "reparent" an [`Entity`](bevy_ecs::entity::Entity). @@ -185,10 +185,10 @@ impl GlobalTransform { /// The transform is expected to be non-degenerate and without shearing, or the output /// will be invalid. #[inline] - pub fn reparented_to(&self, parent: &GlobalTransform) -> Transform { + pub fn reparented_to(&self, parent: &GlobalTransform) -> Transform3d { let relative_affine = parent.affine().inverse() * self.affine(); let (scale, rotation, translation) = relative_affine.to_scale_rotation_translation(); - Transform { + Transform3d { translation, rotation, scale, @@ -297,7 +297,7 @@ impl GlobalTransform { /// Multiplies `self` with `transform` component by component, returning the /// resulting [`GlobalTransform`] #[inline] - pub fn mul_transform(&self, transform: Transform) -> Self { + pub fn mul_transform(&self, transform: Transform3d) -> Self { Self(self.0 * transform.compute_affine()) } } @@ -308,8 +308,8 @@ impl Default for GlobalTransform { } } -impl From for GlobalTransform { - fn from(transform: Transform) -> Self { +impl From for GlobalTransform { + fn from(transform: Transform3d) -> Self { Self(transform.compute_affine()) } } @@ -329,11 +329,11 @@ impl Mul for GlobalTransform { } } -impl Mul for GlobalTransform { +impl Mul for GlobalTransform { type Output = GlobalTransform; #[inline] - fn mul(self, transform: Transform) -> Self::Output { + fn mul(self, transform: Transform3d) -> Self::Output { self.mul_transform(transform) } } @@ -353,21 +353,21 @@ mod test { use bevy_math::EulerRot::XYZ; - fn transform_equal(left: GlobalTransform, right: Transform) -> bool { + fn transform_equal(left: GlobalTransform, right: Transform3d) -> bool { left.0.abs_diff_eq(right.compute_affine(), 0.01) } #[test] fn reparented_to_transform_identity() { - fn reparent_to_same(t1: GlobalTransform, t2: GlobalTransform) -> Transform { + fn reparent_to_same(t1: GlobalTransform, t2: GlobalTransform) -> Transform3d { t2.mul_transform(t1.into()).reparented_to(&t2) } - let t1 = GlobalTransform::from(Transform { + let t1 = GlobalTransform::from(Transform3d { translation: Vec3::new(1034.0, 34.0, -1324.34), rotation: Quat::from_euler(XYZ, 1.0, 0.9, 2.1), scale: Vec3::new(1.0, 1.0, 1.0), }); - let t2 = GlobalTransform::from(Transform { + let t2 = GlobalTransform::from(Transform3d { translation: Vec3::new(0.0, -54.493, 324.34), rotation: Quat::from_euler(XYZ, 1.9, 0.3, 3.0), scale: Vec3::new(1.345, 1.345, 1.345), @@ -382,12 +382,12 @@ mod test { } #[test] fn reparented_usecase() { - let t1 = GlobalTransform::from(Transform { + let t1 = GlobalTransform::from(Transform3d { translation: Vec3::new(1034.0, 34.0, -1324.34), rotation: Quat::from_euler(XYZ, 0.8, 1.9, 2.1), scale: Vec3::new(10.9, 10.9, 10.9), }); - let t2 = GlobalTransform::from(Transform { + let t2 = GlobalTransform::from(Transform3d { translation: Vec3::new(28.0, -54.493, 324.34), rotation: Quat::from_euler(XYZ, 0.0, 3.1, 0.1), scale: Vec3::new(0.9, 0.9, 0.9), diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 7873ae743c827..556adaebb205c 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -37,23 +37,23 @@ fn assert_is_normalized(message: &str, length_squared: f32) { /// Describe the position of an entity. If the entity has a parent, the position is relative /// to its parent position. /// -/// * To place or move an entity, you should set its [`Transform`]. +/// * To place or move an entity, you should set its [`Transform3d`]. /// * To get the global transform of an entity, you should get its [`GlobalTransform`]. -/// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. -/// [`GlobalTransform`] is automatically inserted whenever [`Transform`] is inserted. +/// * To be displayed, an entity must have both a [`Transform3d`] and a [`GlobalTransform`]. +/// [`GlobalTransform`] is automatically inserted whenever [`Transform3d`] is inserted. /// -/// ## [`Transform`] and [`GlobalTransform`] +/// ## [`Transform3d`] and [`GlobalTransform`] /// -/// [`Transform`] is the position of an entity relative to its parent position, or the reference +/// [`Transform3d`] is the position of an entity relative to its parent position, or the reference /// frame if it doesn't have a [`ChildOf`](bevy_ecs::hierarchy::ChildOf) component. /// /// [`GlobalTransform`] is the position of an entity relative to the reference frame. /// -/// [`GlobalTransform`] is updated from [`Transform`] in the [`TransformSystems::Propagate`] +/// [`GlobalTransform`] is updated from [`Transform3d`] in the [`TransformSystems::Propagate`] /// system set. /// /// This system runs during [`PostUpdate`](bevy_app::PostUpdate). If you -/// update the [`Transform`] of an entity during this set or after, you will notice a 1 frame lag +/// update the [`Transform3d`] of an entity during this set or after, you will notice a 1 frame lag /// before the [`GlobalTransform`] is updated. /// /// [`TransformSystems::Propagate`]: crate::TransformSystems::Propagate @@ -79,7 +79,7 @@ fn assert_is_normalized(message: &str, length_squared: f32) { all(feature = "bevy_reflect", feature = "serialize"), reflect(Serialize, Deserialize) )] -pub struct Transform { +pub struct Transform3d { /// Position of the entity. In 2d, the last value of the `Vec3` is used for z-ordering. /// /// See the [`translations`] example for usage. @@ -100,15 +100,15 @@ pub struct Transform { pub scale: Vec3, } -impl Transform { - /// An identity [`Transform`] with no translation, rotation, and a scale of 1 on all axes. - pub const IDENTITY: Self = Transform { +impl Transform3d { + /// An identity [`Transform3d`] with no translation, rotation, and a scale of 1 on all axes. + pub const IDENTITY: Self = Transform3d { translation: Vec3::ZERO, rotation: Quat::IDENTITY, scale: Vec3::ONE, }; - /// Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component + /// Creates a new [`Transform3d`] 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] @@ -122,56 +122,56 @@ impl Transform { pub fn from_matrix(world_from_local: Mat4) -> Self { let (scale, rotation, translation) = world_from_local.to_scale_rotation_translation(); - Transform { + Transform3d { translation, rotation, scale, } } - /// Creates a new [`Transform`], with `translation`. Rotation will be 0 and scale 1 on + /// Creates a new [`Transform3d`], with `translation`. Rotation will be 0 and scale 1 on /// all axes. #[inline] pub const fn from_translation(translation: Vec3) -> Self { - Transform { + Transform3d { translation, ..Self::IDENTITY } } - /// Creates a new [`Transform`], with `rotation`. Translation will be 0 and scale 1 on + /// Creates a new [`Transform3d`], with `rotation`. Translation will be 0 and scale 1 on /// all axes. #[inline] pub const fn from_rotation(rotation: Quat) -> Self { - Transform { + Transform3d { rotation, ..Self::IDENTITY } } - /// Creates a new [`Transform`], with `scale`. Translation will be 0 and rotation 0 on + /// Creates a new [`Transform3d`], with `scale`. Translation will be 0 and rotation 0 on /// all axes. #[inline] pub const fn from_scale(scale: Vec3) -> Self { - Transform { + Transform3d { scale, ..Self::IDENTITY } } - /// Creates a new [`Transform`] that is equivalent to the given [isometry]. + /// Creates a new [`Transform3d`] that is equivalent to the given [isometry]. /// /// [isometry]: Isometry3d #[inline] pub fn from_isometry(iso: Isometry3d) -> Self { - Transform { + Transform3d { translation: iso.translation.into(), rotation: iso.rotation, ..Self::IDENTITY } } - /// Returns this [`Transform`] with a new rotation so that [`Transform::forward`] + /// Returns this [`Transform3d`] with a new rotation so that [`Transform::forward`] /// points towards the `target` position and [`Transform::up`] points towards `up`. /// /// In some cases it's not possible to construct a rotation. Another axis will be picked in those cases: @@ -185,7 +185,7 @@ impl Transform { self } - /// Returns this [`Transform`] with a new rotation so that [`Transform::forward`] + /// Returns this [`Transform3d`] with a new rotation so that [`Transform::forward`] /// points in the given `direction` and [`Transform::up`] points towards `up`. /// /// In some cases it's not possible to construct a rotation. Another axis will be picked in those cases: @@ -199,7 +199,7 @@ impl Transform { self } - /// Rotates this [`Transform`] so that the `main_axis` vector, reinterpreted in local coordinates, points + /// Rotates this [`Transform3d`] so that the `main_axis` vector, reinterpreted in local coordinates, points /// in the given `main_direction`, while `secondary_axis` points towards `secondary_direction`. /// For example, if a spaceship model has its nose pointing in the X-direction in its own local coordinates /// and its dorsal fin pointing in the Y-direction, then `align(Dir3::X, v, Dir3::Y, w)` will make the spaceship's @@ -232,7 +232,7 @@ impl Transform { self } - /// Returns this [`Transform`] with a new translation. + /// Returns this [`Transform3d`] with a new translation. #[inline] #[must_use] pub const fn with_translation(mut self, translation: Vec3) -> Self { @@ -240,7 +240,7 @@ impl Transform { self } - /// Returns this [`Transform`] with a new rotation. + /// Returns this [`Transform3d`] with a new rotation. #[inline] #[must_use] pub const fn with_rotation(mut self, rotation: Quat) -> Self { @@ -248,7 +248,7 @@ impl Transform { self } - /// Returns this [`Transform`] with a new scale. + /// Returns this [`Transform3d`] with a new scale. #[inline] #[must_use] pub const fn with_scale(mut self, scale: Vec3) -> Self { @@ -327,9 +327,9 @@ impl Transform { self.local_z() } - /// Rotates this [`Transform`] by the given rotation. + /// Rotates this [`Transform3d`] by the given rotation. /// - /// If this [`Transform`] has a parent, the `rotation` is relative to the rotation of the parent. + /// If this [`Transform3d`] has a parent, the `rotation` is relative to the rotation of the parent. /// /// # Examples /// @@ -341,9 +341,9 @@ impl Transform { self.rotation = rotation * self.rotation; } - /// Rotates this [`Transform`] around the given `axis` by `angle` (in radians). + /// Rotates this [`Transform3d`] around the given `axis` by `angle` (in radians). /// - /// If this [`Transform`] has a parent, the `axis` is relative to the rotation of the parent. + /// If this [`Transform3d`] has a parent, the `axis` is relative to the rotation of the parent. /// /// # Warning /// @@ -362,39 +362,39 @@ impl Transform { self.rotate(Quat::from_axis_angle(axis.into(), angle)); } - /// Rotates this [`Transform`] around the `X` axis by `angle` (in radians). + /// Rotates this [`Transform3d`] around the `X` axis by `angle` (in radians). /// - /// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + /// If this [`Transform3d`] has a parent, the axis is relative to the rotation of the parent. #[inline] pub fn rotate_x(&mut self, angle: f32) { self.rotate(Quat::from_rotation_x(angle)); } - /// Rotates this [`Transform`] around the `Y` axis by `angle` (in radians). + /// Rotates this [`Transform3d`] around the `Y` axis by `angle` (in radians). /// - /// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + /// If this [`Transform3d`] has a parent, the axis is relative to the rotation of the parent. #[inline] pub fn rotate_y(&mut self, angle: f32) { self.rotate(Quat::from_rotation_y(angle)); } - /// Rotates this [`Transform`] around the `Z` axis by `angle` (in radians). + /// Rotates this [`Transform3d`] around the `Z` axis by `angle` (in radians). /// - /// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + /// If this [`Transform3d`] has a parent, the axis is relative to the rotation of the parent. #[inline] pub fn rotate_z(&mut self, angle: f32) { self.rotate(Quat::from_rotation_z(angle)); } - /// Rotates this [`Transform`] by the given `rotation`. + /// Rotates this [`Transform3d`] by the given `rotation`. /// - /// The `rotation` is relative to this [`Transform`]'s current rotation. + /// The `rotation` is relative to this [`Transform3d`]'s current rotation. #[inline] pub fn rotate_local(&mut self, rotation: Quat) { self.rotation *= rotation; } - /// Rotates this [`Transform`] around its local `axis` by `angle` (in radians). + /// Rotates this [`Transform3d`] around its local `axis` by `angle` (in radians). /// /// # Warning /// @@ -413,42 +413,42 @@ impl Transform { self.rotate_local(Quat::from_axis_angle(axis.into(), angle)); } - /// Rotates this [`Transform`] around its local `X` axis by `angle` (in radians). + /// Rotates this [`Transform3d`] around its local `X` axis by `angle` (in radians). #[inline] pub fn rotate_local_x(&mut self, angle: f32) { self.rotate_local(Quat::from_rotation_x(angle)); } - /// Rotates this [`Transform`] around its local `Y` axis by `angle` (in radians). + /// Rotates this [`Transform3d`] around its local `Y` axis by `angle` (in radians). #[inline] pub fn rotate_local_y(&mut self, angle: f32) { self.rotate_local(Quat::from_rotation_y(angle)); } - /// Rotates this [`Transform`] around its local `Z` axis by `angle` (in radians). + /// Rotates this [`Transform3d`] around its local `Z` axis by `angle` (in radians). #[inline] pub fn rotate_local_z(&mut self, angle: f32) { self.rotate_local(Quat::from_rotation_z(angle)); } - /// Translates this [`Transform`] around a `point` in space. + /// Translates this [`Transform3d`] around a `point` in space. /// - /// If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. + /// If this [`Transform3d`] has a parent, the `point` is relative to the [`Transform3d`] of the parent. #[inline] pub fn translate_around(&mut self, point: Vec3, rotation: Quat) { self.translation = point + rotation * (self.translation - point); } - /// Rotates this [`Transform`] around a `point` in space. + /// Rotates this [`Transform3d`] around a `point` in space. /// - /// If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. + /// If this [`Transform3d`] has a parent, the `point` is relative to the [`Transform3d`] of the parent. #[inline] pub fn rotate_around(&mut self, point: Vec3, rotation: Quat) { self.translate_around(point, rotation); self.rotate(rotation); } - /// Rotates this [`Transform`] so that [`Transform::forward`] points towards the `target` position, + /// Rotates this [`Transform3d`] so that [`Transform::forward`] points towards the `target` position, /// and [`Transform::up`] points towards `up`. /// /// In some cases it's not possible to construct a rotation. Another axis will be picked in those cases: @@ -460,7 +460,7 @@ impl Transform { self.look_to(target - self.translation, up); } - /// Rotates this [`Transform`] so that [`Transform::forward`] points in the given `direction` + /// Rotates this [`Transform3d`] so that [`Transform::forward`] points in the given `direction` /// and [`Transform::up`] points towards `up`. /// /// In some cases it's not possible to construct a rotation. Another axis will be picked in those cases: @@ -479,7 +479,7 @@ impl Transform { self.rotation = Quat::from_mat3(&Mat3::from_cols(right, up, back.into())); } - /// Rotates this [`Transform`] so that the `main_axis` vector, reinterpreted in local coordinates, points + /// Rotates this [`Transform3d`] so that the `main_axis` vector, reinterpreted in local coordinates, points /// in the given `main_direction`, while `secondary_axis` points towards `secondary_direction`. /// /// For example, if a spaceship model has its nose pointing in the X-direction in its own local coordinates @@ -561,14 +561,14 @@ impl Transform { } /// Multiplies `self` with `transform` component by component, returning the - /// resulting [`Transform`] + /// resulting [`Transform3d`] #[inline] #[must_use] - pub fn mul_transform(&self, transform: Transform) -> Self { + pub fn mul_transform(&self, transform: Transform3d) -> Self { let translation = self.transform_point(transform.translation); let rotation = self.rotation * transform.rotation; let scale = self.scale * transform.scale; - Transform { + Transform3d { translation, rotation, scale, @@ -577,11 +577,11 @@ impl Transform { /// Transforms the given `point`, applying scale, rotation and translation. /// - /// If this [`Transform`] has an ancestor entity with a [`Transform`] component, + /// If this [`Transform3d`] has an ancestor entity with a [`Transform3d`] component, /// [`Transform::transform_point`] will transform a point in local space into its /// parent transform's space. /// - /// If this [`Transform`] does not have a parent, [`Transform::transform_point`] will + /// If this [`Transform3d`] does not have a parent, [`Transform::transform_point`] will /// transform a point in local space into worldspace coordinates. /// /// If you always want to transform a point in local space to worldspace, or if you need @@ -612,7 +612,7 @@ impl Transform { } } -impl Default for Transform { +impl Default for Transform3d { fn default() -> Self { Self::IDENTITY } @@ -620,21 +620,21 @@ impl Default for Transform { /// The transform is expected to be non-degenerate and without shearing, or the output /// will be invalid. -impl From for Transform { +impl From for Transform3d { fn from(transform: GlobalTransform) -> Self { transform.compute_transform() } } -impl Mul for Transform { - type Output = Transform; +impl Mul for Transform3d { + type Output = Transform3d; - fn mul(self, transform: Transform) -> Self::Output { + fn mul(self, transform: Transform3d) -> Self::Output { self.mul_transform(transform) } } -impl Mul for Transform { +impl Mul for Transform3d { type Output = GlobalTransform; #[inline] @@ -643,7 +643,7 @@ impl Mul for Transform { } } -impl Mul for Transform { +impl Mul for Transform3d { type Output = Vec3; fn mul(self, value: Vec3) -> Self::Output { @@ -653,7 +653,7 @@ impl Mul for Transform { /// An optimization for transform propagation. This ZST marker component uses change detection to /// mark all entities of the hierarchy as "dirty" if any of their descendants have a changed -/// `Transform`. If this component is *not* marked `is_changed()`, propagation will halt. +/// `Transform3d`. If this component is *not* marked `is_changed()`, propagation will halt. #[derive(Clone, Copy, Default, PartialEq, Debug)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "bevy-support", derive(Component))] diff --git a/crates/bevy_transform/src/helper.rs b/crates/bevy_transform/src/helper.rs index d13822847fc40..b77fa223a3b86 100644 --- a/crates/bevy_transform/src/helper.rs +++ b/crates/bevy_transform/src/helper.rs @@ -8,22 +8,22 @@ use bevy_ecs::{ }; use thiserror::Error; -use crate::components::{GlobalTransform, Transform}; +use crate::components::{GlobalTransform, Transform3d}; /// System parameter for computing up-to-date [`GlobalTransform`]s. /// /// Computing an entity's [`GlobalTransform`] can be expensive so it is recommended /// you use the [`GlobalTransform`] component stored on the entity, unless you need -/// a [`GlobalTransform`] that reflects the changes made to any [`Transform`]s since +/// a [`GlobalTransform`] that reflects the changes made to any [`Transform3d`]s since /// the last time the transform propagation systems ran. #[derive(SystemParam)] pub struct TransformHelper<'w, 's> { parent_query: Query<'w, 's, &'static ChildOf>, - transform_query: Query<'w, 's, &'static Transform>, + transform_query: Query<'w, 's, &'static Transform3d>, } impl<'w, 's> TransformHelper<'w, 's> { - /// Computes the [`GlobalTransform`] of the given entity from the [`Transform`] component on it and its ancestors. + /// Computes the [`GlobalTransform`] of the given entity from the [`Transform3d`] component on it and its ancestors. pub fn compute_global_transform( &self, entity: Entity, @@ -66,8 +66,8 @@ fn map_error(err: QueryEntityError, ancestor: bool) -> ComputeGlobalTransformErr /// Error returned by [`TransformHelper::compute_global_transform`]. #[derive(Debug, Error)] pub enum ComputeGlobalTransformError { - /// The entity or one of its ancestors is missing the [`Transform`] component. - #[error("The entity {0:?} or one of its ancestors is missing the `Transform` component")] + /// The entity or one of its ancestors is missing the [`Transform3d`] component. + #[error("The entity {0:?} or one of its ancestors is missing the `Transform3d` component")] MissingTransform(Entity), /// The entity does not exist. #[error("The entity {0:?} does not exist")] @@ -88,7 +88,7 @@ mod tests { use bevy_math::{Quat, Vec3}; use crate::{ - components::{GlobalTransform, Transform}, + components::{GlobalTransform, Transform3d}, helper::TransformHelper, plugins::TransformPlugin, }; @@ -96,25 +96,25 @@ mod tests { #[test] fn match_transform_propagation_systems() { // Single transform - match_transform_propagation_systems_inner(vec![Transform::from_translation(Vec3::X) + match_transform_propagation_systems_inner(vec![Transform3d::from_translation(Vec3::X) .with_rotation(Quat::from_rotation_y(TAU / 4.)) .with_scale(Vec3::splat(2.))]); // Transform hierarchy match_transform_propagation_systems_inner(vec![ - Transform::from_translation(Vec3::X) + Transform3d::from_translation(Vec3::X) .with_rotation(Quat::from_rotation_y(TAU / 4.)) .with_scale(Vec3::splat(2.)), - Transform::from_translation(Vec3::Y) + Transform3d::from_translation(Vec3::Y) .with_rotation(Quat::from_rotation_z(TAU / 3.)) .with_scale(Vec3::splat(1.5)), - Transform::from_translation(Vec3::Z) + Transform3d::from_translation(Vec3::Z) .with_rotation(Quat::from_rotation_x(TAU / 2.)) .with_scale(Vec3::splat(0.3)), ]); } - fn match_transform_propagation_systems_inner(transforms: Vec) { + fn match_transform_propagation_systems_inner(transforms: Vec) { let mut app = App::new(); app.add_plugins(TransformPlugin); diff --git a/crates/bevy_transform/src/plugins.rs b/crates/bevy_transform/src/plugins.rs index f70e7e1f1d0f3..eb5d51dd0a90d 100644 --- a/crates/bevy_transform/src/plugins.rs +++ b/crates/bevy_transform/src/plugins.rs @@ -13,14 +13,14 @@ pub enum TransformSystems { #[deprecated(since = "0.17.0", note = "Renamed to `TransformSystems`.")] pub type TransformSystem = TransformSystems; -/// The base plugin for handling [`Transform`](crate::components::Transform) components +/// The base plugin for handling [`Transform3d`](crate::components::Transform) components #[derive(Default)] pub struct TransformPlugin; impl Plugin for TransformPlugin { fn build(&self, app: &mut App) { #[cfg(feature = "bevy_reflect")] - app.register_type::() + app.register_type::() .register_type::() .register_type::(); diff --git a/crates/bevy_transform/src/systems.rs b/crates/bevy_transform/src/systems.rs index 62038b37ed90f..685e7cdf87f46 100644 --- a/crates/bevy_transform/src/systems.rs +++ b/crates/bevy_transform/src/systems.rs @@ -1,4 +1,4 @@ -use crate::components::{GlobalTransform, Transform, TransformTreeChanged}; +use crate::components::{GlobalTransform, Transform3d, TransformTreeChanged}; use bevy_ecs::prelude::*; #[cfg(feature = "std")] pub use parallel::propagate_parent_transforms; @@ -12,14 +12,14 @@ pub use serial::propagate_parent_transforms; pub fn sync_simple_transforms( mut query: ParamSet<( Query< - (&Transform, &mut GlobalTransform), + (&Transform3d, &mut GlobalTransform), ( - Or<(Changed, Added)>, + Or<(Changed, Added)>, Without, Without, ), >, - Query<(Ref, &mut GlobalTransform), (Without, Without)>, + Query<(Ref, &mut GlobalTransform), (Without, Without)>, )>, mut orphaned: RemovedComponents, ) { @@ -46,7 +46,11 @@ pub fn sync_simple_transforms( pub fn mark_dirty_trees( changed_transforms: Query< Entity, - Or<(Changed, Changed, Added)>, + Or<( + Changed, + Changed, + Added, + )>, >, mut orphaned: RemovedComponents, mut transforms: Query<(Option<&ChildOf>, &mut TransformTreeChanged)>, @@ -90,7 +94,7 @@ mod serial { use alloc::vec::Vec; use bevy_ecs::prelude::*; - /// Update [`GlobalTransform`] component of entities based on entity hierarchy and [`Transform`] + /// Update [`GlobalTransform`] component of entities based on entity hierarchy and [`Transform3d`] /// component. /// /// Third party plugins should ensure that this is used in concert with @@ -98,12 +102,12 @@ mod serial { /// [`mark_dirty_trees`](super::mark_dirty_trees). pub fn propagate_parent_transforms( mut root_query: Query< - (Entity, &Children, Ref, &mut GlobalTransform), + (Entity, &Children, Ref, &mut GlobalTransform), Without, >, mut orphaned: RemovedComponents, transform_query: Query< - (Ref, &mut GlobalTransform, Option<&Children>), + (Ref, &mut GlobalTransform, Option<&Children>), With, >, child_query: Query<(Entity, Ref), With>, @@ -171,7 +175,7 @@ mod serial { unsafe fn propagate_recursive( parent: &GlobalTransform, transform_query: &Query< - (Ref, &mut GlobalTransform, Option<&Children>), + (Ref, &mut GlobalTransform, Option<&Children>), With, >, child_query: &Query<(Entity, Ref), With>, @@ -260,7 +264,7 @@ mod parallel { Mutex, }; - /// Update [`GlobalTransform`] component of entities based on entity hierarchy and [`Transform`] + /// Update [`GlobalTransform`] component of entities based on entity hierarchy and [`Transform3d`] /// component. /// /// Third party plugins should ensure that this is used in concert with @@ -269,7 +273,7 @@ mod parallel { pub fn propagate_parent_transforms( mut queue: Local, mut roots: Query< - (Entity, Ref, &mut GlobalTransform, &Children), + (Entity, Ref, &mut GlobalTransform, &Children), (Without, Changed), >, nodes: NodeQuery, @@ -495,7 +499,7 @@ mod parallel { ( Entity, ( - Ref<'static, Transform>, + Ref<'static, Transform3d>, Mut<'static, GlobalTransform>, Ref<'static, TransformTreeChanged>, ), @@ -568,8 +572,8 @@ mod test { ComputeTaskPool::get_or_init(TaskPool::default); let mut world = World::default(); let offset_global_transform = - |offset| GlobalTransform::from(Transform::from_xyz(offset, offset, offset)); - let offset_transform = |offset| Transform::from_xyz(offset, offset, offset); + |offset| GlobalTransform::from(Transform3d::from_xyz(offset, offset, offset)); + let offset_transform = |offset| Transform3d::from_xyz(offset, offset, offset); let mut schedule = Schedule::default(); schedule.add_systems( @@ -640,25 +644,25 @@ mod test { ); // Root entity - world.spawn(Transform::from_xyz(1.0, 0.0, 0.0)); + world.spawn(Transform3d::from_xyz(1.0, 0.0, 0.0)); let mut children = Vec::new(); world - .spawn(Transform::from_xyz(1.0, 0.0, 0.0)) + .spawn(Transform3d::from_xyz(1.0, 0.0, 0.0)) .with_children(|parent| { - children.push(parent.spawn(Transform::from_xyz(0.0, 2.0, 0.)).id()); - children.push(parent.spawn(Transform::from_xyz(0.0, 0.0, 3.)).id()); + children.push(parent.spawn(Transform3d::from_xyz(0.0, 2.0, 0.)).id()); + children.push(parent.spawn(Transform3d::from_xyz(0.0, 0.0, 3.)).id()); }); schedule.run(&mut world); assert_eq!( *world.get::(children[0]).unwrap(), - GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform::from_xyz(0.0, 2.0, 0.0) + GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform3d::from_xyz(0.0, 2.0, 0.0) ); assert_eq!( *world.get::(children[1]).unwrap(), - GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform::from_xyz(0.0, 0.0, 3.0) + GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform3d::from_xyz(0.0, 0.0, 3.0) ); } @@ -681,22 +685,22 @@ mod test { let mut commands = Commands::new(&mut queue, &world); let mut children = Vec::new(); commands - .spawn(Transform::from_xyz(1.0, 0.0, 0.0)) + .spawn(Transform3d::from_xyz(1.0, 0.0, 0.0)) .with_children(|parent| { - children.push(parent.spawn(Transform::from_xyz(0.0, 2.0, 0.0)).id()); - children.push(parent.spawn(Transform::from_xyz(0.0, 0.0, 3.0)).id()); + children.push(parent.spawn(Transform3d::from_xyz(0.0, 2.0, 0.0)).id()); + children.push(parent.spawn(Transform3d::from_xyz(0.0, 0.0, 3.0)).id()); }); queue.apply(&mut world); schedule.run(&mut world); assert_eq!( *world.get::(children[0]).unwrap(), - GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform::from_xyz(0.0, 2.0, 0.0) + GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform3d::from_xyz(0.0, 2.0, 0.0) ); assert_eq!( *world.get::(children[1]).unwrap(), - GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform::from_xyz(0.0, 0.0, 3.0) + GlobalTransform::from_xyz(1.0, 0.0, 0.0) * Transform3d::from_xyz(0.0, 0.0, 3.0) ); } @@ -720,10 +724,10 @@ mod test { let parent = { let mut command_queue = CommandQueue::default(); let mut commands = Commands::new(&mut command_queue, &world); - let parent = commands.spawn(Transform::from_xyz(1.0, 0.0, 0.0)).id(); + let parent = commands.spawn(Transform3d::from_xyz(1.0, 0.0, 0.0)).id(); commands.entity(parent).with_children(|parent| { - children.push(parent.spawn(Transform::from_xyz(0.0, 2.0, 0.0)).id()); - children.push(parent.spawn(Transform::from_xyz(0.0, 3.0, 0.0)).id()); + children.push(parent.spawn(Transform3d::from_xyz(0.0, 2.0, 0.0)).id()); + children.push(parent.spawn(Transform3d::from_xyz(0.0, 3.0, 0.0)).id()); }); command_queue.apply(&mut world); schedule.run(&mut world); @@ -802,12 +806,12 @@ mod test { let mut grandchild = Entity::from_raw_u32(1).unwrap(); let parent = app .world_mut() - .spawn(Transform::from_translation(translation)) + .spawn(Transform3d::from_translation(translation)) .with_children(|builder| { child = builder - .spawn(Transform::IDENTITY) + .spawn(Transform3d::IDENTITY) .with_children(|builder| { - grandchild = builder.spawn(Transform::IDENTITY).id(); + grandchild = builder.spawn(Transform3d::IDENTITY).id(); }) .id(); }) @@ -851,9 +855,9 @@ mod test { fn setup_world(world: &mut World) -> (Entity, Entity) { let mut grandchild = Entity::from_raw_u32(0).unwrap(); let child = world - .spawn(Transform::IDENTITY) + .spawn(Transform3d::IDENTITY) .with_children(|builder| { - grandchild = builder.spawn(Transform::IDENTITY).id(); + grandchild = builder.spawn(Transform3d::IDENTITY).id(); }) .id(); (child, grandchild) @@ -866,7 +870,7 @@ mod test { assert_eq!(temp_grandchild, grandchild); app.world_mut() - .spawn(Transform::IDENTITY) + .spawn(Transform3d::IDENTITY) .add_children(&[child]); let mut child_entity = app.world_mut().entity_mut(child); @@ -914,9 +918,9 @@ mod test { .chain(), ); - // Spawn a `Transform` entity with a local translation of `Vec3::ONE` + // Spawn a `Transform3d` entity with a local translation of `Vec3::ONE` let mut spawn_transform_bundle = - || world.spawn(Transform::from_translation(translation)).id(); + || world.spawn(Transform3d::from_translation(translation)).id(); // Spawn parent and child with identical transform bundles let parent = spawn_transform_bundle(); diff --git a/crates/bevy_transform/src/traits.rs b/crates/bevy_transform/src/traits.rs index 6770ebb9c26f6..0adf94deb6140 100644 --- a/crates/bevy_transform/src/traits.rs +++ b/crates/bevy_transform/src/traits.rs @@ -1,6 +1,6 @@ use bevy_math::{Affine3A, Isometry3d, Mat4, Vec3}; -use crate::prelude::{GlobalTransform, Transform}; +use crate::prelude::{GlobalTransform, Transform3d}; /// A trait for point transformation methods. pub trait TransformPoint { @@ -8,7 +8,7 @@ pub trait TransformPoint { fn transform_point(&self, point: impl Into) -> Vec3; } -impl TransformPoint for Transform { +impl TransformPoint for Transform3d { #[inline] fn transform_point(&self, point: impl Into) -> Vec3 { self.transform_point(point.into()) diff --git a/crates/bevy_ui/src/experimental/ghost_hierarchy.rs b/crates/bevy_ui/src/experimental/ghost_hierarchy.rs index 9134f5eebac75..4b96459251101 100644 --- a/crates/bevy_ui/src/experimental/ghost_hierarchy.rs +++ b/crates/bevy_ui/src/experimental/ghost_hierarchy.rs @@ -9,7 +9,7 @@ use bevy_reflect::prelude::*; #[cfg(feature = "ghost_nodes")] use bevy_render::view::Visibility; #[cfg(feature = "ghost_nodes")] -use bevy_transform::prelude::Transform; +use bevy_transform::prelude::Transform3d; #[cfg(feature = "ghost_nodes")] use smallvec::SmallVec; /// Marker component for entities that should be ignored within UI hierarchies. diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index b38241a95a942..573d3fc6456f4 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -14,7 +14,7 @@ use bevy_ecs::{ }; use bevy_math::Vec2; use bevy_sprite::BorderRect; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; use thiserror::Error; use tracing::warn; use ui_surface::UiSurface; @@ -83,7 +83,7 @@ pub fn ui_layout_system( ui_children: UiChildren, mut node_transform_query: Query<( &mut ComputedNode, - &mut Transform, + &mut Transform3d, &Node, Option<&LayoutConfig>, Option<&BorderRadius>, @@ -192,7 +192,7 @@ with UI components as a child of an entity without UI components, your UI layout target_size: Vec2, node_transform_query: &mut Query<( &mut ComputedNode, - &mut Transform, + &mut Transform3d, &Node, Option<&LayoutConfig>, Option<&BorderRadius>, diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index 4592b091d9ce6..9f7c776f7d49d 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -10,7 +10,7 @@ use bevy_render::{ view::VisibilityClass, }; use bevy_sprite::BorderRect; -use bevy_transform::components::Transform; +use bevy_transform::components::Transform3d; use bevy_utils::once; use bevy_window::{PrimaryWindow, WindowRef}; use core::{f32, num::NonZero}; @@ -329,7 +329,7 @@ impl From for ScrollPosition { BorderRadius, FocusPolicy, ScrollPosition, - Transform, + Transform3d, Visibility, VisibilityClass, ZIndex diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 785040c1e9057..c791ad9a1d67f 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -53,7 +53,7 @@ impl Default for TextNodeFlags { /// The string in this component is the first 'text span' in a hierarchy of text spans that are collected into /// a [`ComputedTextBlock`]. See [`TextSpan`](bevy_text::TextSpan) for the component used by children of entities with [`Text`]. /// -/// Note that [`Transform`](bevy_transform::components::Transform) on this entity is managed automatically by the UI layout system. +/// Note that [`Transform3d`](bevy_transform::components::Transform) on this entity is managed automatically by the UI layout system. /// /// /// ``` diff --git a/errors/B0001.md b/errors/B0001.md index 16486cea771e4..2b08fcb883533 100644 --- a/errors/B0001.md +++ b/errors/B0001.md @@ -14,8 +14,8 @@ struct Player; struct Enemy; fn move_enemies_to_player( - mut enemies: Query<&mut Transform, With>, - player: Query<&Transform, With>, + mut enemies: Query<&mut Transform3d, With>, + player: Query<&Transform3d, With>, ) { // ... } @@ -28,7 +28,7 @@ fn main() { } ``` -This will panic, as it's not possible to have both a mutable and an immutable query on `Transform` at the same time. +This will panic, as it's not possible to have both a mutable and an immutable query on `Transform3d` at the same time. You have two solutions: @@ -46,8 +46,8 @@ struct Player; struct Enemy; fn move_enemies_to_player( - mut enemies: Query<&mut Transform, With>, - player: Query<&Transform, (With, Without)>, + mut enemies: Query<&mut Transform3d, With>, + player: Query<&Transform3d, (With, Without)>, ) { // ... } @@ -75,8 +75,8 @@ struct Enemy; fn move_enemies_to_player( mut transforms: ParamSet<( - Query<&mut Transform, With>, - Query<&Transform, With>, + Query<&mut Transform3d, With>, + Query<&Transform3d, With>, )>, ) { // ... diff --git a/errors/B0004.md b/errors/B0004.md index 1f43f5b16357e..816b63217890e 100644 --- a/errors/B0004.md +++ b/errors/B0004.md @@ -29,20 +29,20 @@ fn setup_cube( mut materials: ResMut>, ) { commands - .spawn(Transform::default()) + .spawn(Transform3d::default()) .with_children(|parent| { // cube parent.spawn(( Mesh3d(meshes.add(Cuboid::default())), MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))), - Transform::from_xyz(0.0, 0.5, 0.0), + Transform3d::from_xyz(0.0, 0.5, 0.0), )); }); // camera commands.spawn(( Camera3d::default(), - Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + Transform3d::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), )); } @@ -72,20 +72,20 @@ fn setup_cube( mut materials: ResMut>, ) { commands - .spawn((Transform::default(), Visibility::default())) + .spawn((Transform3d::default(), Visibility::default())) .with_children(|parent| { // cube parent.spawn(( Mesh3d(meshes.add(Cuboid::default())), MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))), - Transform::from_xyz(0.0, 0.5, 0.0), + Transform3d::from_xyz(0.0, 0.5, 0.0), )); }); // camera commands.spawn(( Camera3d::default(), - Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + Transform3d::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), )); } @@ -98,7 +98,7 @@ fn main() { ``` A similar problem occurs when the [`GlobalTransform`] component is missing. -However, it will be automatically inserted whenever `Transform` is +However, it will be automatically inserted whenever `Transform3d` is inserted, as it is a required component. You will most likely encounter this warning when loading a scene diff --git a/errors/B0005.md b/errors/B0005.md index 7fecfd11a1b38..ebc88888322c2 100644 --- a/errors/B0005.md +++ b/errors/B0005.md @@ -4,6 +4,6 @@ A runtime warning. Separate font atlases are created for each font and font size. This is expensive, and the memory is never reclaimed when e.g. interpolating `TextFont::font_size` or `UiScale::scale`. -If you need to smoothly scale font size, use `Transform::scale`. +If you need to smoothly scale font size, use `Transform3d::scale`. You can disable this warning by setting `TextSettings::allow_dynamic_font_size` to `true` or raise the limit by setting `TextSettings::soft_max_font_atlases`. diff --git a/examples/2d/2d_shapes.rs b/examples/2d/2d_shapes.rs index f69e138364190..42e78b14d4862 100644 --- a/examples/2d/2d_shapes.rs +++ b/examples/2d/2d_shapes.rs @@ -64,7 +64,7 @@ fn setup( commands.spawn(( Mesh2d(shape), MeshMaterial2d(materials.add(color)), - Transform::from_xyz( + Transform3d::from_xyz( // Distribute shapes from -X_EXTENT/2 to +X_EXTENT/2. -X_EXTENT / 2. + i as f32 / (num_shapes - 1) as f32 * X_EXTENT, 0.0, diff --git a/examples/2d/2d_viewport_to_world.rs b/examples/2d/2d_viewport_to_world.rs index ce611bd4e9c50..af7c13073c839 100644 --- a/examples/2d/2d_viewport_to_world.rs +++ b/examples/2d/2d_viewport_to_world.rs @@ -53,7 +53,7 @@ fn draw_cursor( } fn controls( - mut camera_query: Query<(&mut Camera, &mut Transform, &mut Projection)>, + mut camera_query: Query<(&mut Camera, &mut Transform3d, &mut Projection)>, window: Query<&Window>, input: Res>, time: Res>, @@ -183,6 +183,6 @@ fn setup( commands.spawn(( Mesh2d(meshes.add(Rectangle::new(50000.0, 50000.0))), MeshMaterial2d(materials.add(Color::linear_rgb(0.01, 0.01, 0.01))), - Transform::from_translation(Vec3::new(0.0, 0.0, -200.0)), + Transform3d::from_translation(Vec3::new(0.0, 0.0, -200.0)), )); } diff --git a/examples/2d/bloom_2d.rs b/examples/2d/bloom_2d.rs index 9d9be1e5c7f10..0a7ba11141b97 100644 --- a/examples/2d/bloom_2d.rs +++ b/examples/2d/bloom_2d.rs @@ -46,7 +46,7 @@ fn setup( Mesh2d(meshes.add(Circle::new(100.))), // 4. Put something bright in a dark environment to see the effect MeshMaterial2d(materials.add(Color::srgb(7.5, 0.0, 7.5))), - Transform::from_translation(Vec3::new(-200., 0., 0.)), + Transform3d::from_translation(Vec3::new(-200., 0., 0.)), )); // Hexagon mesh @@ -54,7 +54,7 @@ fn setup( Mesh2d(meshes.add(RegularPolygon::new(100., 6))), // 4. Put something bright in a dark environment to see the effect MeshMaterial2d(materials.add(Color::srgb(6.25, 9.4, 9.1))), - Transform::from_translation(Vec3::new(200., 0., 0.)), + Transform3d::from_translation(Vec3::new(200., 0., 0.)), )); // UI diff --git a/examples/2d/custom_gltf_vertex_attribute.rs b/examples/2d/custom_gltf_vertex_attribute.rs index 0742e3616fe04..d073406c58d00 100644 --- a/examples/2d/custom_gltf_vertex_attribute.rs +++ b/examples/2d/custom_gltf_vertex_attribute.rs @@ -60,7 +60,7 @@ fn setup( commands.spawn(( Mesh2d(mesh), MeshMaterial2d(materials.add(CustomMaterial {})), - Transform::from_scale(150.0 * Vec3::ONE), + Transform3d::from_scale(150.0 * Vec3::ONE), )); commands.spawn(Camera2d); diff --git a/examples/2d/mesh2d.rs b/examples/2d/mesh2d.rs index 2608b45916d23..f882924c054b9 100644 --- a/examples/2d/mesh2d.rs +++ b/examples/2d/mesh2d.rs @@ -19,6 +19,6 @@ fn setup( commands.spawn(( Mesh2d(meshes.add(Rectangle::default())), MeshMaterial2d(materials.add(Color::from(PURPLE))), - Transform::default().with_scale(Vec3::splat(128.)), + Transform3d::default().with_scale(Vec3::splat(128.)), )); } diff --git a/examples/2d/mesh2d_alpha_mode.rs b/examples/2d/mesh2d_alpha_mode.rs index 60bb6ef3a6147..be50f31870ae9 100644 --- a/examples/2d/mesh2d_alpha_mode.rs +++ b/examples/2d/mesh2d_alpha_mode.rs @@ -36,7 +36,7 @@ fn setup( texture: Some(texture_handle.clone()), ..default() })), - Transform::from_xyz(-400.0, 0.0, 0.0), + Transform3d::from_xyz(-400.0, 0.0, 0.0), )); commands.spawn(( Mesh2d(mesh_handle.clone()), @@ -46,7 +46,7 @@ fn setup( texture: Some(texture_handle.clone()), ..default() })), - Transform::from_xyz(-300.0, 0.0, 1.0), + Transform3d::from_xyz(-300.0, 0.0, 1.0), )); commands.spawn(( Mesh2d(mesh_handle.clone()), @@ -56,7 +56,7 @@ fn setup( texture: Some(texture_handle.clone()), ..default() })), - Transform::from_xyz(-200.0, 0.0, -1.0), + Transform3d::from_xyz(-200.0, 0.0, -1.0), )); // Test the interaction between opaque/mask and transparent meshes @@ -72,7 +72,7 @@ fn setup( texture: Some(texture_handle.clone()), ..default() })), - Transform::from_xyz(200.0, 0.0, 0.0), + Transform3d::from_xyz(200.0, 0.0, 0.0), )); commands.spawn(( Mesh2d(mesh_handle.clone()), @@ -82,7 +82,7 @@ fn setup( texture: Some(texture_handle.clone()), ..default() })), - Transform::from_xyz(300.0, 0.0, 1.0), + Transform3d::from_xyz(300.0, 0.0, 1.0), )); commands.spawn(( Mesh2d(mesh_handle.clone()), @@ -92,6 +92,6 @@ fn setup( texture: Some(texture_handle), ..default() })), - Transform::from_xyz(400.0, 0.0, -1.0), + Transform3d::from_xyz(400.0, 0.0, -1.0), )); } diff --git a/examples/2d/mesh2d_arcs.rs b/examples/2d/mesh2d_arcs.rs index db66b784acd54..6a8ac440b1fd3 100644 --- a/examples/2d/mesh2d_arcs.rs +++ b/examples/2d/mesh2d_arcs.rs @@ -67,7 +67,7 @@ fn setup( commands.spawn(( Mesh2d(meshes.add(sector_mesh)), MeshMaterial2d(material.clone()), - Transform { + Transform3d { translation: Vec3::new(SPACING_X * i as f32 - OFFSET_X, 50.0, 0.0), rotation: Quat::from_rotation_z(sector_angle), ..default() @@ -91,7 +91,7 @@ fn setup( commands.spawn(( Mesh2d(meshes.add(segment_mesh)), MeshMaterial2d(material.clone()), - Transform { + Transform3d { translation: Vec3::new(SPACING_X * i as f32 - OFFSET_X, -50.0, 0.0), rotation: Quat::from_rotation_z(segment_angle), ..default() diff --git a/examples/2d/mesh2d_repeated_texture.rs b/examples/2d/mesh2d_repeated_texture.rs index 096a1a5f99d3e..dc26a08693ee2 100644 --- a/examples/2d/mesh2d_repeated_texture.rs +++ b/examples/2d/mesh2d_repeated_texture.rs @@ -54,10 +54,10 @@ fn setup( texture: Some(image_with_default_sampler.clone()), ..default() })), - Transform::from_translation(Vec3::ZERO), + Transform3d::from_translation(Vec3::ZERO), children![( Text2d::new("Control"), - Transform::from_xyz(0., LABEL_OFFSET, 0.), + Transform3d::from_xyz(0., LABEL_OFFSET, 0.), )], )); @@ -71,10 +71,10 @@ fn setup( uv_transform: Affine2::from_scale(Vec2::new(2., 3.)), ..default() })), - Transform::from_xyz(-RECTANGLE_OFFSET, 0.0, 0.0), + Transform3d::from_xyz(-RECTANGLE_OFFSET, 0.0, 0.0), children![( Text2d::new("Repeat On"), - Transform::from_xyz(0., LABEL_OFFSET, 0.), + Transform3d::from_xyz(0., LABEL_OFFSET, 0.), )], )); @@ -92,16 +92,16 @@ fn setup( uv_transform: Affine2::from_scale(Vec2::new(2., 3.)), ..default() })), - Transform::from_xyz(RECTANGLE_OFFSET, 0.0, 0.0), + Transform3d::from_xyz(RECTANGLE_OFFSET, 0.0, 0.0), children![( Text2d::new("Repeat Off"), - Transform::from_xyz(0., LABEL_OFFSET, 0.), + Transform3d::from_xyz(0., LABEL_OFFSET, 0.), )], )); // camera commands.spawn(( Camera2d, - Transform::default().looking_at(Vec3::ZERO, Vec3::Y), + Transform3d::default().looking_at(Vec3::ZERO, Vec3::Y), )); } diff --git a/examples/2d/mesh2d_vertex_color_texture.rs b/examples/2d/mesh2d_vertex_color_texture.rs index bd6e8199ffb6d..cf808dcea1f75 100644 --- a/examples/2d/mesh2d_vertex_color_texture.rs +++ b/examples/2d/mesh2d_vertex_color_texture.rs @@ -38,13 +38,13 @@ fn setup( commands.spawn(( Mesh2d(mesh_handle.clone()), MeshMaterial2d(materials.add(ColorMaterial::default())), - Transform::from_translation(Vec3::new(-96., 0., 0.)).with_scale(Vec3::splat(128.)), + Transform3d::from_translation(Vec3::new(-96., 0., 0.)).with_scale(Vec3::splat(128.)), )); // Spawning the quad with vertex colors and a texture results in tinting commands.spawn(( Mesh2d(mesh_handle), MeshMaterial2d(materials.add(texture_handle)), - Transform::from_translation(Vec3::new(96., 0., 0.)).with_scale(Vec3::splat(128.)), + Transform3d::from_translation(Vec3::new(96., 0., 0.)).with_scale(Vec3::splat(128.)), )); } diff --git a/examples/2d/move_sprite.rs b/examples/2d/move_sprite.rs index d84ccadc16123..80887fea9beba 100644 --- a/examples/2d/move_sprite.rs +++ b/examples/2d/move_sprite.rs @@ -21,14 +21,17 @@ fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(( Sprite::from_image(asset_server.load("branding/icon.png")), - Transform::from_xyz(0., 0., 0.), + Transform3d::from_xyz(0., 0., 0.), Direction::Right, )); } /// The sprite is animated by changing its translation depending on the time that has passed since /// the last frame. -fn sprite_movement(time: Res