Skip to content

Commit 584c666

Browse files
authored
Reduce dependencies on bevy_render by preferring bevy_mesh imports (#18437)
## Objective Reduce dependencies on `bevy_render` by preferring `bevy_mesh` imports over `bevy_render` re-exports. ```diff - use bevy_render::mesh::Mesh; + use bevy_mesh::Mesh; ``` This is intended to help with #18423 (render crate restructure). Affects `bevy_gltf`, `bevy_animation` and `bevy_picking`. ## But Why? As part of #18423, I'm assuming there'll be a push to make crates less dependent on the big render crates. This PR seemed like a small and safe step along that path - it only changes imports and makes the `bevy_mesh` crate dependency explicit in `Cargo.toml`. Any remaining dependencies on `bevy_render` are true dependencies. ## Testing ``` cargo run --example testbed_3d cargo run --example mesh_picking ```
1 parent 7a37c4a commit 584c666

File tree

13 files changed

+27
-25
lines changed

13 files changed

+27
-25
lines changed

crates/bevy_animation/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ bevy_color = { path = "../bevy_color", version = "0.16.0-dev" }
1616
bevy_derive = { path = "../bevy_derive", version = "0.16.0-dev" }
1717
bevy_log = { path = "../bevy_log", version = "0.16.0-dev" }
1818
bevy_math = { path = "../bevy_math", version = "0.16.0-dev" }
19+
bevy_mesh = { path = "../bevy_mesh", version = "0.16.0-dev" }
1920
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [
2021
"petgraph",
2122
] }

crates/bevy_animation/src/animation_curves.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ use bevy_math::curve::{
100100
iterable::IterableCurve,
101101
Curve, Interval,
102102
};
103+
use bevy_mesh::morph::MorphWeights;
103104
use bevy_platform_support::hash::Hashed;
104105
use bevy_reflect::{FromReflect, Reflect, Reflectable, TypeInfo, Typed};
105-
use bevy_render::mesh::morph::MorphWeights;
106106
use downcast_rs::{impl_downcast, Downcast};
107107

108108
/// A value on a component that Bevy can animate.

crates/bevy_animation/src/gltf_curves.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl<T> WideCubicKeyframeCurve<T> {
373373
/// recommended to use its implementation of the [`IterableCurve`] trait, which allows iterating
374374
/// directly over information derived from the curve without allocating.
375375
///
376-
/// [`MorphWeights`]: bevy_render::prelude::MorphWeights
376+
/// [`MorphWeights`]: bevy_mesh::morph::MorphWeights
377377
#[derive(Debug, Clone, Reflect)]
378378
#[reflect(Clone)]
379379
pub enum WeightsCurve {

crates/bevy_gltf/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.16.0-dev" }
2727
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
2828
bevy_image = { path = "../bevy_image", version = "0.16.0-dev" }
2929
bevy_math = { path = "../bevy_math", version = "0.16.0-dev" }
30+
bevy_mesh = { path = "../bevy_mesh", version = "0.16.0-dev" }
3031
bevy_pbr = { path = "../bevy_pbr", version = "0.16.0-dev" }
3132
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev" }
3233
bevy_render = { path = "../bevy_render", version = "0.16.0-dev" }

crates/bevy_gltf/src/assets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
use bevy_animation::AnimationClip;
55
use bevy_asset::{Asset, Handle};
66
use bevy_ecs::{component::Component, reflect::ReflectComponent};
7+
use bevy_mesh::{skinning::SkinnedMeshInverseBindposes, Mesh};
78
use bevy_pbr::StandardMaterial;
89
use bevy_platform_support::collections::HashMap;
910
use bevy_reflect::{prelude::ReflectDefault, Reflect, TypePath};
10-
use bevy_render::mesh::{skinning::SkinnedMeshInverseBindposes, Mesh};
1111
use bevy_scene::Scene;
1212

1313
use crate::GltfAssetLabel;
@@ -214,7 +214,7 @@ impl GltfPrimitive {
214214
}
215215
}
216216

217-
/// A glTF skin with all of its joint nodes, [`SkinnedMeshInversiveBindposes`](bevy_render::mesh::skinning::SkinnedMeshInverseBindposes)
217+
/// A glTF skin with all of its joint nodes, [`SkinnedMeshInversiveBindposes`](bevy_mesh::skinning::SkinnedMeshInverseBindposes)
218218
/// and an optional [`GltfExtras`].
219219
///
220220
/// See [the relevant glTF specification section](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-skin).

crates/bevy_gltf/src/label.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub enum GltfAssetLabel {
3737
Node(usize),
3838
/// `Mesh{}`: glTF Mesh as a [`GltfMesh`](crate::GltfMesh)
3939
Mesh(usize),
40-
/// `Mesh{}/Primitive{}`: glTF Primitive as a Bevy [`Mesh`](bevy_render::mesh::Mesh)
40+
/// `Mesh{}/Primitive{}`: glTF Primitive as a Bevy [`Mesh`](bevy_mesh::Mesh)
4141
Primitive {
4242
/// Index of the mesh for this primitive
4343
mesh: usize,
@@ -70,7 +70,7 @@ pub enum GltfAssetLabel {
7070
/// `Skin{}`: glTF mesh skin as [`GltfSkin`](crate::GltfSkin)
7171
Skin(usize),
7272
/// `Skin{}/InverseBindMatrices`: glTF mesh skin matrices as Bevy
73-
/// [`SkinnedMeshInverseBindposes`](bevy_render::mesh::skinning::SkinnedMeshInverseBindposes)
73+
/// [`SkinnedMeshInverseBindposes`](bevy_mesh::skinning::SkinnedMeshInverseBindposes)
7474
InverseBindMatrices(usize),
7575
}
7676

crates/bevy_gltf/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ use bevy_platform_support::collections::HashMap;
102102
use bevy_app::prelude::*;
103103
use bevy_asset::AssetApp;
104104
use bevy_image::CompressedImageFormats;
105-
use bevy_render::{mesh::MeshVertexAttribute, renderer::RenderDevice};
105+
use bevy_mesh::MeshVertexAttribute;
106+
use bevy_render::renderer::RenderDevice;
106107

107108
/// The glTF prelude.
108109
///

crates/bevy_gltf/src/loader/gltf_ext/mesh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bevy_render::mesh::PrimitiveTopology;
1+
use bevy_mesh::PrimitiveTopology;
22

33
use gltf::mesh::{Mesh, Mode, Primitive};
44

crates/bevy_gltf/src/loader/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::{
1010
use bevy_animation::{prelude::*, AnimationTarget, AnimationTargetId};
1111
use bevy_asset::{
1212
io::Reader, AssetLoadError, AssetLoader, Handle, LoadContext, ReadAssetBytesError,
13+
RenderAssetUsages,
1314
};
1415
use bevy_color::{Color, LinearRgba};
1516
use bevy_core_pipeline::prelude::Camera3d;
@@ -24,6 +25,11 @@ use bevy_image::{
2425
ImageType, TextureError,
2526
};
2627
use bevy_math::{Mat4, Vec3};
28+
use bevy_mesh::{
29+
morph::{MeshMorphWeights, MorphAttributes, MorphTargetImage, MorphWeights},
30+
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
31+
Indices, Mesh, MeshVertexAttribute, PrimitiveTopology, VertexAttributeValues,
32+
};
2733
#[cfg(feature = "pbr_transmission_textures")]
2834
use bevy_pbr::UvChannel;
2935
use bevy_pbr::{
@@ -32,14 +38,9 @@ use bevy_pbr::{
3238
use bevy_platform_support::collections::{HashMap, HashSet};
3339
use bevy_render::{
3440
camera::{Camera, OrthographicProjection, PerspectiveProjection, Projection, ScalingMode},
35-
mesh::{
36-
morph::{MeshMorphWeights, MorphAttributes, MorphTargetImage, MorphWeights},
37-
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
38-
Indices, Mesh, Mesh3d, MeshVertexAttribute, VertexAttributeValues,
39-
},
41+
mesh::Mesh3d,
4042
primitives::Aabb,
41-
render_asset::RenderAssetUsages,
42-
render_resource::{Face, PrimitiveTopology},
43+
render_resource::Face,
4344
view::Visibility,
4445
};
4546
use bevy_scene::Scene;
@@ -122,10 +123,10 @@ pub enum GltfError {
122123
MissingAnimationSampler(usize),
123124
/// Failed to generate tangents.
124125
#[error("failed to generate tangents: {0}")]
125-
GenerateTangentsError(#[from] bevy_render::mesh::GenerateTangentsError),
126+
GenerateTangentsError(#[from] bevy_mesh::GenerateTangentsError),
126127
/// Failed to generate morph targets.
127128
#[error("failed to generate morph targets: {0}")]
128-
MorphTarget(#[from] bevy_render::mesh::morph::MorphBuildError),
129+
MorphTarget(#[from] bevy_mesh::morph::MorphBuildError),
129130
/// Circular children in Nodes
130131
#[error("GLTF model must be a tree, found cycle instead at node indices: {0:?}")]
131132
#[from(ignore)]
@@ -1775,7 +1776,8 @@ mod test {
17751776
};
17761777
use bevy_ecs::{resource::Resource, world::World};
17771778
use bevy_log::LogPlugin;
1778-
use bevy_render::mesh::{skinning::SkinnedMeshInverseBindposes, MeshPlugin};
1779+
use bevy_mesh::skinning::SkinnedMeshInverseBindposes;
1780+
use bevy_render::mesh::MeshPlugin;
17791781
use bevy_scene::ScenePlugin;
17801782

17811783
fn test_app(dir: Dir) -> App {

crates/bevy_gltf/src/vertex_attributes.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1+
use bevy_mesh::{Mesh, MeshVertexAttribute, VertexAttributeValues as Values, VertexFormat};
12
use bevy_platform_support::collections::HashMap;
2-
use bevy_render::{
3-
mesh::{MeshVertexAttribute, VertexAttributeValues as Values},
4-
prelude::Mesh,
5-
render_resource::VertexFormat,
6-
};
73
use gltf::{
84
accessor::{DataType, Dimensions},
95
mesh::util::{ReadColors, ReadJoints, ReadTexCoords, ReadWeights},

crates/bevy_mesh/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub use mesh::*;
1717
pub use mikktspace::*;
1818
pub use primitives::*;
1919
pub use vertex::*;
20+
pub use wgpu_types::VertexFormat;
2021

2122
bitflags! {
2223
/// Our base mesh pipeline key bits start from the highest bit and go

crates/bevy_picking/src/mesh_picking/ray_cast/intersections.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy_math::{bounding::Aabb3d, Dir3, Mat4, Ray3d, Vec3, Vec3A};
2+
use bevy_mesh::{Indices, Mesh, PrimitiveTopology};
23
use bevy_reflect::Reflect;
3-
use bevy_render::mesh::{Indices, Mesh, PrimitiveTopology};
44

55
use super::Backfaces;
66

crates/bevy_picking/src/mesh_picking/ray_cast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ mod intersections;
77
use bevy_derive::{Deref, DerefMut};
88

99
use bevy_math::{bounding::Aabb3d, Ray3d};
10+
use bevy_mesh::Mesh;
1011
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
11-
use bevy_render::mesh::Mesh;
1212

1313
use intersections::*;
1414
pub use intersections::{ray_aabb_intersection_3d, ray_mesh_intersection, RayMeshHit};

0 commit comments

Comments
 (0)