From 36b95866ad91a21f7bac61b112612026946dd548 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Sat, 3 Aug 2024 20:25:07 -0400 Subject: [PATCH] fix: canvas layer changes, refactor to plugin settings --- CHANGELOG.md | 1 + 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 | 112 +++++++++++++---------------- 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/lib.rs | 2 +- src/plugin.rs | 12 +++- src/render/plugin.rs | 12 ++-- src/render/systems.rs | 29 +++++--- 14 files changed, 96 insertions(+), 88 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e00d0..48b02c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe ### Changed +- `VelloPlugin` now has configuration. To retain previous behavior, use `VelloPlugin::default()`. - The font API has changed significantly. Please visit `examples/text` for further usage. This is to prepare for additional text features such as linebreak behavior, bounded text, and text justification. - `VelloText` has been renamed to `VelloTextSection`. - `VelloText.content` has been renamed to `VelloText.value`. diff --git a/examples/cube3d/src/main.rs b/examples/cube3d/src/main.rs index 6940bcf..11cf294 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) + .add_plugins(VelloPlugin::default()) .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 533b625..4eedd25 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) + .add_plugins(VelloPlugin::default()) .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 9424b82..0bca583 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) + .add_plugins(VelloPlugin::default()) .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 4a0d30c..f3e3306 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) + .add_plugins(VelloPlugin::default()) .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 95dc339..84a328a 100644 --- a/examples/render_layers/src/main.rs +++ b/examples/render_layers/src/main.rs @@ -6,55 +6,71 @@ use bevy_vello::{prelude::*, VelloPlugin}; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugins(VelloPlugin) - .add_systems(Startup, (setup_animation, setup_background)) + .add_plugins(VelloPlugin::default()) .add_systems( - Update, + Startup, ( - layer0_animation, - layer1_animation, - layer2_background, - run_gizmos, + setup_canvas, + setup_gizmos, + setup_animation, + setup_background, ), ) + .add_systems(Update, (animation, background, run_gizmos)) .run(); } -/// A tag that will mark the scene on RenderLayer 0. +/// A tag that will mark the scene with animation. #[derive(Component)] -struct Layer0Scene; +struct AnimationScene; -/// A tag that will mark the scene on RenderLayer 1. +/// A tag that will mark the scene with the blue square. #[derive(Component)] -struct Layer1Scene; +struct BackgroundScene; -/// A tag that will mark the scene on RenderLayer 2. -#[derive(Component)] -struct Layer2Scene; +fn setup_canvas(mut settings: ResMut) { + // There's only 1 Vello canvas, so as long as you use a layer that has a camera, you're good! + settings.canvas_render_layers = RenderLayers::layer(3); // the gizmo camera layer +} -fn setup_animation(mut commands: Commands) { - const LAYER_0: RenderLayers = RenderLayers::layer(0); - const LAYER_1: RenderLayers = RenderLayers::layer(1); +fn setup_gizmos(mut commands: Commands, mut config_store: ResMut) { + // This camera can only see Gizmos. + commands.spawn(( + Camera2dBundle { + camera: Camera { + // This camera will render LAST. + order: 1, + ..default() + }, + ..default() + }, + RenderLayers::layer(3), + )); + let (config, _) = config_store.config_mut::(); + config.render_layers = RenderLayers::layer(3); +} - // This camera can see everything on Layer 1 and Layer 2. +fn setup_animation(mut commands: Commands) { commands.spawn(( Camera2dBundle { camera: Camera { // This camera will render AFTER the blue background camera! - order: 1, + order: 0, ..default() }, ..default() }, - LAYER_0.union(&LAYER_1), + RenderLayers::layer(2), )); - commands.spawn((VelloSceneBundle::default(), Layer0Scene, LAYER_0)); - commands.spawn((VelloSceneBundle::default(), Layer1Scene, LAYER_1)); + commands.spawn(( + VelloSceneBundle::default(), + AnimationScene, + RenderLayers::layer(2), + )); } fn setup_background(mut commands: Commands) { - const LAYER: RenderLayers = RenderLayers::layer(2); commands.spawn(( Camera2dBundle { camera: Camera { @@ -64,13 +80,17 @@ fn setup_background(mut commands: Commands) { }, ..default() }, - LAYER, + RenderLayers::layer(1), + )); + commands.spawn(( + VelloSceneBundle::default(), + BackgroundScene, + RenderLayers::layer(1), )); - commands.spawn((VelloSceneBundle::default(), Layer2Scene, LAYER)); } -fn layer0_animation( - mut query_scene: Query<(&mut Transform, &mut VelloScene), With>, +fn animation( + mut query_scene: Query<(&mut Transform, &mut VelloScene), With>, time: Res