diff --git a/Cargo.toml b/Cargo.toml index 81aedc8..a6d2bf7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,9 +2,8 @@ resolver = "2" members = [ - "config_handler", - "networking", "asset", + "config_handler", "context", "controllable_thread", "engine", @@ -14,6 +13,7 @@ members = [ "loading-screen", "lua-wrapper", "math", + "networking", "presentation", "promise", "ring_buffer", @@ -55,7 +55,6 @@ syn = { version = "2.0.67", features = ["extra-traits", "full"] } quote = "1.0.35" proc-macro2 = "1.0.86" downcast-rs = "2.0.0" -plexus = { version = "0.0.11", default-features = false } utilities = { git = "https://gavania.de/hodasemi/utilities.git" } vulkan-rs = { git = "https://gavania.de/hodasemi/vulkan_lib.git" } diff --git a/asset/src/vertextypes/positiononly.rs b/asset/src/vertextypes/positiononly.rs index a12a935..e961102 100644 --- a/asset/src/vertextypes/positiononly.rs +++ b/asset/src/vertextypes/positiononly.rs @@ -2,8 +2,6 @@ use cgmath::{Vector3, Zero}; use utilities::{impl_reprc, prelude::*}; use vulkan_rs::prelude::*; -use std::mem; - impl_reprc!( #[derive(Copy, Debug)] pub struct PositionOnly { @@ -34,19 +32,11 @@ impl Default for PositionOnly { } impl VertexInputDescription for PositionOnly { - fn bindings() -> Vec { - vec![VkVertexInputBindingDescription { - binding: 0, - stride: mem::size_of::() as u32, - inputRate: VK_VERTEX_INPUT_RATE_VERTEX, - }] - } - fn attributes() -> Vec { vec![VkVertexInputAttributeDescription { location: 0, binding: 0, - format: VK_FORMAT_R32G32B32A32_SFLOAT, + format: VK_FORMAT_R32G32B32_SFLOAT, offset: 0, }] } diff --git a/examples/simple_window/src/main.rs b/examples/simple_window/src/main.rs index 09d950f..e66ee0e 100644 --- a/examples/simple_window/src/main.rs +++ b/examples/simple_window/src/main.rs @@ -17,8 +17,8 @@ fn main() -> Result<()> { world_builder.add_system(GameState::update); world_builder.resources.insert(GameState::default()); - // let dir = Path::new("C:/Users/M.Huebner/Downloads/Space Skybox Generator/Export"); - let dir = Path::new("/home/michaelh/Sync/skybox_labeled"); + let dir = Path::new("C:/Users/M.Huebner/Downloads/skybox"); + // let dir = Path::new("/home/michaelh/Sync/skybox_labeled"); SkyBox::new( &mut world_builder, [ @@ -88,7 +88,7 @@ impl Game { let diff = now.as_secs_f32() - self.start.as_secs_f32(); camera.set_eye_dir( Matrix3::from_angle_z(Deg(diff * 36.0)) - * Matrix3::from_angle_x(Deg(diff.sin() * 45.0)) + * Matrix3::from_angle_x(Deg(diff.sin() * 30.0)) * Vector3::unit_y(), ); view.update_buffer()?; diff --git a/skybox/Cargo.toml b/skybox/Cargo.toml index ccdcfcc..d6d2962 100644 --- a/skybox/Cargo.toml +++ b/skybox/Cargo.toml @@ -6,7 +6,6 @@ edition = "2024" [dependencies] anyhow.workspace = true -plexus.workspace = true utilities.workspace = true ecs.workspace = true diff --git a/skybox/src/cube.rs b/skybox/src/cube.rs new file mode 100644 index 0000000..72c03cd --- /dev/null +++ b/skybox/src/cube.rs @@ -0,0 +1,84 @@ +use engine::prelude::{cgmath::*, *}; + +pub struct CubeCorners(pub [PositionOnly; 8]); + +impl CubeCorners { + pub fn new(offset: Vector3, extent: Vector3) -> Self { + Self([ + // 0 - left bottom front + PositionOnly::new(vec3(offset.x, offset.y, offset.z)), + // 1 - right bottom front + PositionOnly::new(vec3(offset.x + extent.x, offset.y, offset.z)), + // 2 - right top front + PositionOnly::new(vec3(offset.x + extent.x, offset.y + extent.y, offset.z)), + // 3 - left top front + PositionOnly::new(vec3(offset.x, offset.y + extent.y, offset.z)), + // 4 - left bottom back + PositionOnly::new(vec3(offset.x, offset.y, offset.z + extent.z)), + // 5 - right bottom back + PositionOnly::new(vec3(offset.x + extent.x, offset.y, offset.z + extent.z)), + // 6 - right top back + PositionOnly::new(vec3( + offset.x + extent.x, + offset.y + extent.y, + offset.z + extent.z, + )), + // 7 - left top back + PositionOnly::new(vec3(offset.x, offset.y + extent.y, offset.z + extent.z)), + ]) + } +} + +pub struct Plane([PositionOnly; 4]); + +impl Plane { + pub fn triangulate(self) -> [PositionOnly; 6] { + [ + self.0[0], self.0[1], self.0[2], self.0[2], self.0[3], self.0[0], + ] + } +} + +impl<'a> From<(&'a CubeCorners, usize, usize, usize, usize)> for Plane { + fn from((corners, i1, i2, i3, i4): (&'a CubeCorners, usize, usize, usize, usize)) -> Self { + Self([corners.0[i1], corners.0[i2], corners.0[i3], corners.0[i4]]) + } +} + +pub struct Cube { + pub left: Plane, + pub right: Plane, + pub front: Plane, + pub back: Plane, + pub top: Plane, + pub bottom: Plane, +} + +impl Cube { + pub fn triangulate(self) -> [PositionOnly; 36] { + [ + self.front.triangulate(), + self.left.triangulate(), + self.right.triangulate(), + self.back.triangulate(), + self.top.triangulate(), + self.bottom.triangulate(), + ] + .concat() + .try_into() + .unwrap() + } +} + +impl From for Cube { + fn from(corners: CubeCorners) -> Self { + Self { + left: Plane::from((&corners, 0, 3, 4, 7)), + right: Plane::from((&corners, 2, 1, 6, 5)), + front: Plane::from((&corners, 0, 1, 2, 3)), + back: Plane::from((&corners, 5, 4, 7, 6)), + top: Plane::from((&corners, 3, 2, 6, 7)), + bottom: Plane::from((&corners, 5, 4, 0, 1)), + } + } +} diff --git a/skybox/src/lib.rs b/skybox/src/lib.rs index 4d66291..8971d49 100644 --- a/skybox/src/lib.rs +++ b/skybox/src/lib.rs @@ -1,16 +1,11 @@ -mod vertex; +mod cube; use std::{path::PathBuf, sync::Arc, time::Duration}; use anyhow::Result; +use cube::{Cube, CubeCorners}; use ecs::*; -use engine::prelude::{shader_type::*, *}; -use plexus::primitive::{ - cube::{Bounds, Cube}, - decompose::Triangulate, - generate::PolygonsWithPosition, -}; -use vertex::VertexPoint; +use engine::prelude::{cgmath::*, shader_type::*, *}; pub struct SkyBoxImages { left: PathBuf, @@ -40,7 +35,7 @@ pub struct SkyBox { enabled: bool, _cube_map: Arc, - cube_buffer: Arc>, + cube_buffer: Arc>, vertex_shader: Arc>, fragment_shader: Arc>, @@ -63,12 +58,15 @@ impl SkyBox { let images = images.into(); let cube_map = Image::cube_map([ - images.left.try_into()?, - images.right.try_into()?, - images.front.try_into()?, - images.back.try_into()?, - images.top.try_into()?, - images.bottom.try_into()?, + ( + images.front.try_into()?, + vec![ImageModifier::Rotate90, ImageModifier::FlipH], + ), + (images.left.try_into()?, vec![ImageModifier::Rotate90]), + (images.right.try_into()?, vec![ImageModifier::Rotate270]), + (images.back.try_into()?, vec![ImageModifier::FlipH]), + (images.top.try_into()?, vec![ImageModifier::None]), + (images.bottom.try_into()?, vec![ImageModifier::None]), ])? .format(VK_FORMAT_R8G8B8A8_UNORM) .max_mip_map_levels() @@ -128,19 +126,8 @@ impl SkyBox { DescriptorWrite::combined_samplers(1, &[&cube_map]), ])?; - let cube_mesh = Cube::new() - .polygons_with_position_from(Bounds::unit_radius()) - .triangulate() - .map(|d| { - vec![ - [d.a.0.into_inner(), d.a.1.into_inner(), d.a.2.into_inner()], - [d.b.0.into_inner(), d.b.1.into_inner(), d.b.2.into_inner()], - [d.c.0.into_inner(), d.c.1.into_inner(), d.c.2.into_inner()], - ] - }) - .flatten() - .map(|t| VertexPoint::new(t[0] as f32, t[1] as f32, t[2] as f32)) - .collect::>(); + let cube: Cube = CubeCorners::new(vec3(-1.0, -1.0, -1.0), vec3(2.0, 2.0, 2.0)).into(); + let cube_mesh = cube.triangulate(); let command_buffer = CommandBuffer::new_primary() .build(context.device().clone(), context.queue().clone())?; @@ -243,7 +230,7 @@ impl SkyBox { ) -> Result>> { render_target.execute(|render_target| { Pipeline::new_graphics() - .set_vertex_shader::(vertex_shader.clone()) + .set_vertex_shader::(vertex_shader.clone()) .set_fragment_shader(fragment_shader.clone()) .input_assembly(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, false) .default_multisample(sample_count) diff --git a/skybox/src/vertex.rs b/skybox/src/vertex.rs deleted file mode 100644 index ebacc1e..0000000 --- a/skybox/src/vertex.rs +++ /dev/null @@ -1,31 +0,0 @@ -use engine::prelude::*; -use utilities::impl_reprc; - -impl_reprc!( - pub struct VertexPoint { - #[assume_reprc] - v: [f32; 4], - } -); - -impl VertexPoint { - pub fn new(x: impl Into, y: impl Into, z: impl Into) -> Self { - VertexPoint { - v: [x.into(), y.into(), z.into(), 1.0], - } - } -} - -impl VertexInputDescription for VertexPoint { - fn attributes() -> Vec { - vec![ - // position - VkVertexInputAttributeDescription { - location: 0, - binding: 0, - format: VK_FORMAT_R32G32B32_SFLOAT, - offset: 0, - }, - ] - } -}