diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..afd3ea9 --- /dev/null +++ b/Readme.md @@ -0,0 +1,3 @@ +# Experimental game + +- [ ] Skybox diff --git a/assets/.DS_Store b/assets/.DS_Store new file mode 100644 index 0000000..89cc6de Binary files /dev/null and b/assets/.DS_Store differ diff --git a/assets/skybox/.DS_Store b/assets/skybox/.DS_Store new file mode 100644 index 0000000..9b4ea73 Binary files /dev/null and b/assets/skybox/.DS_Store differ diff --git a/assets/skybox/skybox.png b/assets/skybox/skybox.png new file mode 100644 index 0000000..ed92cb0 Binary files /dev/null and b/assets/skybox/skybox.png differ diff --git a/src/assets/mod.rs b/src/assets/mod.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/assets/mod.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/logic/core/player/spawn_player.rs b/src/logic/core/player/spawn_player.rs index 6cc4f25..94fde1e 100644 --- a/src/logic/core/player/spawn_player.rs +++ b/src/logic/core/player/spawn_player.rs @@ -1,14 +1,16 @@ -use bevy::prelude::*; +use bevy::{prelude::*, core_pipeline::Skybox}; use bevy_rapier3d::prelude::*; use crate::{ comps::core::{camera::MainCamera, markers::player::Player}, - constants::player_values::{PLAYER_HEIGHT, PLAYER_INITIAL_WEIGHT, PLAYER_GRAVITY_SCALE, PLAYER_LINEAR_DAMPING}, + constants::player_values::{PLAYER_HEIGHT, PLAYER_INITIAL_WEIGHT, PLAYER_GRAVITY_SCALE, PLAYER_LINEAR_DAMPING}, scenes::scene1::skybox::{CUBEMAPS, Cubemap}, }; use super::player_movement::{PlayerLinearXZState, PlayerLinearYState}; -pub fn spawn_player(mut commands: Commands) { +pub fn spawn_player(mut commands: Commands, asset_server: Res) { + let skybox_handle = asset_server.load(CUBEMAPS[0].0); + commands .spawn(Player) .insert(RigidBody::Dynamic) @@ -44,5 +46,11 @@ pub fn spawn_player(mut commands: Commands) { commands.spawn(MainCamera).insert(Camera3dBundle { transform: Transform::from_xyz(0.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y), ..Default::default() + }) + .insert(Skybox(skybox_handle.clone())); + + commands.insert_resource(Cubemap { + is_loaded: false, + image_handle: skybox_handle, }); } diff --git a/src/main.rs b/src/main.rs index 01c5a4d..04589bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ use bevy::prelude::*; use bevy_rapier3d::prelude::*; use scenes::scene1; -mod assets; mod comps; mod constants; mod logic; diff --git a/src/scenes/scene1/ground.rs b/src/scenes/scene1/ground.rs index 1fc092b..5ed70b5 100644 --- a/src/scenes/scene1/ground.rs +++ b/src/scenes/scene1/ground.rs @@ -7,11 +7,11 @@ pub fn spawn_ground( mut materials: ResMut>, ) { commands - .spawn(Collider::cuboid(20.0, 0.1, 20.0)) + .spawn(Collider::cuboid(30.0, 0.1, 30.0)) .insert(TransformBundle::from(Transform::from_xyz(0.0, -2.0, 0.0))) .insert(RigidBody::Fixed) .insert(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(40.0).into()), + mesh: meshes.add(shape::Plane::from_size(60.0).into()), material: materials.add(StandardMaterial { base_color: Color::WHITE, perceptual_roughness: 1.0, diff --git a/src/scenes/scene1/init.rs b/src/scenes/scene1/init.rs index 57733b1..615fee1 100644 --- a/src/scenes/scene1/init.rs +++ b/src/scenes/scene1/init.rs @@ -11,7 +11,7 @@ use crate::{ }, }; -use super::{ground::spawn_ground, lighting::setup_lighting, obstacles::spawn_obstacles}; +use super::{ground::spawn_ground, lighting::setup_lighting, obstacles::spawn_obstacles, skybox::asset_loaded}; pub fn load_scene(application: &mut App) { application.insert_resource(MouseMovementSettings::default()); @@ -26,6 +26,7 @@ pub fn load_scene(application: &mut App) { application.add_systems(Update, capture_cursor); application.add_systems(Update, sync_player_y_state); application.add_systems(Update, follow_cursor_with_camera); + application.add_systems(Update, asset_loaded); application.add_systems(Startup, setup_lighting); } diff --git a/src/scenes/scene1/mod.rs b/src/scenes/scene1/mod.rs index 118976e..0ad140b 100644 --- a/src/scenes/scene1/mod.rs +++ b/src/scenes/scene1/mod.rs @@ -3,3 +3,4 @@ pub mod init; pub mod ground; pub mod lighting; pub mod obstacles; +pub mod skybox; \ No newline at end of file diff --git a/src/scenes/scene1/skybox.rs b/src/scenes/scene1/skybox.rs new file mode 100644 index 0000000..0efb29c --- /dev/null +++ b/src/scenes/scene1/skybox.rs @@ -0,0 +1,43 @@ +use bevy::{prelude::*, render::{texture::CompressedImageFormats, render_resource::{TextureViewDescriptor, TextureViewDimension}}, core_pipeline::Skybox, asset::LoadState}; + +pub const CUBEMAPS: &[(&str, CompressedImageFormats)] = &[ + ( + "skybox/skybox.png", + CompressedImageFormats::NONE, + ), +]; + +#[derive(Resource)] +pub struct Cubemap { + pub is_loaded: bool, + pub image_handle: Handle, +} + +pub fn asset_loaded( + asset_server: Res, + mut images: ResMut>, + mut cubemap: ResMut, + mut skyboxes: Query<&mut Skybox>, +) { + if !cubemap.is_loaded && asset_server.get_load_state(&cubemap.image_handle) == LoadState::Loaded { + let image = images.get_mut(&cubemap.image_handle).unwrap(); + // NOTE: PNGs do not have any metadata that could indicate they contain a cubemap texture, + // so they appear as one texture. The following code reconfigures the texture as necessary. + if image.texture_descriptor.array_layer_count() == 1 { + + image.reinterpret_stacked_2d_as_array( + image.texture_descriptor.size.height / image.texture_descriptor.size.width, + ); + image.texture_view_descriptor = Some(TextureViewDescriptor { + dimension: Some(TextureViewDimension::Cube), + ..default() + }); + } + + for mut skybox in &mut skyboxes { + skybox.0 = cubemap.image_handle.clone(); + } + + cubemap.is_loaded = true; + } +} \ No newline at end of file