From 8c279c5e0bdba3c109a486b488ec6e7e12554cba Mon Sep 17 00:00:00 2001 From: Torstein Grindvik Date: Thu, 30 May 2024 17:14:24 +0200 Subject: [PATCH] GlobalTransform included Signed-off-by: Torstein Grindvik --- crates/bevy_transform/src/commands.rs | 3 +- .../src/components/global_transform.rs | 10 +++++-- crates/bevy_transform/src/components/mod.rs | 2 -- .../src/components/transform.rs | 28 ++++++++----------- crates/bevy_transform/src/lib.rs | 9 ++---- crates/bevy_transform/src/traits.rs | 1 - 6 files changed, 23 insertions(+), 30 deletions(-) diff --git a/crates/bevy_transform/src/commands.rs b/crates/bevy_transform/src/commands.rs index 8cbad487ba5e9..ec0ef0bc2e4bb 100644 --- a/crates/bevy_transform/src/commands.rs +++ b/crates/bevy_transform/src/commands.rs @@ -1,11 +1,10 @@ //! Extension to [`EntityCommands`] to modify `bevy_hierarchy` hierarchies //! while preserving [`GlobalTransform`]. +use crate::prelude::{GlobalTransform, Transform}; use bevy_ecs::{prelude::Entity, system::EntityCommands, world::Command, world::World}; use bevy_hierarchy::{PushChild, RemoveParent}; -use crate::{GlobalTransform, Transform}; - /// Command similar to [`PushChild`], but updating the child transform to keep /// it at the same [`GlobalTransform`]. /// diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index e34f989ba9d18..050af0274a915 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -2,8 +2,10 @@ use std::ops::Mul; use super::Transform; +#[cfg(feature = "bevy-support")] use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_math::{Affine3A, Dir3, Mat4, Quat, Vec3, Vec3A}; +#[cfg(feature = "bevy-support")] use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// Describe the position of an entity relative to the reference frame. @@ -34,9 +36,13 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// - [`transform`] /// /// [`transform`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/transform.rs -#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect)] +#[derive(Debug, PartialEq, Clone, Copy)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] -#[reflect(Component, Default, PartialEq)] +#[cfg_attr( + feature = "bevy-support", + derive(Component, Reflect), + reflect(Component, Default, PartialEq) +)] pub struct GlobalTransform(Affine3A); macro_rules! impl_local_axis { diff --git a/crates/bevy_transform/src/components/mod.rs b/crates/bevy_transform/src/components/mod.rs index 5422f3f18be59..10d3f72e3a463 100644 --- a/crates/bevy_transform/src/components/mod.rs +++ b/crates/bevy_transform/src/components/mod.rs @@ -1,7 +1,5 @@ -#[cfg(feature = "bevy-support")] mod global_transform; mod transform; -#[cfg(feature = "bevy-support")] pub use global_transform::*; pub use transform::*; diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index c6e6f39d2a7cc..28240c783cddf 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -1,6 +1,5 @@ use std::ops::Mul; -#[cfg(feature = "bevy-support")] use super::GlobalTransform; #[cfg(feature = "bevy-support")] use bevy_ecs::{component::Component, prelude::ReflectComponent}; @@ -551,24 +550,19 @@ impl Mul for Transform { } } -#[cfg(feature = "bevy-support")] -mod bevy_support { - use super::*; - - /// The transform is expected to be non-degenerate and without shearing, or the output - /// will be invalid. - impl From for Transform { - fn from(transform: GlobalTransform) -> Self { - transform.compute_transform() - } +/// The transform is expected to be non-degenerate and without shearing, or the output +/// will be invalid. +impl From for Transform { + fn from(transform: GlobalTransform) -> Self { + transform.compute_transform() } +} - impl Mul for Transform { - type Output = GlobalTransform; +impl Mul for Transform { + type Output = GlobalTransform; - #[inline] - fn mul(self, global_transform: GlobalTransform) -> Self::Output { - GlobalTransform::from(self) * global_transform - } + #[inline] + fn mul(self, global_transform: GlobalTransform) -> Self::Output { + GlobalTransform::from(self) * global_transform } } diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index 83a7956b7a303..ca8b07737bb20 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -33,15 +33,12 @@ pub mod systems; #[doc(hidden)] pub mod prelude { #[doc(hidden)] - pub use crate::components::Transform; + pub use crate::components::*; #[cfg(feature = "bevy-support")] #[doc(hidden)] pub use crate::{ - bundles::TransformBundle, commands::BuildChildrenTransformExt, components::*, - helper::TransformHelper, plugins::TransformPlugin, traits::TransformPoint, + bundles::TransformBundle, commands::BuildChildrenTransformExt, helper::TransformHelper, + plugins::TransformPlugin, traits::TransformPoint, }; } - -#[cfg(feature = "bevy-support")] -use prelude::{GlobalTransform, Transform}; diff --git a/crates/bevy_transform/src/traits.rs b/crates/bevy_transform/src/traits.rs index 320d5f5d7b6ec..f0984272abc9e 100644 --- a/crates/bevy_transform/src/traits.rs +++ b/crates/bevy_transform/src/traits.rs @@ -15,7 +15,6 @@ impl TransformPoint for Transform { } } -#[cfg(feature = "bevy-support")] impl TransformPoint for GlobalTransform { #[inline] fn transform_point(&self, point: impl Into) -> Vec3 {