Skip to content

Commit 8986355

Browse files
committed
Add DisableGizmos
1 parent 469a19c commit 8986355

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

crates/bevy_gizmos/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ use bevy_reflect::{
3838
};
3939
use bevy_render::{
4040
color::Color,
41-
extract_component::{ComponentUniforms, DynamicUniformIndex, UniformComponentPlugin},
41+
extract_component::{
42+
ComponentUniforms, DynamicUniformIndex, ExtractComponent, ExtractComponentPlugin,
43+
UniformComponentPlugin,
44+
},
4245
primitives::Aabb,
4346
render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets},
4447
render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass},
@@ -80,7 +83,10 @@ impl Plugin for GizmoPlugin {
8083

8184
app.add_plugins(UniformComponentPlugin::<LineGizmoUniform>::default())
8285
.add_asset::<LineGizmo>()
83-
.add_plugins(RenderAssetPlugin::<LineGizmo>::default())
86+
.add_plugins((
87+
RenderAssetPlugin::<LineGizmo>::default(),
88+
ExtractComponentPlugin::<DisableGizmos>::default(),
89+
))
8490
.init_resource::<LineGizmoHandles>()
8591
.init_resource::<GizmoConfig>()
8692
.init_resource::<GizmoStorage>()
@@ -127,6 +133,10 @@ impl Plugin for GizmoPlugin {
127133
}
128134
}
129135

136+
/// Cameras with this component will not render gizmos.
137+
#[derive(Component, Clone, ExtractComponent)]
138+
pub struct DisableGizmos;
139+
130140
/// A [`Resource`] that stores configuration for gizmos.
131141
#[derive(Resource, Clone)]
132142
pub struct GizmoConfig {

crates/bevy_gizmos/src/pipeline_2d.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use crate::{
2-
line_gizmo_vertex_buffer_layouts, DrawLineGizmo, LineGizmo, LineGizmoUniformBindgroupLayout,
3-
SetLineGizmoBindGroup, LINE_SHADER_HANDLE,
2+
line_gizmo_vertex_buffer_layouts, DisableGizmos, DrawLineGizmo, LineGizmo,
3+
LineGizmoUniformBindgroupLayout, SetLineGizmoBindGroup, LINE_SHADER_HANDLE,
44
};
55
use bevy_app::{App, Plugin};
66
use bevy_asset::Handle;
77
use bevy_core_pipeline::core_2d::Transparent2d;
88

99
use bevy_ecs::{
1010
prelude::Entity,
11+
query::Without,
1112
schedule::IntoSystemConfigs,
1213
system::{Query, Res, ResMut, Resource},
1314
world::{FromWorld, World},
@@ -133,7 +134,7 @@ fn queue_line_gizmos_2d(
133134
msaa: Res<Msaa>,
134135
line_gizmos: Query<(Entity, &Handle<LineGizmo>)>,
135136
line_gizmo_assets: Res<RenderAssets<LineGizmo>>,
136-
mut views: Query<(&ExtractedView, &mut RenderPhase<Transparent2d>)>,
137+
mut views: Query<(&ExtractedView, &mut RenderPhase<Transparent2d>), Without<DisableGizmos>>,
137138
) {
138139
let draw_function = draw_functions.read().get_id::<DrawLineGizmo2d>().unwrap();
139140

crates/bevy_gizmos/src/pipeline_3d.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
line_gizmo_vertex_buffer_layouts, DrawLineGizmo, GizmoConfig, LineGizmo,
2+
line_gizmo_vertex_buffer_layouts, DisableGizmos, DrawLineGizmo, GizmoConfig, LineGizmo,
33
LineGizmoUniformBindgroupLayout, SetLineGizmoBindGroup, LINE_SHADER_HANDLE,
44
};
55
use bevy_app::{App, Plugin};
@@ -8,6 +8,7 @@ use bevy_core_pipeline::core_3d::Transparent3d;
88

99
use bevy_ecs::{
1010
prelude::Entity,
11+
query::Without,
1112
schedule::IntoSystemConfigs,
1213
system::{Query, Res, ResMut, Resource},
1314
world::{FromWorld, World},
@@ -159,7 +160,7 @@ fn queue_line_gizmos_3d(
159160
config: Res<GizmoConfig>,
160161
line_gizmos: Query<(Entity, &Handle<LineGizmo>)>,
161162
line_gizmo_assets: Res<RenderAssets<LineGizmo>>,
162-
mut views: Query<(&ExtractedView, &mut RenderPhase<Transparent3d>)>,
163+
mut views: Query<(&ExtractedView, &mut RenderPhase<Transparent3d>), Without<DisableGizmos>>,
163164
) {
164165
let draw_function = draw_functions.read().get_id::<DrawLineGizmo3d>().unwrap();
165166

0 commit comments

Comments
 (0)