use bevy::{ math::Vec3A, prelude::*, render::primitives::{Aabb, Sphere}, window::{CursorGrabMode, PrimaryWindow, Window, WindowMode}, }; use big_space::{ camera::{CameraController, CameraInput}, FloatingOrigin, GridCell, }; fn main() { App::new() .add_plugins(DefaultPlugins.build().disable::()) .add_plugin(big_space::FloatingOriginPlugin::::default()) .add_plugin(big_space::debug::FloatingOriginDebugPlugin::::default()) .add_plugin(big_space::camera::CameraControllerPlugin::::default()) .add_plugin(bevy_framepace::FramepacePlugin) .insert_resource(ClearColor(Color::BLACK)) .add_startup_system(setup) .add_system(cursor_grab_system) .add_system(ui_text_system) .add_startup_system(ui_setup) .run() } fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { // camera commands.spawn(( Camera3dBundle { transform: Transform::from_xyz(0.0, 0.0, 8.0) .looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), ..default() }, GridCell::::default(), // All spatial entities need this component FloatingOrigin, // Important: marks this as the entity to use as the floating origin CameraController::default().with_max_speed(10e35), // Built-in camera controller )); let mesh_handle = meshes.add( shape::Icosphere { radius: 0.5, subdivisions: 32, } .try_into() .unwrap(), ); let matl_handle = materials.add(StandardMaterial { base_color: Color::BLUE, perceptual_roughness: 0.8, reflectance: 1.0, ..default() }); let mut translation = Vec3::ZERO; for i in 1..=37_i128 { let j = 10_f32.powf(i as f32 - 10.0); translation.x += j; commands.spawn(( PbrBundle { mesh: mesh_handle.clone(), material: matl_handle.clone(), transform: Transform::from_scale(Vec3::splat(j)).with_translation(translation), ..default() }, Aabb::from(Sphere { center: Vec3A::ZERO, radius: j / 2.0, }), GridCell::::default(), )); } // light commands.spawn((DirectionalLightBundle { directional_light: DirectionalLight { illuminance: 100_000.0, ..default() }, ..default() },)); } #[derive(Component, Reflect)] pub struct BigSpaceDebugText; fn ui_setup(mut commands: Commands, asset_server: Res) { commands.spawn(( TextBundle::from_section( "", TextStyle { font: asset_server.load("fonts/FiraMono-Regular.ttf"), font_size: 18.0, color: Color::WHITE, }, ) .with_text_alignment(TextAlignment::Left) .with_style(Style { position_type: PositionType::Absolute, position: UiRect { top: Val::Px(10.0), left: Val::Px(10.0), ..default() }, ..default() }), BigSpaceDebugText, )); } fn ui_text_system( mut text: Query<&mut Text, With>, time: Res