Stop using Handle<T> as a component in bevy_gizmos (#15713)

# Objective

- Another step towards removing the `Component` impl on `Handle<T>`

## Solution

- Yeet
This commit is contained in:
Tim 2024-10-07 22:57:26 +00:00 committed by GitHub
parent 91bed8ce51
commit bef44d7ac2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 46 deletions

View file

@ -1,13 +1,13 @@
//! A module for the [`GizmoConfig<T>`] [`Resource`].
use crate as bevy_gizmos;
use crate::{self as bevy_gizmos};
pub use bevy_gizmos_macros::GizmoConfigGroup;
#[cfg(all(
feature = "bevy_render",
any(feature = "bevy_pbr", feature = "bevy_sprite")
))]
use bevy_ecs::component::Component;
use {crate::LineGizmo, bevy_asset::Handle, bevy_ecs::component::Component};
use bevy_ecs::{reflect::ReflectResource, system::Resource};
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath};
@ -201,18 +201,5 @@ pub(crate) struct GizmoMeshConfig {
pub line_perspective: bool,
pub line_style: GizmoLineStyle,
pub render_layers: bevy_render::view::RenderLayers,
}
#[cfg(all(
feature = "bevy_render",
any(feature = "bevy_pbr", feature = "bevy_sprite")
))]
impl From<&GizmoConfig> for GizmoMeshConfig {
fn from(item: &GizmoConfig) -> Self {
GizmoMeshConfig {
line_perspective: item.line_perspective,
line_style: item.line_style,
render_layers: item.render_layers.clone(),
}
}
pub handle: Handle<LineGizmo>,
}

View file

@ -83,6 +83,8 @@ use bevy_ecs::{
use bevy_math::Vec3;
use bevy_reflect::TypePath;
use crate::config::GizmoMeshConfig;
#[cfg(feature = "bevy_render")]
use {
bevy_ecs::{
@ -456,9 +458,13 @@ fn extract_gizmo_data(
#[cfg(feature = "webgl")]
_padding: Default::default(),
},
(*handle).clone_weak(),
#[cfg(any(feature = "bevy_pbr", feature = "bevy_sprite"))]
config::GizmoMeshConfig::from(config),
GizmoMeshConfig {
line_perspective: config.line_perspective,
line_style: config.line_style,
render_layers: config.render_layers.clone(),
handle: handle.clone(),
},
TemporaryRenderEntity,
));
}
@ -598,20 +604,20 @@ struct DrawLineGizmo;
impl<P: PhaseItem> RenderCommand<P> for DrawLineGizmo {
type Param = SRes<RenderAssets<GpuLineGizmo>>;
type ViewQuery = ();
type ItemQuery = Read<Handle<LineGizmo>>;
type ItemQuery = Read<GizmoMeshConfig>;
#[inline]
fn render<'w>(
_item: &P,
_view: ROQueryItem<'w, Self::ViewQuery>,
handle: Option<ROQueryItem<'w, Self::ItemQuery>>,
config: Option<ROQueryItem<'w, Self::ItemQuery>>,
line_gizmos: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let Some(handle) = handle else {
let Some(config) = config else {
return RenderCommandResult::Skip;
};
let Some(line_gizmo) = line_gizmos.into_inner().get(handle) else {
let Some(line_gizmo) = line_gizmos.into_inner().get(&config.handle) else {
return RenderCommandResult::Skip;
};
@ -651,20 +657,20 @@ struct DrawLineJointGizmo;
impl<P: PhaseItem> RenderCommand<P> for DrawLineJointGizmo {
type Param = SRes<RenderAssets<GpuLineGizmo>>;
type ViewQuery = ();
type ItemQuery = Read<Handle<LineGizmo>>;
type ItemQuery = Read<GizmoMeshConfig>;
#[inline]
fn render<'w>(
_item: &P,
_view: ROQueryItem<'w, Self::ViewQuery>,
handle: Option<ROQueryItem<'w, Self::ItemQuery>>,
config: Option<ROQueryItem<'w, Self::ItemQuery>>,
line_gizmos: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let Some(handle) = handle else {
let Some(config) = config else {
return RenderCommandResult::Skip;
};
let Some(line_gizmo) = line_gizmos.into_inner().get(handle) else {
let Some(line_gizmo) = line_gizmos.into_inner().get(&config.handle) else {
return RenderCommandResult::Skip;
};

View file

@ -1,12 +1,10 @@
use crate::{
config::{GizmoLineJoint, GizmoLineStyle, GizmoMeshConfig},
line_gizmo_vertex_buffer_layouts, line_joint_gizmo_vertex_buffer_layouts, DrawLineGizmo,
DrawLineJointGizmo, GizmoRenderSystem, GpuLineGizmo, LineGizmo,
LineGizmoUniformBindgroupLayout, SetLineGizmoBindGroup, LINE_JOINT_SHADER_HANDLE,
LINE_SHADER_HANDLE,
DrawLineJointGizmo, GizmoRenderSystem, GpuLineGizmo, LineGizmoUniformBindgroupLayout,
SetLineGizmoBindGroup, LINE_JOINT_SHADER_HANDLE, LINE_SHADER_HANDLE,
};
use bevy_app::{App, Plugin};
use bevy_asset::Handle;
use bevy_core_pipeline::core_2d::{Transparent2d, CORE_2D_DEPTH_FORMAT};
use bevy_ecs::{
@ -285,7 +283,7 @@ fn queue_line_gizmos_2d(
pipeline: Res<LineGizmoPipeline>,
mut pipelines: ResMut<SpecializedRenderPipelines<LineGizmoPipeline>>,
pipeline_cache: Res<PipelineCache>,
line_gizmos: Query<(Entity, &Handle<LineGizmo>, &GizmoMeshConfig)>,
line_gizmos: Query<(Entity, &GizmoMeshConfig)>,
line_gizmo_assets: Res<RenderAssets<GpuLineGizmo>>,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent2d>>,
mut views: Query<(Entity, &ExtractedView, &Msaa, Option<&RenderLayers>)>,
@ -301,12 +299,12 @@ fn queue_line_gizmos_2d(
| Mesh2dPipelineKey::from_hdr(view.hdr);
let render_layers = render_layers.unwrap_or_default();
for (entity, handle, config) in &line_gizmos {
for (entity, config) in &line_gizmos {
if !config.render_layers.intersects(render_layers) {
continue;
}
let Some(line_gizmo) = line_gizmo_assets.get(handle) else {
let Some(line_gizmo) = line_gizmo_assets.get(&config.handle) else {
continue;
};
@ -338,7 +336,7 @@ fn queue_line_joint_gizmos_2d(
pipeline: Res<LineJointGizmoPipeline>,
mut pipelines: ResMut<SpecializedRenderPipelines<LineJointGizmoPipeline>>,
pipeline_cache: Res<PipelineCache>,
line_gizmos: Query<(Entity, &Handle<LineGizmo>, &GizmoMeshConfig)>,
line_gizmos: Query<(Entity, &GizmoMeshConfig)>,
line_gizmo_assets: Res<RenderAssets<GpuLineGizmo>>,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent2d>>,
mut views: Query<(Entity, &ExtractedView, &Msaa, Option<&RenderLayers>)>,
@ -357,12 +355,12 @@ fn queue_line_joint_gizmos_2d(
| Mesh2dPipelineKey::from_hdr(view.hdr);
let render_layers = render_layers.unwrap_or_default();
for (entity, handle, config) in &line_gizmos {
for (entity, config) in &line_gizmos {
if !config.render_layers.intersects(render_layers) {
continue;
}
let Some(line_gizmo) = line_gizmo_assets.get(handle) else {
let Some(line_gizmo) = line_gizmo_assets.get(&config.handle) else {
continue;
};

View file

@ -1,12 +1,10 @@
use crate::{
config::{GizmoLineJoint, GizmoLineStyle, GizmoMeshConfig},
line_gizmo_vertex_buffer_layouts, line_joint_gizmo_vertex_buffer_layouts, DrawLineGizmo,
DrawLineJointGizmo, GizmoRenderSystem, GpuLineGizmo, LineGizmo,
LineGizmoUniformBindgroupLayout, SetLineGizmoBindGroup, LINE_JOINT_SHADER_HANDLE,
LINE_SHADER_HANDLE,
DrawLineJointGizmo, GizmoRenderSystem, GpuLineGizmo, LineGizmoUniformBindgroupLayout,
SetLineGizmoBindGroup, LINE_JOINT_SHADER_HANDLE, LINE_SHADER_HANDLE,
};
use bevy_app::{App, Plugin};
use bevy_asset::Handle;
use bevy_core_pipeline::{
core_3d::{Transparent3d, CORE_3D_DEPTH_FORMAT},
prepass::{DeferredPrepass, DepthPrepass, MotionVectorPrepass, NormalPrepass},
@ -280,7 +278,7 @@ fn queue_line_gizmos_3d(
pipeline: Res<LineGizmoPipeline>,
mut pipelines: ResMut<SpecializedRenderPipelines<LineGizmoPipeline>>,
pipeline_cache: Res<PipelineCache>,
line_gizmos: Query<(Entity, &Handle<LineGizmo>, &GizmoMeshConfig)>,
line_gizmos: Query<(Entity, &GizmoMeshConfig)>,
line_gizmo_assets: Res<RenderAssets<GpuLineGizmo>>,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent3d>>,
mut views: Query<(
@ -331,12 +329,12 @@ fn queue_line_gizmos_3d(
view_key |= MeshPipelineKey::DEFERRED_PREPASS;
}
for (entity, handle, config) in &line_gizmos {
for (entity, config) in &line_gizmos {
if !config.render_layers.intersects(render_layers) {
continue;
}
let Some(line_gizmo) = line_gizmo_assets.get(handle) else {
let Some(line_gizmo) = line_gizmo_assets.get(&config.handle) else {
continue;
};
@ -369,7 +367,7 @@ fn queue_line_joint_gizmos_3d(
pipeline: Res<LineJointGizmoPipeline>,
mut pipelines: ResMut<SpecializedRenderPipelines<LineJointGizmoPipeline>>,
pipeline_cache: Res<PipelineCache>,
line_gizmos: Query<(Entity, &Handle<LineGizmo>, &GizmoMeshConfig)>,
line_gizmos: Query<(Entity, &GizmoMeshConfig)>,
line_gizmo_assets: Res<RenderAssets<GpuLineGizmo>>,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent3d>>,
mut views: Query<(
@ -423,12 +421,12 @@ fn queue_line_joint_gizmos_3d(
view_key |= MeshPipelineKey::DEFERRED_PREPASS;
}
for (entity, handle, config) in &line_gizmos {
for (entity, config) in &line_gizmos {
if !config.render_layers.intersects(render_layers) {
continue;
}
let Some(line_gizmo) = line_gizmo_assets.get(handle) else {
let Some(line_gizmo) = line_gizmo_assets.get(&config.handle) else {
continue;
};