Skip to content

Commit

Permalink
Make bevy_render optional
Browse files Browse the repository at this point in the history
  • Loading branch information
sytherax authored and jakobhellermann committed Jul 6, 2024
1 parent b18706c commit 0b1e058
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 35 deletions.
9 changes: 5 additions & 4 deletions crates/bevy-inspector-egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ categories = [
]

[features]
default = ["bevy_pbr"]
default = ["bevy_pbr", "bevy_render"]
bevy_render = ["dep:bevy_render", "dep:bevy_core_pipeline"]
highlight_changes = []

[dependencies]
Expand All @@ -35,9 +36,9 @@ bevy_time = { version = "0.14.0" }
bevy_utils = { version = "0.14.0" }
bevy_window = { version = "0.14.0" }

bevy_core_pipeline = { version = "0.14.0" }
bevy_pbr = { version = "0.14.0", optional = true }
bevy_render = { version = "0.14.0" }
bevy_render = { version = "0.14", optional = true }
bevy_core_pipeline = { version = "0.14", optional = true }
bevy_pbr = { version = "0.14", optional = true }

egui = "0.28"
bevy_egui = "0.28"
Expand Down
19 changes: 14 additions & 5 deletions crates/bevy-inspector-egui/src/inspector_egui_impls/bevy_impls.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
use bevy_asset::{Assets, Handle};
use bevy_color::{Color, Hsla, Hsva, Lcha, LinearRgba, Srgba};
use bevy_ecs::entity::Entity;
use bevy_ecs::world::CommandQueue;
use bevy_ecs::world::World;
use bevy_ecs::{entity::Entity, world::CommandQueue};
use bevy_render::mesh::Mesh;
use bevy_render::view::RenderLayers;
use egui::Color32;
use std::any::Any;

#[cfg(feature = "bevy_render")]
use ::{
bevy_asset::Assets, bevy_asset::Handle, bevy_render::mesh::Mesh,
bevy_render::view::RenderLayers,
};

#[cfg(feature = "bevy_render")]
use crate::bevy_inspector::errors::{dead_asset_handle, show_error};
use crate::{
bevy_inspector::errors::{dead_asset_handle, no_world_in_context, show_error},
bevy_inspector::errors::no_world_in_context,
egui_utils,
inspector_options::std_options::{EntityDisplay, EntityOptions},
reflect_inspector::{Context, InspectorUi},
Expand Down Expand Up @@ -79,6 +85,7 @@ impl InspectorPrimitive for Entity {
}
}

#[cfg(feature = "bevy_render")]
impl InspectorPrimitive for Handle<Mesh> {
fn ui(
&mut self,
Expand Down Expand Up @@ -140,6 +147,7 @@ impl InspectorPrimitive for Handle<Mesh> {
}
}

#[cfg(feature = "bevy_render")]
fn mesh_ui_inner(mesh: &Mesh, ui: &mut egui::Ui) {
egui::Grid::new("mesh").show(ui, |ui| {
ui.label("primitive_topology");
Expand Down Expand Up @@ -279,6 +287,7 @@ impl InspectorPrimitive for Color {
}
}

#[cfg(feature = "bevy_render")]
impl InspectorPrimitive for RenderLayers {
fn ui(&mut self, ui: &mut egui::Ui, _: &dyn Any, id: egui::Id, _: InspectorUi<'_, '_>) -> bool {
let mut new_value = None;
Expand Down
11 changes: 8 additions & 3 deletions crates/bevy-inspector-egui/src/inspector_egui_impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{

mod bevy_impls;
mod glam_impls;
#[cfg(feature = "bevy_render")]
mod image;
mod std_impls;

Expand Down Expand Up @@ -306,11 +307,15 @@ pub fn register_glam_impls(type_registry: &mut TypeRegistry) {
/// Register [`InspectorEguiImpl`]s for `bevy` types
#[rustfmt::skip]
pub fn register_bevy_impls(type_registry: &mut TypeRegistry) {
add_of_with_many::<bevy_asset::Handle<bevy_render::texture::Image>>(type_registry, many_unimplemented::<bevy_asset::Handle<bevy_render::texture::Image>>);
add_of_with_many::<bevy_asset::Handle<bevy_render::mesh::Mesh>>(type_registry, many_unimplemented::<bevy_asset::Handle<bevy_render::mesh::Mesh>>);
add_of_with_many::<bevy_ecs::entity::Entity>(type_registry, many_unimplemented::<bevy_ecs::entity::Entity>);
add::<bevy_color::Color>(type_registry);
add::<bevy_render::view::RenderLayers>(type_registry);

#[cfg(feature = "bevy_render")]
{
// add_of_with_many::<bevy_asset::Handle<bevy_render::texture::Image>>(type_registry, many_unimplemented::<bevy_asset::Handle<bevy_render::texture::Image>>);
// add_of_with_many::<bevy_asset::Handle<bevy_render::mesh::Mesh>>(type_registry, many_unimplemented::<bevy_asset::Handle<bevy_render::mesh::Mesh>>);
add::<bevy_render::view::RenderLayers>(type_registry);
}
}

pub(crate) fn change_slider<T>(
Expand Down
51 changes: 28 additions & 23 deletions crates/bevy-inspector-egui/src/inspector_options/default_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn insert_options_struct<T: 'static>(
}
}

#[allow(dead_code)]
fn insert_options_enum<T: 'static>(
type_registry: &mut TypeRegistry,
fields: &[(&'static str, &'static str, &dyn TypeData)],
Expand Down Expand Up @@ -154,30 +155,33 @@ pub fn register_default_options(type_registry: &mut TypeRegistry) {
],
);

#[rustfmt::skip]
insert_options_struct::<bevy_render::view::ColorGradingSection>(
type_registry,
&[
("saturation", &NumberOptions::<f32>::positive().with_speed(0.01)),
("contrast", &NumberOptions::<f32>::positive().with_speed(0.01)),
("gamma", &NumberOptions::<f32>::positive().with_speed(0.01)),
("gain", &NumberOptions::<f32>::positive().with_speed(0.01)),
("lift", &NumberOptions::<f32>::positive().with_speed(0.01)),
],
);
#[cfg(feature = "bevy_render")]
{
#[rustfmt::skip]
insert_options_struct::<bevy_render::view::ColorGradingSection>(
type_registry,
&[
("saturation", &NumberOptions::<f32>::positive().with_speed(0.01)),
("contrast", &NumberOptions::<f32>::positive().with_speed(0.01)),
("gamma", &NumberOptions::<f32>::positive().with_speed(0.01)),
("gain", &NumberOptions::<f32>::positive().with_speed(0.01)),
("lift", &NumberOptions::<f32>::positive().with_speed(0.01)),
],
);

#[rustfmt::skip]
insert_options_struct::<bevy_render::view::ColorGradingGlobal>(
type_registry,
&[
("exposure", &NumberOptions::<f32>::positive().with_speed(0.01)),
("temperature", &NumberOptions::<f32>::positive().with_speed(0.01)),
("tint", &NumberOptions::<f32>::positive().with_speed(0.01)),
("hue", &NumberOptions::<f32>::positive().with_speed(0.01)),
("post_saturation", &NumberOptions::<f32>::positive().with_speed(0.01)),
("midtones_range", &NumberOptions::<f32>::positive().with_speed(0.01)),
],
);
#[rustfmt::skip]
insert_options_struct::<bevy_render::view::ColorGradingGlobal>(
type_registry,
&[
("exposure", &NumberOptions::<f32>::positive().with_speed(0.01)),
("temperature", &NumberOptions::<f32>::positive().with_speed(0.01)),
("tint", &NumberOptions::<f32>::positive().with_speed(0.01)),
("hue", &NumberOptions::<f32>::positive().with_speed(0.01)),
("post_saturation", &NumberOptions::<f32>::positive().with_speed(0.01)),
("midtones_range", &NumberOptions::<f32>::positive().with_speed(0.01)),
],
);
}

#[cfg(feature = "bevy_pbr")]
{
Expand Down Expand Up @@ -228,6 +232,7 @@ pub fn register_default_options(type_registry: &mut TypeRegistry) {
}

#[rustfmt::skip]
#[cfg(feature = "bevy_render")]
insert_options_enum::<bevy_core_pipeline::core_3d::Camera3dDepthLoadOp>(
type_registry,
&[
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy-inspector-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
pub mod bevy_inspector;
pub mod inspector_egui_impls;
pub mod inspector_options;
#[cfg(feature = "bevy_render")]
pub mod quick;
pub mod reflect_inspector;
pub mod restricted_world_view;
Expand All @@ -145,6 +146,7 @@ pub mod dropdown;
mod egui_utils;
mod utils;

#[cfg(feature = "bevy_render")]
pub use bevy_egui;
pub use egui;

Expand Down

0 comments on commit 0b1e058

Please sign in to comment.