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

Upgrading to Bevy 0.12 #52

Closed
Closed
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/target
Cargo.lock
.vscode
.vscode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to remove additional changes from this file.


.idea/
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "bevy_polyline"
version = "0.7.0"
version = "0.8.0"
description = "Polyline Rendering for Bevy"
license = "MIT OR Apache-2.0"
repository = "https://github.com/ForesightMiningSoftwareCorporation/bevy_polyline"
Expand All @@ -17,22 +17,22 @@ authors = [
]

[dependencies]
bitflags = "2.3"
bevy = { version = "0.11.0", default-features = false, features = [
bitflags = "2.4.1"
bevy = { version = "0.12.0", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset",
] }

[dependencies.naga]
features = ["glsl-in", "spv-out", "wgsl-out"]
version = "0.12"
version = "0.14"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you set it to 0.13? This is what bevy use.


[dev-dependencies]
lazy_static = "1.4.0"
rand = "0.8.4"
ringbuffer = "0.14"
bevy = { version = "0.11.0", default-features = false, features = [
ringbuffer = "0.15"
bevy = { version = "0.12", default-features = false, features = [
"bevy_winit",
"bevy_pbr",
"x11",
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Due to instancing, Bevy Polyline only makes one drawcall per `PolyLine`, one for
We intend to track the `main` branch of Bevy. PRs supporting this are welcome!

| bevy | bevy_polyline |
| ---- | ------------- |
|------|---------------|
| 0.12 | 0.8 |
| 0.11 | 0.7 |
| 0.10 | 0.5, 0.6 |
| 0.9 | 0.4 |
Expand Down
3 changes: 3 additions & 0 deletions examples/depth_bias.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::f32::consts::TAU;
use std::f64::consts::TAU as TAU64;
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};

use bevy::prelude::*;
use bevy_polyline::prelude::*;
Expand All @@ -23,6 +24,8 @@ fn main() {
.insert_resource(ClearColor(Color::BLACK))
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugins(FrameTimeDiagnosticsPlugin::default())
.add_plugins(LogDiagnosticsPlugin::default())
Comment on lines +27 to +28
Copy link
Contributor

@Shatur Shatur Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you included these plugins into examples?

.add_plugins(PolylinePlugin)
.add_systems(Update, (move_camera, rotate_plane))
.add_systems(Startup, setup)
Expand Down
3 changes: 3 additions & 0 deletions examples/linestrip.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use bevy::{pbr::PointLightBundle, prelude::*};
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy_polyline::prelude::*;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugins(FrameTimeDiagnosticsPlugin::default())
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(PolylinePlugin)
.add_systems(Startup, setup)
.add_systems(Update, rotator_system)
Expand Down
3 changes: 3 additions & 0 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
use bevy_polyline::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(FrameTimeDiagnosticsPlugin::default())
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(PolylinePlugin)
.add_systems(Startup, setup)
.run();
Expand Down
13 changes: 7 additions & 6 deletions examples/nbody.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy_polyline::prelude::*;

use lazy_static::*;
use rand::{prelude::*, Rng};
use ringbuffer::{ConstGenericRingBuffer, RingBufferExt, RingBufferWrite};
use ringbuffer::{ConstGenericRingBuffer, RingBuffer};

const NUM_BODIES: usize = 512;
const TRAIL_LENGTH: usize = 1024;
Expand All @@ -24,14 +24,14 @@ fn main() {
..Default::default()
})
.add_plugins(DefaultPlugins)
.add_plugins(FrameTimeDiagnosticsPlugin::default())
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(PolylinePlugin)
.add_systems(Startup, setup)
.add_systems(
Update,
((nbody_system, update_trails).chain(), rotator_system),
)
.add_plugins(FrameTimeDiagnosticsPlugin::default())
.add_plugins(LogDiagnosticsPlugin::default())
.run();
}

Expand Down Expand Up @@ -101,7 +101,7 @@ fn rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<Rotates
(t * 0.1).sin() * 2000.0,
r * f32::sin(t * 0.1),
)
.looking_at(Vec3::ZERO, Vec3::Y);
.looking_at(Vec3::ZERO, Vec3::Y);
}
}

Expand Down Expand Up @@ -147,6 +147,7 @@ impl Simulation {
None
}
}

#[derive(Component, Clone, Default, Debug)]
struct Trail(ConstGenericRingBuffer<Vec3A, TRAIL_LENGTH>);

Expand Down Expand Up @@ -208,7 +209,7 @@ fn update_trails(
query.for_each_mut(|(body, mut trail, polyline)| {
if let Some(position) = trail.0.back() {
let last_vec = *position - body.position;
let last_last_vec = if let Some(position) = trail.0.get(-2) {
let last_last_vec = if let Some(position) = trail.0.get_signed(-2) {
*position - body.position
} else {
last_vec
Expand All @@ -221,7 +222,7 @@ fn update_trails(
} else {
// If the last point didn't actually add much of a curve, just overwrite it.
if polylines.get_mut(polyline).unwrap().vertices.len() > 1 {
*trail.0.get_mut(-1).unwrap() = body.position;
*trail.0.get_mut_signed(-1).unwrap() = body.position;
*polylines
.get_mut(polyline)
.unwrap()
Expand Down
3 changes: 3 additions & 0 deletions examples/perspective.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
use bevy_polyline::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(FrameTimeDiagnosticsPlugin::default())
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(PolylinePlugin)
.add_systems(Startup, setup)
.add_systems(Update, (move_camera, toggle_perspective))
Expand Down
16 changes: 5 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]

use bevy::{prelude::*, reflect::TypeUuid};
use bevy::prelude::*;
use material::PolylineMaterialPlugin;
use polyline::{PolylineBasePlugin, PolylineRenderPlugin};
use polyline::{PolylineRenderPlugin};

pub mod material;
pub mod polyline;
Expand All @@ -14,20 +14,14 @@ pub mod prelude {
pub use crate::PolylinePlugin;
}

pub const SHADER_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 12823766040132746065);
pub const SHADER_HANDLE: Handle<Shader> =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle::weak_from_u128(12823766040132746065);

pub struct PolylinePlugin;

impl Plugin for PolylinePlugin {
fn build(&self, app: &mut bevy::prelude::App) {
let mut shaders = app.world.get_resource_mut::<Assets<Shader>>().unwrap();
shaders.set_untracked(
SHADER_HANDLE,
Shader::from_wgsl(include_str!("shaders/polyline.wgsl"), file!()),
);
fn build(&self, app: &mut App) {
app.add_plugins((
PolylineBasePlugin,
PolylineRenderPlugin,
PolylineMaterialPlugin,
));
Expand Down
68 changes: 38 additions & 30 deletions src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bevy::{
},
},
prelude::*,
reflect::{TypePath, TypeUuid},
reflect::{TypePath},
render::{
extract_component::ExtractComponentPlugin,
render_asset::{RenderAsset, RenderAssetPlugin, RenderAssets},
Expand All @@ -28,8 +28,7 @@ use bevy::{
};
use std::fmt::Debug;

#[derive(Component, Debug, PartialEq, Clone, Copy, TypeUuid, TypePath)]
#[uuid = "69b87497-2ba0-4c38-ba82-f54bf1ffe873"]
#[derive(Asset, Debug, PartialEq, Clone, Copy, TypePath)]
pub struct PolylineMaterial {
/// Width of the line.
///
Expand Down Expand Up @@ -74,11 +73,11 @@ impl Default for PolylineMaterial {

impl PolylineMaterial {
fn fragment_shader() -> Handle<Shader> {
SHADER_HANDLE.typed()
SHADER_HANDLE
}

fn vertex_shader() -> Handle<Shader> {
SHADER_HANDLE.typed()
SHADER_HANDLE
}

pub fn bind_group_layout(render_device: &RenderDevice) -> BindGroupLayout {
Expand Down Expand Up @@ -138,7 +137,7 @@ impl RenderAsset for PolylineMaterial {

fn prepare_asset(
material: Self::ExtractedAsset,
(device, queue, polyline_pipeline): &mut bevy::ecs::system::SystemParamItem<Self::Param>,
(device, queue, polyline_pipeline): &mut SystemParamItem<Self::Param>,
) -> Result<
Self::PreparedAsset,
bevy::render::render_asset::PrepareAssetError<Self::ExtractedAsset>,
Expand All @@ -152,27 +151,28 @@ impl RenderAsset for PolylineMaterial {
let mut buffer = UniformBuffer::from(value);
buffer.write_buffer(device, queue);

let bind_group = device.create_bind_group(&BindGroupDescriptor {
entries: &[BindGroupEntry {
binding: 0,
resource: buffer.binding().unwrap(),
}],
label: Some("polyline_material_bind_group"),
layout: &polyline_pipeline.material_layout,
});

let alpha_mode = if material.color.a() < 1.0 {
AlphaMode::Blend
if let Some(binding) = buffer.binding() {
let bind_group = device.create_bind_group(
"polyline_material_bind_group",
&polyline_pipeline.material_layout,
&BindGroupEntries::single(binding),
);

let alpha_mode = if material.color.a() < 1.0 {
AlphaMode::Blend
} else {
AlphaMode::Opaque
};

Ok(GpuPolylineMaterial {
buffer,
perspective: material.perspective,
alpha_mode,
bind_group,
})
} else {
AlphaMode::Opaque
};

Ok(GpuPolylineMaterial {
buffer,
perspective: material.perspective,
alpha_mode,
bind_group,
})
panic!();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you panic here?

}
}
}

Expand All @@ -182,7 +182,7 @@ pub struct PolylineMaterialPlugin;

impl Plugin for PolylineMaterialPlugin {
fn build(&self, app: &mut App) {
app.add_asset::<PolylineMaterial>()
app.init_asset::<PolylineMaterial>()
.add_plugins(ExtractComponentPlugin::<Handle<PolylineMaterial>>::default())
.add_plugins(RenderAssetPlugin::<PolylineMaterial>::default());
}
Expand Down Expand Up @@ -250,10 +250,11 @@ type DrawMaterial = (
);

pub struct SetPolylineViewBindGroup<const I: usize>;

impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetPolylineViewBindGroup<I> {
type Param = ();
type ViewWorldQuery = (Read<ViewUniformOffset>, Read<PolylineViewBindGroup>);
type ItemWorldQuery = ();
type Param = ();

#[inline]
fn render<'w>(
Expand All @@ -269,10 +270,11 @@ impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetPolylineViewBindGroup
}

pub struct SetMaterialBindGroup<const I: usize>;

impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetMaterialBindGroup<I> {
type Param = SRes<RenderAssets<PolylineMaterial>>;
type ViewWorldQuery = ();
type ItemWorldQuery = Read<Handle<PolylineMaterial>>;
type Param = SRes<RenderAssets<PolylineMaterial>>;

fn render<'w>(
_item: &P,
Expand Down Expand Up @@ -311,7 +313,7 @@ pub fn queue_material_polylines(
)>,
) {
for (view, visible_entities, mut opaque_phase, mut alpha_mask_phase, mut transparent_phase) in
views.iter_mut()
views.iter_mut()
{
let draw_opaque = opaque_draw_functions
.read()
Expand Down Expand Up @@ -358,6 +360,8 @@ pub fn queue_material_polylines(
// -z in front of the camera, values in view space decrease away from the
// camera. Flipping the sign of mesh_z results in the correct front-to-back ordering
distance: -polyline_z,
batch_range: 0..1,
dynamic_offset: None,
});
}
AlphaMode::Mask(_) => {
Expand All @@ -370,6 +374,8 @@ pub fn queue_material_polylines(
// -z in front of the camera, values in view space decrease away from the
// camera. Flipping the sign of mesh_z results in the correct front-to-back ordering
distance: -polyline_z,
batch_range: 0..1,
dynamic_offset: None,
});
}
AlphaMode::Blend
Expand All @@ -385,6 +391,8 @@ pub fn queue_material_polylines(
// -z in front of the camera, the largest distance is -far with values increasing toward the
// camera. As such we can just use mesh_z as the distance
distance: polyline_z,
batch_range: 0..1,
dynamic_offset: None,
});
}
}
Expand Down
Loading