Skip to content

Commit

Permalink
Merge pull request #38 from james-j-obrien/bevy-0.13
Browse files Browse the repository at this point in the history
Update to Bevy 0.13
  • Loading branch information
james-j-obrien authored Feb 17, 2024
2 parents e1c33dc + e5f3d0e commit ec611e2
Show file tree
Hide file tree
Showing 28 changed files with 1,105 additions and 717 deletions.
1,252 changes: 797 additions & 455 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ keywords = ["bevy", "gamedev", "graphics"]
license = "MIT OR Apache-2.0"
name = "bevy_vector_shapes"
repository = "https://github.com/james-j-obrien/bevy_vector_shapes"
version = "0.6.0"
version = "0.7.0"

[dependencies]
any_vec = "0.13.0"
bevy = { version = "0.12" , default-features = false, features = [
bevy = { version = "0.13" , default-features = false, features = [
"bevy_core_pipeline",
"bevy_pbr",
"bevy_render",
Expand All @@ -28,5 +28,5 @@ bevy = { version = "0.12" , default-features = false, features = [
]}
bitfield = "0.14.0"
bitflags = "2.3"
smallvec = "1.11.1"
wgpu = "0.17.1"
smallvec = "1.13.1"
wgpu = { version = "0.19.1", default-features = false }
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fn draw(mut painter: ShapePainter) {

| bevy | bevy_vector_shapes |
| ---- | ------------------ |
| 0.13 | 0.7.0 |
| 0.12 | 0.6.0 |
| 0.11 | 0.5.2 |
| 0.10 | 0.4.6 |
Expand Down
2 changes: 1 addition & 1 deletion examples/billboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn draw_gallery(
painter: ShapePainter,
mut cameras: Query<&mut Transform, With<Camera3d>>,
) {
cameras.for_each_mut(|mut tf| {
cameras.iter_mut().for_each(|mut tf| {
*tf = Transform::from_translation(
Quat::from_rotation_y(time.elapsed_seconds()) * Vec3::new(0., 2.5, 16.),
)
Expand Down
5 changes: 4 additions & 1 deletion examples/bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ fn setup(mut commands: Commands) {
..default()
},));

// Note: [`ShapeBundle`] does not include `RenderLayers` by default so the associated field
// on [`ShapeConfig`] will be ignored, add the component manually or use [`ShapeCommands::rect`]
// instead which will handle adding the `RenderLayers` component
commands.spawn(
ShapeBundle::rect(
&ShapeConfig {
Expand All @@ -34,7 +37,7 @@ fn setup(mut commands: Commands) {
}

fn update_shapes(time: Res<Time>, mut shapes: Query<&mut Transform, With<ShapeMaterial>>) {
shapes.for_each_mut(|mut tf| {
shapes.iter_mut().for_each(|mut tf| {
tf.rotate_local_z(time.delta_seconds());
})
}
4 changes: 2 additions & 2 deletions examples/canvas_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
});
}

fn update_canvas(keys: Res<Input<KeyCode>>, mut canvas: Query<&mut Canvas>) {
fn update_canvas(keys: Res<ButtonInput<KeyCode>>, mut canvas: Query<&mut Canvas>) {
let mut canvas = canvas.single_mut();

if keys.just_pressed(KeyCode::Space) {
canvas.redraw();
}

if keys.just_pressed(KeyCode::M) {
if keys.just_pressed(KeyCode::KeyM) {
canvas.mode = match canvas.mode {
CanvasMode::Continuous => CanvasMode::Persistent,
CanvasMode::Persistent => CanvasMode::OnDemand,
Expand Down
7 changes: 5 additions & 2 deletions examples/parenting_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Alternatively see the `bundles` example to spawn shapes as bundles and bypass ShapeCommands entirely.
use std::f32::consts::PI;

use bevy::math::primitives::Cuboid;
use bevy::prelude::*;
use bevy_vector_shapes::prelude::*;

Expand Down Expand Up @@ -38,7 +39,7 @@ fn setup(mut commands: Commands, mut shapes: ShapeCommands, mut meshes: ResMut<A
}
});

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

// When spawning non-shapes as children of shapes you can use `with_children` like normal
shapes
Expand All @@ -60,5 +61,7 @@ fn setup(mut commands: Commands, mut shapes: ShapeCommands, mut meshes: ResMut<A
}

fn rotate_targets(time: Res<Time>, mut target: Query<&mut Transform, With<Target>>) {
target.for_each_mut(|mut tf| tf.rotation *= Quat::from_rotation_z(time.delta_seconds()))
target
.iter_mut()
.for_each(|mut tf| tf.rotation *= Quat::from_rotation_z(time.delta_seconds()))
}
8 changes: 2 additions & 6 deletions examples/render_layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::f32::consts::PI;

use bevy::{
core_pipeline::clear_color::ClearColorConfig,
prelude::*,
render::{camera::RenderTarget, texture::ImageSampler, view::RenderLayers},
};
Expand Down Expand Up @@ -45,11 +44,8 @@ fn setup(

commands.spawn((
Camera3dBundle {
camera_3d: Camera3d {
clear_color: ClearColorConfig::Custom(Color::WHITE),
..default()
},
camera: Camera {
clear_color: ClearColorConfig::Custom(Color::WHITE),
// render before the "main pass" camera
order: -1,
target: RenderTarget::Image(image_handle.clone()),
Expand All @@ -63,7 +59,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(Mesh::from(Cuboid::new(cube_size, cube_size, cube_size)));

// This material has the texture that has been rendered.
let material_handle = materials.add(StandardMaterial {
Expand Down
6 changes: 4 additions & 2 deletions examples/retained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ fn setup(mut commands: Commands, mut shapes: ShapeCommands) {
});
}

fn rotate_circle(time: Res<Time>, mut circle: Query<&mut Transform, With<Disc>>) {
circle.for_each_mut(|mut tf| tf.rotation *= Quat::from_rotation_z(time.delta_seconds()))
fn rotate_circle(time: Res<Time>, mut circle: Query<&mut Transform, With<DiscComponent>>) {
circle
.iter_mut()
.for_each(|mut tf| tf.rotation *= Quat::from_rotation_z(time.delta_seconds()))
}
2 changes: 1 addition & 1 deletion examples/textured.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Demonstrated shapes respecting render layers
// Adapted directly from https://github.com/bevyengine/bevy/blob/main/examples/3d/render_to_texture.rs

use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*};
use bevy::prelude::*;
use bevy_vector_shapes::prelude::*;

mod gallery_3d;
Expand Down
2 changes: 1 addition & 1 deletion examples/thickness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn draw_gallery(
mut cameras: Query<&mut Transform, With<Camera3d>>,
) {
painter.reset();
cameras.for_each_mut(|mut tf| {
cameras.iter_mut().for_each(|mut tf| {
*tf = Transform::from_xyz(0., 0., 20. + 10.0 * time.elapsed_seconds().sin())
.looking_at(Vec3::ZERO, Vec3::Y);
});
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ impl Plugin for Shape2dPlugin {
app.insert_resource(BaseShapeConfig(self.base_config.clone()))
.add_plugins(PainterPlugin)
.add_plugins(ShapeRenderPlugin)
.add_plugins(ShapeTypePlugin::<Line>::default())
.add_plugins(ShapeTypePlugin::<Disc>::default())
.add_plugins(ShapeTypePlugin::<Rectangle>::default())
.add_plugins(ShapeTypePlugin::<RegularPolygon>::default())
.add_plugins(ShapeTypePlugin::<Triangle>::default());
.add_plugins(ShapeTypePlugin::<LineComponent>::default())
.add_plugins(ShapeTypePlugin::<DiscComponent>::default())
.add_plugins(ShapeTypePlugin::<RectangleComponent>::default())
.add_plugins(ShapeTypePlugin::<RegularPolygonComponent>::default())
.add_plugins(ShapeTypePlugin::<TriangleComponent>::default());
}
}

Expand Down Expand Up @@ -132,10 +132,10 @@ impl Plugin for ShapePlugin {
if !self.exclude_2d {
app.add_plugins(Shape2dPlugin::new(self.base_config.clone()));
}
app.add_plugins(ShapeType3dPlugin::<Line>::default())
.add_plugins(ShapeType3dPlugin::<Disc>::default())
.add_plugins(ShapeType3dPlugin::<Rectangle>::default())
.add_plugins(ShapeType3dPlugin::<RegularPolygon>::default())
.add_plugins(ShapeType3dPlugin::<Triangle>::default());
app.add_plugins(ShapeType3dPlugin::<LineComponent>::default())
.add_plugins(ShapeType3dPlugin::<DiscComponent>::default())
.add_plugins(ShapeType3dPlugin::<RectangleComponent>::default())
.add_plugins(ShapeType3dPlugin::<RegularPolygonComponent>::default())
.add_plugins(ShapeType3dPlugin::<TriangleComponent>::default());
}
}
67 changes: 31 additions & 36 deletions src/painter/canvas.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use bevy::{
core_pipeline::clear_color::ClearColorConfig,
ecs::system::EntityCommands,
prelude::*,
render::{
Expand All @@ -14,40 +13,37 @@ use wgpu::{Extent3d, TextureDescriptor, TextureDimension, TextureFormat, Texture
///
/// Replaces the image handle when the canvas is resized and applies [`CanvasMode`] behaviours.
pub fn update_canvases(
mut canvases: Query<(
&mut Canvas,
&mut Camera,
&mut Camera2d,
&mut OrthographicProjection,
)>,
mut canvases: Query<(&mut Canvas, &mut Camera, &mut OrthographicProjection)>,
) {
canvases.for_each_mut(|(mut canvas, mut camera, mut camera_2d, mut projection)| {
if let RenderTarget::Image(camera_handle) = &camera.target {
if camera_handle != &canvas.image {
camera.target = RenderTarget::Image(canvas.image.clone());
projection.set_changed();
canvases
.iter_mut()
.for_each(|(mut canvas, mut camera, mut projection)| {
if let RenderTarget::Image(camera_handle) = &camera.target {
if camera_handle != &canvas.image {
camera.target = RenderTarget::Image(canvas.image.clone());
projection.set_changed();
}
}
}

match canvas.mode {
CanvasMode::Continuous => {
camera_2d.clear_color = canvas.clear_color.clone();
camera.is_active = true;
}
CanvasMode::Persistent => {
if canvas.redraw {
camera_2d.clear_color = canvas.clear_color.clone();
} else {
camera_2d.clear_color = ClearColorConfig::None;
match canvas.mode {
CanvasMode::Continuous => {
camera.clear_color = canvas.clear_color.clone();
camera.is_active = true;
}
CanvasMode::Persistent => {
if canvas.redraw {
camera.clear_color = canvas.clear_color.clone();
} else {
camera.clear_color = ClearColorConfig::None;
}
}
CanvasMode::OnDemand => {
camera.is_active = canvas.redraw;
}
}
CanvasMode::OnDemand => {
camera.is_active = canvas.redraw;
}
}

canvas.redraw = false;
})
canvas.redraw = false;
})
}

/// Enum that determines when canvases are cleared and redrawn.
Expand Down Expand Up @@ -195,13 +191,12 @@ impl CanvasBundle {
pub fn new(image: Handle<Image>, config: CanvasConfig) -> Self {
Self {
camera: Camera2dBundle {
camera_2d: Camera2d {
clear_color: config.clear_color.clone(),
},
camera_2d: Camera2d,
camera: Camera {
order: config.order,
hdr: config.hdr,
target: RenderTarget::Image(image.clone()),
clear_color: config.clear_color.clone(),
..default()
},
..default()
Expand All @@ -221,23 +216,23 @@ impl CanvasBundle {
}

/// Extension trait for [`Commands`] to allow spawning of [`CanvasBundle`] entities.
pub trait CanvasCommands<'w, 's> {
pub trait CanvasCommands<'w> {
/// Spawns a [`CanvasBundle`] according to the given [`CanvasConfig`].
///
/// Returns the created [`Handle<Image>`] and [`EntityCommands`].
fn spawn_canvas(
&mut self,
assets: &mut Assets<Image>,
config: CanvasConfig,
) -> (Handle<Image>, EntityCommands<'w, 's, '_>);
) -> (Handle<Image>, EntityCommands);
}

impl<'w, 's> CanvasCommands<'w, 's> for Commands<'w, 's> {
impl<'w, 's> CanvasCommands<'w> for Commands<'w, 's> {
fn spawn_canvas(
&mut self,
assets: &mut Assets<Image>,
config: CanvasConfig,
) -> (Handle<Image>, EntityCommands<'w, 's, '_>) {
) -> (Handle<Image>, EntityCommands) {
let handle = Canvas::create_image(
assets,
config.width,
Expand Down
Loading

0 comments on commit ec611e2

Please sign in to comment.