Skip to content

Commit 597de92

Browse files
authored
Make bevy_gltf optional for bevy_pbr (#22838)
# Objective - `bevy_pbr` no longer strictly requires `bevy_gltf` ## Solution - Make `bevy_gltf` an optional dependency, and feature gate the usage ## Testing - `cargo run --example animated_mesh` compiles `bevy_gltf` and displays the fox and grass - `cargo run --example 3d_shapes --no-default-features --features default_app,default_platform,3d_api,bevy_pbr,bevy_ui` compiles without `bevy_gltf` or `gltf`
1 parent c495cd4 commit 597de92

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

crates/bevy_internal/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ bevy_anti_alias = ["dep:bevy_anti_alias", "bevy_core_pipeline"]
251251
bevy_post_process = ["dep:bevy_post_process", "bevy_core_pipeline"]
252252
bevy_pbr = [
253253
"dep:bevy_pbr",
254-
"bevy_gltf",
255254
"bevy_light",
256255
"bevy_material",
257256
"bevy_core_pipeline",
@@ -268,7 +267,7 @@ bevy_ui_render = ["dep:bevy_ui_render", "bevy_sprite_render", "bevy_ui"]
268267
bevy_solari = ["dep:bevy_solari", "bevy_pbr"]
269268
bevy_gizmos = ["dep:bevy_gizmos", "bevy_camera", "bevy_light?/bevy_gizmos"]
270269
bevy_gizmos_render = ["dep:bevy_gizmos_render", "bevy_gizmos"]
271-
bevy_gltf = ["dep:bevy_gltf", "bevy_scene"]
270+
bevy_gltf = ["dep:bevy_gltf", "bevy_scene", "bevy_pbr?/bevy_gltf"]
272271

273272
# Used to disable code that is unsupported when Bevy is dynamically linked
274273
dynamic_linking = ["bevy_diagnostic/dynamic_linking"]

crates/bevy_pbr/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ keywords = ["bevy"]
1111
[features]
1212
webgl = ["bevy_light/webgl"]
1313
webgpu = ["bevy_light/webgpu"]
14-
pbr_transmission_textures = ["bevy_gltf/pbr_transmission_textures"]
14+
pbr_transmission_textures = ["bevy_gltf?/pbr_transmission_textures"]
1515
pbr_multi_layer_material_textures = [
16-
"bevy_gltf/pbr_multi_layer_material_textures",
16+
"bevy_gltf?/pbr_multi_layer_material_textures",
1717
]
18-
pbr_anisotropy_texture = ["bevy_gltf/pbr_anisotropy_texture"]
19-
pbr_specular_textures = ["bevy_gltf/pbr_specular_textures"]
18+
pbr_anisotropy_texture = ["bevy_gltf?/pbr_anisotropy_texture"]
19+
pbr_specular_textures = ["bevy_gltf?/pbr_specular_textures"]
2020
experimental_pbr_pcss = ["bevy_light/experimental_pbr_pcss"]
2121
pbr_clustered_decals = []
2222
pbr_light_textures = []
@@ -43,7 +43,7 @@ bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.19.0-dev" }
4343
bevy_derive = { path = "../bevy_derive", version = "0.19.0-dev" }
4444
bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.19.0-dev" }
4545
bevy_ecs = { path = "../bevy_ecs", version = "0.19.0-dev" }
46-
bevy_gltf = { path = "../bevy_gltf", version = "0.19.0-dev" }
46+
bevy_gltf = { path = "../bevy_gltf", version = "0.19.0-dev", optional = true }
4747
bevy_light = { path = "../bevy_light", version = "0.19.0-dev" }
4848
bevy_log = { path = "../bevy_log", version = "0.19.0-dev" }
4949
bevy_image = { path = "../bevy_image", version = "0.19.0-dev" }

crates/bevy_pbr/src/gltf.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ pub(crate) fn add_gltf(app: &mut App) {
2929
.push(Box::new(GltfExtensionHandlerPbr));
3030
}
3131

32-
fn standard_material_from_gltf_material(material: &GltfMaterial) -> StandardMaterial {
32+
/// Converts a [`GltfMaterial`] to a [`StandardMaterial`]
33+
pub fn standard_material_from_gltf_material(material: &GltfMaterial) -> StandardMaterial {
3334
StandardMaterial {
3435
base_color: material.base_color,
3536
base_color_channel: material.base_color_channel.clone(),

crates/bevy_pbr/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mod atmosphere;
2828
mod cluster;
2929
mod components;
3030
pub mod contact_shadows;
31+
#[cfg(feature = "bevy_gltf")]
3132
mod gltf;
3233
use bevy_render::sync_component::SyncComponent;
3334
pub use contact_shadows::{
@@ -224,6 +225,7 @@ impl Plugin for PbrPlugin {
224225
))
225226
.add_plugins((ScatteringMediumPlugin, AtmospherePlugin));
226227

228+
#[cfg(feature = "bevy_gltf")]
227229
if self.gltf_enable_standard_materials {
228230
gltf::add_gltf(app);
229231
}

release-content/migration-guides/gltf_pbr.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pull_requests: [22569]
55

66
Previously, `bevy_gltf` depended on `bevy_pbr`. This meant scene definition was tightly coupled to rendering. This dependency has been inverted, to allow `bevy_gltf` to function without any of the rendering stack present.
77

8+
`bevy_gltf` is also an optional dependency.
9+
810
In 0.18, loading a material sub-asset would return a `Handle<StandardMaterial>`.
911

1012
```rs

0 commit comments

Comments
 (0)