Skip to content

Commit

Permalink
Merge pull request #20 from johanhelsing/bevy-0.9
Browse files Browse the repository at this point in the history
Update to Bevy 0.9
  • Loading branch information
johanhelsing authored Nov 20, 2022
2 parents 993e15c + f259a2c commit af56400
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 324 deletions.
12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ repository = "https://github.com/johanhelsing/bevy_smud"
version = "0.3.1"

[dependencies]
bevy = {version = "0.8", default-features = false, features = ["render", "bevy_asset"]}
bevy-inspector-egui = {version = "0.13", optional = true}
bitflags = "1.2"
bevy = {version = "0.9", default-features = false, features = ["render", "bevy_asset"]}
bytemuck = "1.7"
copyless = "0.1"

[dev-dependencies]
bevy = {version = "0.8", default-features = false, features = [
bevy = {version = "0.9", default-features = false, features = [
"render",
"bevy_winit",
"x11", # github actions runenrs don't have libxkbcommon installed, so can't use wayland
"filesystem_watcher",
]}
bevy_asset_loader = "0.13"
bevy_lospec = "0.2"
bevy_pancam = "0.6"
bevy_asset_loader = "0.14"
bevy_lospec = "0.3"
bevy_pancam = "0.7"
rand = "0.8"

[profile.dev]
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn spawn_circle(
) {
let circle = shaders.add_sdf_expr("sd_circle(p, 50.)");

commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
shape: SmudShape {
color: Color::TOMATO,
sdf: circle,
Expand All @@ -58,8 +58,6 @@ Other than that, make sure you understand how to combine shapes, use symmetries

Also, check out the [examples](examples). In particular, the [basic](examples/basic.rs) example should be a good place to start.

The library also has *some* level of ui support. The [ui](examples/ui.rs) example shows how to create a "bevy" button.

## Showcase

Send me a PR if you want your project featured here:
Expand Down
2 changes: 1 addition & 1 deletion assets/star_bevy.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ fn star(p: vec2<f32>) -> f32 {
fn sdf(p: vec2<f32>) -> f32 {
let b = bevy(p);
let s = star(p);
return mix(b, s, sin(time.seconds_since_startup) * 0.5 + 0.5);
return mix(b, s, sin(globals.time) * 0.5 + 0.5);
// return mix(b, s, 1.0);
}
9 changes: 4 additions & 5 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use bevy_smud::prelude::*;

fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_plugin(SmudPlugin)
.add_startup_system(setup)
Expand Down Expand Up @@ -36,7 +35,7 @@ return sd_circle(p - vec2<f32>(20., 0.), 40.);
// If the sdf gets very complicated, you can keep it in a .wgsl file:
let bevy = asset_server.load("bevy.wgsl");

commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
shape: SmudShape {
color: Color::TOMATO,
sdf: circle,
Expand All @@ -48,7 +47,7 @@ return sd_circle(p - vec2<f32>(20., 0.), 40.);
..default()
});

commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::X * 200.),
shape: SmudShape {
color: Color::rgb(0.7, 0.6, 0.4),
Expand All @@ -59,7 +58,7 @@ return sd_circle(p - vec2<f32>(20., 0.), 40.);
..default()
});

commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
transform: Transform {
translation: Vec3::X * -200.,
scale: Vec3::splat(0.4),
Expand All @@ -76,5 +75,5 @@ return sd_circle(p - vec2<f32>(20., 0.), 40.);
..default()
});

commands.spawn_bundle(Camera2dBundle::default());
commands.spawn(Camera2dBundle::default());
}
15 changes: 7 additions & 8 deletions examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ enum GameState {
Running,
}

#[derive(AssetCollection)]
#[derive(Resource, AssetCollection)]
struct AssetHandles {
#[asset(path = "vinik24.json")]
palette: Handle<bevy_lospec::Palette>,
Expand Down Expand Up @@ -71,8 +71,8 @@ fn setup(
.copied()
.unwrap_or(Color::PINK);

commands
.spawn_bundle(ShapeBundle {
commands.spawn((
ShapeBundle {
transform: Transform::from_translation(Vec3::new(
i as f32 * spacing - w as f32 * spacing / 2.,
j as f32 * spacing - h as f32 * spacing / 2.,
Expand All @@ -85,13 +85,12 @@ fn setup(
..default()
},
..default()
})
.insert(Index(i + j * w));
},
Index(i + j * w),
));
}
}
commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));
}

// fn update(mut query: Query<(&mut Transform, &Index), With<SmudShape>>, time: Res<Time>) {
Expand Down
7 changes: 2 additions & 5 deletions examples/bevy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use bevy_smud::*;

fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(ClearColor(Color::rgb(0.7, 0.8, 0.7)))
.add_plugins(DefaultPlugins)
.add_plugin(SmudPlugin)
Expand All @@ -16,7 +15,7 @@ fn main() {
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let bevy_shape_shader = asset_server.load("bevy.wgsl");

commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
shape: SmudShape {
color: Color::rgb(0.36, 0.41, 0.45),
sdf: bevy_shape_shader,
Expand All @@ -26,7 +25,5 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
});

commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));
}
11 changes: 4 additions & 7 deletions examples/custom_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use bevy_smud::{prelude::*, SIMPLE_FILL_HANDLE};

fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(ClearColor(Color::BLACK))
.add_plugins(DefaultPlugins)
.add_plugin(SmudPlugin)
Expand All @@ -21,7 +20,7 @@ fn setup(
// The fill takes a distance and a color and returns another color
let sin_fill = shaders.add_fill_body("return vec4<f32>(color.rgb, sin(d));");

commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
shape: SmudShape {
color: Color::TEAL,
sdf: asset_server.load("bevy.wgsl"),
Expand All @@ -31,7 +30,7 @@ fn setup(
..default()
});

commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::X * 600.),
shape: SmudShape {
color: Color::BLUE,
Expand All @@ -42,7 +41,7 @@ fn setup(
..default()
});

commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::X * -600.),
shape: SmudShape {
color: Color::ORANGE,
Expand All @@ -60,7 +59,5 @@ return vec4<f32>(color.rgb, a * color.a);
..default()
});

commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));
}
15 changes: 7 additions & 8 deletions examples/gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum GameState {
Running,
}

#[derive(AssetCollection)]
#[derive(Resource, AssetCollection)]
struct AssetHandles {
#[asset(path = "vinik24.json")]
palette: Handle<bevy_lospec::Palette>,
Expand Down Expand Up @@ -98,8 +98,8 @@ fn setup(

let index = i + j * w;

commands
.spawn_bundle(ShapeBundle {
commands.spawn((
ShapeBundle {
transform: Transform::from_translation(Vec3::new(
i as f32 * spacing - w as f32 * spacing / 2.,
j as f32 * spacing - h as f32 * spacing / 2.,
Expand All @@ -113,14 +113,13 @@ fn setup(
fill: fills.choose(&mut rng).unwrap().clone(),
},
..default()
})
.insert(Index(index));
},
Index(index),
));
}
}

commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));
}

// fn update(mut query: Query<(&mut Transform, &Index), With<SmudShape>>, time: Res<Time>) {
Expand Down
13 changes: 7 additions & 6 deletions examples/hot_reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ use bevy_smud::prelude::*;

fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_plugins(DefaultPlugins.set(AssetPlugin {
// enable hot-reloading so we can see changes to wgsl files without relaunching the app
watch_for_changes: true,
..default()
}))
.add_plugin(SmudPlugin)
.add_startup_system(setup)
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
asset_server.watch_for_changes().unwrap();

// When sdfs are loaded from files, hot reloading works as normal
// Open up assets/bevy.wgsl and make some changes and see them reflected when you save
let bevy = asset_server.load("bevy.wgsl");

commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
transform: Transform {
scale: Vec3::splat(0.4),
..default()
Expand All @@ -33,5 +34,5 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
});

commands.spawn_bundle(Camera2dBundle::default());
commands.spawn(Camera2dBundle::default());
}
11 changes: 4 additions & 7 deletions examples/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use bevy_smud::prelude::*;

fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(ClearColor(Color::rgb(0.7, 0.8, 0.7)))
.add_plugins(DefaultPlugins)
.add_plugin(SmudPlugin)
Expand All @@ -15,7 +14,7 @@ fn main() {

fn setup(mut commands: Commands, mut shaders: ResMut<Assets<Shader>>) {
// pupil
commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::Z * 3.),
shape: SmudShape {
color: Color::rgb(0.0, 0.0, 0.0),
Expand All @@ -27,7 +26,7 @@ fn setup(mut commands: Commands, mut shaders: ResMut<Assets<Shader>>) {
});

// iris
commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::Z * 2.),
shape: SmudShape {
color: Color::rgb(0.46, 0.42, 0.80),
Expand All @@ -39,7 +38,7 @@ fn setup(mut commands: Commands, mut shaders: ResMut<Assets<Shader>>) {
});

// sclera
commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::Z * 1.),
shape: SmudShape {
color: Color::rgb(0.83, 0.82, 0.80),
Expand All @@ -50,7 +49,5 @@ fn setup(mut commands: Commands, mut shaders: ResMut<Assets<Shader>>) {
..default()
});

commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));
}
8 changes: 2 additions & 6 deletions examples/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use bevy_smud::*;

fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(ClearColor(Color::rgb(0.7, 0.8, 0.7)))
.add_plugins(DefaultPlugins)
.add_plugin(SmudPlugin)
Expand All @@ -14,10 +13,9 @@ fn main() {
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
asset_server.watch_for_changes().unwrap();
let bevy_shape_shader = asset_server.load("star_bevy.wgsl");

commands.spawn_bundle(ShapeBundle {
commands.spawn(ShapeBundle {
shape: SmudShape {
color: Color::rgb(0.36, 0.41, 0.45),
sdf: bevy_shape_shader,
Expand All @@ -27,7 +25,5 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
});

commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));
}
13 changes: 5 additions & 8 deletions examples/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use bevy_smud::*;
fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(ClearColor(Color::rgb(0.7, 0.8, 0.7)))
.add_plugins(DefaultPlugins)
.add_plugin(SmudPlugin)
Expand All @@ -26,34 +25,32 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {

let shape = SmudShape {
color: Color::rgb(0.36, 0.41, 0.45),
sdf: bevy_shape_shader.clone(),
sdf: bevy_shape_shader,
frame: Frame::Quad(295.),
..default()
};

// Bevies, all the way down
commands
.spawn_bundle(ShapeBundle {
.spawn(ShapeBundle {
shape: shape.clone(),
..default()
})
.with_children(|parent| {
parent
.spawn_bundle(ShapeBundle {
.spawn(ShapeBundle {
transform,
shape: shape.clone(),
..default()
})
.with_children(|parent| {
parent.spawn_bundle(ShapeBundle {
parent.spawn(ShapeBundle {
transform,
shape: shape.clone(),
..default()
});
});
});

commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));
}
Loading

0 comments on commit af56400

Please sign in to comment.