Skip to content

Commit

Permalink
Cleanup and sprite support
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-blackbird committed Jan 5, 2024
1 parent b4a99e9 commit 23a1efa
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ opt-level = 1

[dependencies]
bevy = { version = "0.12", default-features = false, features = [
"bevy_render",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_sprite",
] }
bevy_mod_picking = { version = "0.17", default-features = false, features = [
"selection",
Expand All @@ -29,6 +28,7 @@ bevy_mod_raycast = "0.16"
[dev-dependencies]
bevy = { version = "0.12", default-features = false, features = [
"bevy_pbr",
"bevy_sprite",
"bevy_winit",
"x11",
"tonemapping_luts",
Expand All @@ -37,7 +37,7 @@ bevy = { version = "0.12", default-features = false, features = [
] }
bevy_mod_picking = { version = "0.17", default-features = false, features = [
"selection",
"backend_raycast",
"highlight",
"bevy_picking_raycast",
"backend_raycast",
"backend_sprite",
] }
2 changes: 0 additions & 2 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use irate_transform_gizmo::{GizmoPickSource, GizmoTransformable, TransformGizmoP

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.insert_resource(ClearColor(Color::BLACK))
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
Expand Down
54 changes: 54 additions & 0 deletions examples/demo_2d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use bevy::{prelude::*, window::PresentMode};
use bevy_mod_picking::{DefaultPickingPlugins, PickableBundle};
use irate_transform_gizmo::{GizmoPickSource, GizmoTransformable, TransformGizmoPlugin};

fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::Immediate,
..default()
}),
..default()
}),
DefaultPickingPlugins,
TransformGizmoPlugin::default(),
))
.add_systems(Startup, setup)
.run();
}

fn setup(
mut commands: Commands,
) {
commands.spawn((
SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::new(500., 50.)),
color: Color::ORANGE_RED,
..default()
},
transform: Transform::from_xyz(0.0, -100., 0.0),
..default()
},
PickableBundle::default(),
GizmoTransformable,
));

commands.spawn((
SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::splat(200.)),
color: Color::ORANGE,
..default()
},
transform: Transform::from_xyz(0.0, 25., 0.0),
..default()
},
PickableBundle::default(),
GizmoTransformable,
));

commands.spawn((Camera2dBundle::default(), GizmoPickSource::default()));
}
1 change: 0 additions & 1 deletion examples/parenting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use irate_transform_gizmo::{GizmoPickSource, GizmoTransformable, TransformGizmoP

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
Expand Down
23 changes: 19 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,13 +603,22 @@ fn adjust_view_translate_gizmo(
}

fn gizmo_cam_copy_settings(
main_cam: Query<(Ref<Camera>, Ref<GlobalTransform>, Ref<Projection>), With<GizmoPickSource>>,
main_cam: Query<
(
Ref<Camera>,
Ref<GlobalTransform>,
AnyOf<(Ref<Projection>, Ref<OrthographicProjection>)>,
),
With<GizmoPickSource>,
>,
mut gizmo_cam: Query<
(&mut Camera, &mut GlobalTransform, &mut Projection),
(With<InternalGizmoCamera>, Without<GizmoPickSource>),
>,
) {
let (main_cam, main_cam_pos, main_proj) = if let Ok(x) = main_cam.get_single() {
let (main_cam, main_cam_pos, (main_proj, main_proj_ortho)) = if let Ok(x) =
main_cam.get_single()
{
x
} else {
error!("No `GizmoPickSource` found! Insert the `GizmoPickSource` component onto your primary 3d camera");
Expand All @@ -623,7 +632,13 @@ fn gizmo_cam_copy_settings(
*gizmo_cam = main_cam.clone();
gizmo_cam.order += 10;
}
if main_proj.is_changed() {
*proj = main_proj.clone();
if let Some(main_proj) = main_proj {
if main_proj.is_changed() {
*proj = main_proj.clone();
}
} else if let Some(main_proj_ortho) = main_proj_ortho {
if main_proj_ortho.is_changed() {
*proj = Projection::Orthographic(main_proj_ortho.clone());
}
}
}

0 comments on commit 23a1efa

Please sign in to comment.