Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau committed Mar 26, 2024
1 parent 8130962 commit 5a6c38c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
3 changes: 0 additions & 3 deletions examples/scene/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ publish = false
[dependencies]
bevy_vello = { path = "../../" }
bevy = { workspace = true }
bevy_pancam = { version = "0.11", features = ["bevy_egui"] }
bevy_egui = "0.25"
console_error_panic_hook = "0.1"
5 changes: 1 addition & 4 deletions examples/scene/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
use bevy::asset::AssetMetaCheck;
use bevy::prelude::*;
use bevy_egui::EguiPlugin;
use bevy_vello::prelude::*;
use bevy_vello::vello::{kurbo, peniko};

fn main() {
let mut app = App::new();
app.insert_resource(AssetMetaCheck::Never)
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
.add_plugins(VelloPlugin)
.add_plugins(bevy_pancam::PanCamPlugin)
.add_systems(Startup, setup_vector_graphics)
.add_systems(Update, simple_animation);
app.run();
}

fn setup_vector_graphics(mut commands: Commands) {
commands.spawn((Camera2dBundle::default(), bevy_pancam::PanCam::default()));
commands.spawn(Camera2dBundle::default());
commands.spawn(VelloSceneBundle {
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
..default()
Expand Down
13 changes: 7 additions & 6 deletions src/render/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ pub fn render_scene(
let mut scene = Scene::new();

enum RenderItem<'a> {
Vector(&'a ExtractedRenderAsset),
Asset(&'a ExtractedRenderAsset),
Scene(&'a ExtractedRenderScene),
Text(&'a ExtractedRenderText),
}
let mut render_queue: Vec<(f32, CoordinateSpace, (&PreparedAffine, RenderItem))> =
render_vectors
.iter()
.map(|(a, b)| (b.z_index, b.render_mode, (a, RenderItem::Vector(b))))
.map(|(a, b)| (b.z_index, b.render_mode, (a, RenderItem::Asset(b))))
.collect();
render_queue.extend(query_render_texts.iter().map(|(a, b)| {
(
Expand Down Expand Up @@ -111,7 +111,7 @@ pub fn render_scene(
// scene to be rendered
for (_, _, (&PreparedAffine(affine), render_item)) in render_queue.iter_mut() {
match render_item {
RenderItem::Vector(ExtractedRenderAsset {
RenderItem::Asset(ExtractedRenderAsset {
asset,
theme,
alpha,
Expand Down Expand Up @@ -150,11 +150,12 @@ pub fn render_scene(
}
}

// TODO: Vello should be ignoring 0-sized buffers in the future, so this could go away.
// Prevent a panic in the vello renderer if all the items contain empty encoding data
let empty_encodings = render_queue
.iter()
.filter(|(_, _, (_, it))| match it {
RenderItem::Vector(a) => match &a.asset.data {
.filter(|(_, _, (_, item))| match item {
RenderItem::Asset(a) => match &a.asset.data {
VectorFile::Svg { scene: svg, .. } => svg.encoding().is_empty(),
VectorFile::Lottie { composition } => composition.layers.is_empty(),
},
Expand All @@ -173,7 +174,7 @@ pub fn render_scene(
&scene,
&gpu_image.texture_view,
&RenderParams {
base_color: vello::peniko::Color::BLACK.with_alpha_factor(0.0),
base_color: vello::peniko::Color::TRANSPARENT,
width: gpu_image.size.x as u32,
height: gpu_image.size.y as u32,
antialiasing_method: vello::AaConfig::Area,
Expand Down

0 comments on commit 5a6c38c

Please sign in to comment.