Skip to content

Commit

Permalink
Fixed demo not working in web
Browse files Browse the repository at this point in the history
  • Loading branch information
urholaukkarinen committed Apr 5, 2024
1 parent 86d612c commit 9b9b450
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
13 changes: 8 additions & 5 deletions crates/transform-gizmo-bevy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ use bevy::window::PrimaryWindow;
use render::{DrawDataHandles, TransformGizmoRenderPlugin};
use transform_gizmo::config::{DEFAULT_SNAP_ANGLE, DEFAULT_SNAP_DISTANCE, DEFAULT_SNAP_SCALE};

pub use transform_gizmo::{GizmoConfig, *};
pub use transform_gizmo::{
math::{Pos2, Rect},
GizmoConfig, *,
};

pub mod prelude;

Expand Down Expand Up @@ -155,13 +158,13 @@ fn update_gizmos(
return;
};

let Some(viewport) = camera.physical_viewport_rect() else {
let Some(viewport) = camera.logical_viewport_rect() else {
return;
};

let viewport = transform_gizmo::math::Rect::from_min_max(
transform_gizmo::math::Pos2::new(viewport.min.x as _, viewport.min.y as _),
transform_gizmo::math::Pos2::new(viewport.max.x as _, viewport.max.y as _),
let viewport = Rect::from_min_max(
Pos2::new(viewport.min.x, viewport.min.y),
Pos2::new(viewport.max.x, viewport.max.y),
);

let projection_matrix = camera.projection_matrix();
Expand Down
7 changes: 6 additions & 1 deletion crates/transform-gizmo-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ transform-gizmo-bevy.workspace = true
transform-gizmo-egui.workspace = true

bevy.workspace = true
bevy_egui = { git = "https://github.com/mvlabat/bevy_egui.git", rev = "cfd819ee9bdfb58101ac3efb6bcd4b6336860773" }
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"

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

[lints]
workspace = true
20 changes: 3 additions & 17 deletions crates/transform-gizmo-demo/src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{math::DQuat, prelude::*, render::camera::Viewport};
use bevy::{math::DQuat, prelude::*};
use bevy_egui::{
egui::{self, Layout, Widget},
EguiContexts, EguiPlugin,
Expand All @@ -19,7 +19,6 @@ impl Plugin for GuiPlugin {
fn update_ui(
mut contexts: EguiContexts,
mut gizmo_options: ResMut<GizmoOptions>,
mut camera: Query<&mut Camera>,
keyboard_input: Res<ButtonInput<KeyCode>>,

gizmo_targets: Query<&GizmoTarget>,
Expand All @@ -45,25 +44,12 @@ fn update_ui(
draw_options(ui, &mut gizmo_options);
});

// Use a transparent panel as the camera viewport
egui::CentralPanel::default()
.frame(egui::Frame::none())
.show(contexts.ctx_mut(), |ui| {
ui.allocate_ui(ui.available_size(), |ui| {
let clip_rect = ui.clip_rect();

let mut camera = camera.single_mut();
camera.viewport = Some(Viewport {
physical_position: UVec2::new(clip_rect.left() as _, clip_rect.top() as _),
physical_size: UVec2::new(clip_rect.width() as _, clip_rect.height() as _),
..default()
});

let latest_gizmo_result =
gizmo_targets.iter().find_map(|target| target.latest_result);
let latest_gizmo_result = gizmo_targets.iter().find_map(|target| target.latest_result);

draw_gizmo_result(ui, latest_gizmo_result);
});
draw_gizmo_result(ui, latest_gizmo_result);
});
}

Expand Down
2 changes: 1 addition & 1 deletion crates/transform-gizmo-demo/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn setup_scene(
material: materials.add(colors[i as usize % colors.len()]),
transform: Transform::from_xyz(
-(cube_count / 2) as f32 * 1.5 + (i as f32 * 1.5),
1.0,
0.0,
0.0,
),
..default()
Expand Down

0 comments on commit 9b9b450

Please sign in to comment.