Skip to content

Commit

Permalink
Merge pull request #69 from zhaop/bevy-0.14
Browse files Browse the repository at this point in the history
Upgrade to Bevy 0.14
  • Loading branch information
urholaukkarinen authored Jul 7, 2024
2 parents a30088d + 08e5d3c commit ecb30de
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 51 deletions.
34 changes: 18 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["crates/*", "examples/*"]

[workspace.package]
version = "0.2.0"
rust-version = "1.77.0"
rust-version = "1.79.0"
edition = "2021"
license = "MIT OR Apache-2.0"
homepage = "https://github.com/urholaukkarinen/transform-gizmo"
Expand All @@ -26,22 +26,24 @@ mint = "0.5"
enum_dispatch = "0.3.12"
ahash = "0.8.7"
enumset = "1.1.3"
bevy = "0.13"
bytemuck = "1.5"
uuid = "1.1"
bevy = "0.14"

bevy_app = { version = "0.13", default-features = false }
bevy_core = { version = "0.13", default-features = false }
bevy_core_pipeline = { version = "0.13", default-features = false }
bevy_reflect = { version = "0.13", default-features = false }
bevy_math = { version = "0.13", features = ["mint"], default-features = false }
bevy_render = { version = "0.13", default-features = false }
bevy_input = { version = "0.13", default-features = false }
bevy_asset = { version = "0.13", default-features = false }
bevy_utils = { version = "0.13", default-features = false }
bevy_pbr = { version = "0.13", default-features = false }
bevy_ecs = { version = "0.13", default-features = false }
bevy_log = { version = "0.13", default-features = false }
bevy_window = { version = "0.13", default-features = false }
bevy_transform = { version = "0.13", default-features = false }
bevy_app = { version = "0.14", default-features = false }
bevy_core = { version = "0.14", default-features = false }
bevy_core_pipeline = { version = "0.14", default-features = false }
bevy_reflect = { version = "0.14", default-features = false }
bevy_math = { version = "0.14", features = ["mint"], default-features = false }
bevy_render = { version = "0.14", default-features = false }
bevy_input = { version = "0.14", default-features = false }
bevy_asset = { version = "0.14", default-features = false }
bevy_utils = { version = "0.14", default-features = false }
bevy_pbr = { version = "0.14", default-features = false }
bevy_ecs = { version = "0.14", default-features = false }
bevy_log = { version = "0.14", default-features = false }
bevy_window = { version = "0.14", default-features = false }
bevy_transform = { version = "0.14", default-features = false }

[profile.release]
opt-level = "s"
Expand Down
4 changes: 3 additions & 1 deletion crates/transform-gizmo-bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ bevy_ecs.workspace = true
bevy_log.workspace = true
bevy_window.workspace = true
bevy_transform.workspace = true
bytemuck.workspace = true
uuid.workspace = true

[dev-dependencies]
bevy = "0.13"
bevy = "0.14"

[lints]
workspace = true
3 changes: 2 additions & 1 deletion crates/transform-gizmo-bevy/examples/bevy_minimal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! A very simple example
//! See the project root's `examples` directory for more examples
use bevy::color::palettes::css::LIME;
use bevy::prelude::*;
use transform_gizmo_bevy::*;

Expand Down Expand Up @@ -30,7 +31,7 @@ fn setup(
commands.spawn((
PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::GREEN),
material: materials.add(Color::from(LIME)),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
..default()
},
Expand Down
5 changes: 3 additions & 2 deletions crates/transform-gizmo-bevy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ use bevy_input::prelude::*;
use bevy_math::{DQuat, DVec3, Vec2};
use bevy_render::prelude::*;
use bevy_transform::prelude::*;
use bevy_utils::{HashMap, Uuid};
use bevy_utils::HashMap;
use bevy_window::{PrimaryWindow, Window};
use uuid::Uuid;

use render::{DrawDataHandles, TransformGizmoRenderPlugin};
use transform_gizmo::config::{
Expand Down Expand Up @@ -421,7 +422,7 @@ fn update_gizmos(
Pos2::new(viewport.max.x, viewport.max.y),
);

let projection_matrix = camera.projection_matrix();
let projection_matrix = camera.clip_from_view();

let view_matrix = camera_transform.compute_matrix().inverse();

Expand Down
52 changes: 29 additions & 23 deletions crates/transform-gizmo-bevy/src/render.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bevy_app::{App, Plugin};
use bevy_asset::{load_internal_asset, Asset, Handle};
use bevy_core::cast_slice;
use bevy_core_pipeline::core_3d::{Transparent3d, CORE_3D_DEPTH_FORMAT};
use bevy_core_pipeline::prepass::{
DeferredPrepass, DepthPrepass, MotionVectorPrepass, NormalPrepass,
Expand All @@ -18,8 +17,8 @@ use bevy_render::render_asset::{
RenderAssets,
};
use bevy_render::render_phase::{
AddRenderCommand, DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, RenderPhase,
SetItemPipeline, TrackedRenderPass,
AddRenderCommand, DrawFunctions, PhaseItem, PhaseItemExtraIndex, RenderCommand,
RenderCommandResult, SetItemPipeline, TrackedRenderPass, ViewSortedRenderPhases,
};
use bevy_render::render_resource::{
BlendState, Buffer, BufferInitDescriptor, BufferUsages, ColorTargetState, ColorWrites,
Expand All @@ -32,7 +31,9 @@ use bevy_render::renderer::RenderDevice;
use bevy_render::texture::BevyDefault;
use bevy_render::view::{ExtractedView, RenderLayers, ViewTarget};
use bevy_render::{Extract, Render, RenderApp, RenderSet};
use bevy_utils::{HashMap, HashSet, Uuid};
use bevy_utils::{HashMap, HashSet};
use bytemuck::cast_slice;
use uuid::Uuid;

const GIZMO_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(7414812681337026784);

Expand All @@ -43,9 +44,9 @@ impl Plugin for TransformGizmoRenderPlugin {
load_internal_asset!(app, GIZMO_SHADER_HANDLE, "gizmo.wgsl", Shader::from_wgsl);

app.init_resource::<DrawDataHandles>()
.add_plugins(RenderAssetPlugin::<GizmoDrawData>::default());
.add_plugins(RenderAssetPlugin::<GizmoBuffers>::default());

let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
};

Expand All @@ -56,12 +57,12 @@ impl Plugin for TransformGizmoRenderPlugin {
Render,
queue_transform_gizmos
.in_set(RenderSet::Queue)
.after(prepare_assets::<GizmoDrawData>),
.after(prepare_assets::<GizmoBuffers>),
);
}

fn finish(&self, app: &mut App) {
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
};

Expand Down Expand Up @@ -99,44 +100,44 @@ pub(crate) struct GizmoBuffers {
index_count: u32,
}

impl RenderAsset for GizmoDrawData {
type PreparedAsset = GizmoBuffers;
impl RenderAsset for GizmoBuffers {
type SourceAsset = GizmoDrawData;
type Param = SRes<RenderDevice>;

fn asset_usage(&self) -> RenderAssetUsages {
fn asset_usage(_source_asset: &Self::SourceAsset) -> RenderAssetUsages {
RenderAssetUsages::all()
}

fn prepare_asset(
self,
source_asset: Self::SourceAsset,
render_device: &mut SystemParamItem<Self::Param>,
) -> Result<Self::PreparedAsset, PrepareAssetError<Self>> {
let position_buffer_data = cast_slice(&self.0.vertices);
) -> Result<Self, PrepareAssetError<Self::SourceAsset>> {
let position_buffer_data = cast_slice(&source_asset.0.vertices);
let position_buffer = render_device.create_buffer_with_data(&BufferInitDescriptor {
usage: BufferUsages::VERTEX,
label: Some("TransformGizmo Position Buffer"),
contents: position_buffer_data,
});

let index_buffer_data = cast_slice(&self.0.indices);
let index_buffer_data = cast_slice(&source_asset.0.indices);
let index_buffer = render_device.create_buffer_with_data(&BufferInitDescriptor {
usage: BufferUsages::INDEX,
label: Some("TransformGizmo Index Buffer"),
contents: index_buffer_data,
});

let color_buffer_data = cast_slice(&self.0.colors);
let color_buffer_data = cast_slice(&source_asset.0.colors);
let color_buffer = render_device.create_buffer_with_data(&BufferInitDescriptor {
usage: BufferUsages::VERTEX,
label: Some("TransformGizmo Color Buffer"),
contents: color_buffer_data,
});

Ok(GizmoBuffers {
Ok(Self {
index_buffer,
position_buffer,
color_buffer,
index_count: self.0.indices.len() as u32,
index_count: source_asset.0.indices.len() as u32,
})
}
}
Expand All @@ -146,7 +147,7 @@ struct DrawTransformGizmo;
impl<P: PhaseItem> RenderCommand<P> for DrawTransformGizmo {
type ViewQuery = ();
type ItemQuery = Read<Handle<GizmoDrawData>>;
type Param = SRes<RenderAssets<GizmoDrawData>>;
type Param = SRes<RenderAssets<GizmoBuffers>>;

#[inline]
fn render<'w>(
Expand Down Expand Up @@ -287,10 +288,10 @@ fn queue_transform_gizmos(
pipeline_cache: Res<PipelineCache>,
msaa: Res<Msaa>,
transform_gizmos: Query<(Entity, &Handle<GizmoDrawData>)>,
transform_gizmo_assets: Res<RenderAssets<GizmoDrawData>>,
transform_gizmo_assets: Res<RenderAssets<GizmoBuffers>>,
mut views: Query<(
Entity,
&ExtractedView,
&mut RenderPhase<Transparent3d>,
Option<&RenderLayers>,
(
Has<NormalPrepass>,
Expand All @@ -299,16 +300,21 @@ fn queue_transform_gizmos(
Has<DeferredPrepass>,
),
)>,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent3d>>,
) {
let draw_function = draw_functions.read().get_id::<DrawGizmo>().unwrap();

for (
view_entity,
view,
mut transparent_phase,
_render_layers,
(normal_prepass, depth_prepass, motion_vector_prepass, deferred_prepass),
) in &mut views
{
let Some(transparent_phase) = transparent_render_phases.get_mut(&view_entity) else {
continue;
};

let mut view_key = MeshPipelineKey::from_msaa_samples(msaa.samples())
| MeshPipelineKey::from_hdr(view.hdr);

Expand Down Expand Up @@ -348,7 +354,7 @@ fn queue_transform_gizmos(
pipeline,
distance: 0.,
batch_range: 0..1,
dynamic_offset: None,
extra_index: PhaseItemExtraIndex::NONE,
});
}
}
Expand Down
9 changes: 4 additions & 5 deletions examples/bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ publish = false
transform-gizmo-bevy.workspace = true

bevy.workspace = true
bevy_infinite_grid = { git = "https://github.com/XYCaptain/bevy_infinite_grid.git", rev = "1e5259a52a7dfaca65402c2c57c1d81c2bc443e9" }
bevy_mod_picking = "0.18.0"
bevy_mod_outline = "0.7.0"
bevy_infinite_grid = { git = "https://github.com/tychedelia/bevy_infinite_grid.git", rev = "4044e3219868d82a7db4326a48af58f829c109aa" }
bevy_mod_picking = "0.20.0"
bevy_mod_outline = { git = "https://github.com/komadori/bevy_mod_outline.git", rev = "d24b2eaec26b02f91ef99ebf0d86b982ea05a0ed" }

[dependencies.bevy_egui]
git = "https://github.com/mvlabat/bevy_egui.git"
rev = "cfd819ee9bdfb58101ac3efb6bcd4b6336860773"
version = "0.28"
features = ["open_url", "default_fonts", "render"]
default-features = false

Expand Down
2 changes: 1 addition & 1 deletion examples/bevy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod scene;

fn main() {
App::new()
.insert_resource(ClearColor(Color::rgb_u8(20, 20, 20)))
.insert_resource(ClearColor(Color::srgb_u8(20, 20, 20)))
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "transform-gizmo-demo".into(),
Expand Down
3 changes: 2 additions & 1 deletion examples/bevy/src/scene.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes::css::{BLUE, LIME, RED};
use bevy::prelude::*;
use bevy_mod_outline::*;
use bevy_mod_picking::prelude::*;
Expand Down Expand Up @@ -37,7 +38,7 @@ fn setup_scene(

let cube_count: i32 = 3;

let colors = [Color::RED, Color::GREEN, Color::BLUE];
let colors: [Color; 3] = [RED.into(), LIME.into(), BLUE.into()];

for i in 0..cube_count {
commands
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.77.0"
channel = "1.79.0"
components = ["rustfmt", "clippy"]
targets = ["wasm32-unknown-unknown"]

0 comments on commit ecb30de

Please sign in to comment.