-
Notifications
You must be signed in to change notification settings - Fork 43
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
Changes from all commits
85b133f
8492365
65c4c12
34b4df4
9b54dea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/target | ||
Cargo.lock | ||
.vscode | ||
.vscode | ||
|
||
.idea/ |
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" | ||
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
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::*; | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
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; | ||
|
@@ -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> = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use |
||
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, | ||
)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ use bevy::{ | |
}, | ||
}, | ||
prelude::*, | ||
reflect::{TypePath, TypeUuid}, | ||
reflect::{TypePath}, | ||
render::{ | ||
extract_component::ExtractComponentPlugin, | ||
render_asset::{RenderAsset, RenderAssetPlugin, RenderAssets}, | ||
|
@@ -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. | ||
/// | ||
|
@@ -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 { | ||
|
@@ -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>, | ||
|
@@ -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!(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you panic here? |
||
} | ||
} | ||
} | ||
|
||
|
@@ -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()); | ||
} | ||
|
@@ -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>( | ||
|
@@ -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, | ||
|
@@ -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() | ||
|
@@ -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(_) => { | ||
|
@@ -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 | ||
|
@@ -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, | ||
}); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.