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

Require a VelloView marker for cameras rendering Vello graphics #85

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ You can find its changes [documented below](#061---2024-08-14).

This release supports Bevy version 0.14 and has an [MSRV][] of 1.80.

### Added

- Added `VelloView` marker component used for identifying cameras rendering vello content.

### Changed

- bevy_vello now uses Bevy 0.15
- `Camera2d` now requires a `VelloView` marker for rendering.
- `VelloAsset` assets have been separated into `VelloSvg` and `VelloLottie`
- `VelloAssetBundle` has been separated into `VelloSvgBundle` and `VelloLottieBundle`
- `Handle<VelloAsset>` has been separated into `VelloSvgHandle` and `VelloLottieHandle`
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 @@ -25,7 +25,7 @@ fn main() {
}

fn setup_vector_graphics(mut commands: Commands, asset_server: ResMut<AssetServer>) {
commands.spawn((Camera2d, bevy_pancam::PanCam::default()));
commands.spawn((Camera2d, bevy_pancam::PanCam::default(), VelloView));
commands
.spawn(VelloLottieBundle {
asset: VelloLottieHandle(asset_server.load("embedded://demo/assets/calendar.json")),
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 @@ -19,7 +19,7 @@ fn main() {
}

fn setup_vector_graphics(mut commands: Commands, asset_server: ResMut<AssetServer>) {
commands.spawn(Camera2d);
commands.spawn((Camera2d, VelloView));

commands.spawn(VelloSvgBundle {
asset: VelloSvgHandle(asset_server.load("embedded://drag_n_drop/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 @@ -17,7 +17,7 @@ fn main() {
}

fn load_lottie(mut commands: Commands, asset_server: ResMut<AssetServer>) {
commands.spawn(Camera2d);
commands.spawn((Camera2d, VelloView));

// Yes, it's this simple.
commands.spawn(VelloLottieBundle {
Expand Down
2 changes: 2 additions & 0 deletions examples/render_layers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn setup_gizmos(mut commands: Commands, mut config_store: ResMut<GizmoConfigStor
..default()
},
RenderLayers::layer(3),
VelloView,
));
let (config, _) = config_store.config_mut::<DefaultGizmoConfigGroup>();
config.render_layers = RenderLayers::layer(3);
Expand All @@ -47,6 +48,7 @@ fn setup_scene(mut commands: Commands) {
..default()
},
RenderLayers::layer(1).with(2),
VelloView,
));

commands.spawn((
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 @@ -11,7 +11,7 @@ fn main() {
}

fn setup_vector_graphics(mut commands: Commands) {
commands.spawn(Camera2d);
commands.spawn((Camera2d, VelloView));
commands.spawn(VelloSceneBundle::default());
}

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 @@ -12,7 +12,7 @@ fn main() {
}

fn setup_ui(mut commands: Commands) {
commands.spawn(Camera2d);
commands.spawn((Camera2d, VelloView));

let one_third = Val::Percent(100.0 / 3.0);
commands.spawn((
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 @@ -17,7 +17,7 @@ fn main() {
}

fn load_svg(mut commands: Commands, asset_server: ResMut<AssetServer>) {
commands.spawn(Camera2d);
commands.spawn((Camera2d, VelloView));

// Yes, it's this simple.
commands.spawn(VelloSvgBundle {
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 @@ -20,7 +20,7 @@ fn main() {
}

fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2d);
commands.spawn((Camera2d, VelloView));
}

fn setup_worldspace_text(mut commands: Commands, asset_server: ResMut<AssetServer>) {
Expand Down
10 changes: 8 additions & 2 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ fn render_svg_debug(
Without<Node>,
>,
assets: Res<Assets<VelloSvg>>,
query_cam: Query<(&Camera, &GlobalTransform, &OrthographicProjection), With<Camera2d>>,
query_cam: Query<
(&Camera, &GlobalTransform, &OrthographicProjection),
(With<Camera2d>, With<VelloView>),
>,
mut gizmos: Gizmos,
) {
let Ok((camera, view, projection)) = query_cam.get_single() else {
Expand Down Expand Up @@ -162,7 +165,10 @@ fn render_text_debug(
),
Without<Node>,
>,
query_cam: Query<(&Camera, &GlobalTransform, &OrthographicProjection), With<Camera2d>>,
query_cam: Query<
(&Camera, &GlobalTransform, &OrthographicProjection),
(With<Camera2d>, With<VelloView>),
>,
fonts: Res<Assets<VelloFont>>,
mut gizmos: Gizmos,
) {
Expand Down
3 changes: 2 additions & 1 deletion src/integrations/dot_lottie/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
PlaybackPlayMode,
},
PlaybackDirection, PlaybackLoopBehavior, PlaybackOptions, PlayerTransition, Playhead,
VelloView,
};
use bevy::{prelude::*, utils::Instant};
use std::time::Duration;
Expand Down Expand Up @@ -146,7 +147,7 @@ pub fn run_transitions(
)>,
mut assets: ResMut<Assets<VelloLottie>>,
windows: Query<&Window>,
query_view: Query<(&Camera, &GlobalTransform), With<Camera2d>>,
query_view: Query<(&Camera, &GlobalTransform), (With<Camera2d>, With<VelloView>)>,
buttons: Res<ButtonInput<MouseButton>>,
mut hovered: Local<bool>,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod prelude {

pub use crate::{
debug::DebugVisualizations,
render::{SkipEncoding, VelloRenderSettings},
render::{SkipEncoding, VelloRenderSettings, VelloView},
text::{VelloFont, VelloTextAnchor, VelloTextSection, VelloTextStyle},
CoordinateSpace, VelloScene, VelloSceneBundle, VelloTextBundle,
};
Expand Down
5 changes: 5 additions & 0 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use bevy::{
prelude::*,
render::{
extract_component::ExtractComponent,
mesh::MeshVertexBufferLayoutRef,
render_resource::{
AsBindGroup, RenderPipelineDescriptor, ShaderRef, SpecializedMeshPipelineError,
Expand All @@ -27,6 +28,10 @@ pub(crate) use plugin::VelloRenderPlugin;
/// A handle to the screen space render target shader.
pub const SSRT_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(2314894693238056781);

/// A component that should be added to the camera that will render Vello assets.
#[derive(Component, Debug, Clone, Copy, ExtractComponent)]
pub struct VelloView;

/// A canvas material, with a shader that samples a texture with view-independent UV coordinates.
#[derive(AsBindGroup, TypePath, Asset, Clone)]
pub struct VelloCanvasMaterial {
Expand Down
4 changes: 3 additions & 1 deletion src/render/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
};
use crate::{
render::{VelloCanvasMaterial, VelloRenderer, SSRT_SHADER_HANDLE},
VelloFont, VelloScene, VelloTextSection,
VelloFont, VelloScene, VelloTextSection, VelloView,
};
use bevy::{
asset::load_internal_asset,
Expand Down Expand Up @@ -71,6 +71,8 @@ impl Plugin for VelloRenderPlugin {
.run_if(resource_exists::<RenderDevice>),
);

app.add_plugins(ExtractComponentPlugin::<VelloView>::default());

app.insert_resource(self.canvas_settings.clone())
.add_plugins((
Material2dPlugin::<VelloCanvasMaterial>::default(),
Expand Down
15 changes: 12 additions & 3 deletions src/render/prepare.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use super::extract::{ExtractedPixelScale, ExtractedRenderScene, ExtractedRenderText};
use super::{
extract::{ExtractedPixelScale, ExtractedRenderScene, ExtractedRenderText},
VelloView,
};
use crate::CoordinateSpace;
use bevy::{
prelude::*,
Expand Down Expand Up @@ -30,7 +33,10 @@ pub trait PrepareRenderInstance {

pub fn prepare_scene_affines(
mut commands: Commands,
views: Query<(&ExtractedCamera, &ExtractedView, Option<&RenderLayers>), With<Camera2d>>,
views: Query<
(&ExtractedCamera, &ExtractedView, Option<&RenderLayers>),
(With<Camera2d>, With<VelloView>),
>,
render_entities: Query<(Entity, &ExtractedRenderScene)>,
) {
for (camera, view, maybe_camera_layers) in views.iter() {
Expand Down Expand Up @@ -118,7 +124,10 @@ pub fn prepare_scene_affines(

pub fn prepare_text_affines(
mut commands: Commands,
views: Query<(&ExtractedCamera, &ExtractedView, Option<&RenderLayers>), With<Camera2d>>,
views: Query<
(&ExtractedCamera, &ExtractedView, Option<&RenderLayers>),
(With<Camera2d>, With<VelloView>),
>,
render_entities: Query<(Entity, &ExtractedRenderText)>,
pixel_scale: Res<ExtractedPixelScale>,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/render/systems.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
extract::{ExtractedRenderText, SSRenderTarget},
prepare::PreparedAffine,
VelloCanvasMaterial, VelloCanvasSettings, VelloRenderSettings, VelloRenderer,
VelloCanvasMaterial, VelloCanvasSettings, VelloRenderSettings, VelloRenderer, VelloView,
};
use crate::{
render::extract::ExtractedRenderScene, CoordinateSpace, VelloFont, VelloScene, VelloTextSection,
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn setup_image(images: &mut Assets<Image>, window: &WindowResolution) -> Han
#[allow(clippy::complexity)]
pub fn render_frame(
ss_render_target: Query<&SSRenderTarget>,
views: Query<(&ExtractedCamera, Option<&RenderLayers>), With<Camera2d>>,
views: Query<(&ExtractedCamera, Option<&RenderLayers>), (With<Camera2d>, With<VelloView>)>,
#[cfg(feature = "svg")] view_svgs: Query<(&PreparedAffine, &ExtractedSvgAsset)>,
#[cfg(feature = "lottie")] view_lotties: Query<(&PreparedAffine, &ExtractedLottieAsset)>,
#[cfg(feature = "lottie")] mut velato_renderer: ResMut<super::VelatoRenderer>,
Expand Down
Loading