Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass RenderLayers to VelloCanvas #71

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/cube3d/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<VelloTarget>::default());
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
..default()
}))
.add_plugins(EguiPlugin)
.add_plugins(VelloPlugin)
.add_plugins(VelloPlugin::default())
.init_resource::<EmbeddedAssetRegistry>()
.add_plugins(bevy_pancam::PanCamPlugin)
.add_systems(Startup, setup_vector_graphics)
Expand Down
2 changes: 1 addition & 1 deletion examples/drag_n_drop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion examples/lottie/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/render_layers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_vello::{prelude::*, VelloPlugin};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(VelloPlugin)
.add_plugins(VelloPlugin::default())
.add_systems(Startup, (setup_animation, setup_background))
.add_systems(
Update,
Expand Down
2 changes: 1 addition & 1 deletion examples/scene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy_vello::{
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(VelloPlugin)
.add_plugins(VelloPlugin::default())
.add_systems(Startup, setup_vector_graphics)
.add_systems(Update, simple_animation)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/scene_ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::f64::consts::{FRAC_PI_4, SQRT_2};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(VelloPlugin)
.add_plugins(VelloPlugin::default())
.add_systems(Startup, setup_ui)
.add_systems(Update, update_ui)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/svg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
meta_check: AssetMetaCheck::Never,
..default()
}))
.add_plugins(VelloPlugin)
.add_plugins(VelloPlugin::default())
.add_systems(Startup, load_svg);
embedded_asset!(app, "assets/fountain.svg");
app.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/text/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
meta_check: AssetMetaCheck::Never,
..default()
}))
.add_plugins(VelloPlugin)
.add_plugins(VelloPlugin::default())
.add_systems(
Startup,
(setup_camera, setup_screenspace_text, setup_worldspace_text),
Expand Down
19 changes: 12 additions & 7 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ use crate::{
debug::DebugVisualizationsPlugin, render::VelloRenderPlugin, text::VelloFontLoader, VelloAsset,
VelloFont,
};
use bevy::{asset::load_internal_binary_asset, prelude::*};
use bevy::{asset::load_internal_binary_asset, prelude::*, render::view::RenderLayers};

pub struct VelloPlugin;
#[derive(Default)]
pub struct VelloPlugin {
pub canvas_render_layers: Option<RenderLayers>,
}

impl Plugin for VelloPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(VelloRenderPlugin)
.add_plugins(DebugVisualizationsPlugin)
.init_asset::<VelloAsset>()
.init_asset::<VelloFont>()
.init_asset_loader::<VelloFontLoader>();
app.add_plugins(VelloRenderPlugin {
canvas_render_layers: self.canvas_render_layers.clone(),
})
.add_plugins(DebugVisualizationsPlugin)
.init_asset::<VelloAsset>()
.init_asset::<VelloFont>()
.init_asset_loader::<VelloFontLoader>();
#[cfg(feature = "svg")]
app.add_plugins(crate::integrations::svg::SvgIntegrationPlugin);
#[cfg(feature = "lottie")]
Expand Down
10 changes: 8 additions & 2 deletions src/render/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ use bevy::{
extract_component::ExtractComponentPlugin,
render_asset::RenderAssetPlugin,
renderer::RenderDevice,
view::{check_visibility, VisibilitySystems},
view::{check_visibility, RenderLayers, VisibilitySystems},
Render, RenderApp, RenderSet,
},
sprite::Material2dPlugin,
};

pub struct VelloRenderPlugin;
#[derive(Resource, Default, Clone)]
pub struct VelloRenderPlugin {
/// the render layer that will be used for the vello canvas mesh
pub canvas_render_layers: Option<RenderLayers>,
}

impl Plugin for VelloRenderPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(self.clone());
ChristopherBiscardi marked this conversation as resolved.
Show resolved Hide resolved

load_internal_asset!(
app,
SSRT_SHADER_HANDLE,
Expand Down
12 changes: 9 additions & 3 deletions src/render/systems.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
extract::{ExtractedRenderAsset, ExtractedRenderText, SSRenderTarget},
prepare::PreparedAffine,
VelloRenderer,
VelloRenderPlugin, VelloRenderer,
};
use crate::{
render::extract::ExtractedRenderScene, CoordinateSpace, VelloAsset, VelloCanvasMaterial,
Expand Down Expand Up @@ -282,6 +282,7 @@ pub fn setup_ss_rendertarget(
mut custom_materials: ResMut<Assets<VelloCanvasMaterial>>,
windows: Query<&Window>,
mut render_target_mesh_handle: Local<Option<Handle<Mesh>>>,
config: Res<VelloRenderPlugin>,
) {
let Ok(window) = windows.get_single() else {
return;
Expand Down Expand Up @@ -317,7 +318,7 @@ pub fn setup_ss_rendertarget(
texture: texture_image,
});

commands
let entity = commands
.spawn(MaterialMesh2dBundle {
mesh,
material,
Expand All @@ -327,7 +328,12 @@ pub fn setup_ss_rendertarget(
..Default::default()
})
.insert(NoFrustumCulling)
.insert(render_target);
.insert(render_target)
.id();

if let Some(layer) = &config.canvas_render_layers {
commands.entity(entity).insert(layer.clone());
}
}

/// Hide the render target canvas if there is nothing to render
Expand Down
Loading