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

Changes needed to get rive-bevy working with bevy 0.13.0 and vello 0.1.0 #19

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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,356 changes: 866 additions & 490 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ categories = ["game-development"]
license = "MIT"
readme = "../README.md"

[features]
default = []

[dependencies]
bevy = "0.12.0"
bevy = "0.13.0"
etagere = "0.2.8"
rive-rs = { git = "https://github.com/rive-app/rive-rs", features = ["vello"] }
vello = { git = "https://github.com/linebender/vello", rev = "ee3a076" }

vello = "0.1.0"
rive-rs = { path = "../rive-rs/rive-rs", features = ["vello"] }


[dev-dependencies]
rand = "0.8.5"
Expand Down
26 changes: 10 additions & 16 deletions examples/3d-hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ fn setup(
asset_server: Res<AssetServer>,
) {
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(50.0).into()),
material: materials.add(Color::rgb(0.3, 0.3, 0.3).into()),
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)),
material: materials.add(Color::rgb(0.3, 0.3, 0.3)),
transform: Transform::from_xyz(0.0, -5.0, 0.0),
..default()
});
Expand Down Expand Up @@ -88,14 +88,8 @@ fn setup(

// opaque sphere
commands.spawn(PbrBundle {
mesh: meshes.add(
Mesh::try_from(shape::Icosphere {
radius: 2.0,
subdivisions: 3,
})
.unwrap(),
),
material: materials.add(Color::rgb(0.7, 0.2, 0.1).into()),
mesh: meshes.add(Sphere::new(2.0).mesh().ico(5).unwrap()),
material: materials.add(Color::rgb(0.7, 0.2, 0.1)),
transform: Transform::from_xyz(0.0, 0.5, -5.5),
..default()
});
Expand Down Expand Up @@ -158,25 +152,25 @@ fn setup(
fn camera_control_system(
mut camera: Query<(&mut Camera, &mut Transform, &GlobalTransform), With<Camera3d>>,
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
) {
let (mut camera, mut camera_transform, _) = camera.single_mut();

if input.just_pressed(KeyCode::H) {
if input.just_pressed(KeyCode::KeyH) {
camera.hdr = !camera.hdr;
}

let rotation = if input.pressed(KeyCode::Left) {
let rotation = if input.pressed(KeyCode::ArrowLeft) {
time.delta_seconds()
} else if input.pressed(KeyCode::Right) {
} else if input.pressed(KeyCode::ArrowRight) {
-time.delta_seconds()
} else {
0.0
};

let movement = if input.pressed(KeyCode::Up) {
let movement = if input.pressed(KeyCode::ArrowUp) {
-time.delta_seconds()
} else if input.pressed(KeyCode::Down) {
} else if input.pressed(KeyCode::ArrowDown) {
time.delta_seconds()
} else {
0.0
Expand Down
26 changes: 13 additions & 13 deletions examples/rive-input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ fn setup_text(mut commands: Commands) {
}

fn update_state_machine_system(
kbd: Res<Input<KeyCode>>,
kbd: Res<ButtonInput<KeyCode>>,
mut query: Query<(Entity, &mut RiveStateMachine)>,
mut input_events: EventWriter<events::Input>,
) {
if kbd.just_pressed(KeyCode::Return) {
if kbd.just_pressed(KeyCode::Enter) {
// Get the State Machine and its Entity
let (entity, state_machine) = query.single_mut();

Expand Down Expand Up @@ -138,30 +138,30 @@ fn update_state_machine_system(
}

fn update_rive_text_system(
kbd: Res<Input<KeyCode>>,
kbd: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut RiveStateMachine>,
mut string: Local<String>,
mut evr_char: EventReader<ReceivedCharacter>,
) {
// On toggle, clear the string.
if kbd.just_pressed(KeyCode::Return) {
if kbd.just_pressed(KeyCode::Enter) {
string.clear();
return;
}

let mut did_change = false;
if kbd.just_pressed(KeyCode::Back) {
if kbd.just_pressed(KeyCode::Backspace) {
did_change = true;
string.pop();
}
for ev in evr_char.read() {
// Ignore control (special) characters.
if !ev.char.is_control() {
string.push(ev.char);
did_change = true;
info!("{}", string.as_str());
}
}
// for ev in evr_char.read() {
// // Ignore control (special) characters.
// if !ev.char.chars().last().is_control() {
// string.push(ev.char);
// did_change = true;
// info!("{}", string.as_str());
// }
// }

// Update our Rive text if the string changed.
if did_change {
Expand Down
46 changes: 23 additions & 23 deletions examples/shmup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
use std::time::Duration;

use bevy::{
core_pipeline::bloom::BloomSettings, prelude::*, render::render_resource::Extent3d,
sprite::collide_aabb::collide, sprite::MaterialMesh2dBundle, window,
core_pipeline::bloom::BloomSettings,
math::bounding::{Aabb2d, IntersectsVolume},
prelude::*,
render::render_resource::Extent3d,
sprite::MaterialMesh2dBundle,
window,
};

use rand::prelude::*;
Expand Down Expand Up @@ -327,7 +331,7 @@ fn setup(
}

fn player_movement_system(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut query: Query<(&mut Transform, &mut Player)>,
time_step: Res<Time>,
) {
Expand All @@ -340,11 +344,11 @@ fn player_movement_system(
let mut direction = 0.0;
player.target_drift = 0.0;

if keyboard_input.pressed(KeyCode::Left) {
if keyboard_input.pressed(KeyCode::ArrowLeft) {
direction -= 1.0;
player.target_drift = -100.0;
}
if keyboard_input.pressed(KeyCode::Right) {
if keyboard_input.pressed(KeyCode::ArrowRight) {
direction += 1.0;
player.target_drift = 100.0;
}
Expand Down Expand Up @@ -384,7 +388,7 @@ fn instantiate_projectile_system(mut query: Query<&mut RiveStateMachine, Added<E

fn player_control_system(
mut commands: Commands,
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
query: Query<(Entity, &Transform, &Player)>,
mut input_events: EventWriter<events::Input>,
mut images: ResMut<Assets<Image>>,
Expand Down Expand Up @@ -477,14 +481,12 @@ fn collision_system(
// Enemy projectiles on player
for (projectile_entity, transform) in &enemy_projectiles {
for (player_entity, player_transform, collider, mut player) in player_query.iter_mut() {
let collision = collide(
transform.translation,
PROJECTILE_SIZE,
player_transform.translation,
collider.size,
);
let collision =
Aabb2d::new(transform.translation.truncate(), PROJECTILE_SIZE / 2.).intersects(
&Aabb2d::new(player_transform.translation.truncate(), collider.size / 2.),
);

if collision.is_some() {
if collision {
if !player.is_alive {
continue; // player already destroyed, waiting to despawn
}
Expand All @@ -507,14 +509,12 @@ fn collision_system(
for (enemy_entity, enemy_transform, collider, mut enemy, mut target_position) in
enemy_query.iter_mut()
{
let collision = collide(
transform.translation,
PROJECTILE_SIZE,
enemy_transform.translation,
collider.size,
);
let collision =
Aabb2d::new(transform.translation.truncate(), PROJECTILE_SIZE / 2.).intersects(
&Aabb2d::new(enemy_transform.translation.truncate(), collider.size / 2.),
);

if collision.is_some() {
if collision {
if !enemy.is_alive {
continue; // enemy already destroyed, waiting to despawn
}
Expand Down Expand Up @@ -741,7 +741,7 @@ fn spawn_background(
) {
commands.spawn((
MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(200.0).into()).into(),
mesh: meshes.add(Circle::new(200.0)).into(),
material: materials.add(ColorMaterial::from(Color::rgb(7.5, 5.0, 7.5))),
transform: Transform::from_translation(Vec3::new(750.0, 500.0, -5.0)),
..default()
Expand All @@ -751,7 +751,7 @@ fn spawn_background(

commands.spawn((
MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(190.0).into()).into(),
mesh: meshes.add(Circle::new(190.0)).into(),
material: materials.add(ColorMaterial::from(Color::rgb(1.0, 6.0, 7.0))),
transform: Transform::from_translation(Vec3::new(-900.0, -500.0, -5.0)),
..default()
Expand All @@ -774,7 +774,7 @@ fn spawn_background(
let size = rand::thread_rng().gen_range(0.1..2.5);

commands.spawn(MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(size).into()).into(),
mesh: meshes.add(Circle::new(size)).into(),
material: materials.add(ColorMaterial::from(color)),
transform: Transform::from_translation(Vec3::new(
WINDOW_SIZE.x / 2. * x,
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn setup_animation(
let animation_image_handle = images.add(animation_image.clone());

let cube_size = 4.0;
let cube_handle = meshes.add(Mesh::from(shape::Box::new(cube_size, cube_size, cube_size)));
let cube_handle = meshes.add(Cuboid::new(cube_size, cube_size, cube_size));

let material_handle = materials.add(StandardMaterial {
base_color_texture: Some(animation_image_handle.clone()),
Expand Down
10 changes: 3 additions & 7 deletions examples/ui-on-cube.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use bevy::{
core_pipeline::clear_color::ClearColorConfig, prelude::*, render::render_resource::Extent3d,
window,
};
use bevy::{prelude::*, render::render_resource::Extent3d, window};
use rive_bevy::{LinearAnimation, RivePlugin, SceneTarget, SpriteEntity, StateMachine};

#[derive(Component)]
Expand Down Expand Up @@ -30,7 +27,7 @@ fn setup(
commands.spawn(PointLightBundle {
point_light: PointLight {
// A bit brighter to make Marty clearly visible.
intensity: 3000.0,
intensity: 3000000.0,
..default()
},
// Light in front of the 3D camera.
Expand All @@ -39,7 +36,7 @@ fn setup(
});

let cube_size = 4.0;
let cube_handle = meshes.add(Mesh::from(shape::Box::new(cube_size, cube_size, cube_size)));
let cube_handle = meshes.add(Cuboid::new(cube_size, cube_size, cube_size));

let material_handle = materials.add(StandardMaterial {
base_color_texture: Some(cube_image_handle.clone()),
Expand Down Expand Up @@ -86,7 +83,6 @@ fn setup(
},
camera_2d: Camera2d {
// We don't want to clear the 3D objects behind our UI.
clear_color: ClearColorConfig::None,
},
..default()
});
Expand Down
12 changes: 6 additions & 6 deletions src/components.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use bevy::{prelude::*, render::extract_component::ExtractComponent};
use vello::SceneFragment;
use vello::Scene;

use crate::Riv;

Expand Down Expand Up @@ -57,29 +57,29 @@ pub struct SceneTarget {
}

#[derive(Component, Deref)]
pub(crate) struct VelloFragment(pub Arc<SceneFragment>);
pub(crate) struct VelloFragment(pub Arc<Scene>);

#[derive(Component)]
pub(crate) struct VelloScene {
pub fragment: Arc<vello::SceneFragment>,
pub fragment: Arc<vello::Scene>,
pub image_handle: Handle<Image>,
pub width: u32,
pub height: u32,
}

impl ExtractComponent for VelloScene {
type Query = (
type QueryData = (
&'static VelloFragment,
&'static Handle<Image>,
&'static Viewport,
);

type Filter = ();
type QueryFilter = ();

type Out = Self;

fn extract_component(
(fragment, image, viewport): bevy::ecs::query::QueryItem<'_, Self::Query>,
(fragment, image, viewport): bevy::ecs::query::QueryItem<'_, Self::QueryData>,
) -> Option<Self> {
Some(Self {
fragment: fragment.0.clone(),
Expand Down
Loading