engine/skybox/src/lib.rs

80 lines
1.9 KiB
Rust
Raw Normal View History

2025-02-28 14:13:19 +00:00
use std::{path::PathBuf, sync::Arc};
use anyhow::Result;
use context::prelude::*;
use ecs::*;
pub struct SkyBoxImages {
left: PathBuf,
right: PathBuf,
front: PathBuf,
back: PathBuf,
top: PathBuf,
bottom: PathBuf,
}
impl<T: ExactSizeIterator<Item = PathBuf>> From<T> for SkyBoxImages {
fn from(mut paths: T) -> Self {
debug_assert_eq!(paths.len(), 6);
Self {
left: paths.next().unwrap(),
right: paths.next().unwrap(),
front: paths.next().unwrap(),
back: paths.next().unwrap(),
top: paths.next().unwrap(),
bottom: paths.next().unwrap(),
}
}
}
pub struct SkyBox {
cube_map: Arc<Image>,
}
impl SkyBox {
2025-03-01 05:43:44 +00:00
pub fn new(world: &mut WorldBuilder, images: impl Into<SkyBoxImages>) -> Result<()> {
2025-02-28 14:13:19 +00:00
let images = images.into();
2025-03-01 05:43:44 +00:00
let context = world.resources.get_mut::<Context>();
context.render_core_mut().add_render_routine::<Self>(1);
2025-02-28 14:13:19 +00:00
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()?,
])?
.max_mip_map_levels()
.attach_pretty_sampler(context.device())?
.build(context.device(), context.queue())?;
2025-03-01 05:43:44 +00:00
let me = Self { cube_map };
world.resources.insert(me);
Ok(())
2025-02-28 14:13:19 +00:00
}
}
2025-03-01 05:01:46 +00:00
impl TScene for SkyBox {
fn process(
&mut self,
buffer_recorder: &mut CommandBufferRecorder<'_>,
images: &TargetMode<Vec<Arc<Image>>>,
indices: &TargetMode<usize>,
world: &World,
) -> Result<()> {
todo!()
}
fn resize(
&mut self,
window_width: f32,
window_height: f32,
images: &TargetMode<Vec<Arc<Image>>>,
) -> Result<()> {
todo!()
}
}