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

feat: implement required components #115

Merged
merged 6 commits into from
Feb 11, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This release supports Bevy version 0.14 and has an [MSRV][] of 1.80.
- The license on bevy_vello no longer includes OFL 1.1
- The `experimental-dotLottie` feature was removed and merged into the `lottie` feature.
- `DotLottiePlayer` was renamed to `LottiePlayer`.
- All render types (`VelloSvgHandle`, `VelloLottieHandle`, `VelloScene`, and `VelloTextSection`) now have required components as an alternative to their bundle counterparts.

### Fixed

Expand Down
20 changes: 4 additions & 16 deletions examples/drag_n_drop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ fn button_system(
};
let handle = asset_server.add(svg);
commands.trigger(CleanupEvent);
commands.spawn(VelloSvgBundle {
asset: VelloSvgHandle(handle),
..default()
});
commands.spawn(VelloSvgHandle(handle));
} else if file_name.ends_with(".json") {
let lottie = match bevy_vello::integrations::lottie::load_lottie_from_bytes(&file) {
Ok(lottie) => lottie,
Expand All @@ -130,10 +127,7 @@ fn button_system(
};
let handle = asset_server.add(lottie);
commands.trigger(CleanupEvent);
commands.spawn(VelloLottieBundle {
asset: VelloLottieHandle(handle),
..default()
});
commands.spawn(VelloLottieHandle(handle));
}
}
}
Expand All @@ -156,16 +150,10 @@ fn drag_and_drop(
let lottie_ext = OsStr::new("json");
if ext == svg_ext {
commands.trigger(CleanupEvent);
commands.spawn(VelloSvgBundle {
asset: VelloSvgHandle(asset_server.load(path_buf.clone())),
..default()
});
commands.spawn(VelloSvgHandle(asset_server.load(path_buf.clone())));
} else if ext == lottie_ext {
commands.trigger(CleanupEvent);
commands.spawn(VelloLottieBundle {
asset: VelloLottieHandle(asset_server.load(path_buf.clone())),
..default()
});
commands.spawn(VelloLottieHandle(asset_server.load(path_buf.clone())));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/headless/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn setup(mut commands: Commands) {
None,
&kurbo::Circle::new((0.0, 0.0), 50.0),
);
commands.spawn(VelloSceneBundle { scene, ..default() });
commands.spawn(scene);
}

fn screenshot(mut commands: Commands) {
Expand Down
13 changes: 6 additions & 7 deletions examples/lottie/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ fn main() {
fn load_lottie(mut commands: Commands, asset_server: ResMut<AssetServer>) {
commands.spawn((Camera2d, VelloView));

// Yes, it's this simple.
commands.spawn(VelloLottieBundle {
asset: VelloLottieHandle(asset_server.load("embedded://lottie/assets/Tiger.json")),
debug_visualizations: DebugVisualizations::Visible,
transform: Transform::from_scale(Vec3::splat(0.5)),
..default()
});
// You can also use `VelloLottieBundle`
commands
.spawn(VelloLottieHandle(
asset_server.load("embedded://lottie/assets/Tiger.json"),
))
.insert(Transform::from_scale(Vec3::splat(0.5)));
}
12 changes: 2 additions & 10 deletions examples/render_layers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,8 @@ fn setup_scene(mut commands: Commands) {
VelloView,
));

commands.spawn((
VelloSceneBundle::default(),
BackgroundScene,
RenderLayers::layer(1),
));
commands.spawn((
VelloSceneBundle::default(),
AnimationScene,
RenderLayers::layer(2),
));
commands.spawn((VelloScene::new(), BackgroundScene, RenderLayers::layer(1)));
commands.spawn((VelloScene::new(), AnimationScene, RenderLayers::layer(2)));
}

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

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

fn simple_animation(mut query_scene: Single<(&mut Transform, &mut VelloScene)>, time: Res<Time>) {
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 @@ -30,7 +30,7 @@ fn setup_ui(mut commands: Commands) {
},
BorderColor(css::FUCHSIA.with_alpha(0.5).into()),
Interaction::default(),
VelloScene::default(),
VelloScene::new(),
CoordinateSpace::ScreenSpace,
));
}
Expand Down
13 changes: 6 additions & 7 deletions examples/svg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ fn main() {
fn load_svg(mut commands: Commands, asset_server: ResMut<AssetServer>) {
commands.spawn((Camera2d, VelloView));

// Yes, it's this simple.
commands.spawn(VelloSvgBundle {
asset: VelloSvgHandle(asset_server.load("embedded://svg/assets/fountain.svg")),
debug_visualizations: DebugVisualizations::Visible,
transform: Transform::from_scale(Vec3::splat(5.0)),
..default()
});
// You can also use `VelloSvgBundle`
commands
.spawn(VelloSvgHandle(
asset_server.load("embedded://svg/assets/fountain.svg"),
))
.insert(Transform::from_scale(Vec3::splat(5.0)));
}
13 changes: 5 additions & 8 deletions examples/text/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ fn setup_camera(mut commands: Commands) {
}

fn setup_worldspace_text(mut commands: Commands, asset_server: ResMut<AssetServer>) {
commands.spawn(VelloTextBundle {
text: VelloTextSection {
commands
.spawn(VelloTextSection {
value: "Default font\nand multi-line support.".to_string(),
..default()
},
text_anchor: VelloTextAnchor::Center,
transform: Transform::from_xyz(0.0, 100.0, 0.0),
debug_visualizations: DebugVisualizations::Visible,
..default()
});
})
.insert(DebugVisualizations::Visible)
.insert(VelloTextAnchor::Center);

commands.spawn(VelloTextBundle {
text: VelloTextSection {
Expand Down
13 changes: 11 additions & 2 deletions src/integrations/lottie/asset.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use super::{LottiePlayer, PlaybackOptions, Playhead};
use crate::prelude::*;
use bevy::{prelude::*, reflect::TypePath};
use std::sync::Arc;

#[derive(Component, Default, Debug, Clone, Deref, DerefMut, PartialEq, Eq)]
#[require(Playhead, PlaybackOptions, LottiePlayer)]
#[require(
VelloLottieAnchor,
CoordinateSpace,
Playhead,
PlaybackOptions,
LottiePlayer,
Transform,
DebugVisualizations,
Visibility
)]
pub struct VelloLottieHandle(pub Handle<VelloLottie>);

#[derive(Asset, TypePath, Clone)]
Expand Down
6 changes: 6 additions & 0 deletions src/integrations/lottie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ pub struct VelloLottieBundle {
pub asset_anchor: VelloLottieAnchor,
/// The coordinate space in which this vector should be rendered.
pub coordinate_space: CoordinateSpace,
/// The current playhead for the animation
pub playhead: Playhead,
/// The playback options for the animation
pub playback_options: PlaybackOptions,
/// The player used for advanced state machine transitions and playback control.
pub player: LottiePlayer,
/// A transform to apply to this vector
pub transform: Transform,
/// Whether to render debug visualizations
Expand Down
8 changes: 8 additions & 0 deletions src/integrations/svg/asset.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
use crate::prelude::*;
use bevy::{prelude::*, reflect::TypePath};
use std::sync::Arc;

#[derive(Component, Default, Debug, Clone, Deref, DerefMut, PartialEq, Eq)]
#[require(
VelloSvgAnchor,
CoordinateSpace,
Transform,
DebugVisualizations,
Visibility
)]
pub struct VelloSvgHandle(pub Handle<VelloSvg>);

#[derive(Asset, TypePath, Clone)]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct VelloTextBundle {

/// A simple newtype component wrapper for [`vello::Scene`] for rendering.
#[derive(Component, Default, Clone, Deref, DerefMut)]
#[require(CoordinateSpace, Transform, Visibility)]
pub struct VelloScene(vello::Scene);

impl VelloScene {
Expand Down
9 changes: 8 additions & 1 deletion src/text/vello_text.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use crate::VelloFont;
use crate::{debug::DebugVisualizations, CoordinateSpace, VelloFont};
use bevy::prelude::*;
use vello::peniko::{self, Brush};

#[derive(Component, Default, Clone)]
#[require(
VelloTextAnchor,
CoordinateSpace,
Transform,
DebugVisualizations,
Visibility
)]
pub struct VelloTextSection {
pub value: String,
pub style: VelloTextStyle,
Expand Down
Loading