Skip to content

2d Transforms #19389

New issue

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

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

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion assets/scenes/load_scene_example.scn.ron
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_animation/src/animatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_animation/src/animation_curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//!
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_audio/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_audio/src/sinks.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/core_2d/camera_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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;
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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")))]
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_gizmos/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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()),
)
}
4 changes: 2 additions & 2 deletions crates/bevy_gizmos/src/retained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<GizmoAsset>,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_gizmos/src/rounded_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_gltf/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -108,7 +108,7 @@ pub struct GltfNode {
/// Skin of the node.
pub skin: Option<Handle<GltfSkin>>,
/// 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,
Expand All @@ -122,7 +122,7 @@ impl GltfNode {
node: &gltf::Node,
children: Vec<Handle<GltfNode>>,
mesh: Option<Handle<GltfMesh>>,
transform: bevy_transform::prelude::Transform,
transform: bevy_transform::prelude::Transform3d,
skin: Option<Handle<GltfSkin>>,
extras: Option<GltfExtras>,
) -> Self {
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_gltf/src/loader/gltf_ext/scene.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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),
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_gltf/src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Vec3> = tr.map(Vec3::from).collect();
if keyframe_timestamps.len() == 1 {
Some(VariableCurve::new(AnimatableCurve::new(
Expand Down Expand Up @@ -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<Quat> =
rots.into_f32().map(Quat::from_array).collect();
if keyframe_timestamps.len() == 1 {
Expand Down Expand Up @@ -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<Vec3> = scale.map(Vec3::from).collect();
if keyframe_timestamps.len() == 1 {
Some(VariableCurve::new(AnimatableCurve::new(
Expand Down Expand Up @@ -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(
Expand All @@ -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")]
Expand Down Expand Up @@ -1292,7 +1292,7 @@ fn load_node(
node_index_to_entity_map: &mut HashMap<usize, Entity>,
entity_to_skin_index_map: &mut EntityHashMap<usize>,
active_camera_found: &mut bool,
parent_transform: &Transform,
parent_transform: &Transform3d,
#[cfg(feature = "bevy_animation")] animation_roots: &HashSet<usize>,
#[cfg(feature = "bevy_animation")] mut animation_context: Option<AnimationContext>,
document: &Document,
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_mesh/src/mesh.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy_transform::components::Transform;
use bevy_transform::components::Transform3d;
pub use wgpu_types::PrimitiveTopology;

use super::{
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -1228,7 +1228,7 @@ impl Mesh {
}
}

impl core::ops::Mul<Mesh> for Transform {
impl core::ops::Mul<Mesh> for Transform3d {
type Output = Mesh;

fn mul(self, rhs: Mesh) -> Self::Output {
Expand All @@ -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]
Expand Down Expand Up @@ -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)) =
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/decal/clustered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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::<LightVisibilityClass>)]
pub struct ClusteredDecal {
/// The image that the clustered decal projects.
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/light/directional_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use super::*;
CascadesFrusta,
CascadeShadowConfig,
CascadesVisibleEntities,
Transform,
Transform3d,
Visibility,
VisibilityClass
)]
Expand Down
Loading
Loading