diff --git a/Cargo.toml b/Cargo.toml index f6a30b4892e0d..28ac1cf7e3cd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -348,6 +348,9 @@ ios_simulator = ["bevy_internal/ios_simulator"] # Enable built in global state machines bevy_state = ["bevy_internal/bevy_state"] +# Enable C style struct representation to allow passing built-in types over FFI +repr_c = ["bevy_internal/repr_c"] + [dependencies] bevy_internal = { path = "crates/bevy_internal", version = "0.15.0-dev", default-features = false } diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 821350c24c1c3..02fbbeec77366 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -195,6 +195,13 @@ ios_simulator = ["bevy_pbr?/ios_simulator", "bevy_render?/ios_simulator"] # Enable built in global state machines bevy_state = ["dep:bevy_state"] +# Enable C style struct representation to allow passing built-in types over FFI +repr_c = [ + "bevy_transform/repr_c", + "bevy_math/repr_c", + "bevy_reflect/repr_c" +] + [dependencies] # bevy bevy_a11y = { path = "../bevy_a11y", version = "0.15.0-dev" } diff --git a/crates/bevy_math/Cargo.toml b/crates/bevy_math/Cargo.toml index eebd683cfc7d9..ab28fe90a9df7 100644 --- a/crates/bevy_math/Cargo.toml +++ b/crates/bevy_math/Cargo.toml @@ -52,6 +52,11 @@ debug_glam_assert = ["glam/debug-glam-assert"] # Enable the rand dependency for shape_sampling rand = ["dep:rand", "dep:rand_distr", "glam/rand"] +repr_c = [ + "glam/scalar-math", + "bevy_reflect/repr_c" +] + [lints] workspace = true diff --git a/crates/bevy_math/src/affine3.rs b/crates/bevy_math/src/affine3.rs index 654721bdfe8a4..9235f4e0f75d0 100644 --- a/crates/bevy_math/src/affine3.rs +++ b/crates/bevy_math/src/affine3.rs @@ -7,6 +7,7 @@ use bevy_reflect::Reflect; /// significant performance impact. Convert to `glam::Affine3A` to do /// non-trivial calculations. #[cfg_attr(feature = "bevy_reflect", derive(Reflect))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Affine3 { /// Scaling, rotation, shears, and other non-translation affine transforms pub matrix3: Mat3, diff --git a/crates/bevy_math/src/aspect_ratio.rs b/crates/bevy_math/src/aspect_ratio.rs index 97960015a5ac1..62bf9015e2fd5 100644 --- a/crates/bevy_math/src/aspect_ratio.rs +++ b/crates/bevy_math/src/aspect_ratio.rs @@ -8,6 +8,7 @@ use bevy_reflect::Reflect; /// An `AspectRatio` is the ratio of width to height. #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct AspectRatio(f32); impl AspectRatio { diff --git a/crates/bevy_math/src/bounding/bounded2d/mod.rs b/crates/bevy_math/src/bounding/bounded2d/mod.rs index 87123075a90b0..270ac9f7a4bd3 100644 --- a/crates/bevy_math/src/bounding/bounded2d/mod.rs +++ b/crates/bevy_math/src/bounding/bounded2d/mod.rs @@ -32,6 +32,7 @@ pub trait Bounded2d { #[doc(alias = "BoundingRectangle")] #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Aabb2d { /// The minimum, conventionally bottom-left, point of the box pub min: Vec2, diff --git a/crates/bevy_math/src/bounding/bounded3d/mod.rs b/crates/bevy_math/src/bounding/bounded3d/mod.rs index 4e67a4d4084f2..39f912307006d 100644 --- a/crates/bevy_math/src/bounding/bounded3d/mod.rs +++ b/crates/bevy_math/src/bounding/bounded3d/mod.rs @@ -35,6 +35,7 @@ pub trait Bounded3d { /// A 3D axis-aligned bounding box #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Aabb3d { /// The minimum point of the box pub min: Vec3A, diff --git a/crates/bevy_math/src/bounding/raycast2d.rs b/crates/bevy_math/src/bounding/raycast2d.rs index e3a4764725171..de4f924819375 100644 --- a/crates/bevy_math/src/bounding/raycast2d.rs +++ b/crates/bevy_math/src/bounding/raycast2d.rs @@ -7,6 +7,7 @@ use bevy_reflect::Reflect; /// A raycast intersection test for 2D bounding volumes #[derive(Clone, Debug)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct RayCast2d { /// The ray for the test pub ray: Ray2d, @@ -105,6 +106,7 @@ impl IntersectsVolume for RayCast2d { /// An intersection test that casts an [`Aabb2d`] along a ray. #[derive(Clone, Debug)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct AabbCast2d { /// The ray along which to cast the bounding volume pub ray: RayCast2d, @@ -143,6 +145,7 @@ impl IntersectsVolume for AabbCast2d { /// An intersection test that casts a [`BoundingCircle`] along a ray. #[derive(Clone, Debug)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct BoundingCircleCast { /// The ray along which to cast the bounding volume pub ray: RayCast2d, diff --git a/crates/bevy_math/src/bounding/raycast3d.rs b/crates/bevy_math/src/bounding/raycast3d.rs index 24b28e2774ebd..83b0fe0f70125 100644 --- a/crates/bevy_math/src/bounding/raycast3d.rs +++ b/crates/bevy_math/src/bounding/raycast3d.rs @@ -7,6 +7,7 @@ use bevy_reflect::Reflect; /// A raycast intersection test for 3D bounding volumes #[derive(Clone, Debug)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct RayCast3d { /// The origin of the ray. pub origin: Vec3A, @@ -100,6 +101,7 @@ impl IntersectsVolume for RayCast3d { /// An intersection test that casts an [`Aabb3d`] along a ray. #[derive(Clone, Debug)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct AabbCast3d { /// The ray along which to cast the bounding volume pub ray: RayCast3d, @@ -143,6 +145,7 @@ impl IntersectsVolume for AabbCast3d { /// An intersection test that casts a [`BoundingSphere`] along a ray. #[derive(Clone, Debug)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct BoundingSphereCast { /// The ray along which to cast the bounding volume pub ray: RayCast3d, diff --git a/crates/bevy_math/src/compass.rs b/crates/bevy_math/src/compass.rs index ed1d4b947f248..2141a07e7b1bc 100644 --- a/crates/bevy_math/src/compass.rs +++ b/crates/bevy_math/src/compass.rs @@ -23,6 +23,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; all(feature = "serialize", feature = "bevy_reflect"), reflect(Deserialize, Serialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub enum CompassQuadrant { /// Corresponds to [`Dir2::Y`] and [`Dir2::NORTH`] North, diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index df061195a7308..15dead5750eba 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -92,6 +92,7 @@ pub type Direction3d = Dir3; reflect(Serialize, Deserialize) )] #[doc(alias = "Direction2d")] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Dir2(Vec2); impl Primitive2d for Dir2 {} @@ -345,6 +346,7 @@ impl approx::UlpsEq for Dir2 { reflect(Serialize, Deserialize) )] #[doc(alias = "Direction3d")] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Dir3(Vec3); impl Primitive3d for Dir3 {} @@ -551,6 +553,7 @@ impl approx::UlpsEq for Dir3 { reflect(Serialize, Deserialize) )] #[doc(alias = "Direction3dA")] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Dir3A(Vec3A); impl Primitive3d for Dir3A {} diff --git a/crates/bevy_math/src/float_ord.rs b/crates/bevy_math/src/float_ord.rs index 63360449258d3..e116339a71d16 100644 --- a/crates/bevy_math/src/float_ord.rs +++ b/crates/bevy_math/src/float_ord.rs @@ -22,6 +22,7 @@ use bevy_reflect::Reflect; derive(Reflect), reflect(Debug, PartialEq, Hash) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct FloatOrd(pub f32); impl PartialOrd for FloatOrd { diff --git a/crates/bevy_math/src/lib.rs b/crates/bevy_math/src/lib.rs index 868dae094510d..4d9d5f8f56083 100644 --- a/crates/bevy_math/src/lib.rs +++ b/crates/bevy_math/src/lib.rs @@ -25,6 +25,9 @@ mod rects; mod rotation2d; #[cfg(feature = "rand")] pub mod sampling; + +// mod quat; + pub use compass::{CompassOctant, CompassQuadrant}; pub use affine3::*; @@ -58,4 +61,4 @@ pub mod prelude { }; } -pub use glam::*; +pub use glam::*; \ No newline at end of file diff --git a/crates/bevy_math/src/primitives/dim2.rs b/crates/bevy_math/src/primitives/dim2.rs index e96160367802b..2cc8cd4c14a31 100644 --- a/crates/bevy_math/src/primitives/dim2.rs +++ b/crates/bevy_math/src/primitives/dim2.rs @@ -20,6 +20,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Circle { /// The radius of the circle pub radius: f32, @@ -107,6 +108,7 @@ impl Measured2d for Circle { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Arc2d { /// The radius of the circle pub radius: f32, @@ -274,6 +276,7 @@ impl Arc2d { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct CircularSector { /// The arc defining the sector #[cfg_attr(feature = "serialize", serde(flatten))] @@ -413,6 +416,7 @@ impl CircularSector { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct CircularSegment { /// The arc defining the segment #[cfg_attr(feature = "serialize", serde(flatten))] diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index 5eb456f37c101..a3751327c7b4d 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -20,6 +20,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Sphere { /// The radius of the sphere pub radius: f32, @@ -92,6 +93,7 @@ impl Measured3d for Sphere { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Plane3d { /// The normal of the plane. The plane will be placed perpendicular to this direction pub normal: Dir3, @@ -164,6 +166,7 @@ impl Plane3d { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct InfinitePlane3d { /// The normal of the plane. The plane will be placed perpendicular to this direction pub normal: Dir3, @@ -226,6 +229,7 @@ impl InfinitePlane3d { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Line3d { /// The direction of the line pub direction: Dir3, @@ -241,6 +245,7 @@ impl Primitive3d for Line3d {} all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Segment3d { /// The direction of the line pub direction: Dir3, @@ -300,6 +305,7 @@ impl Segment3d { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Polyline3d { /// The vertices of the polyline #[cfg_attr(feature = "serialize", serde(with = "super::serde::array"))] @@ -331,6 +337,7 @@ impl Polyline3d { /// For a version without alloc: [`Polyline3d`] #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct BoxedPolyline3d { /// The vertices of the polyline pub vertices: Box<[Vec3]>, @@ -366,6 +373,7 @@ impl BoxedPolyline3d { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Cuboid { /// Half of the width, height and depth of the cuboid pub half_size: Vec3, @@ -458,6 +466,7 @@ impl Measured3d for Cuboid { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Cylinder { /// The radius of the cylinder pub radius: f32, @@ -536,6 +545,7 @@ impl Measured3d for Cylinder { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Capsule3d { /// The radius of the capsule pub radius: f32, @@ -606,6 +616,7 @@ impl Measured3d for Capsule3d { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Cone { /// The radius of the base pub radius: f32, @@ -684,6 +695,7 @@ impl Measured3d for Cone { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct ConicalFrustum { /// The radius of the top of the frustum pub radius_top: f32, @@ -736,6 +748,7 @@ pub enum TorusKind { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Torus { /// The radius of the tube of the torus #[doc( @@ -847,6 +860,7 @@ impl Measured3d for Torus { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Triangle3d { /// The vertices of the triangle. pub vertices: [Vec3; 3], @@ -1040,6 +1054,7 @@ impl Measured2d for Triangle3d { all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Tetrahedron { /// The vertices of the tetrahedron. pub vertices: [Vec3; 4], diff --git a/crates/bevy_math/src/primitives/mod.rs b/crates/bevy_math/src/primitives/mod.rs index 460e635867ecb..3d40a885472d8 100644 --- a/crates/bevy_math/src/primitives/mod.rs +++ b/crates/bevy_math/src/primitives/mod.rs @@ -18,6 +18,7 @@ pub trait Primitive3d {} /// The winding order for a set of points #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[doc(alias = "Orientation")] +#[cfg_attr(feature = "repr_c", repr(C))] pub enum WindingOrder { /// A clockwise winding order Clockwise, diff --git a/crates/bevy_math/src/ray.rs b/crates/bevy_math/src/ray.rs index df490a506cf49..a5d0baa469ec0 100644 --- a/crates/bevy_math/src/ray.rs +++ b/crates/bevy_math/src/ray.rs @@ -16,6 +16,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; all(feature = "serialize", feature = "bevy_reflect"), reflect(Deserialize, Serialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Ray2d { /// The origin of the ray. pub origin: Vec2, @@ -65,6 +66,7 @@ impl Ray2d { all(feature = "serialize", feature = "bevy_reflect"), reflect(Deserialize, Serialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Ray3d { /// The origin of the ray. pub origin: Vec3, diff --git a/crates/bevy_math/src/rects/irect.rs b/crates/bevy_math/src/rects/irect.rs index ae858a88c0bfe..49fa5b6f0e83f 100644 --- a/crates/bevy_math/src/rects/irect.rs +++ b/crates/bevy_math/src/rects/irect.rs @@ -25,6 +25,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct IRect { /// The minimum corner point of the rect. pub min: IVec2, diff --git a/crates/bevy_math/src/rects/rect.rs b/crates/bevy_math/src/rects/rect.rs index 8e804dcd085f0..3783fd8d38d07 100644 --- a/crates/bevy_math/src/rects/rect.rs +++ b/crates/bevy_math/src/rects/rect.rs @@ -25,6 +25,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Rect { /// The minimum corner point of the rect. pub min: Vec2, diff --git a/crates/bevy_math/src/rects/urect.rs b/crates/bevy_math/src/rects/urect.rs index 54cde829040fc..356946fad1d6f 100644 --- a/crates/bevy_math/src/rects/urect.rs +++ b/crates/bevy_math/src/rects/urect.rs @@ -25,6 +25,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; all(feature = "serialize", feature = "bevy_reflect"), reflect(Serialize, Deserialize) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct URect { /// The minimum corner point of the rect. pub min: UVec2, diff --git a/crates/bevy_math/src/rotation2d.rs b/crates/bevy_math/src/rotation2d.rs index 77011f93a3cd7..3b4cf479151c7 100644 --- a/crates/bevy_math/src/rotation2d.rs +++ b/crates/bevy_math/src/rotation2d.rs @@ -42,6 +42,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; reflect(Serialize, Deserialize) )] #[doc(alias = "rotation", alias = "rotation2d", alias = "rotation_2d")] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Rot2 { /// The cosine of the rotation angle in radians. /// diff --git a/crates/bevy_math/src/sampling/standard.rs b/crates/bevy_math/src/sampling/standard.rs index 9c5ff1fa3dea4..1cda3f8ffc2e7 100644 --- a/crates/bevy_math/src/sampling/standard.rs +++ b/crates/bevy_math/src/sampling/standard.rs @@ -25,12 +25,13 @@ use std::f32::consts::TAU; use crate::{ primitives::{Circle, Sphere}, - Dir2, Dir3, Dir3A, Quat, Rot2, ShapeSample, Vec3A, + Dir2, Dir3, Dir3A, Rot2, ShapeSample, Vec3A, }; use rand::{ distributions::{Distribution, Standard}, Rng, }; +use crate::prelude::Quat; /// Ergonomics trait for a type with a [`Standard`] distribution, allowing values to be generated /// uniformly from an [`Rng`] by a method in its own namespace. @@ -95,5 +96,4 @@ impl Distribution for Standard { } impl FromRng for Rot2 {} - impl FromRng for Quat {} diff --git a/crates/bevy_reflect/Cargo.toml b/crates/bevy_reflect/Cargo.toml index 8cdd32204f741..38f91c5ca8112 100644 --- a/crates/bevy_reflect/Cargo.toml +++ b/crates/bevy_reflect/Cargo.toml @@ -20,6 +20,8 @@ uuid = ["dep:uuid"] # When enabled, allows documentation comments to be accessed via reflection documentation = ["bevy_reflect_derive/documentation"] +repr_c = ["glam/scalar-math"] + [dependencies] # bevy bevy_reflect_derive = { path = "derive", version = "0.15.0-dev" } diff --git a/crates/bevy_reflect/src/impls/glam.rs b/crates/bevy_reflect/src/impls/glam.rs index 06823374b0c08..5d06eecc1e66b 100644 --- a/crates/bevy_reflect/src/impls/glam.rs +++ b/crates/bevy_reflect/src/impls/glam.rs @@ -332,4 +332,5 @@ impl_reflect!( impl_reflect_value!(::glam::EulerRot(Debug, Default)); impl_reflect_value!(::glam::BVec3A(Debug, Default)); +#[cfg(not(feature = "repr_c"))] impl_reflect_value!(::glam::BVec4A(Debug, Default)); diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index d60efb0977eb2..f75771e47006d 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -700,10 +700,10 @@ pub fn prepare_sprite_image_bind_groups( } let transform = extracted_sprite.transform.affine() * Affine3A::from_scale_rotation_translation( - quad_size.extend(1.0), - Quat::IDENTITY, - (quad_size * (-extracted_sprite.anchor - Vec2::splat(0.5))).extend(0.0), - ); + quad_size.extend(1.0), + Quat::IDENTITY, + (quad_size * (-extracted_sprite.anchor - Vec2::splat(0.5))).extend(0.0) + ); // Store the vertex data and add the item to the render phase sprite_meta diff --git a/crates/bevy_transform/Cargo.toml b/crates/bevy_transform/Cargo.toml index e5edff96ea9ed..5436ee9bc7544 100644 --- a/crates/bevy_transform/Cargo.toml +++ b/crates/bevy_transform/Cargo.toml @@ -48,6 +48,8 @@ default = ["bevy-support"] serialize = ["dep:serde", "bevy_math/serialize"] +repr_c = [] + [lints] workspace = true diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index fa5384c1d0253..642d69971d82b 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -42,6 +42,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; derive(Component, Reflect), reflect(Component, Default, PartialEq) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct GlobalTransform(Affine3A); macro_rules! impl_local_axis { diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 554d5f66177f5..575926b128370 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -40,6 +40,7 @@ use std::ops::Mul; derive(Component, Reflect), reflect(Component, Default, PartialEq) )] +#[cfg_attr(feature = "repr_c", repr(C))] pub struct Transform { /// Position of the entity. In 2d, the last value of the `Vec3` is used for z-ordering. /// @@ -82,7 +83,6 @@ impl Transform { #[inline] pub fn from_matrix(world_from_local: Mat4) -> Self { let (scale, rotation, translation) = world_from_local.to_scale_rotation_translation(); - Transform { translation, rotation,