Skip to content

Commit abbaa47

Browse files
hukasudependabot[bot]alice-i-cecile
authored
Glam 0.31 (#22681)
# Objective Adopt and closes #22665 ## Solution Delete bevy's `Affine3`, create an extension trait for methods create for old bevy's `Affine3` to be used by glam's `Affine3`, and register glam's `Affine3` for reflection ## Testing `cargo run -p ci` --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alice Cecile <[email protected]>
1 parent 7bc8892 commit abbaa47

File tree

15 files changed

+48
-55
lines changed

15 files changed

+48
-55
lines changed

benches/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bevy_platform = { path = "../crates/bevy_platform", default-features = false, fe
3030
] }
3131

3232
# Other crates
33-
glam = { version = "0.30.7", default-features = false, features = [
33+
glam = { version = "0.31.0", default-features = false, features = [
3434
"std",
3535
"rand",
3636
] }

crates/bevy_gizmos_render/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use bevy_ecs::{
3030
schedule::{IntoScheduleConfigs, SystemSet},
3131
system::Res,
3232
};
33+
use bevy_math::Affine3Ext;
3334

3435
use {bevy_gizmos::config::GizmoMeshConfig, bevy_mesh::VertexBufferLayout};
3536

@@ -183,7 +184,7 @@ fn extract_gizmo_data(
183184

184185
commands.spawn((
185186
LineGizmoUniform {
186-
world_from_local: Affine3::from(&Affine3A::IDENTITY).to_transpose(),
187+
world_from_local: Affine3::from(Affine3A::IDENTITY).to_transpose(),
187188
line_width: config.line.width,
188189
depth_bias: config.depth_bias,
189190
joints_resolution,

crates/bevy_gizmos_render/src/retained.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::LineGizmoUniform;
44
use bevy_camera::visibility::RenderLayers;
55
use bevy_gizmos::retained::Gizmo;
6-
use bevy_math::Affine3;
6+
use bevy_math::{Affine3, Affine3Ext};
77
use bevy_render::sync_world::{MainEntity, TemporaryRenderEntity};
88
use bevy_utils::once;
99
use tracing::warn;
@@ -57,7 +57,7 @@ pub(crate) fn extract_linegizmos(
5757

5858
values.push((
5959
LineGizmoUniform {
60-
world_from_local: Affine3::from(&transform.affine()).to_transpose(),
60+
world_from_local: Affine3::from(transform.affine()).to_transpose(),
6161
line_width: gizmo.line_config.width,
6262
depth_bias: gizmo.depth_bias,
6363
joints_resolution,

crates/bevy_math/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords = ["bevy"]
1010
rust-version = "1.85.0"
1111

1212
[dependencies]
13-
glam = { version = "0.30.7", default-features = false, features = ["bytemuck"] }
13+
glam = { version = "0.31.0", default-features = false, features = ["bytemuck"] }
1414
thiserror = { version = "2", default-features = false }
1515
derive_more = { version = "2", default-features = false, features = [
1616
"from",
@@ -37,7 +37,7 @@ rand = "0.9"
3737
rand_chacha = "0.9"
3838
# Enable the approx feature when testing.
3939
bevy_math = { path = ".", default-features = false, features = ["approx"] }
40-
glam = { version = "0.30.7", default-features = false, features = ["approx"] }
40+
glam = { version = "0.31.0", default-features = false, features = ["approx"] }
4141

4242
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
4343
getrandom = { version = "0.3", default-features = false, features = [

crates/bevy_math/src/affine3.rs

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
use glam::{Affine3A, Mat3, Vec3, Vec3Swizzles, Vec4};
1+
use glam::{Affine3, Affine3A, Vec3Swizzles, Vec4};
22

3-
#[cfg(feature = "bevy_reflect")]
4-
use bevy_reflect::Reflect;
5-
6-
/// Reduced-size version of `glam::Affine3A` for use when storage has
7-
/// significant performance impact. Convert to `glam::Affine3A` to do
8-
/// non-trivial calculations.
9-
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
10-
pub struct Affine3 {
11-
/// Scaling, rotation, shears, and other non-translation affine transforms
12-
pub matrix3: Mat3,
13-
/// Translation
14-
pub translation: Vec3,
3+
/// Extension trait for [`Affine3`]
4+
pub trait Affine3Ext {
5+
/// Calculates the transpose of the affine 4x3 matrix to a 3x4 and formats it for packing into GPU buffers
6+
fn to_transpose(self) -> [Vec4; 3];
7+
/// Calculates the inverse transpose of the 3x3 matrix and formats it for packing into GPU buffers
8+
fn inverse_transpose_3x3(self) -> ([Vec4; 2], f32);
159
}
1610

17-
impl Affine3 {
18-
/// Calculates the transpose of the affine 4x3 matrix to a 3x4 and formats it for packing into GPU buffers
11+
impl Affine3Ext for Affine3 {
1912
#[inline]
20-
pub fn to_transpose(&self) -> [Vec4; 3] {
13+
fn to_transpose(self) -> [Vec4; 3] {
2114
let transpose_3x3 = self.matrix3.transpose();
2215
[
2316
transpose_3x3.x_axis.extend(self.translation.x),
@@ -26,9 +19,8 @@ impl Affine3 {
2619
]
2720
}
2821

29-
/// Calculates the inverse transpose of the 3x3 matrix and formats it for packing into GPU buffers
3022
#[inline]
31-
pub fn inverse_transpose_3x3(&self) -> ([Vec4; 2], f32) {
23+
fn inverse_transpose_3x3(self) -> ([Vec4; 2], f32) {
3224
let inverse_transpose_3x3 = Affine3A::from(self).inverse().matrix3.transpose();
3325
(
3426
[
@@ -43,21 +35,3 @@ impl Affine3 {
4335
)
4436
}
4537
}
46-
47-
impl From<&Affine3A> for Affine3 {
48-
fn from(affine: &Affine3A) -> Self {
49-
Self {
50-
matrix3: affine.matrix3.into(),
51-
translation: affine.translation.into(),
52-
}
53-
}
54-
}
55-
56-
impl From<&Affine3> for Affine3A {
57-
fn from(affine3: &Affine3) -> Self {
58-
Self {
59-
matrix3: affine3.matrix3.into(),
60-
translation: affine3.translation.into(),
61-
}
62-
}
63-
}

crates/bevy_mesh/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ wgpu-types = { version = "28", default-features = false }
3131
serde = { version = "1", default-features = false, features = [
3232
"derive",
3333
], optional = true }
34-
hexasphere = "16.0"
34+
hexasphere = "17.0"
3535
thiserror = { version = "2", default-features = false }
3636
tracing = { version = "0.1", default-features = false, features = ["std"] }
3737
derive_more = { version = "2", default-features = false, features = ["from"] }

crates/bevy_pbr/src/meshlet/instance_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ impl InstanceManager {
110110
flags |= MeshFlags::SIGN_DETERMINANT_MODEL_3X3;
111111
}
112112
let transforms = MeshTransforms {
113-
world_from_local: (&transform).into(),
114-
previous_world_from_local: (&previous_transform).into(),
113+
world_from_local: transform.into(),
114+
previous_world_from_local: previous_transform.into(),
115115
flags: flags.bits(),
116116
};
117117

crates/bevy_pbr/src/render/mesh.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use bevy_light::{
3030
EnvironmentMapLight, IrradianceVolume, NotShadowCaster, NotShadowReceiver,
3131
ShadowFilteringMethod, TransmittedShadowReceiver,
3232
};
33-
use bevy_math::{Affine3, Rect, UVec2, Vec3, Vec4};
33+
use bevy_math::{Affine3, Affine3Ext, Rect, UVec2, Vec3, Vec4};
3434
use bevy_mesh::{
3535
skinning::SkinnedMesh, BaseMeshPipelineKey, Mesh, Mesh3d, MeshTag, MeshVertexBufferLayoutRef,
3636
VertexAttributeDescriptor,
@@ -1455,11 +1455,11 @@ pub fn extract_meshes_for_cpu_building(
14551455
entity,
14561456
RenderMeshInstanceCpu {
14571457
transforms: MeshTransforms {
1458-
world_from_local: (&world_from_local).into(),
1459-
previous_world_from_local: (&previous_transform
1458+
world_from_local: world_from_local.into(),
1459+
previous_world_from_local: (previous_transform
14601460
.map(|t| t.0)
14611461
.unwrap_or(world_from_local))
1462-
.into(),
1462+
.into(),
14631463
flags: mesh_flags.bits(),
14641464
},
14651465
shared,
@@ -1719,7 +1719,7 @@ fn extract_mesh_for_gpu_building(
17191719

17201720
let gpu_mesh_instance_builder = RenderMeshInstanceGpuBuilder {
17211721
shared,
1722-
world_from_local: (&transform.affine()).into(),
1722+
world_from_local: (transform.affine()).into(),
17231723
lightmap_uv_rect,
17241724
mesh_flags,
17251725
previous_input_index,

crates/bevy_reflect/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ derive_more = { version = "2", default-features = false, features = ["from"] }
116116
serde = { version = "1", default-features = false, features = ["alloc"] }
117117
assert_type_match = "0.1.1"
118118
smallvec = { version = "1", default-features = false, optional = true }
119-
glam = { version = "0.30.7", default-features = false, features = [
119+
glam = { version = "0.31.0", default-features = false, features = [
120120
"serde",
121121
], optional = true }
122122
indexmap = { version = "2.5.0", default-features = false, optional = true }

crates/bevy_reflect/src/impls/glam.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ impl_reflect!(
413413
translation: Vec2,
414414
}
415415
);
416+
impl_reflect!(
417+
#[reflect(Clone, Debug, PartialEq, Default, Deserialize, Serialize)]
418+
#[type_path = "glam"]
419+
struct Affine3 {
420+
matrix3: Mat3,
421+
translation: Vec3,
422+
}
423+
);
416424
impl_reflect!(
417425
#[reflect(Clone, Debug, PartialEq, Default, Deserialize, Serialize)]
418426
#[type_path = "glam"]

0 commit comments

Comments
 (0)