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

Simbleau/bevy 0.15 #88

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 8 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# LINEBENDER LINT SET - .clippy.toml - v1
# See https://linebender.org/wiki/canonical-lints/
# The default Clippy value is capped at 8 bytes, which was chosen to improve performance on 32-bit.
# Given that we are building for the future and even low-end mobile phones have 64-bit CPUs,
# it makes sense to optimize for 64-bit and accept the performance hits on 32-bit.
# 16 bytes is the number of bytes that fits into two 64-bit CPU registers.
trivial-copy-size-limit = 16
# END LINEBENDER LINT SET
71 changes: 65 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ 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_core_pipeline",
"bevy_window",
"bevy_pbr",
"bevy_render",
"bevy_ui",
Expand Down Expand Up @@ -52,17 +53,75 @@ repository.workspace = true
[dependencies]
bevy = { workspace = true }
vello = "0.2.1"
vello_svg = "0.3.0"
velato = "0.3.0"
thiserror = "1.0.61"
once_cell = "1.19.0"
vello_svg = "0.3.1"
velato = "0.3.1"
thiserror = "2.0.6"
once_cell = "1.20.2"

[dev-dependencies]
wasm-bindgen-test = "0.3.42"
wasm-bindgen-test = "0.3.49"

[features]
default = ["default_font"]
svg = []
lottie = []
experimental-dotLottie = ["lottie"]
default_font = []


[workspace.lints]
# LINEBENDER LINT SET - Cargo.toml - v2
# See https://linebender.org/wiki/canonical-lints/
rust.keyword_idents_2024 = "forbid"
rust.non_ascii_idents = "forbid"
rust.non_local_definitions = "forbid"
rust.unsafe_op_in_unsafe_fn = "forbid"
rust.elided_lifetimes_in_paths = "warn"
rust.let_underscore_drop = "warn"
rust.missing_debug_implementations = "warn"
rust.missing_docs = "warn"
rust.single_use_lifetimes = "warn"
rust.trivial_numeric_casts = "warn"
rust.unexpected_cfgs = "warn"
rust.unit_bindings = "warn"
rust.unnameable_types = "warn"
rust.unreachable_pub = "warn"
rust.unused_import_braces = "warn"
rust.unused_lifetimes = "warn"
rust.unused_macro_rules = "warn"
rust.unused_qualifications = "warn"
rust.variant_size_differences = "warn"
clippy.allow_attributes = "warn"
clippy.allow_attributes_without_reason = "warn"
clippy.cast_possible_truncation = "warn"
clippy.collection_is_never_read = "warn"
clippy.dbg_macro = "warn"
clippy.debug_assert_with_mut_call = "warn"
clippy.doc_markdown = "warn"
clippy.exhaustive_enums = "warn"
clippy.fn_to_numeric_cast_any = "forbid"
clippy.infinite_loop = "warn"
clippy.large_include_file = "warn"
clippy.large_stack_arrays = "warn"
clippy.match_same_arms = "warn"
clippy.mismatching_type_param_order = "warn"
clippy.missing_assert_message = "warn"
clippy.missing_errors_doc = "warn"
clippy.missing_fields_in_debug = "warn"
clippy.missing_panics_doc = "warn"
clippy.partial_pub_fields = "warn"
clippy.return_self_not_must_use = "warn"
clippy.same_functions_in_if_condition = "warn"
clippy.semicolon_if_nothing_returned = "warn"
clippy.shadow_unrelated = "warn"
clippy.should_panic_without_expect = "warn"
clippy.todo = "warn"
clippy.trivially_copy_pass_by_ref = "warn"
clippy.unseparated_literal_suffix = "warn"
clippy.use_self = "warn"
clippy.wildcard_imports = "warn"
clippy.cargo_common_metadata = "warn"
clippy.negative_feature_names = "warn"
clippy.redundant_feature_names = "warn"
clippy.wildcard_dependencies = "warn"
# END LINEBENDER LINT SET
29 changes: 18 additions & 11 deletions src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Logic for rendering debug visualizations
use crate::{
text::VelloTextAnchor, CoordinateSpace, VelloAsset, VelloAssetAnchor, VelloFont,
text::VelloTextAnchor, CoordinateSpace, VelloAsset, VelloAsset2d, VelloAssetAnchor, VelloFont,
VelloTextSection,
};
use bevy::{color::palettes::css, math::Vec3Swizzles, prelude::*};
Expand All @@ -27,7 +27,7 @@ pub enum DebugVisualizations {
fn render_asset_debug(
query_vectors: Query<
(
&Handle<VelloAsset>,
&VelloAsset2d,
&VelloAssetAnchor,
&GlobalTransform,
&CoordinateSpace,
Expand All @@ -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.id()) {
match space {
CoordinateSpace::WorldSpace => {
// Origin
Expand All @@ -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 {
Expand Down Expand Up @@ -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::from_xy(rect_center.x, rect_center.y),
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;
Expand Down Expand Up @@ -195,9 +199,8 @@ 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,
rect.size() * Vec2::new(1.0, 1.0),
Isometry2d::from_xy(rect_center.x, rect_center.y),
rect.size() * Vec2::new(1.0, 1.0), // TODO: Why do we *= 1?
css::WHITE,
);
}
Expand All @@ -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::from_xy(position.x, position.y),
size,
css::WHITE,
);
}
9 changes: 8 additions & 1 deletion src/integrations/asset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::VectorFile;
use bevy::{prelude::*, reflect::TypePath};

#[derive(Component, Default, Debug, Clone, Deref, DerefMut, PartialEq, Eq)]
// TODO: Add required components
pub struct VelloAsset2d(pub Handle<VelloAsset>);

// TODO: Split this into VelloSvg and VelloLottie
#[derive(Asset, TypePath, Clone)]
pub struct VelloAsset {
pub file: VectorFile,
Expand Down Expand Up @@ -36,13 +41,15 @@ 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 })
}
}

/// Describes how the asset is positioned relative to its [`Transform`]. It defaults to [`VelloAssetAnchor::Center`].
#[derive(Component, Default, Clone, Copy, PartialEq, Eq)]
// TODO: Add required components
pub enum VelloAssetAnchor {
/// Bounds start from the render position and advance up and to the right.
BottomLeft,
Expand Down
11 changes: 5 additions & 6 deletions src/integrations/dot_lottie/player_state.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::PlayerTransition;
use crate::{PlaybackOptions, Theme, VelloAsset};
use bevy::prelude::*;
use crate::{PlaybackOptions, Theme, VelloAsset2d};

#[derive(Debug, Clone)]
pub struct PlayerState {
pub id: &'static str,
pub asset: Option<Handle<VelloAsset>>,
pub asset: Option<VelloAsset2d>,
pub theme: Option<Theme>,
pub options: Option<PlaybackOptions>,
pub transitions: Vec<PlayerTransition>,
Expand All @@ -28,7 +27,7 @@ impl PlayerState {
}
}

pub fn asset(mut self, asset: Handle<VelloAsset>) -> Self {
pub fn asset(mut self, asset: VelloAsset2d) -> Self {
self.asset.replace(asset);
self
}
Expand Down Expand Up @@ -58,7 +57,7 @@ impl PlayerState {
self
}

pub fn set_asset(mut self, asset: Option<Handle<VelloAsset>>) -> Self {
pub fn set_asset(mut self, asset: Option<VelloAsset2d>) -> Self {
self.asset = asset;
self
}
Expand Down Expand Up @@ -88,7 +87,7 @@ impl PlayerState {
self
}

pub fn get_asset(&self) -> Option<&Handle<VelloAsset>> {
pub fn get_asset(&self) -> Option<&VelloAsset2d> {
self.asset.as_ref()
}

Expand Down
12 changes: 6 additions & 6 deletions src/integrations/dot_lottie/systems.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::DotLottiePlayer;
use crate::{
integrations::lottie::PlaybackPlayMode, PlaybackDirection, PlaybackLoopBehavior,
PlaybackOptions, PlayerTransition, Playhead, VectorFile, VelloAsset,
PlaybackOptions, PlayerTransition, Playhead, VectorFile, VelloAsset, VelloAsset2d,
};
use bevy::{prelude::*, utils::Instant};
use std::time::Duration;
Expand All @@ -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<VelloAsset>,
&VelloAsset2d,
&mut Playhead,
&mut DotLottiePlayer,
&PlaybackOptions,
Expand Down Expand Up @@ -70,7 +70,7 @@ pub fn advance_dot_lottie_playheads(

// 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)
Expand Down Expand Up @@ -139,7 +139,7 @@ pub fn run_transitions(
&Playhead,
&PlaybackOptions,
&GlobalTransform,
&mut Handle<VelloAsset>,
&mut VelloAsset2d,
)>,
mut assets: ResMut<Assets<VelloAsset>>,
windows: Query<&Window>,
Expand All @@ -156,7 +156,7 @@ pub fn run_transitions(

let pointer_pos = window
.cursor_position()
.and_then(|cursor| camera.viewport_to_world(view, cursor))
.and_then(|cursor| camera.viewport_to_world(view, cursor).ok())
.map(|ray| ray.origin.truncate());

for (mut player, playhead, options, gtransform, current_asset_handle) in query_player.iter_mut()
Expand Down Expand Up @@ -312,7 +312,7 @@ pub fn transition_state(
let Some(VelloAsset {
file: VectorFile::Lottie(composition),
..
}) = assets.get(target_asset)
}) = assets.get(target_asset.id())
else {
warn!("not ready for state transition, re-queueing {next_state}...");
player.next_state = Some(next_state);
Expand Down
12 changes: 6 additions & 6 deletions src/integrations/lottie/asset_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
VelloAsset,
};
use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
asset::{io::Reader, AssetLoader, LoadContext},
prelude::*,
utils::ConditionalSendFuture,
};
Expand All @@ -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<Output = Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion src/integrations/lottie/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ impl Plugin for LottieIntegrationPlugin {
systems::advance_playheads_with_options,
),
)
.add_systems(Last, systems::spawn_playheads);
.add_observer(systems::spawn_playheads);
}
}
Loading
Loading