Skip to content

Commit

Permalink
update to bevy-0.13 (#16)
Browse files Browse the repository at this point in the history
* update to bevy-0.13

* fix more build issues

nothing visible atm though

* update render asset usages

now we get validation errors, so making progress?

* fix material

* fix doctests

* remove unused uuid literals

* switch to bind group 2 for custom shader bindings
  • Loading branch information
brandon-reinhart authored Mar 5, 2024
1 parent d562da1 commit ff0b74c
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 53 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ exclude = [

[dependencies]
rusty_spine = "0.7"
bevy = { version = "0.12", default-features = false, features = [ "bevy_render", "bevy_asset", "bevy_sprite" ] }
glam = { version = "0.24", features = [ "mint" ] }
bevy = { version = "0.13", default-features = false, features = [ "bevy_render", "bevy_asset", "bevy_sprite" ] }
glam = { version = "0.25", features = [ "mint" ] }
thiserror = "1.0.50"

[dev-dependencies]
lerp = "0.4"
bevy = { version = "0.12", default-features = true }
lerp = "0.5"
bevy = { version = "0.13", default-features = true }

[workspace]
resolver = "2"
Expand Down
6 changes: 3 additions & 3 deletions assets/shaders/custom.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ fn vertex(vertex: Vertex) -> VertexOutput {
return out;
}

@group(1) @binding(0)
@group(2) @binding(0)
var texture: texture_2d<f32>;
@group(1) @binding(1)
@group(2) @binding(1)
var texture_sampler: sampler;

@group(1) @binding(2)
@group(2) @binding(2)
var<uniform> time: f32;

@fragment
Expand Down
8 changes: 4 additions & 4 deletions examples/3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
..default()
});

Expand Down Expand Up @@ -107,8 +107,8 @@ fn controls(
mut window_query: Query<&mut Window, With<PrimaryWindow>>,
mut mouse_motion_events: EventReader<MouseMotion>,
mut orbit_query: Query<(&mut Orbit, &mut Transform)>,
mouse_buttons: Res<Input<MouseButton>>,
keys: Res<Input<KeyCode>>,
mouse_buttons: Res<ButtonInput<MouseButton>>,
keys: Res<ButtonInput<KeyCode>>,
) {
let mut window = window_query.single_mut();
if mouse_buttons.just_pressed(MouseButton::Left) {
Expand Down
5 changes: 2 additions & 3 deletions examples/custom_material.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{
ecs::system::{StaticSystemParam, SystemParam},
prelude::*,
reflect::{TypePath, TypeUuid},
reflect::TypePath,
render::{
mesh::MeshVertexBufferLayout,
render_resource::{
Expand Down Expand Up @@ -85,8 +85,7 @@ fn on_spawn(
#[derive(Component)]
pub struct MySpine;

#[derive(Asset, AsBindGroup, TypeUuid, TypePath, Clone, Default)]
#[uuid = "2e85f9ae-049a-4bb5-9f5d-ebaaa208df60"]
#[derive(Asset, AsBindGroup, TypePath, Clone, Default)]
pub struct MyMaterial {
#[texture(0)]
#[sampler(1)]
Expand Down
2 changes: 1 addition & 1 deletion examples/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn on_spine_event(
color: Color::WHITE,
},
)
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
transform: Transform::from_xyz(0., -200., 1.),
..Default::default()
})
Expand Down
14 changes: 7 additions & 7 deletions examples/spineboy/player.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bevy::prelude::*;
use bevy_spine::prelude::*;
use lerp::Lerp;

use crate::bullet::{BulletSpawnEvent, BulletSystem};

Expand Down Expand Up @@ -225,7 +224,8 @@ fn player_aim(
spine.animation_state.track_at_index_mut(PLAYER_TRACK_AIM)
{
let alpha = aim_track.alpha() * 2.5;
aim_track.set_alpha(alpha.lerp(1., time.delta_seconds()).clamp(0., 1.));
aim_track
.set_alpha(lerp::Lerp::lerp(alpha, 1., time.delta_seconds()).clamp(0., 1.));
}
}
}
Expand All @@ -237,7 +237,7 @@ fn player_shoot(
mut spine_query: Query<(&mut Spine, &Transform)>,
mut bullet_spawn_events: EventWriter<BulletSpawnEvent>,
global_transform_query: Query<&GlobalTransform>,
mouse_buttons: Res<Input<MouseButton>>,
mouse_buttons: Res<ButtonInput<MouseButton>>,
time: Res<Time>,
) {
for (mut shoot, player) in shoot_query.iter_mut() {
Expand Down Expand Up @@ -265,16 +265,16 @@ fn player_shoot(

fn player_move(
mut player_query: Query<(&mut Player, &mut Transform, &mut Spine)>,
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
) {
for (mut player, mut player_transform, mut player_spine) in player_query.iter_mut() {
if player.spawned {
let mut movement = 0.;
if keys.pressed(KeyCode::A) {
if keys.pressed(KeyCode::KeyA) {
movement -= 1.;
}
if keys.pressed(KeyCode::D) {
if keys.pressed(KeyCode::KeyD) {
movement += 1.;
}
player.movement_velocity =
Expand All @@ -295,7 +295,7 @@ fn player_move(
}
}

fn player_jump(mut player_query: Query<(&mut Spine, &Player)>, keys: Res<Input<KeyCode>>) {
fn player_jump(mut player_query: Query<(&mut Spine, &Player)>, keys: Res<ButtonInput<KeyCode>>) {
for (mut spine, player) in player_query.iter_mut() {
if !player.spawned {
continue;
Expand Down
14 changes: 5 additions & 9 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{path::Path, sync::Arc};
use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
prelude::*,
reflect::{TypePath, TypeUuid},
reflect::TypePath,
utils::BoxedFuture,
};
use rusty_spine::SpineError;
Expand All @@ -20,8 +20,7 @@ pub enum SpineLoaderError {
/// Bevy asset for [`rusty_spine::Atlas`], loaded from `.atlas` files.
///
/// For loading a complete skeleton, see [`SkeletonData`].
#[derive(Asset, Debug, TypeUuid, TypePath)]
#[uuid = "e58e872a-9d35-41bf-b561-95f843686004"]
#[derive(Asset, Debug, TypePath)]
pub struct Atlas {
pub atlas: Arc<rusty_spine::Atlas>,
}
Expand Down Expand Up @@ -63,8 +62,7 @@ impl AssetLoader for AtlasLoader {
/// Bevy asset for [`rusty_spine::SkeletonJson`], loaded from `.json` files.
///
/// For loading a complete skeleton, see [`SkeletonData`].
#[derive(Asset, Debug, TypeUuid, TypePath)]
#[uuid = "8637cf16-90c4-4825-bdf2-277e38788365"]
#[derive(Asset, Debug, TypePath)]
pub struct SkeletonJson {
pub json: Vec<u8>,
}
Expand Down Expand Up @@ -100,8 +98,7 @@ impl AssetLoader for SkeletonJsonLoader {
/// Bevy asset for [`rusty_spine::SkeletonBinary`], loaded from `.skel` files.
///
/// For loading a complete skeleton, see [`SkeletonData`].
#[derive(Asset, Debug, TypeUuid, TypePath)]
#[uuid = "2a2a342a-29ae-4417-adf5-06ea7f0732d0"]
#[derive(Asset, Debug, TypePath)]
pub struct SkeletonBinary {
pub binary: Vec<u8>,
}
Expand Down Expand Up @@ -138,8 +135,7 @@ impl AssetLoader for SkeletonBinaryLoader {
/// skeleton (either [`SkeletonJson`] or [`SkeletonBinary`]).
///
/// See [`SkeletonData::new_from_json`] or [`SkeletonData::new_from_binary`].
#[derive(Asset, Debug, TypeUuid, TypePath)]
#[uuid = "7796a37b-37a4-49ea-bf4e-fb7344aa6015"]
#[derive(Asset, Debug, TypePath)]
pub struct SkeletonData {
pub atlas_handle: Handle<Atlas>,
pub kind: SkeletonDataKind,
Expand Down
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use bevy::{
prelude::*,
render::{
mesh::{Indices, MeshVertexAttribute},
render_asset::RenderAssetUsages,
render_resource::{PrimitiveTopology, VertexFormat},
texture::{ImageAddressMode, ImageFilterMode, ImageSampler, ImageSamplerDescriptor},
},
Expand Down Expand Up @@ -418,7 +419,7 @@ impl Default for SpineSettings {
/// mut spine_ready_events: EventReader<SpineReadyEvent>,
/// mut spine_query: Query<&mut Spine, With<MySpine>>
/// ) {
/// for spine_ready_event in spine_ready_events.iter() {
/// for spine_ready_event in spine_ready_events.read() {
/// if let Ok(mut spine) = spine_query.get_mut(spine_ready_event.entity) {
/// // the skeleton will start playing the animation the same frame it spawns on
/// spine.animation_state.set_animation_by_name(0, "animation", true);
Expand Down Expand Up @@ -465,7 +466,7 @@ pub struct SpineReadyEvent {
/// mut commands: Commands,
/// asset_server: Res<AssetServer>,
/// ) {
/// for event in spine_events.iter() {
/// for event in spine_events.read() {
/// if let SpineEvent::Event { name, entity, .. } = event {
/// println!("spine event fired: {}", name);
/// println!("from entity: {:?}", entity);
Expand Down Expand Up @@ -714,8 +715,11 @@ fn spine_spawn(
.with_children(|parent| {
let mut z = 0.;
for (index, _) in controller.skeleton.slots().enumerate() {
let mut mesh =
Mesh::new(PrimitiveTopology::TriangleList);
let mut mesh = Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::MAIN_WORLD
| RenderAssetUsages::RENDER_WORLD,
);
empty_mesh(&mut mesh);
let mesh_handle = meshes.add(mesh);
parent.spawn((
Expand Down Expand Up @@ -990,7 +994,7 @@ fn spine_update_meshes(
for _ in 0..vertices.len() {
normals.push([0., 0., 0.]);
}
mesh.set_indices(Some(Indices::U16(indices)));
mesh.insert_indices(Indices::U16(indices));
mesh.insert_attribute(
MeshVertexAttribute::new("Vertex_Position", 0, VertexFormat::Float32x2),
vertices,
Expand Down Expand Up @@ -1022,15 +1026,13 @@ fn spine_update_meshes(
}

fn empty_mesh(mesh: &mut Mesh) {
let indices = Indices::U32(vec![]);

let positions: Vec<[f32; 3]> = vec![];
let normals: Vec<[f32; 3]> = vec![];
let uvs: Vec<[f32; 2]> = vec![];
let colors: Vec<[f32; 4]> = vec![];
let dark_colors: Vec<[f32; 4]> = vec![];

mesh.set_indices(Some(indices));
mesh.remove_indices();
mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions);
mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, normals);
mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs);
Expand Down
15 changes: 3 additions & 12 deletions src/materials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy::{
asset::Asset,
ecs::system::{StaticSystemParam, SystemParam},
prelude::*,
reflect::{TypePath, TypeUuid},
reflect::TypePath,
render::{
mesh::{MeshVertexAttribute, MeshVertexBufferLayout},
render_resource::{
Expand Down Expand Up @@ -129,10 +129,9 @@ pub struct SpineSettingsQuery<'w, 's> {
}

macro_rules! material {
($(#[$($attrss:tt)*])* $uuid:literal, $name:ident, $blend_mode:expr, $premultiplied_alpha:expr, $blend_state:expr) => {
($(#[$($attrss:tt)*])* $name:ident, $blend_mode:expr, $premultiplied_alpha:expr, $blend_state:expr) => {
$(#[$($attrss)*])*
#[derive(Asset, Default, AsBindGroup, TypeUuid, TypePath, Clone)]
#[uuid = $uuid]
#[derive(Asset, Default, AsBindGroup, TypePath, Clone)]
pub struct $name {
#[texture(0)]
#[sampler(1)]
Expand Down Expand Up @@ -203,7 +202,6 @@ macro_rules! material {

material!(
/// Normal blend mode material, non-premultiplied-alpha
"22413663-46b0-4b9b-b714-d72fb87dc7ef",
SpineNormalMaterial,
BlendMode::Normal,
false,
Expand All @@ -223,7 +221,6 @@ material!(

material!(
/// Additive blend mode material, non-premultiplied-alpha
"092d3b15-c3b4-45d6-95fd-3a24a86e08d7",
SpineAdditiveMaterial,
BlendMode::Additive,
false,
Expand All @@ -243,7 +240,6 @@ material!(

material!(
/// Multiply blend mode material, non-premultiplied-alpha
"ec4d2018-ad8f-4ff8-bbf7-33f13dab7ef3",
SpineMultiplyMaterial,
BlendMode::Multiply,
false,
Expand All @@ -263,7 +259,6 @@ material!(

material!(
/// Screen blend mode material, non-premultiplied-alpha
"5d357844-6a06-4238-aaef-9da95186590b",
SpineScreenMaterial,
BlendMode::Screen,
false,
Expand All @@ -283,7 +278,6 @@ material!(

material!(
/// Normal blend mode material, premultiplied-alpha
"296e2f58-f5f0-4a51-9f4b-dbcec06ddc04",
SpineNormalPmaMaterial,
BlendMode::Normal,
true,
Expand All @@ -303,7 +297,6 @@ material!(

material!(
/// Additive blend mode material, premultiplied-alpha
"0f546186-4e05-434b-a0e1-3e1454b2cc7a",
SpineAdditivePmaMaterial,
BlendMode::Additive,
true,
Expand All @@ -323,7 +316,6 @@ material!(

material!(
/// Multiply blend mode material, premultiplied-alpha
"d8ef56cf-88b9-46f8-971b-7583baf8c20b",
SpineMultiplyPmaMaterial,
BlendMode::Multiply,
true,
Expand All @@ -343,7 +335,6 @@ material!(

material!(
/// Screen blend mode material, premultiplied-alpha
"1cd4d391-e106-4585-928f-124f998f28b6",
SpineScreenPmaMaterial,
BlendMode::Screen,
true,
Expand Down
4 changes: 2 additions & 2 deletions src/spine.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ fn vertex(vertex: Vertex) -> VertexOutput {
return out;
}

@group(1) @binding(0)
@group(2) @binding(0)
var texture: texture_2d<f32>;
@group(1) @binding(1)
@group(2) @binding(1)
var texture_sampler: sampler;

@fragment
Expand Down
1 change: 1 addition & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn test_app() -> App {
..default()
}
.into(),
..default()
})
.build()
.disable::<WinitPlugin>(),
Expand Down

0 comments on commit ff0b74c

Please sign in to comment.