Skip to content

Commit

Permalink
fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aevyrie committed May 6, 2024
1 parent 837b83d commit d4fccd1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 44 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension_anchor_indicator = ["bevy_gizmos"]
extension_independent_skybox = ["bevy_asset", "bevy_core_pipeline"]

[dependencies]
bevy_app = "0.13"
bevy_app = "=0.13"
bevy_derive = "0.13"
bevy_ecs = "0.13"
bevy_input = "0.13"
Expand All @@ -35,7 +35,7 @@ bevy_gizmos = { version = "0.13", optional = true }
bevy_picking_core = "0.18"

[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = [
bevy = { version = "0.13", features = [
"bevy_gizmos",
"bevy_gltf",
"bevy_scene",
Expand All @@ -52,5 +52,5 @@ bevy_mod_picking = { version = "0.18", default-features = false, features = [
"backend_raycast",
] }

big_space = "0.5"
big_space = "0.6"
rand = "0.8"
40 changes: 22 additions & 18 deletions examples/cad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
specular_map: specular_map.clone(),
},
EditorCam {
orbit_constraint: OrbitConstraint::Fixed {
up: Vec3::Y,
can_pass_tdc: false,
},
orbit_constraint: OrbitConstraint::Free,
last_anchor_depth: 2.0,
..Default::default()
},
Expand Down Expand Up @@ -100,21 +97,28 @@ fn setup_ui(mut commands: Commands) {
font_size: 20.0,
..default()
};
commands.spawn(
TextBundle::from_sections(vec![
TextSection::new("Left Mouse - Pan\n", style.clone()),
TextSection::new("Right Mouse - Orbit\n", style.clone()),
TextSection::new("Scroll - Zoom\n", style.clone()),
TextSection::new("P - Toggle projection\n", style.clone()),
TextSection::new("E - Toggle explode\n", style.clone()),
])
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(12.0),
left: Val::Px(12.0),
commands
.spawn((NodeBundle {
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
padding: UiRect::all(Val::Px(20.)),
..default()
},
..default()
}),
);
},))
.with_children(|parent| {
parent.spawn(
TextBundle::from_sections(vec![
TextSection::new("Left Mouse - Pan\n", style.clone()),
TextSection::new("Right Mouse - Orbit\n", style.clone()),
TextSection::new("Scroll - Zoom\n", style.clone()),
TextSection::new("P - Toggle projection\n", style.clone()),
TextSection::new("E - Toggle explode\n", style.clone()),
])
.with_style(Style { ..default() }),
);
});
}

#[derive(Component)]
Expand Down
59 changes: 36 additions & 23 deletions examples/floating_origin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use bevy::prelude::*;
use bevy_editor_cam::{controller::component::EditorCam, DefaultEditorCamPlugins};
use big_space::{FloatingOrigin, GridCell};
use big_space::{
reference_frame::RootReferenceFrame, world_query::GridTransformReadOnly, FloatingOrigin,
GridCell, IgnoreFloatingOrigin,
};

fn main() {
App::new()
Expand All @@ -13,6 +16,7 @@ fn main() {
))
.insert_resource(ClearColor(Color::BLACK))
.add_systems(Startup, (setup, ui_setup))
.add_systems(PreUpdate, ui_text_system)
.run()
}

Expand Down Expand Up @@ -73,9 +77,6 @@ fn setup(
#[derive(Component, Reflect)]
pub struct BigSpaceDebugText;

#[derive(Component, Reflect)]
pub struct FunFactText;

fn ui_setup(mut commands: Commands) {
commands.spawn((
TextBundle::from_section(
Expand All @@ -94,25 +95,37 @@ fn ui_setup(mut commands: Commands) {
..default()
}),
BigSpaceDebugText,
IgnoreFloatingOrigin,
));
}

commands.spawn((
TextBundle::from_section(
"",
TextStyle {
font_size: 52.0,
color: Color::WHITE,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
right: Val::Px(10.0),
left: Val::Px(10.0),
..default()
})
.with_text_justify(JustifyText::Center),
FunFactText,
));
#[allow(clippy::type_complexity)]
fn ui_text_system(
mut debug_text: Query<(&mut Text, &GlobalTransform), With<BigSpaceDebugText>>,
origin: Query<GridTransformReadOnly<i128>, With<FloatingOrigin>>,
reference_frame: Res<RootReferenceFrame<i128>>,
) {
let origin = origin.single();
let translation = origin.transform.translation;

let grid_text = format!(
"GridCell: {}x, {}y, {}z",
origin.cell.x, origin.cell.y, origin.cell.z
);

let translation_text = format!(
"Transform: {:>8.2}x, {:>8.2}y, {:>8.2}z",
translation.x, translation.y, translation.z
);

let real_position = reference_frame.grid_position_double(origin.cell, origin.transform);
let real_position_text = format!(
"Combined: {}x, {}y, {}z",
real_position.x, real_position.y, real_position.z
);

let mut debug_text = debug_text.single_mut();

debug_text.0.sections[0].value =
format!("{grid_text}\n{translation_text}\n{real_position_text}");
}

0 comments on commit d4fccd1

Please sign in to comment.