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

Support bevy 0.15 #85

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
48 changes: 23 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ resolver = "2"
members = ["crates/*", "examples/*"]

[workspace.package]
version = "0.4.0"
rust-version = "1.78.0"
version = "0.5.0"
rust-version = "1.82.0"
edition = "2021"
license = "MIT OR Apache-2.0"
homepage = "https://github.com/urholaukkarinen/transform-gizmo"
repository = "https://github.com/urholaukkarinen/transform-gizmo"
authors = ["Urho Laukkarinen <[email protected]>"]

[workspace.dependencies]
transform-gizmo = { version = "0.4.0", path = "crates/transform-gizmo" }
transform-gizmo-egui = { version = "0.4.0", path = "crates/transform-gizmo-egui" }
transform-gizmo-bevy = { version = "0.4.0", path = "crates/transform-gizmo-bevy" }
transform-gizmo = { version = "0.5.0", path = "crates/transform-gizmo" }
transform-gizmo-egui = { version = "0.5.0", path = "crates/transform-gizmo-egui" }
transform-gizmo-bevy = { version = "0.5.0", path = "crates/transform-gizmo-bevy" }

egui = "0.29"
eframe = "0.29"
Expand All @@ -28,32 +28,31 @@ ahash = "0.8.7"
enumset = "1.1.3"
bytemuck = "1.5"
uuid = "1.1"
bevy = "0.14"
bevy = "0.15"

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 }
bevy_app = { version = "0.15", default-features = false }
bevy_core = { version = "0.15", default-features = false }
bevy_core_pipeline = { version = "0.15", default-features = false }
bevy_reflect = { version = "0.15", default-features = false }
bevy_math = { version = "0.15", features = ["mint"], default-features = false }
bevy_render = { version = "0.15", default-features = false }
bevy_input = { version = "0.15", default-features = false }
bevy_asset = { version = "0.15", default-features = false }
bevy_utils = { version = "0.15", default-features = false }
bevy_pbr = { version = "0.15", default-features = false }
bevy_ecs = { version = "0.15", default-features = false }
bevy_log = { version = "0.15", default-features = false }
bevy_window = { version = "0.15", default-features = false }
bevy_transform = { version = "0.15", default-features = false }
bevy_derive = { version = "0.15", default-features = false }
bevy_image = { version = "0.15", default-features = false }

[profile.release]
opt-level = "s"
panic = "abort"

[workspace.lints.rust]
elided_lifetimes_in_paths = "allow"
future_incompatible = "deny"
nonstandard_style = "deny"
rust_2018_idioms = "warn"
rust_2021_prelude_collisions = "deny"
semicolon_in_expressions_from_macros = "deny"
trivial_numeric_casts = "deny"
Expand All @@ -64,7 +63,6 @@ unused_lifetimes = "deny"
unsafe_code = "deny"

[workspace.lints.clippy]
all = "deny"
as_ptr_cast_mut = "deny"
await_holding_lock = "deny"
bool_to_int_with_if = "deny"
Expand Down Expand Up @@ -133,7 +131,7 @@ match_same_arms = "deny"
match_wild_err_arm = "deny"
match_wildcard_for_single_variants = "deny"
mem_forget = "deny"
mismatched_target_os = "deny"
unexpected_cfgs = "deny"
mismatching_type_param_order = "deny"
missing_enforced_import_renames = "deny"
missing_safety_doc = "deny"
Expand Down
8 changes: 5 additions & 3 deletions crates/transform-gizmo-bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "transform-gizmo-bevy"
description = "bevy integration for transform-gizmo"
version.workspace = true
rust-version = "1.79.0"
rust-version = "1.82.0"
edition.workspace = true
license.workspace = true
homepage.workspace = true
Expand Down Expand Up @@ -36,11 +36,13 @@ bevy_ecs.workspace = true
bevy_log.workspace = true
bevy_window.workspace = true
bevy_transform.workspace = true
bevy_derive.workspace = true
bevy_image.workspace = true
bytemuck.workspace = true
uuid.workspace = true

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

[lints]
workspace = true
workspace = true
26 changes: 10 additions & 16 deletions crates/transform-gizmo-bevy/examples/bevy_minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,26 @@ fn setup(
) {
// camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(1.0, 3.0, -5.0))
.looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_translation(Vec3::new(1.0, 3.0, -5.0)).looking_at(Vec3::ZERO, Vec3::Y),
Msaa::Sample2,
GizmoCamera,
));

// cube
commands.spawn((
PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::from(LIME)),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
..default()
},
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::from(LIME))),
Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
GizmoTarget::default(),
));

// light
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));
}
4 changes: 3 additions & 1 deletion crates/transform-gizmo-bevy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,9 @@ fn draw_gizmos(
if is_new_asset {
let asset = draw_data_assets.add(bevy_draw_data);

draw_data_handles.handles.insert(*gizmo_uuid, asset.clone());
draw_data_handles
.handles
.insert(*gizmo_uuid, asset.clone().into());
}
}
}
Expand Down
69 changes: 53 additions & 16 deletions crates/transform-gizmo-bevy/src/render.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use bevy_app::{App, Plugin};
use bevy_asset::{load_internal_asset, Asset, Handle};
use bevy_asset::{load_internal_asset, Asset, AssetId, Handle};
use bevy_core_pipeline::core_3d::{Transparent3d, CORE_3D_DEPTH_FORMAT};
use bevy_core_pipeline::prepass::{
DeferredPrepass, DepthPrepass, MotionVectorPrepass, NormalPrepass,
};
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::prelude::*;
use bevy_ecs::query::ROQueryItem;
use bevy_ecs::system::lifetimeless::{Read, SRes};
use bevy_ecs::system::SystemParamItem;
use bevy_image::BevyDefault as _;
use bevy_pbr::{MeshPipeline, MeshPipelineKey, SetMeshViewBindGroup};
use bevy_reflect::TypePath;
use bevy_reflect::{Reflect, TypePath};
use bevy_render::extract_component::ExtractComponent;
use bevy_render::mesh::PrimitiveTopology;
use bevy_render::prelude::*;
use bevy_render::render_asset::{
Expand All @@ -28,13 +31,14 @@ use bevy_render::render_resource::{
VertexAttribute, VertexBufferLayout, VertexFormat, VertexState, VertexStepMode,
};
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};
use bytemuck::cast_slice;
use uuid::Uuid;

use crate::GizmoCamera;

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

pub(crate) struct TransformGizmoRenderPlugin;
Expand Down Expand Up @@ -74,7 +78,30 @@ impl Plugin for TransformGizmoRenderPlugin {

#[derive(Resource, Default)]
pub(crate) struct DrawDataHandles {
pub(crate) handles: HashMap<Uuid, Handle<GizmoDrawData>>,
pub(crate) handles: HashMap<Uuid, GizmoDrawDataHandle>,
}

#[derive(
Component, Default, Clone, Debug, Deref, DerefMut, Reflect, PartialEq, Eq, ExtractComponent,
)]
#[reflect(Component)]
pub(crate) struct GizmoDrawDataHandle(pub(crate) Handle<GizmoDrawData>);

impl From<Handle<GizmoDrawData>> for GizmoDrawDataHandle {
fn from(handle: Handle<GizmoDrawData>) -> Self {
Self(handle)
}
}

impl From<GizmoDrawDataHandle> for AssetId<GizmoDrawData> {
fn from(handle: GizmoDrawDataHandle) -> Self {
handle.0.id()
}
}
impl From<&GizmoDrawDataHandle> for AssetId<GizmoDrawData> {
fn from(handle: &GizmoDrawDataHandle) -> Self {
handle.0.id()
}
}

fn extract_gizmo_data(mut commands: Commands, handles: Extract<Res<DrawDataHandles>>) {
Expand All @@ -85,7 +112,7 @@ fn extract_gizmo_data(mut commands: Commands, handles: Extract<Res<DrawDataHandl
.collect::<HashSet<_>>();

for handle in handle_weak_refs {
commands.spawn((handle,));
commands.spawn(GizmoDrawDataHandle(handle));
}
}

Expand Down Expand Up @@ -146,7 +173,7 @@ struct DrawTransformGizmo;

impl<P: PhaseItem> RenderCommand<P> for DrawTransformGizmo {
type ViewQuery = ();
type ItemQuery = Read<Handle<GizmoDrawData>>;
type ItemQuery = Read<GizmoDrawDataHandle>;
type Param = SRes<RenderAssets<GizmoBuffers>>;

#[inline]
Expand All @@ -158,11 +185,11 @@ impl<P: PhaseItem> RenderCommand<P> for DrawTransformGizmo {
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let Some(handle) = handle else {
return RenderCommandResult::Failure;
return RenderCommandResult::Failure("No GizmoDrawDataHandle component found");
};

let Some(gizmo) = gizmos.into_inner().get(handle) else {
return RenderCommandResult::Failure;
return RenderCommandResult::Failure("No GizmoDrawDataHandle inner found");
};

pass.set_index_buffer(gizmo.index_buffer.slice(..), 0, IndexFormat::Uint32);
Expand Down Expand Up @@ -199,8 +226,9 @@ impl SpecializedRenderPipeline for TransformGizmoPipeline {

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
let mut shader_defs = vec![
#[cfg(feature = "webgl")]
"SIXTEEN_BYTE_ALIGNMENT".into(),
// TODO: When is this flag actually used?
// #[cfg(feature = "webgl")]
// "SIXTEEN_BYTE_ALIGNMENT".into(),
];

if key.perspective {
Expand All @@ -220,6 +248,7 @@ impl SpecializedRenderPipeline for TransformGizmoPipeline {

RenderPipelineDescriptor {
label: Some("TransformGizmo Pipeline".into()),
zero_initialize_workgroup_memory: true, // ?
vertex: VertexState {
shader: GIZMO_SHADER_HANDLE,
entry_point: "vertex".into(),
Expand Down Expand Up @@ -286,12 +315,13 @@ fn queue_transform_gizmos(
pipeline: Res<TransformGizmoPipeline>,
mut pipelines: ResMut<SpecializedRenderPipelines<TransformGizmoPipeline>>,
pipeline_cache: Res<PipelineCache>,
msaa: Res<Msaa>,
transform_gizmos: Query<(Entity, &Handle<GizmoDrawData>)>,
msaa_q: Query<Option<&Msaa>, With<GizmoCamera>>,
transform_gizmos: Query<(Entity, &GizmoDrawDataHandle)>,
transform_gizmo_assets: Res<RenderAssets<GizmoBuffers>>,
mut views: Query<(
Entity,
&ExtractedView,
Option<&Msaa>,
Option<&RenderLayers>,
(
Has<NormalPrepass>,
Expand All @@ -303,10 +333,11 @@ fn queue_transform_gizmos(
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent3d>>,
) {
let draw_function = draw_functions.read().get_id::<DrawGizmo>().unwrap();

let camera_msaa = msaa_q.get_single().ok().flatten();
for (
view_entity,
view,
entity_msaa,
_render_layers,
(normal_prepass, depth_prepass, motion_vector_prepass, deferred_prepass),
) in &mut views
Expand All @@ -315,7 +346,13 @@ fn queue_transform_gizmos(
continue;
};

let mut view_key = MeshPipelineKey::from_msaa_samples(msaa.samples())
// entity_msaa > camera_msaa > default
let msaa_sample_count = entity_msaa.map_or(
camera_msaa.unwrap_or(&Msaa::default()).samples(),
Msaa::samples,
);

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

if normal_prepass {
Expand All @@ -335,7 +372,7 @@ fn queue_transform_gizmos(
}

for (entity, handle) in &transform_gizmos {
let Some(_) = transform_gizmo_assets.get(handle.id()) else {
let Some(_) = transform_gizmo_assets.get(handle.0.id()) else {
continue;
};

Expand All @@ -349,7 +386,7 @@ fn queue_transform_gizmos(
);

transparent_phase.add(Transparent3d {
entity,
entity: (entity, view_entity.into()), // TODO: ???
draw_function,
pipeline,
distance: 0.,
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bevy_mod_picking = "0.20.0"
bevy_mod_outline = { git = "https://github.com/komadori/bevy_mod_outline.git", rev = "d24b2eaec26b02f91ef99ebf0d86b982ea05a0ed" }

[dependencies.bevy_egui]
version = "0.28"
version = "0.29"
features = ["open_url", "default_fonts", "render"]
default-features = false

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain → rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.79.0"
channel = "1.82.0"
components = ["rustfmt", "clippy"]
targets = ["wasm32-unknown-unknown"]
Loading