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

Bevy v0.15.0 #87

Merged
merged 28 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
89fbbed
Upgrade bevy to v0.15.0 and fix build
egenard Dec 10, 2024
6ca6446
Fix examples with default features build
egenard Dec 10, 2024
a93689c
build: remove unused file
simbleau Dec 11, 2024
a6fc8d6
fix: lint
simbleau Dec 11, 2024
c00e61f
build: add common API derives
simbleau Dec 11, 2024
f9ef95f
fix: lints
simbleau Dec 11, 2024
9745cea
fix: use .id()
simbleau Dec 11, 2024
01a82e2
fix: dotLottie features
simbleau Dec 11, 2024
24edfaa
fix: unnecessary mut
simbleau Dec 11, 2024
47ec0f0
refactor: style on setup_ss_rendertarget
simbleau Dec 11, 2024
cbc7c9b
fix: lint
simbleau Dec 11, 2024
512de03
refactor: remove required components from bundles
simbleau Dec 11, 2024
4f5fbf2
Implement Deref for VelloAssetHandle
egenard Dec 11, 2024
838c968
Fix lottie theme color setting
egenard Dec 11, 2024
e5f48bb
Fix redundant Deref impl
egenard Dec 11, 2024
140060b
build: update closer with velato fork
simbleau Jan 28, 2025
30dc935
fix: more examples, clippy lints
simbleau Jan 28, 2025
987aa93
fix: transparency
simbleau Jan 28, 2025
bfe188f
fix: add back whitespace
simbleau Jan 28, 2025
8742d6e
fix: use alpha blending
simbleau Jan 28, 2025
f6546ca
fix: add `TemporaryRenderEntity` marker
simbleau Jan 29, 2025
d9f170a
fix: resizing the window
simbleau Jan 29, 2025
90469e9
fix: pixel scale
simbleau Jan 29, 2025
f783857
build: use velato 0.5.0
simbleau Feb 2, 2025
16dddce
fix: color remapping
simbleau Feb 2, 2025
7f2e8d1
docs: update README, changelog
simbleau Feb 2, 2025
5ab5c10
fix(ci): install deps
simbleau Feb 2, 2025
f9504eb
ci: update apt-get
simbleau Feb 2, 2025
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
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"

Expand Down
35 changes: 16 additions & 19 deletions examples/cube3d/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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),
Expand All @@ -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),
);
Expand Down Expand Up @@ -168,7 +165,7 @@ fn render_texture(
/// Rotates the outer cube (main pass)
fn cube_rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<MainPassCube>>) {
for mut transform in &mut query {
transform.rotate_x(1.0 * time.delta_seconds());
transform.rotate_y(0.7 * time.delta_seconds());
transform.rotate_x(1.0 * time.delta_secs());
transform.rotate_y(0.7 * time.delta_secs());
}
}
4 changes: 2 additions & 2 deletions examples/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
26 changes: 11 additions & 15 deletions examples/render_layers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ struct BackgroundScene;
fn setup_gizmos(mut commands: Commands, mut config_store: ResMut<GizmoConfigStore>) {
// This camera can only see Gizmos.
commands.spawn((
Camera2dBundle {
camera: Camera {
// This camera will render LAST.
order: 1,
..default()
},
Camera2d,
Camera {
// This camera will render LAST.
order: 1,
..default()
},
RenderLayers::layer(3),
Expand All @@ -42,12 +40,10 @@ fn setup_gizmos(mut commands: Commands, mut config_store: ResMut<GizmoConfigStor

fn setup_scene(mut commands: Commands) {
commands.spawn((
Camera2dBundle {
camera: Camera {
// This camera will render first.
order: -1,
..default()
},
Camera2d,
Camera {
// This camera will render first.
order: -1,
..default()
},
RenderLayers::layer(1).with(2),
Expand All @@ -69,7 +65,7 @@ fn animation(
mut query_scene: Query<(&mut Transform, &mut VelloScene), With<AnimationScene>>,
time: Res<Time>,
) {
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 (mut transform, mut scene) = query_scene.single_mut();
// Reset scene every frame
*scene = VelloScene::default();
Expand All @@ -85,7 +81,7 @@ fn animation(
scene.fill(
peniko::Fill::NonZero,
kurbo::Affine::default(),
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(-50.0, -50.0, 50.0, 50.0, (sin_time as f64) * 50.0),
);
Expand All @@ -101,7 +97,7 @@ fn background(mut query_scene: Query<&mut VelloScene, With<BackgroundScene>>) {
scene.fill(
peniko::Fill::NonZero,
kurbo::Affine::default(),
peniko::Color::rgb(0.0, 0.0, 1.0),
peniko::Color::new([0.0, 0.0, 1.0, 1.0]),
None,
&kurbo::RoundedRect::new(-200.0, -200.0, 200.0, 200.0, 0.0),
);
Expand Down
6 changes: 3 additions & 3 deletions examples/scene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ fn main() {
}

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

fn simple_animation(mut query_scene: Query<(&mut Transform, &mut VelloScene)>, time: Res<Time>) {
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 (mut transform, mut scene) = query_scene.single_mut();
// Reset scene every frame
*scene = VelloScene::default();
Expand All @@ -32,7 +32,7 @@ fn simple_animation(mut query_scene: Query<(&mut Transform, &mut VelloScene)>, t
scene.fill(
peniko::Fill::NonZero,
kurbo::Affine::default(),
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(-50.0, -50.0, 50.0, 50.0, (sin_time as f64) * 50.0),
);
Expand Down
29 changes: 13 additions & 16 deletions examples/scene_ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,27 @@ fn main() {
}

fn setup_ui(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let one_third = Val::Percent(100.0 / 3.0);
commands.spawn((
NodeBundle {
style: Style {
position_type: PositionType::Absolute,
left: one_third,
top: one_third,
width: one_third,
height: one_third,
border: UiRect::all(Val::Px(2.0)),
..default()
},
border_color: css::FUCHSIA.with_alpha(0.5).into(),
Node {
position_type: PositionType::Absolute,
left: one_third,
top: one_third,
width: one_third,
height: one_third,
border: UiRect::all(Val::Px(2.0)),
..default()
},
BorderColor(css::FUCHSIA.with_alpha(0.5).into()),
Interaction::default(),
VelloScene::default(),
CoordinateSpace::ScreenSpace,
));
}

fn update_ui(mut query: Query<(&Node, &Interaction, &mut VelloScene)>) {
fn update_ui(mut query: Query<(&ComputedNode, &Interaction, &mut VelloScene)>) {
let Ok((node, interaction, mut scene)) = query.get_single_mut() else {
return;
};
Expand All @@ -52,8 +49,8 @@ fn update_ui(mut query: Query<(&Node, &Interaction, &mut VelloScene)>) {
match *interaction {
Interaction::Hovered | Interaction::Pressed => {
let color = match *interaction {
Interaction::Hovered => peniko::Color::GREEN,
Interaction::Pressed => peniko::Color::rgba8(0, 110, 0, 255),
Interaction::Hovered => peniko::Color::from_rgba8(0, 255, 0, 255),
Interaction::Pressed => peniko::Color::from_rgba8(0, 110, 0, 255),
_ => unreachable!(),
};

Expand Down Expand Up @@ -88,7 +85,7 @@ fn update_ui(mut query: Query<(&Node, &Interaction, &mut VelloScene)>) {
scene.fill(
peniko::Fill::NonZero,
kurbo::Affine::default(),
peniko::Color::RED,
peniko::Color::from_rgba8(255, 0, 0, 255),
None,
&kurbo::Circle::new(center, radius),
);
Expand Down
23 changes: 10 additions & 13 deletions 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(Camera2dBundle::default());
commands.spawn(Camera2d);
}

fn setup_worldspace_text(mut commands: Commands, asset_server: ResMut<AssetServer>) {
Expand Down Expand Up @@ -58,7 +58,7 @@ fn setup_screenspace_text(mut commands: Commands) {
value: "Screen-space text rendered by Vello!".to_string(),
style: VelloTextStyle {
font_size: 24.0,
brush: peniko::Brush::Solid(peniko::Color::RED),
brush: peniko::Brush::Solid(peniko::Color::from_rgba8(255, 0, 0, 155)),
..default()
},
},
Expand All @@ -70,20 +70,17 @@ fn setup_screenspace_text(mut commands: Commands) {
});

// Bevy text
commands.spawn(
TextBundle::from_section(
"Screen-space text rendered by Bevy!",
TextStyle {
font_size: 24.0,
..default()
},
)
.with_style(Style {
commands
.spawn(Node {
position_type: PositionType::Absolute,
top: Val::Px(100.0),
left: Val::Px(100.0),
..default()
})
.with_text_justify(JustifyText::Left),
);
.insert(Text::new("Screen-space text rendered by Bevy!"))
.insert(TextFont {
font_size: 24.,
..default()
})
.insert(TextLayout::new_with_justify(justifytext::Left));
}
29 changes: 18 additions & 11 deletions src/debug.rs
Original file line number Diff line number Diff line change
@@ -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::*};

Expand All @@ -27,7 +27,7 @@ pub enum DebugVisualizations {
fn render_asset_debug(
query_vectors: Query<
(
&Handle<VelloAsset>,
&VelloAssetHandle,
&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.0) {
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::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;
Expand Down Expand Up @@ -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,
);
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::new(position, Rot2::degrees(0.0)),
size,
css::WHITE,
);
}
6 changes: 5 additions & 1 deletion src/integrations/asset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::VectorFile;
use bevy::{prelude::*, reflect::TypePath};

#[derive(Component, Default, Clone)]
pub struct VelloAssetHandle(pub Handle<VelloAsset>);

#[derive(Asset, TypePath, Clone)]
pub struct VelloAsset {
pub file: VectorFile,
Expand Down Expand Up @@ -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 })
}
}
Expand Down
Loading
Loading