diff --git a/Cargo.toml b/Cargo.toml index 5ca7ad3..7c477df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2021" name = "bevy_polyline" -version = "0.9.0" +version = "0.10.0" description = "Polyline Rendering for Bevy" license = "MIT OR Apache-2.0" repository = "https://github.com/ForesightMiningSoftwareCorporation/bevy_polyline" diff --git a/README.md b/README.md index 2ca84ab..c4e442e 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ We intend to track the `main` branch of Bevy. PRs supporting this are welcome! | bevy | bevy_polyline | | ---- | ------------- | +| 0.14 | 0.10 | | 0.13 | 0.9 | | 0.12 | 0.8 | | 0.11 | 0.7 | diff --git a/examples/depth_bias.rs b/examples/depth_bias.rs index fcfa16a..9d925d2 100644 --- a/examples/depth_bias.rs +++ b/examples/depth_bias.rs @@ -1,6 +1,7 @@ use std::f32::consts::TAU; use std::f64::consts::TAU as TAU64; +use bevy::color::palettes::css::RED; use bevy::prelude::*; use bevy_polyline::prelude::*; @@ -80,7 +81,7 @@ fn setup( }), material: materials.add(PolylineMaterial { width: 5.0, - color: bevy::color::palettes::css::RED.into(), + color: RED.into(), depth_bias: -1.0, perspective: false, }), diff --git a/examples/linestrip.rs b/examples/linestrip.rs index d428021..f616fbd 100644 --- a/examples/linestrip.rs +++ b/examples/linestrip.rs @@ -1,4 +1,4 @@ -use bevy::{pbr::PointLightBundle, prelude::*}; +use bevy::{color::palettes::css::RED, pbr::PointLightBundle, prelude::*}; use bevy_polyline::prelude::*; fn main() { @@ -33,7 +33,7 @@ fn setup( }), material: polyline_materials.add(PolylineMaterial { width: 2.0, - color: bevy::color::palettes::css::RED.into(), + color: RED.into(), perspective: false, // Bias the line toward the camera so the line at the cube-plane intersection is visible depth_bias: -0.0002, diff --git a/examples/minimal.rs b/examples/minimal.rs index e5ede7a..b77d70e 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -1,4 +1,4 @@ -use bevy::prelude::*; +use bevy::{color::palettes::css::RED, prelude::*}; use bevy_polyline::prelude::*; fn main() { @@ -20,7 +20,7 @@ fn setup( }), material: polyline_materials.add(PolylineMaterial { width: 10.0, - color: bevy::color::palettes::css::RED.into(), + color: RED.into(), perspective: false, ..default() }), diff --git a/examples/perspective.rs b/examples/perspective.rs index 315df31..28740c2 100644 --- a/examples/perspective.rs +++ b/examples/perspective.rs @@ -1,4 +1,4 @@ -use bevy::prelude::*; +use bevy::{color::palettes::css::RED, prelude::*}; use bevy_polyline::prelude::*; fn main() { @@ -21,7 +21,7 @@ fn setup( }), material: polyline_materials.add(PolylineMaterial { width: 10.0, - color: bevy::color::palettes::css::RED.into(), + color: RED.into(), perspective: true, ..default() }), diff --git a/src/material.rs b/src/material.rs index dae8cdd..555baae 100644 --- a/src/material.rs +++ b/src/material.rs @@ -292,18 +292,13 @@ pub fn queue_material_polylines( mut alpha_mask_phases: ResMut>, mut transparent_phases: ResMut>, ) { - let draw_opaque = opaque_draw_functions - .read() - .get_id::() - .unwrap(); + let draw_opaque = opaque_draw_functions.read().id::(); let draw_alpha_mask = alpha_mask_draw_functions .read() - .get_id::() - .unwrap(); + .id::(); let draw_transparent = transparent_draw_functions .read() - .get_id::() - .unwrap(); + .id::(); for (view_entity, view, visible_entities) in &views { let inverse_view_matrix = view.world_from_view.compute_matrix().inverse(); @@ -329,64 +324,60 @@ pub fn queue_material_polylines( let pipeline_id = pipelines.specialize(&pipeline_cache, &material_pipeline, polyline_key); - let (mut opaque_phase, mut alpha_mask_phase, mut transparent_phase) = ( + let (Some(opaque_phase), Some(alpha_mask_phase), Some(transparent_phase)) = ( opaque_phases.get_mut(&view_entity), alpha_mask_phases.get_mut(&view_entity), transparent_phases.get_mut(&view_entity), - ); + ) else { + continue; + }; - // NOTE: row 2 of the inverse view matrix dotted with column 3 of the model matrix - // gives the z component of translation of the mesh in view space - let polyline_z = inverse_view_row_2.dot(polyline_uniform.transform.col(3)); match material.alpha_mode { AlphaMode::Opaque => { - if let Some(opaque_phase) = opaque_phase.as_mut() { - opaque_phase.add( - Opaque3dBinKey { - pipeline: pipeline_id, - draw_function: draw_opaque, - // The draw command doesn't use a mesh handle so we don't need an `asset_id` - asset_id: AssetId::::invalid().untyped(), - material_bind_group_id: Some(material.bind_group.id()), - lightmap_image: None, - }, - *visible_entity, - BinnedRenderPhaseType::NonMesh, - ); - } + opaque_phase.add( + Opaque3dBinKey { + pipeline: pipeline_id, + draw_function: draw_opaque, + // The draw command doesn't use a mesh handle so we don't need an `asset_id` + asset_id: AssetId::::invalid().untyped(), + material_bind_group_id: Some(material.bind_group.id()), + lightmap_image: None, + }, + *visible_entity, + BinnedRenderPhaseType::NonMesh, + ); } AlphaMode::Mask(_) => { - if let Some(alpha_mask_phase) = alpha_mask_phase.as_mut() { - alpha_mask_phase.add( - OpaqueNoLightmap3dBinKey { - draw_function: draw_alpha_mask, - pipeline: pipeline_id, - asset_id: AssetId::::invalid().untyped(), - material_bind_group_id: Some(material.bind_group.id()), - }, - *visible_entity, - BinnedRenderPhaseType::NonMesh, - ); - } + alpha_mask_phase.add( + OpaqueNoLightmap3dBinKey { + draw_function: draw_alpha_mask, + pipeline: pipeline_id, + asset_id: AssetId::::invalid().untyped(), + material_bind_group_id: Some(material.bind_group.id()), + }, + *visible_entity, + BinnedRenderPhaseType::NonMesh, + ); } AlphaMode::Blend | AlphaMode::Premultiplied | AlphaMode::Add | AlphaMode::Multiply => { - if let Some(transparent_phase) = transparent_phase.as_mut() { - transparent_phase.add(Transparent3d { - entity: *visible_entity, - draw_function: draw_transparent, - pipeline: pipeline_id, - // NOTE: Back-to-front ordering for transparent with ascending sort means far should have the - // lowest sort key and getting closer should increase. As we have - // -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, - extra_index: PhaseItemExtraIndex::NONE, - }); - } + // NOTE: row 2 of the inverse view matrix dotted with column 3 of the model matrix + // gives the z component of translation of the mesh in view space + let polyline_z = inverse_view_row_2.dot(polyline_uniform.transform.col(3)); + transparent_phase.add(Transparent3d { + entity: *visible_entity, + draw_function: draw_transparent, + pipeline: pipeline_id, + // NOTE: Back-to-front ordering for transparent with ascending sort means far should have the + // lowest sort key and getting closer should increase. As we have + // -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, + extra_index: PhaseItemExtraIndex::NONE, + }); } } }