From 89fbbed0af67ce4020928728750d5f8d546cbcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elie=20G=C3=A9nard?= Date: Tue, 10 Dec 2024 17:42:29 +0100 Subject: [PATCH 01/28] Upgrade bevy to v0.15.0 and fix build --- Cargo.toml | 12 ++++++---- examples/demo/Cargo.toml | 4 ++-- src/debug.rs | 29 +++++++++++++++---------- src/integrations/asset.rs | 6 ++++- src/integrations/dot_lottie/systems.rs | 6 ++--- src/integrations/lottie/asset_loader.rs | 10 ++++----- src/integrations/lottie/systems.rs | 22 +++++++++---------- src/integrations/lottie/theme.rs | 2 +- src/integrations/mod.rs | 2 +- src/integrations/svg/asset_loader.rs | 10 ++++----- src/lib.rs | 4 ++-- src/render/extract.rs | 14 ++++++------ src/render/mod.rs | 3 +++ src/render/plugin.rs | 4 ++-- src/render/systems.rs | 26 ++++++++++------------ src/text/font.rs | 9 +++----- src/text/font_loader.rs | 12 +++++----- src/text/vello_text.rs | 3 ++- 18 files changed, 96 insertions(+), 82 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 94b695c3..d84b10b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,10 @@ license = "(MIT OR Apache-2.0) AND OFL-1.1" repository = "https://github.com/linebender/bevy_vello" [workspace.dependencies] -bevy = { version = "0.14.0", default-features = false, features = [ +bevy = { version = "0.15.0", default-features = false, features = [ "bevy_asset", "bevy_winit", + "bevy_window", "bevy_core_pipeline", "bevy_pbr", "bevy_render", @@ -51,9 +52,12 @@ repository.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] bevy = { workspace = true } -vello = "0.2.1" -vello_svg = "0.3.0" -velato = "0.3.0" +# vello = "0.3.0" +vello = { git = "https://github.com/linebender/vello", rev = "2e2cb1601de7faa85cb3fa87cd03bac9ea10d233" } +# vello_svg = "0.5.0" +vello_svg = { git = "https://github.com/linebender/vello_svg", rev = "129542b8947558879b32b12356ebeed9e9f5cba0" } +# velato = "0.4.0" +velato = { git = "https://github.com/linebender/velato", rev = "2d6cd9516f93d662c6ea4096bbf837b8151dfc76" } thiserror = "1.0.61" once_cell = "1.19.0" diff --git a/examples/demo/Cargo.toml b/examples/demo/Cargo.toml index 2526f191..1c0dd285 100644 --- a/examples/demo/Cargo.toml +++ b/examples/demo/Cargo.toml @@ -10,5 +10,5 @@ publish = false [dependencies] bevy_vello = { path = "../../", features = ["experimental-dotLottie"] } bevy = { workspace = true } -bevy_pancam = { version = "0.12.0", features = ["bevy_egui"] } -bevy_egui = "0.28.0" +bevy_pancam = { version = "0.16.0", features = ["bevy_egui"] } +bevy_egui = "0.31.0" diff --git a/src/debug.rs b/src/debug.rs index d7f8bf2d..46fafb9f 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -1,7 +1,7 @@ //! Logic for rendering debug visualizations use crate::{ - text::VelloTextAnchor, CoordinateSpace, VelloAsset, VelloAssetAnchor, VelloFont, - VelloTextSection, + text::VelloTextAnchor, CoordinateSpace, VelloAsset, VelloAssetAnchor, VelloAssetHandle, + VelloFont, VelloTextSection, }; use bevy::{color::palettes::css, math::Vec3Swizzles, prelude::*}; @@ -27,7 +27,7 @@ pub enum DebugVisualizations { fn render_asset_debug( query_vectors: Query< ( - &Handle, + &VelloAssetHandle, &VelloAssetAnchor, &GlobalTransform, &CoordinateSpace, @@ -48,7 +48,7 @@ fn render_asset_debug( .iter() .filter(|(_, _, _, _, d)| **d == DebugVisualizations::Visible) { - if let Some(asset) = assets.get(asset) { + if let Some(asset) = assets.get(&asset.0) { match space { CoordinateSpace::WorldSpace => { // Origin @@ -63,14 +63,14 @@ fn render_asset_debug( CoordinateSpace::ScreenSpace => { // Origin let origin = gtransform.translation().xy(); - let Some(origin) = camera.viewport_to_world_2d(view, origin) else { + let Ok(origin) = camera.viewport_to_world_2d(view, origin) else { continue; }; draw_origin(&mut gizmos, projection, origin); // Bounding box let gtransform = &asset_anchor.compute(asset, gtransform); let rect_center = gtransform.translation().xy(); - let Some(rect_center) = camera.viewport_to_world_2d(view, rect_center) else { + let Ok(rect_center) = camera.viewport_to_world_2d(view, rect_center) else { continue; }; let Some(rect) = asset.bb_in_screen_space(gtransform, camera, view) else { @@ -148,13 +148,17 @@ fn render_text_debug( } }; let rect_center = origin + rect.size() / 2.0; - gizmos.rect_2d(rect_center, 0.0, rect.size(), css::WHITE); + gizmos.rect_2d( + Isometry2d::new(rect_center, Rot2::degrees(0.0)), + rect.size(), + css::WHITE, + ); } CoordinateSpace::ScreenSpace => { let Some(rect) = text.bb_in_screen_space(font, gtransform, camera, view) else { continue; }; - let Some(mut origin) = + let Ok(mut origin) = camera.viewport_to_world_2d(view, gtransform.translation().xy()) else { continue; @@ -195,8 +199,7 @@ fn render_text_debug( }; let rect_center = origin + Vec2::new(rect.width() / 2.0, -rect.height() / 2.0); gizmos.rect_2d( - rect_center, - 0.0, + Isometry2d::new(rect_center, Rot2::degrees(0.0)), rect.size() * Vec2::new(1.0, 1.0), css::WHITE, ); @@ -221,5 +224,9 @@ fn draw_origin(gizmos: &mut Gizmos, projection: &OrthographicProjection, origin: /// A helper method to draw the bounding box fn draw_bounding_box(gizmos: &mut Gizmos, position: Vec2, size: Vec2) { - gizmos.rect_2d(position, 0.0, size, css::WHITE); + gizmos.rect_2d( + Isometry2d::new(position, Rot2::degrees(0.0)), + size, + css::WHITE, + ); } diff --git a/src/integrations/asset.rs b/src/integrations/asset.rs index 4884e641..718c1639 100644 --- a/src/integrations/asset.rs +++ b/src/integrations/asset.rs @@ -1,6 +1,9 @@ use crate::VectorFile; use bevy::{prelude::*, reflect::TypePath}; +#[derive(Component, Default, Clone)] +pub struct VelloAssetHandle(pub Handle); + #[derive(Asset, TypePath, Clone)] pub struct VelloAsset { pub file: VectorFile, @@ -36,7 +39,8 @@ impl VelloAsset { let Rect { min, max } = self.bb_in_world_space(gtransform); camera .viewport_to_world_2d(camera_transform, min) - .zip(camera.viewport_to_world_2d(camera_transform, max)) + .ok() + .zip(camera.viewport_to_world_2d(camera_transform, max).ok()) .map(|(min, max)| Rect { min, max }) } } diff --git a/src/integrations/dot_lottie/systems.rs b/src/integrations/dot_lottie/systems.rs index 87564dbe..4d65af2c 100644 --- a/src/integrations/dot_lottie/systems.rs +++ b/src/integrations/dot_lottie/systems.rs @@ -1,7 +1,7 @@ use super::DotLottiePlayer; use crate::{ integrations::lottie::PlaybackPlayMode, PlaybackDirection, PlaybackLoopBehavior, - PlaybackOptions, PlayerTransition, Playhead, VectorFile, VelloAsset, + PlaybackOptions, PlayerTransition, Playhead, VectorFile, VelloAsset, VelloAssetHandle, }; use bevy::{prelude::*, utils::Instant}; use std::time::Duration; @@ -10,7 +10,7 @@ use vello_svg::usvg::strict_num::Ulps; /// Advance all the dotLottie playheads in the scene pub fn advance_dot_lottie_playheads( mut query: Query<( - &Handle, + &VelloAssetHandle, &mut Playhead, &mut DotLottiePlayer, &PlaybackOptions, @@ -139,7 +139,7 @@ pub fn run_transitions( &Playhead, &PlaybackOptions, &GlobalTransform, - &mut Handle, + &mut VelloAssetHandle, )>, mut assets: ResMut>, windows: Query<&Window>, diff --git a/src/integrations/lottie/asset_loader.rs b/src/integrations/lottie/asset_loader.rs index 3ec8c6b8..1d251e51 100644 --- a/src/integrations/lottie/asset_loader.rs +++ b/src/integrations/lottie/asset_loader.rs @@ -18,11 +18,11 @@ impl AssetLoader for VelloLottieLoader { type Error = VectorLoaderError; - fn load<'a>( - &'a self, - reader: &'a mut Reader, - _settings: &'a Self::Settings, - load_context: &'a mut LoadContext, + fn load( + & self, + reader: & mut dyn Reader, + _settings: & Self::Settings, + load_context: & mut LoadContext, ) -> impl ConditionalSendFuture> { Box::pin(async move { let mut bytes = Vec::new(); diff --git a/src/integrations/lottie/systems.rs b/src/integrations/lottie/systems.rs index ed8ea73e..d2d68887 100644 --- a/src/integrations/lottie/systems.rs +++ b/src/integrations/lottie/systems.rs @@ -1,6 +1,6 @@ use crate::{ integrations::lottie::PlaybackPlayMode, PlaybackDirection, PlaybackLoopBehavior, - PlaybackOptions, Playhead, VectorFile, VelloAsset, + PlaybackOptions, Playhead, VectorFile, VelloAsset, VelloAssetHandle, }; use bevy::{prelude::*, utils::Instant}; use std::time::Duration; @@ -9,7 +9,7 @@ use vello_svg::usvg::strict_num::Ulps; /// Spawn playheads for Lotties. Every Lottie gets exactly 1 playhead. pub fn spawn_playheads( mut commands: Commands, - query: Query<(Entity, &Handle, Option<&PlaybackOptions>), Without>, + query: Query<(Entity, &VelloAssetHandle, Option<&PlaybackOptions>), Without>, assets: Res>, ) { for (entity, handle, options) in query.iter() { @@ -18,7 +18,7 @@ pub fn spawn_playheads( file: _file @ VectorFile::Lottie(composition), .. }, - ) = assets.get(handle) + ) = assets.get(&handle.0) { let frame = match options { Some(options) => match options.direction { @@ -39,11 +39,11 @@ pub fn spawn_playheads( /// Advance all lottie playheads without playback options in the scene pub fn advance_playheads_without_options( #[cfg(feature = "experimental-dotLottie")] mut query: Query< - (&Handle, &mut Playhead), + (&VelloAssetHandle, &mut Playhead), (Without, Without), >, #[cfg(not(feature = "experimental-dotLottie"))] mut query: Query< - (&Handle, &mut Playhead), + (&VelloAssetHandle, &mut Playhead), Without, >, mut assets: ResMut>, @@ -54,7 +54,7 @@ pub fn advance_playheads_without_options( let Some(VelloAsset { file: VectorFile::Lottie(composition), .. - }) = assets.get_mut(asset_handle.id()) + }) = assets.get_mut(asset_handle.0.id()) else { continue; }; @@ -69,7 +69,7 @@ pub fn advance_playheads_without_options( // Advance playhead let length = end_frame - start_frame; - playhead.frame += (time.delta_seconds_f64() * composition.frame_rate) % length; + playhead.frame += (time.delta_secs_f64() * composition.frame_rate) % length; if playhead.frame > end_frame { // Wrap around to the beginning of the segment @@ -81,11 +81,11 @@ pub fn advance_playheads_without_options( /// Advance all lottie playheads with playback options in the scene pub fn advance_playheads_with_options( #[cfg(feature = "experimental-dotLottie")] mut query: Query< - (&Handle, &mut Playhead, &PlaybackOptions), + (&VelloAssetHandle, &mut Playhead, &PlaybackOptions), Without, >, #[cfg(not(feature = "experimental-dotLottie"))] mut query: Query<( - &Handle, + &VelloAssetHandle, &mut Playhead, &PlaybackOptions, )>, @@ -97,7 +97,7 @@ pub fn advance_playheads_with_options( let Some(VelloAsset { file: VectorFile::Lottie(composition), .. - }) = assets.get_mut(asset_handle.id()) + }) = assets.get_mut(asset_handle.0.id()) else { continue; }; @@ -134,7 +134,7 @@ pub fn advance_playheads_with_options( // Advance playhead let length = end_frame - start_frame; - playhead.frame += (time.delta_seconds_f64() + playhead.frame += (time.delta_secs_f64() * options.speed * composition.frame_rate * (options.direction as i32 as f64) diff --git a/src/integrations/lottie/theme.rs b/src/integrations/lottie/theme.rs index a1af1a8a..d4bc1f0a 100644 --- a/src/integrations/lottie/theme.rs +++ b/src/integrations/lottie/theme.rs @@ -67,7 +67,7 @@ impl Theme { // TODO: Vello hasn't fully implemented color spaces yet, so I'm very unsure of // which color space to use here. let target_color = target_color.to_linear(); - let target_color = vello::peniko::Color::rgba( + let target_color = vello::peniko::Color::from_rgba8( target_color.red as _, target_color.green as _, target_color.blue as _, diff --git a/src/integrations/mod.rs b/src/integrations/mod.rs index 632c66a2..ad4ddf73 100644 --- a/src/integrations/mod.rs +++ b/src/integrations/mod.rs @@ -18,7 +18,7 @@ mod error; pub use error::VectorLoaderError; mod asset; -pub use asset::{VelloAsset, VelloAssetAnchor}; +pub use asset::{VelloAsset, VelloAssetAnchor, VelloAssetHandle}; #[derive(Clone)] pub enum VectorFile { diff --git a/src/integrations/svg/asset_loader.rs b/src/integrations/svg/asset_loader.rs index 644cab7d..ff8a0cf5 100644 --- a/src/integrations/svg/asset_loader.rs +++ b/src/integrations/svg/asset_loader.rs @@ -18,11 +18,11 @@ impl AssetLoader for VelloSvgLoader { type Error = VectorLoaderError; - fn load<'a>( - &'a self, - reader: &'a mut Reader, - _settings: &'a Self::Settings, - load_context: &'a mut LoadContext, + fn load( + & self, + reader: & mut dyn Reader, + _settings: & Self::Settings, + load_context: & mut LoadContext, ) -> impl ConditionalSendFuture> { Box::pin(async move { let mut bytes = Vec::new(); diff --git a/src/lib.rs b/src/lib.rs index 60a37dcf..aa63bd81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,7 @@ pub mod prelude { pub use crate::{ debug::DebugVisualizations, - integrations::{VectorFile, VelloAsset, VelloAssetAnchor}, + integrations::{VectorFile, VelloAsset, VelloAssetAnchor, VelloAssetHandle}, render::{SkipEncoding, VelloRenderSettings}, text::{VelloFont, VelloTextAnchor, VelloTextSection, VelloTextStyle}, CoordinateSpace, VelloAssetBundle, VelloScene, VelloSceneBundle, VelloTextBundle, @@ -50,7 +50,7 @@ pub enum CoordinateSpace { #[derive(Bundle, Default)] pub struct VelloAssetBundle { /// Asset data to render - pub asset: Handle, + pub asset: VelloAssetHandle, /// How the asset is positioned relative to its [`Transform`]. pub asset_anchor: VelloAssetAnchor, /// The coordinate space in which this vector should be rendered. diff --git a/src/render/extract.rs b/src/render/extract.rs index 68fd37de..6203c336 100644 --- a/src/render/extract.rs +++ b/src/render/extract.rs @@ -11,7 +11,7 @@ pub struct ExtractedRenderAsset { pub asset_anchor: VelloAssetAnchor, pub transform: GlobalTransform, pub render_mode: CoordinateSpace, - pub ui_node: Option, + pub ui_node: Option, pub render_layers: Option, pub alpha: f32, #[cfg(feature = "lottie")] @@ -26,11 +26,11 @@ pub fn extract_svg_assets( query_vectors: Extract< Query< ( - &Handle, + &VelloAssetHandle, &VelloAssetAnchor, &CoordinateSpace, &GlobalTransform, - Option<&Node>, + Option<&ComputedNode>, Option<&RenderLayers>, &ViewVisibility, &InheritedVisibility, @@ -84,13 +84,13 @@ pub fn extract_lottie_assets( query_vectors: Extract< Query< ( - &Handle, + &VelloAssetHandle, &VelloAssetAnchor, &CoordinateSpace, &GlobalTransform, &crate::Playhead, Option<&crate::Theme>, - Option<&Node>, + Option<&ComputedNode>, Option<&RenderLayers>, &ViewVisibility, &InheritedVisibility, @@ -144,7 +144,7 @@ pub struct ExtractedRenderScene { pub scene: VelloScene, pub transform: GlobalTransform, pub render_mode: CoordinateSpace, - pub ui_node: Option, + pub ui_node: Option, pub render_layers: Option, } @@ -158,7 +158,7 @@ pub fn extract_scenes( &GlobalTransform, &ViewVisibility, &InheritedVisibility, - Option<&Node>, + Option<&ComputedNode>, Option<&RenderLayers>, ), Without, diff --git a/src/render/mod.rs b/src/render/mod.rs index 8ed57cb3..b3205440 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -26,6 +26,9 @@ pub(crate) use plugin::VelloRenderPlugin; /// A handle to the screen space render target shader. pub const SSRT_SHADER_HANDLE: Handle = Handle::weak_from_u128(2314894693238056781); +#[derive(Component, Clone)] +pub struct VelloCanvasMaterialHandle(Handle); + /// A canvas material, with a shader that samples a texture with view-independent UV coordinates. #[derive(AsBindGroup, TypePath, Asset, Clone)] pub struct VelloCanvasMaterial { diff --git a/src/render/plugin.rs b/src/render/plugin.rs index 0fb258c1..3ccb35d4 100644 --- a/src/render/plugin.rs +++ b/src/render/plugin.rs @@ -4,7 +4,7 @@ use super::{ }; use crate::{ render::{VelloCanvasMaterial, VelloRenderer, SSRT_SHADER_HANDLE}, - VelloAsset, VelloFont, VelloScene, VelloTextSection, + VelloAssetHandle, VelloFont, VelloScene, VelloTextSection, }; use bevy::{ asset::load_internal_asset, @@ -95,7 +95,7 @@ impl Plugin for VelloRenderPlugin { check_visibility::< Or<( With, - With>, + With, With, )>, > diff --git a/src/render/systems.rs b/src/render/systems.rs index 4afab4e1..e7717663 100644 --- a/src/render/systems.rs +++ b/src/render/systems.rs @@ -1,11 +1,12 @@ use super::{ extract::{ExtractedRenderAsset, ExtractedRenderText, SSRenderTarget}, prepare::PreparedAffine, - VelloCanvasMaterial, VelloCanvasSettings, VelloRenderSettings, VelloRenderer, + VelloCanvasMaterial, VelloCanvasMaterialHandle, VelloCanvasSettings, VelloRenderSettings, + VelloRenderer, }; use crate::{ - render::extract::ExtractedRenderScene, CoordinateSpace, VelloAsset, VelloFont, VelloScene, - VelloTextSection, + render::extract::ExtractedRenderScene, CoordinateSpace, VelloAssetHandle, VelloFont, + VelloScene, VelloTextSection, }; use bevy::{ prelude::*, @@ -21,7 +22,7 @@ use bevy::{ texture::GpuImage, view::{NoFrustumCulling, RenderLayers}, }, - sprite::{MaterialMesh2dBundle, Mesh2dHandle}, + sprite::MeshMaterial2d, window::{WindowResized, WindowResolution}, }; use vello::{kurbo::Affine, RenderParams, Scene}; @@ -244,7 +245,7 @@ pub fn render_frame( pub fn resize_rendertargets( mut window_resize_events: EventReader, - mut query: Query<(&mut SSRenderTarget, &Handle)>, + mut query: Query<(&mut SSRenderTarget, &mut VelloCanvasMaterialHandle)>, mut images: ResMut>, mut target_materials: ResMut>, windows: Query<&Window>, @@ -261,9 +262,9 @@ pub fn resize_rendertargets( if size.width == 0 || size.height == 0 { return; } - for (mut target, target_mat_handle) in query.iter_mut() { + for (mut target, mut target_mat_handle) in query.iter_mut() { let image = setup_image(&mut images, &window.resolution); - if let Some(mat) = target_materials.get_mut(target_mat_handle) { + if let Some(mat) = target_materials.get_mut(&mut target_mat_handle.0) { target.0 = image.clone(); mat.texture = image; } @@ -315,17 +316,14 @@ pub fn setup_ss_rendertarget( }); let texture_image = setup_image(&mut images, &window.resolution); let render_target = SSRenderTarget(texture_image.clone()); - let mesh = Mesh2dHandle(mesh_handle.clone()); + let mesh = Mesh2d(mesh_handle.clone()); let material = custom_materials.add(VelloCanvasMaterial { texture: texture_image, }); commands - .spawn(MaterialMesh2dBundle { - mesh, - material, - ..default() - }) + .spawn(mesh) + .insert(MeshMaterial2d(material)) .insert(NoFrustumCulling) .insert(render_target) .insert(settings.render_layers.clone()); @@ -351,7 +349,7 @@ pub fn hide_when_empty( (), Or<( With, - With>, + With, With, )>, >, diff --git a/src/text/font.rs b/src/text/font.rs index c83f6886..5da2bc9b 100644 --- a/src/text/font.rs +++ b/src/text/font.rs @@ -2,13 +2,10 @@ use super::{vello_text::VelloTextSection, VelloTextAnchor}; use bevy::{prelude::*, reflect::TypePath, render::render_asset::RenderAsset}; use std::sync::Arc; use vello::{ - glyph::{ - skrifa::{FontRef, MetadataProvider}, - Glyph, - }, kurbo::Affine, peniko::{self, Blob, Font}, - Scene, + skrifa::{FontRef, MetadataProvider}, + Glyph, Scene, }; const VARIATIONS: &[(&str, f32)] = &[]; @@ -105,7 +102,7 @@ impl VelloFont { pen_x += advance; width = width.max(pen_x); Some(Glyph { - id: gid.to_u16() as u32, + id: gid.to_u32(), x, y: pen_y, }) diff --git a/src/text/font_loader.rs b/src/text/font_loader.rs index 05bbcda5..9acdb786 100644 --- a/src/text/font_loader.rs +++ b/src/text/font_loader.rs @@ -1,7 +1,7 @@ use super::font::VelloFont; use crate::integrations::VectorLoaderError; use bevy::{ - asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext}, + asset::{io::Reader, AssetLoader, LoadContext}, utils::ConditionalSendFuture, }; @@ -15,11 +15,11 @@ impl AssetLoader for VelloFontLoader { type Error = VectorLoaderError; - fn load<'a>( - &'a self, - reader: &'a mut Reader, - _settings: &'a Self::Settings, - _load_context: &'a mut LoadContext, + fn load( + & self, + reader: & mut dyn Reader, + _settings: & Self::Settings, + _load_context: & mut LoadContext, ) -> impl ConditionalSendFuture> { Box::pin(async move { let mut bytes = Vec::new(); diff --git a/src/text/vello_text.rs b/src/text/vello_text.rs index 192b009b..54ee812e 100644 --- a/src/text/vello_text.rs +++ b/src/text/vello_text.rs @@ -80,7 +80,8 @@ impl VelloTextSection { let Rect { min, max } = self.bb_in_world_space(font, gtransform); camera .viewport_to_world_2d(camera_transform, min) - .zip(camera.viewport_to_world_2d(camera_transform, max)) + .ok() + .zip(camera.viewport_to_world_2d(camera_transform, max).ok()) .map(|(min, max)| Rect { min, max }) } } From 6ca64468fb772c162c71eeb82329a5988f9fd2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elie=20G=C3=A9nard?= Date: Tue, 10 Dec 2024 18:19:28 +0100 Subject: [PATCH 02/28] Fix examples with default features build --- examples/cube3d/src/main.rs | 35 ++++++++++++++---------------- examples/render_layers/src/main.rs | 26 ++++++++++------------ examples/scene/src/main.rs | 6 ++--- examples/scene_ui/src/main.rs | 29 +++++++++++-------------- examples/text/src/main.rs | 23 +++++++++----------- 5 files changed, 53 insertions(+), 66 deletions(-) diff --git a/examples/cube3d/src/main.rs b/examples/cube3d/src/main.rs index 60ad858f..191fcb06 100644 --- a/examples/cube3d/src/main.rs +++ b/examples/cube3d/src/main.rs @@ -97,24 +97,21 @@ fn setup( }); // Main pass cube, with material containing the rendered first pass texture. commands.spawn(( - PbrBundle { - mesh: meshes.add(Cuboid::new(4.0, 4.0, 4.0)), - material: material_handle, - transform: Transform::from_xyz(0.0, 0.0, 1.5) - .with_rotation(Quat::from_rotation_x(-std::f32::consts::PI / 5.0)), - ..default() - }, + Mesh3d(meshes.add(Cuboid::new(4.0, 4.0, 4.0))), + MeshMaterial3d(material_handle), + Transform::from_xyz(0.0, 0.0, 1.5) + .with_rotation(Quat::from_rotation_x(-std::f32::consts::PI / 5.0)), MainPassCube, )); // The main pass camera. - commands.spawn(PointLightBundle { - transform: Transform::from_translation(Vec3::new(0.0, 0.0, 10.0)), - ..default() - }); - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(0.0, 0.0, 15.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); + commands + .spawn(PointLight::default()) + .insert(Transform::from_translation(Vec3::new(0.0, 0.0, 10.0))); + + commands + .spawn(Camera3d::default()) + .insert(Transform::from_xyz(0.0, 0.0, 15.0).looking_at(Vec3::ZERO, Vec3::Y)); + commands.spawn(VelloTarget(image_handle)); } @@ -131,7 +128,7 @@ fn render_texture( let mut scene = VelloScene::default(); // Animate the scene - let sin_time = time.elapsed_seconds().sin().mul_add(0.5, 0.5); + let sin_time = time.elapsed_secs().sin().mul_add(0.5, 0.5); let c = Vec3::lerp( Vec3::new(-1.0, 0.0, 1.0), Vec3::new(1.0, 0.0, 1.0), @@ -140,7 +137,7 @@ fn render_texture( scene.fill( peniko::Fill::NonZero, kurbo::Affine::translate((128.0, 128.0)), - peniko::Color::rgb(c.x as f64, c.y as f64, c.z as f64), + peniko::Color::new([c.x, c.y, c.z, 1.]), None, &kurbo::RoundedRect::new(0.0, 0.0, 256.0, 256.0, (sin_time as f64) * 128.0), ); @@ -168,7 +165,7 @@ fn render_texture( /// Rotates the outer cube (main pass) fn cube_rotator_system(time: Res