implement reflection for more glam types (#5194)
# Objective - To implement `Reflect` for more glam types. ## Solution insert `impl_reflect_struct` invocations for more glam types. I am not sure about the boolean vectors, since none of them implement `Serde::Serialize/Deserialize`, and the SIMD versions don't have public fields. I do still think implementing reflection is useful for BVec's since then they can be incorporated into `Reflect`'ed components and set dynamically even if as a whole + it's more consistent. ## Changelog Implemented `Reflect` for the following types - BVec2 - BVec3 - **BVec3A** (on simd supported platforms only) - BVec4 - **BVec4A** (on simd supported platforms only) - Mat2 - Mat3A - DMat2 - Affine2 - Affine3A - DAffine2 - DAffine3 - EulerRot
This commit is contained in:
		
							parent
							
								
									5b5013d540
								
							
						
					
					
						commit
						61e5bfb2ed
					
				| @ -88,6 +88,31 @@ 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 BVec4 { | ||||
|         x: bool, | ||||
|         y: bool, | ||||
|         z: bool, | ||||
|         w: bool, | ||||
|     } | ||||
| ); | ||||
| 
 | ||||
| impl_reflect_struct!( | ||||
|     #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] | ||||
|     struct DVec2 { | ||||
| @ -113,6 +138,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 +153,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 +171,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 +196,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
 | ||||
| @ -158,3 +235,13 @@ 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)); | ||||
| 
 | ||||
| // 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"))] | ||||
| impl_reflect_value!(BVec4A(Debug, PartialEq, Default)); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Maksymilian Mozolewski
						Maksymilian Mozolewski