Add image modifier to cube map generation
This commit is contained in:
parent
71ddeee80c
commit
7115f199c1
1 changed files with 33 additions and 6 deletions
|
@ -9,6 +9,15 @@ use std::path::Path;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
pub enum ImageModifier {
|
||||||
|
None,
|
||||||
|
Rotate90,
|
||||||
|
Rotate180,
|
||||||
|
Rotate270,
|
||||||
|
FlipV,
|
||||||
|
FlipH,
|
||||||
|
}
|
||||||
|
|
||||||
enum ImageSourceType {
|
enum ImageSourceType {
|
||||||
Empty,
|
Empty,
|
||||||
Raw(Vec<u8>),
|
Raw(Vec<u8>),
|
||||||
|
@ -699,16 +708,34 @@ impl Image {
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `array` - Source images
|
/// * `array` - Source images
|
||||||
pub fn cube_map(array: [AssetPath; 6]) -> Result<ImageBuilder> {
|
pub fn cube_map(array: [(AssetPath, ImageModifier); 6]) -> Result<ImageBuilder> {
|
||||||
let images = array
|
let mut dyn_images = array
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|path| {
|
.map(|(path, modifier)| {
|
||||||
image::open(&path.full_path())
|
Ok((
|
||||||
.map(|i| i.to_rgba8())
|
image::open(&path.full_path())
|
||||||
.map_err(|err| anyhow::Error::new(err).context(path.full_path()))
|
.map_err(|err| anyhow::Error::new(err).context(path.full_path()))?,
|
||||||
|
modifier,
|
||||||
|
))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>>>()?;
|
.collect::<Result<Vec<_>>>()?;
|
||||||
|
|
||||||
|
for (image, modifier) in dyn_images.iter_mut() {
|
||||||
|
match modifier {
|
||||||
|
ImageModifier::None => (),
|
||||||
|
ImageModifier::Rotate90 => *image = image.rotate90(),
|
||||||
|
ImageModifier::Rotate180 => *image = image.rotate180(),
|
||||||
|
ImageModifier::Rotate270 => *image = image.rotate270(),
|
||||||
|
ImageModifier::FlipV => *image = image.flipv(),
|
||||||
|
ImageModifier::FlipH => *image = image.fliph(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let images = dyn_images
|
||||||
|
.into_iter()
|
||||||
|
.map(|(image, _)| image.to_rgba8())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let width = images[0].width();
|
let width = images[0].width();
|
||||||
let height = images[0].height();
|
let height = images[0].height();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue