From 73cee1842a9638aaeef4a456548a853033e8f29e Mon Sep 17 00:00:00 2001 From: Nixon Date: Fri, 27 Oct 2023 23:44:55 +0800 Subject: [PATCH 1/9] exp: cubic curve animation --- examples/with_bevy/src/main.rs | 124 +++++++++++++++++++++++---------- 1 file changed, 87 insertions(+), 37 deletions(-) diff --git a/examples/with_bevy/src/main.rs b/examples/with_bevy/src/main.rs index eb88c4872..61b3f1519 100644 --- a/examples/with_bevy/src/main.rs +++ b/examples/with_bevy/src/main.rs @@ -1,5 +1,5 @@ use bevy::render::{Render, RenderSet}; -use vello::kurbo::{Affine, Point, Rect}; +use vello::kurbo::{Affine, BezPath, PathEl, Point, Rect}; use vello::peniko::{Color, Fill, Gradient, Stroke}; use vello::{Renderer, RendererOptions, Scene, SceneBuilder, SceneFragment}; @@ -16,6 +16,18 @@ use bevy::{ }, }; +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .add_plugin(VelloPlugin) + .add_systems(Startup, setup) + .add_systems(Update, bevy::window::close_on_esc) + // .add_systems(Update, cube_rotator_system) + .add_plugin(ExtractComponentPlugin::::default()) + .add_systems(Update, render_fragment) + .run() +} + #[derive(Resource)] struct VelloRenderer(Renderer); @@ -38,7 +50,9 @@ struct VelloPlugin; impl Plugin for VelloPlugin { fn build(&self, app: &mut App) { - let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return }; + let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { + return; + }; render_app.init_resource::(); // This should probably use the render graph, but working out the dependencies there is awkward render_app.add_systems(Render, render_scenes.in_set(RenderSet::Render)); @@ -53,37 +67,33 @@ fn render_scenes( queue: Res, ) { for scene in &mut scenes { - let gpu_image = gpu_images.get(&scene.1).unwrap(); + let Some(gpu_image) = gpu_images.get(&scene.1) else { + continue; + }; + let params = vello::RenderParams { - base_color: vello::peniko::Color::AQUAMARINE, + base_color: vello::peniko::Color::TRANSPARENT, width: gpu_image.size.x as u32, height: gpu_image.size.y as u32, }; renderer .0 .render_to_texture( + // WGPU device.wgpu_device(), + // WGPU &*queue, + // Vello &scene.0, + // WGPU &gpu_image.texture_view, + // Vello ¶ms, ) .unwrap(); } } -fn main() { - App::new() - .add_plugins(DefaultPlugins) - .add_plugin(VelloPlugin) - .add_systems(Startup, setup) - .add_systems(Update, bevy::window::close_on_esc) - .add_systems(Update, cube_rotator_system) - .add_plugin(ExtractComponentPlugin::::default()) - .add_systems(Update, render_fragment) - .run() -} - // Marks the main pass cube, to which the texture is applied. #[derive(Component)] struct MainPassCube; @@ -198,36 +208,76 @@ fn cube_rotator_system(time: Res