Skip to content

Commit 9dac92e

Browse files
BendzaeIceSentry
andauthored
Bevy 0.15 (#70)
Co-authored-by: IceSentry <[email protected]>
1 parent 81a38cd commit 9dac92e

File tree

9 files changed

+132
-125
lines changed

9 files changed

+132
-125
lines changed

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
edition = "2021"
33
name = "bevy_polyline"
4-
version = "0.10.0"
4+
version = "0.11.0"
55
description = "Polyline Rendering for Bevy"
66
license = "MIT OR Apache-2.0"
77
repository = "https://github.com/ForesightMiningSoftwareCorporation/bevy_polyline"
@@ -18,7 +18,7 @@ authors = [
1818

1919
[dependencies]
2020
bitflags = "2.3"
21-
bevy = { version = "0.14", default-features = false, features = [
21+
bevy = { version = "0.15", default-features = false, features = [
2222
"bevy_core_pipeline",
2323
"bevy_render",
2424
"bevy_asset",
@@ -29,7 +29,8 @@ bytemuck = "1.16.1"
2929
lazy_static = "1.4.0"
3030
rand = "0.8.4"
3131
ringbuffer = "0.15"
32-
bevy = { version = "0.14", default-features = false, features = [
32+
bevy = { version = "0.15", default-features = false, features = [
33+
"bevy_window",
3334
"bevy_winit",
3435
"bevy_pbr",
3536
"x11",

examples/depth_bias.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use bevy_polyline::prelude::*;
2222
fn main() {
2323
App::new()
2424
.insert_resource(ClearColor(Color::BLACK))
25-
.insert_resource(Msaa::Sample4)
2625
.add_plugins(DefaultPlugins)
2726
.add_plugins(PolylinePlugin)
2827
.add_systems(Update, (move_camera, rotate_plane))
@@ -34,7 +33,7 @@ fn main() {
3433
struct Rotating(f64);
3534

3635
fn rotate_plane(time: Res<Time>, mut animated: Query<(&mut Transform, &Rotating)>) {
37-
let time = time.elapsed_seconds_f64();
36+
let time = time.elapsed_secs_f64();
3837
for (mut trans, Rotating(period)) in animated.iter_mut() {
3938
let angle = time % period / period * TAU64;
4039
let rot = Quat::from_rotation_y(angle as f32);
@@ -61,30 +60,29 @@ fn setup(
6160
mut polylines: ResMut<Assets<Polyline>>,
6261
mut materials: ResMut<Assets<PolylineMaterial>>,
6362
) {
64-
commands
65-
.spawn(Camera3dBundle::default())
66-
.insert(Transform::from_xyz(100.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y));
6763
commands.spawn((
68-
PbrBundle {
69-
mesh: meshes.add(Cuboid::from_size(Vec3::new(0.01, 100.0, 10000.0)).mesh()),
70-
material: pbr_materials.add(Color::WHITE),
71-
..default()
72-
},
64+
Camera3d::default(),
65+
Msaa::Sample4,
66+
Transform::from_xyz(100.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
67+
));
68+
commands.spawn((
69+
Mesh3d(meshes.add(Cuboid::from_size(Vec3::new(0.01, 100.0, 10000.0)).mesh())),
70+
MeshMaterial3d(pbr_materials.add(Color::WHITE)),
7371
Rotating(30.0),
7472
));
7573
let top = Vec3::Y * 100.0;
7674
let bottom = Vec3::Y * -100.0;
7775
// Show the middle as a vertical red bar.
7876
commands.spawn(PolylineBundle {
79-
polyline: polylines.add(Polyline {
77+
polyline: PolylineHandle(polylines.add(Polyline {
8078
vertices: vec![top, bottom],
81-
}),
82-
material: materials.add(PolylineMaterial {
79+
})),
80+
material: PolylineMaterialHandle(materials.add(PolylineMaterial {
8381
width: 5.0,
8482
color: RED.into(),
8583
depth_bias: -1.0,
8684
perspective: false,
87-
}),
85+
})),
8886
..Default::default()
8987
});
9088
// Draw from bottom to top, red to purple, -1.0 to 1.0 horizontal lines
@@ -93,15 +91,15 @@ fn setup(
9391
let left = Vec3::new(0.0, bias * 35.0, -500.0);
9492
let right = Vec3::new(0.0, bias * 35.0, 500.0);
9593
commands.spawn(PolylineBundle {
96-
polyline: polylines.add(Polyline {
94+
polyline: PolylineHandle(polylines.add(Polyline {
9795
vertices: vec![left, right],
98-
}),
99-
material: materials.add(PolylineMaterial {
96+
})),
97+
material: PolylineMaterialHandle(materials.add(PolylineMaterial {
10098
width: 1.0,
10199
color: Color::hsl((bias + 1.0) / 2.0 * 270.0, 1.0, 0.5).to_linear(),
102100
depth_bias: bias,
103101
perspective: false,
104-
}),
102+
})),
105103
..Default::default()
106104
});
107105
}

examples/linestrip.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use bevy::{color::palettes::css::RED, pbr::PointLightBundle, prelude::*};
1+
use bevy::{color::palettes::css::RED, prelude::*};
22
use bevy_polyline::prelude::*;
33

44
fn main() {
55
App::new()
6-
.insert_resource(Msaa::Sample4)
76
.add_plugins(DefaultPlugins)
87
.add_plugins(PolylinePlugin)
98
.add_systems(Startup, setup)
@@ -19,7 +18,7 @@ fn setup(
1918
mut polylines: ResMut<Assets<Polyline>>,
2019
) {
2120
commands.spawn(PolylineBundle {
22-
polyline: polylines.add(Polyline {
21+
polyline: PolylineHandle(polylines.add(Polyline {
2322
vertices: vec![
2423
Vec3::new(-0.5, -0.5, -0.5),
2524
Vec3::new(0.5, -0.5, -0.5),
@@ -30,45 +29,39 @@ fn setup(
3029
Vec3::new(0.5, -0.5, 0.5),
3130
Vec3::new(-0.5, -0.5, 0.5),
3231
],
33-
}),
34-
material: polyline_materials.add(PolylineMaterial {
32+
})),
33+
material: PolylineMaterialHandle(polyline_materials.add(PolylineMaterial {
3534
width: 2.0,
3635
color: RED.into(),
3736
perspective: false,
3837
// Bias the line toward the camera so the line at the cube-plane intersection is visible
3938
depth_bias: -0.0002,
40-
}),
39+
})),
4140
..Default::default()
4241
});
4342

4443
// circular base
45-
commands.spawn(PbrBundle {
46-
mesh: meshes.add(Circle::new(4.0)),
47-
material: standard_materials.add(Color::WHITE),
48-
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2))
44+
commands.spawn((
45+
Mesh3d(meshes.add(Circle::new(4.0))),
46+
MeshMaterial3d(standard_materials.add(Color::WHITE)),
47+
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2))
4948
.with_translation(Vec3::new(0.0, -0.5, 0.0)),
50-
..default()
51-
});
49+
));
5250
// cube
53-
commands.spawn(PbrBundle {
54-
mesh: meshes.add(Cuboid::from_size(Vec3::ONE)),
55-
material: standard_materials.add(Color::srgb_u8(124, 144, 255)),
56-
transform: Transform::from_xyz(0.0, 0.0, 0.0),
57-
..default()
58-
});
51+
commands.spawn((
52+
Mesh3d(meshes.add(Cuboid::from_size(Vec3::ONE))),
53+
MeshMaterial3d(standard_materials.add(Color::srgb_u8(124, 144, 255))),
54+
Transform::from_xyz(0.0, 0.0, 0.0),
55+
));
5956

6057
// light
61-
commands.spawn(PointLightBundle {
62-
transform: Transform::from_xyz(4.0, 8.0, 4.0),
63-
..Default::default()
64-
});
58+
commands.spawn((PointLight::default(), Transform::from_xyz(4.0, 8.0, 4.0)));
6559

6660
// camera
6761
commands.spawn((
68-
Camera3dBundle {
69-
transform: Transform::from_xyz(-2.0, 2.5, -5.0).looking_at(Vec3::ZERO, Vec3::Y),
70-
..Camera3dBundle::default()
71-
},
62+
Camera3d::default(),
63+
Msaa::Sample4,
64+
Transform::from_xyz(-2.0, 2.5, -5.0).looking_at(Vec3::ZERO, Vec3::Y),
7265
Rotates,
7366
));
7467
}
@@ -80,7 +73,7 @@ struct Rotates;
8073
fn rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<Rotates>>) {
8174
for mut transform in query.iter_mut() {
8275
*transform = Transform::from_rotation(Quat::from_rotation_y(
83-
(4.0 * std::f32::consts::PI / 20.0) * time.delta_seconds(),
76+
(4.0 * std::f32::consts::PI / 20.0) * time.delta_secs(),
8477
)) * *transform;
8578
}
8679
}

examples/minimal.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,26 @@ fn setup(
1515
mut polylines: ResMut<Assets<Polyline>>,
1616
) {
1717
commands.spawn(PolylineBundle {
18-
polyline: polylines.add(Polyline {
18+
polyline: PolylineHandle(polylines.add(Polyline {
1919
vertices: vec![-Vec3::ONE, Vec3::ONE],
20-
}),
21-
material: polyline_materials.add(PolylineMaterial {
20+
})),
21+
material: PolylineMaterialHandle(polyline_materials.add(PolylineMaterial {
2222
width: 10.0,
2323
color: RED.into(),
2424
perspective: false,
2525
..default()
26-
}),
26+
})),
2727
..default()
2828
});
2929

3030
// camera
31-
commands.spawn(Camera3dBundle {
32-
transform: Transform::from_xyz(0.0, 0.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
33-
camera: Camera {
31+
commands.spawn((
32+
Camera3d::default(),
33+
Camera {
3434
hdr: true,
3535
..default()
3636
},
37-
..default()
38-
});
37+
Msaa::Sample4,
38+
Transform::from_xyz(0.0, 0.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
39+
));
3940
}

examples/nbody.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::f32::consts::PI;
22

33
use bevy::{
4+
core_pipeline::{bloom::Bloom, tonemapping::Tonemapping},
45
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
56
math::Vec3A,
67
prelude::*,
@@ -18,7 +19,6 @@ const MINIMUM_ANGLE: f32 = 1.483_418_7; // == acos(5 degrees)
1819
fn main() {
1920
App::new()
2021
.insert_resource(ClearColor(Color::BLACK))
21-
.insert_resource(Msaa::Sample4)
2222
.insert_resource(Simulation {
2323
scale: 1e6,
2424
..Default::default()
@@ -59,32 +59,33 @@ fn setup(
5959
},
6060
Trail(ConstGenericRingBuffer::<Vec3A, TRAIL_LENGTH>::new()),
6161
PolylineBundle {
62-
polyline: polylines.add(Polyline {
62+
polyline: PolylineHandle(polylines.add(Polyline {
6363
vertices: Vec::with_capacity(TRAIL_LENGTH),
64-
}),
65-
material: polyline_materials.add(PolylineMaterial {
66-
width: (size * 0.1).powf(1.8),
67-
color: Color::hsl(rng.gen_range(0.0..360.0), 1.0, rng.gen_range(1.2..3.0))
68-
.to_linear(),
69-
perspective: true,
70-
..Default::default()
71-
}),
64+
})),
65+
material: PolylineMaterialHandle(
66+
polyline_materials.add(PolylineMaterial {
67+
width: (size * 0.1).powf(1.8),
68+
color: Color::hsl(rng.gen_range(0.0..360.0), 1.0, rng.gen_range(1.2..3.0))
69+
.to_linear(),
70+
perspective: true,
71+
..Default::default()
72+
}),
73+
),
7274
..Default::default()
7375
},
7476
));
7577
}
7678

7779
// camera
7880
commands.spawn((
79-
Camera3dBundle {
80-
camera: Camera {
81-
hdr: true,
82-
..default()
83-
},
84-
tonemapping: bevy::core_pipeline::tonemapping::Tonemapping::TonyMcMapface,
81+
Camera3d::default(),
82+
Camera {
83+
hdr: true,
8584
..default()
8685
},
87-
bevy::core_pipeline::bloom::BloomSettings { ..default() },
86+
Msaa::Sample4,
87+
Tonemapping::TonyMcMapface,
88+
Bloom::default(),
8889
Rotates,
8990
));
9091
}
@@ -95,7 +96,7 @@ struct Rotates;
9596

9697
fn rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<Rotates>>) {
9798
for mut transform in query.iter_mut() {
98-
let t = time.elapsed_seconds();
99+
let t = time.elapsed_secs();
99100
let r = 1100.0;
100101
*transform = Transform::from_xyz(
101102
r * f32::cos(t * 0.1),
@@ -136,7 +137,7 @@ impl Default for Simulation {
136137
impl Simulation {
137138
fn update(&mut self, time: &Time) {
138139
if !self.is_paused {
139-
self.accumulator += time.delta_seconds();
140+
self.accumulator += time.delta_secs();
140141
}
141142
}
142143

@@ -157,7 +158,7 @@ const EPSILON: f32 = 1.;
157158
fn nbody_system(
158159
time: Res<Time>,
159160
mut simulation: ResMut<Simulation>,
160-
mut query: Query<(Entity, &mut Body, &mut Trail, &Handle<Polyline>)>,
161+
mut query: Query<(Entity, &mut Body, &mut Trail, &PolylineHandle)>,
161162
) {
162163
let mut bodies = query.iter_mut().collect::<Vec<_>>();
163164
// dbg!(&bodies);
@@ -204,7 +205,7 @@ fn nbody_system(
204205

205206
fn update_trails(
206207
mut polylines: ResMut<Assets<Polyline>>,
207-
mut query: Query<(&Body, &mut Trail, &Handle<Polyline>)>,
208+
mut query: Query<(&Body, &mut Trail, &PolylineHandle)>,
208209
) {
209210
query.iter_mut().for_each(|(body, mut trail, polyline)| {
210211
if let Some(position) = trail.0.back() {
@@ -217,14 +218,14 @@ fn update_trails(
217218
let gt_min_angle = last_vec.dot(last_last_vec) > MINIMUM_ANGLE;
218219
if gt_min_angle {
219220
trail.0.push(body.position);
220-
polylines.get_mut(polyline).unwrap().vertices =
221+
polylines.get_mut(&polyline.0).unwrap().vertices =
221222
trail.0.iter().map(|v| Vec3::from(*v)).collect()
222223
} else {
223224
// If the last point didn't actually add much of a curve, just overwrite it.
224-
if polylines.get_mut(polyline).unwrap().vertices.len() > 1 {
225+
if polylines.get_mut(&polyline.0).unwrap().vertices.len() > 1 {
225226
*trail.0.get_mut_signed(-1).unwrap() = body.position;
226227
*polylines
227-
.get_mut(polyline)
228+
.get_mut(&polyline.0)
228229
.unwrap()
229230
.vertices
230231
.last_mut()
@@ -233,7 +234,7 @@ fn update_trails(
233234
}
234235
} else {
235236
trail.0.push(body.position);
236-
polylines.get_mut(polyline).unwrap().vertices =
237+
polylines.get_mut(&polyline.0).unwrap().vertices =
237238
trail.0.iter().map(|v| Vec3::from(*v)).collect()
238239
}
239240
});

0 commit comments

Comments
 (0)