From 52b2a5048cb30fe36f1b11733fc7877bff56d933 Mon Sep 17 00:00:00 2001 From: Christopher Biscardi Date: Sat, 3 Aug 2024 14:17:41 -0700 Subject: [PATCH] use a Resource instead --- examples/cube3d/src/main.rs | 2 +- examples/demo/src/main.rs | 2 +- examples/drag_n_drop/src/main.rs | 2 +- examples/lottie/src/main.rs | 2 +- examples/render_layers/src/main.rs | 2 +- examples/scene/src/main.rs | 2 +- examples/scene_ui/src/main.rs | 2 +- examples/svg/src/main.rs | 2 +- examples/text/src/main.rs | 2 +- src/plugin.rs | 18 +++++++----------- src/render/plugin.rs | 8 ++++---- src/render/systems.rs | 9 +++++---- 12 files changed, 25 insertions(+), 28 deletions(-) diff --git a/examples/cube3d/src/main.rs b/examples/cube3d/src/main.rs index 11cf294..6940bcf 100644 --- a/examples/cube3d/src/main.rs +++ b/examples/cube3d/src/main.rs @@ -33,7 +33,7 @@ fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins) - .add_plugins(VelloPlugin::default()) + .add_plugins(VelloPlugin) .add_systems(Startup, setup) .add_systems(Update, cube_rotator_system) .add_plugins(ExtractComponentPlugin::::default()); diff --git a/examples/demo/src/main.rs b/examples/demo/src/main.rs index 4eedd25..533b625 100644 --- a/examples/demo/src/main.rs +++ b/examples/demo/src/main.rs @@ -15,7 +15,7 @@ fn main() { ..default() })) .add_plugins(EguiPlugin) - .add_plugins(VelloPlugin::default()) + .add_plugins(VelloPlugin) .init_resource::() .add_plugins(bevy_pancam::PanCamPlugin) .add_systems(Startup, setup_vector_graphics) diff --git a/examples/drag_n_drop/src/main.rs b/examples/drag_n_drop/src/main.rs index 0bca583..9424b82 100644 --- a/examples/drag_n_drop/src/main.rs +++ b/examples/drag_n_drop/src/main.rs @@ -10,7 +10,7 @@ fn main() { meta_check: AssetMetaCheck::Never, ..default() })) - .add_plugins(VelloPlugin::default()) + .add_plugins(VelloPlugin) .add_systems(Startup, setup_vector_graphics) .add_systems(Update, drag_and_drop); embedded_asset!(app, "assets/fountain.svg"); diff --git a/examples/lottie/src/main.rs b/examples/lottie/src/main.rs index f3e3306..4a0d30c 100644 --- a/examples/lottie/src/main.rs +++ b/examples/lottie/src/main.rs @@ -10,7 +10,7 @@ fn main() { meta_check: AssetMetaCheck::Never, ..default() })) - .add_plugins(VelloPlugin::default()) + .add_plugins(VelloPlugin) .add_systems(Startup, load_lottie); embedded_asset!(app, "assets/Tiger.json"); app.run(); diff --git a/examples/render_layers/src/main.rs b/examples/render_layers/src/main.rs index 0f78f2d..95dc339 100644 --- a/examples/render_layers/src/main.rs +++ b/examples/render_layers/src/main.rs @@ -6,7 +6,7 @@ use bevy_vello::{prelude::*, VelloPlugin}; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugins(VelloPlugin::default()) + .add_plugins(VelloPlugin) .add_systems(Startup, (setup_animation, setup_background)) .add_systems( Update, diff --git a/examples/scene/src/main.rs b/examples/scene/src/main.rs index 95828b2..5266236 100644 --- a/examples/scene/src/main.rs +++ b/examples/scene/src/main.rs @@ -8,7 +8,7 @@ use bevy_vello::{ fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugins(VelloPlugin::default()) + .add_plugins(VelloPlugin) .add_systems(Startup, setup_vector_graphics) .add_systems(Update, simple_animation) .run(); diff --git a/examples/scene_ui/src/main.rs b/examples/scene_ui/src/main.rs index 6735c68..c78cc9d 100644 --- a/examples/scene_ui/src/main.rs +++ b/examples/scene_ui/src/main.rs @@ -5,7 +5,7 @@ use std::f64::consts::{FRAC_PI_4, SQRT_2}; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugins(VelloPlugin::default()) + .add_plugins(VelloPlugin) .add_systems(Startup, setup_ui) .add_systems(Update, update_ui) .run(); diff --git a/examples/svg/src/main.rs b/examples/svg/src/main.rs index 8db803e..91be0f9 100644 --- a/examples/svg/src/main.rs +++ b/examples/svg/src/main.rs @@ -10,7 +10,7 @@ fn main() { meta_check: AssetMetaCheck::Never, ..default() })) - .add_plugins(VelloPlugin::default()) + .add_plugins(VelloPlugin) .add_systems(Startup, load_svg); embedded_asset!(app, "assets/fountain.svg"); app.run(); diff --git a/examples/text/src/main.rs b/examples/text/src/main.rs index f152d0d..e7e857e 100644 --- a/examples/text/src/main.rs +++ b/examples/text/src/main.rs @@ -10,7 +10,7 @@ fn main() { meta_check: AssetMetaCheck::Never, ..default() })) - .add_plugins(VelloPlugin::default()) + .add_plugins(VelloPlugin) .add_systems( Startup, (setup_camera, setup_screenspace_text, setup_worldspace_text), diff --git a/src/plugin.rs b/src/plugin.rs index 33ff06e..347addc 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -2,22 +2,18 @@ use crate::{ debug::DebugVisualizationsPlugin, render::VelloRenderPlugin, text::VelloFontLoader, VelloAsset, VelloFont, }; -use bevy::{asset::load_internal_binary_asset, prelude::*, render::view::RenderLayers}; +use bevy::{asset::load_internal_binary_asset, prelude::*}; #[derive(Default)] -pub struct VelloPlugin { - pub canvas_render_layers: Option, -} +pub struct VelloPlugin; impl Plugin for VelloPlugin { fn build(&self, app: &mut App) { - app.add_plugins(VelloRenderPlugin { - canvas_render_layers: self.canvas_render_layers.clone(), - }) - .add_plugins(DebugVisualizationsPlugin) - .init_asset::() - .init_asset::() - .init_asset_loader::(); + app.add_plugins(VelloRenderPlugin) + .add_plugins(DebugVisualizationsPlugin) + .init_asset::() + .init_asset::() + .init_asset_loader::(); #[cfg(feature = "svg")] app.add_plugins(crate::integrations::svg::SvgIntegrationPlugin); #[cfg(feature = "lottie")] diff --git a/src/render/plugin.rs b/src/render/plugin.rs index 330c607..8f0aaf7 100644 --- a/src/render/plugin.rs +++ b/src/render/plugin.rs @@ -19,16 +19,16 @@ use bevy::{ sprite::Material2dPlugin, }; -#[derive(Resource, Default, Clone)] -pub struct VelloRenderPlugin { +pub struct VelloRenderPlugin; + +#[derive(Default, Resource, Clone)] +pub struct VelloRenderSettings { /// the render layer that will be used for the vello canvas mesh pub canvas_render_layers: Option, } impl Plugin for VelloRenderPlugin { fn build(&self, app: &mut App) { - app.insert_resource(self.clone()); - load_internal_asset!( app, SSRT_SHADER_HANDLE, diff --git a/src/render/systems.rs b/src/render/systems.rs index dbd2c77..78b4ee6 100644 --- a/src/render/systems.rs +++ b/src/render/systems.rs @@ -1,7 +1,8 @@ use super::{ extract::{ExtractedRenderAsset, ExtractedRenderText, SSRenderTarget}, + plugin::VelloRenderSettings, prepare::PreparedAffine, - VelloRenderPlugin, VelloRenderer, + VelloRenderer, }; use crate::{ render::extract::ExtractedRenderScene, CoordinateSpace, VelloAsset, VelloCanvasMaterial, @@ -282,7 +283,7 @@ pub fn setup_ss_rendertarget( mut custom_materials: ResMut>, windows: Query<&Window>, mut render_target_mesh_handle: Local>>, - config: Res, + config: Option>, ) { let Ok(window) = windows.get_single() else { return; @@ -331,8 +332,8 @@ pub fn setup_ss_rendertarget( .insert(render_target) .id(); - if let Some(layer) = &config.canvas_render_layers { - commands.entity(entity).insert(layer.clone()); + if let Some(layer) = config.and_then(|config| config.canvas_render_layers.clone()) { + commands.entity(entity).insert(layer); } }