From debeb15504dc077453232f9bd453eb4540af9640 Mon Sep 17 00:00:00 2001 From: makspll Date: Mon, 4 Jul 2022 13:52:26 +0100 Subject: [PATCH 1/8] implement reflection for more glam types --- crates/bevy_reflect/src/impls/glam.rs | 85 +++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/crates/bevy_reflect/src/impls/glam.rs b/crates/bevy_reflect/src/impls/glam.rs index 2310e640eded1..eb48b16961b21 100644 --- a/crates/bevy_reflect/src/impls/glam.rs +++ b/crates/bevy_reflect/src/impls/glam.rs @@ -88,6 +88,39 @@ impl_reflect_struct!( } ); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Default)] + struct BVec2 { + x: bool, + y: bool, + } +); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Default)] + struct BVec3 { + x: bool, + y: bool, + z: bool, + } +); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Default)] + struct BVec3A {} +); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Default)] + struct BVec4 { + x: bool, + y: bool, + z: bool, + w: bool, + } +); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Default)] + struct BVec4A {} +); + impl_reflect_struct!( #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] struct DVec2 { @@ -113,6 +146,13 @@ impl_reflect_struct!( } ); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] + struct Mat2 { + x_axis: Vec2, + y_axis: Vec2, + } +); impl_reflect_struct!( #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] struct Mat3 { @@ -121,6 +161,14 @@ impl_reflect_struct!( z_axis: Vec3, } ); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] + struct Mat3A { + x_axis: Vec3A, + y_axis: Vec3A, + z_axis: Vec3A, + } +); impl_reflect_struct!( #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] struct Mat4 { @@ -131,6 +179,13 @@ impl_reflect_struct!( } ); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] + struct DMat2 { + x_axis: DVec2, + y_axis: DVec2, + } +); impl_reflect_struct!( #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] struct DMat3 { @@ -149,6 +204,36 @@ impl_reflect_struct!( } ); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] + struct Affine2 { + matrix2: Mat2, + translation: Vec2, + } +); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] + struct Affine3A { + matrix3: Mat3A, + translation: Vec3A, + } +); + +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] + struct DAffine2 { + matrix2: DMat2, + translation: DVec2, + } +); +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] + struct DAffine3 { + matrix3: DMat3, + translation: DVec3, + } +); + // Quat fields are read-only (as of now), and reflection is currently missing // mechanisms for read-only fields. I doubt those mechanisms would be added, // so for now quaternions will remain as values. They are represented identically From 3b3dad241d0824198ca1b70da3688cd1afb3613b Mon Sep 17 00:00:00 2001 From: makspll Date: Mon, 4 Jul 2022 14:11:26 +0100 Subject: [PATCH 2/8] implement `Reflect` for EulerRot --- crates/bevy_reflect/src/impls/glam.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/bevy_reflect/src/impls/glam.rs b/crates/bevy_reflect/src/impls/glam.rs index eb48b16961b21..b13b85aef1f98 100644 --- a/crates/bevy_reflect/src/impls/glam.rs +++ b/crates/bevy_reflect/src/impls/glam.rs @@ -243,3 +243,5 @@ impl_reflect_value!(DQuat(Debug, PartialEq, Serialize, Deserialize, Default)); impl_from_reflect_value!(Quat); impl_from_reflect_value!(DQuat); + +impl_reflect_value!(EulerRot(Debug, Default)); From 164e2c3ebdc5464b6860ea4ebd76447ece215a66 Mon Sep 17 00:00:00 2001 From: makspll Date: Mon, 4 Jul 2022 14:44:56 +0100 Subject: [PATCH 3/8] change reflect_struct to reflect_value for BVec3/4A --- crates/bevy_reflect/src/impls/glam.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/bevy_reflect/src/impls/glam.rs b/crates/bevy_reflect/src/impls/glam.rs index b13b85aef1f98..03b855ab4f27b 100644 --- a/crates/bevy_reflect/src/impls/glam.rs +++ b/crates/bevy_reflect/src/impls/glam.rs @@ -103,10 +103,6 @@ impl_reflect_struct!( z: bool, } ); -impl_reflect_struct!( - #[reflect(Debug, PartialEq, Default)] - struct BVec3A {} -); impl_reflect_struct!( #[reflect(Debug, PartialEq, Default)] struct BVec4 { @@ -116,10 +112,6 @@ impl_reflect_struct!( w: bool, } ); -impl_reflect_struct!( - #[reflect(Debug, PartialEq, Default)] - struct BVec4A {} -); impl_reflect_struct!( #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] @@ -245,3 +237,6 @@ impl_from_reflect_value!(Quat); impl_from_reflect_value!(DQuat); impl_reflect_value!(EulerRot(Debug, Default)); + +impl_reflect_value!(BVec3A(Debug, PartialEq, Default)); +impl_reflect_value!(BVec4A(Debug, PartialEq, Default)); \ No newline at end of file From 892b9a655f58ab0979e1c6df6bac102e2f0fb398 Mon Sep 17 00:00:00 2001 From: makspll Date: Mon, 4 Jul 2022 15:14:34 +0100 Subject: [PATCH 4/8] fix formatting --- crates/bevy_reflect/src/impls/glam.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_reflect/src/impls/glam.rs b/crates/bevy_reflect/src/impls/glam.rs index 03b855ab4f27b..ee3dc473c82e6 100644 --- a/crates/bevy_reflect/src/impls/glam.rs +++ b/crates/bevy_reflect/src/impls/glam.rs @@ -239,4 +239,4 @@ impl_from_reflect_value!(DQuat); impl_reflect_value!(EulerRot(Debug, Default)); impl_reflect_value!(BVec3A(Debug, PartialEq, Default)); -impl_reflect_value!(BVec4A(Debug, PartialEq, Default)); \ No newline at end of file +impl_reflect_value!(BVec4A(Debug, PartialEq, Default)); From cc08206e5147e6479aab102f644b418bfca3c3c9 Mon Sep 17 00:00:00 2001 From: Maksymilian Mozolewski Date: Tue, 5 Jul 2022 12:41:39 +0100 Subject: [PATCH 5/8] BVec3/4A behind glam supported simd feature flags --- crates/bevy_reflect/src/impls/glam.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/bevy_reflect/src/impls/glam.rs b/crates/bevy_reflect/src/impls/glam.rs index ee3dc473c82e6..392f93bf29c54 100644 --- a/crates/bevy_reflect/src/impls/glam.rs +++ b/crates/bevy_reflect/src/impls/glam.rs @@ -238,5 +238,10 @@ impl_from_reflect_value!(DQuat); impl_reflect_value!(EulerRot(Debug, Default)); + +// Wasm type aliases these to the non simd versions when there is no support +// ideally it shouldn't do that and there's an issue on glam for this +#[cfg(any(target_feature = "sse2", target_feature = "simd128"))] impl_reflect_value!(BVec3A(Debug, PartialEq, Default)); +#[cfg(any(target_feature = "sse2", target_feature = "simd128"))] impl_reflect_value!(BVec4A(Debug, PartialEq, Default)); From 0ccf1348d74597d3de3a75a4fd6997cad645b6ed Mon Sep 17 00:00:00 2001 From: makspll Date: Tue, 5 Jul 2022 12:44:42 +0100 Subject: [PATCH 6/8] formatting fixes --- crates/bevy_reflect/src/impls/glam.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/bevy_reflect/src/impls/glam.rs b/crates/bevy_reflect/src/impls/glam.rs index 392f93bf29c54..bc0228498fede 100644 --- a/crates/bevy_reflect/src/impls/glam.rs +++ b/crates/bevy_reflect/src/impls/glam.rs @@ -238,7 +238,6 @@ impl_from_reflect_value!(DQuat); impl_reflect_value!(EulerRot(Debug, Default)); - // Wasm type aliases these to the non simd versions when there is no support // ideally it shouldn't do that and there's an issue on glam for this #[cfg(any(target_feature = "sse2", target_feature = "simd128"))] From f7e71f8dbb4204a743307b4d9869f33c9cd6faf1 Mon Sep 17 00:00:00 2001 From: makspll Date: Tue, 5 Jul 2022 12:44:48 +0100 Subject: [PATCH 7/8] typo --- crates/bevy_reflect/src/impls/glam.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_reflect/src/impls/glam.rs b/crates/bevy_reflect/src/impls/glam.rs index bc0228498fede..f375935f5a91f 100644 --- a/crates/bevy_reflect/src/impls/glam.rs +++ b/crates/bevy_reflect/src/impls/glam.rs @@ -238,7 +238,7 @@ impl_from_reflect_value!(DQuat); impl_reflect_value!(EulerRot(Debug, Default)); -// Wasm type aliases these to the non simd versions when there is no support +// glam type aliases these to the non simd versions when there is no support (this breaks wasm builds for example) // ideally it shouldn't do that and there's an issue on glam for this #[cfg(any(target_feature = "sse2", target_feature = "simd128"))] impl_reflect_value!(BVec3A(Debug, PartialEq, Default)); From d47efcc74973c6b1dd280b90be1d046956b61509 Mon Sep 17 00:00:00 2001 From: Maksymilian Mozolewski Date: Tue, 5 Jul 2022 12:59:49 +0100 Subject: [PATCH 8/8] Update crates/bevy_reflect/src/impls/glam.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François --- crates/bevy_reflect/src/impls/glam.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_reflect/src/impls/glam.rs b/crates/bevy_reflect/src/impls/glam.rs index f375935f5a91f..c84fcbffaaf27 100644 --- a/crates/bevy_reflect/src/impls/glam.rs +++ b/crates/bevy_reflect/src/impls/glam.rs @@ -240,6 +240,7 @@ impl_reflect_value!(EulerRot(Debug, Default)); // glam type aliases these to the non simd versions when there is no support (this breaks wasm builds for example) // ideally it shouldn't do that and there's an issue on glam for this +// https://github.com/bitshifter/glam-rs/issues/306 #[cfg(any(target_feature = "sse2", target_feature = "simd128"))] impl_reflect_value!(BVec3A(Debug, PartialEq, Default)); #[cfg(any(target_feature = "sse2", target_feature = "simd128"))]