From e6210002c94f0e2d570f77f242c158fc36c38093 Mon Sep 17 00:00:00 2001 From: NickAc <32451103+NickAcPT@users.noreply.github.com> Date: Sun, 11 Aug 2024 14:18:51 +0100 Subject: [PATCH] Add warnings to model generation --- .../src/generator.rs | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/utils/nmsr-rendering-blockbench-model-generator-experiment/src/generator.rs b/utils/nmsr-rendering-blockbench-model-generator-experiment/src/generator.rs index 08823d4..23a2025 100644 --- a/utils/nmsr-rendering-blockbench-model-generator-experiment/src/generator.rs +++ b/utils/nmsr-rendering-blockbench-model-generator-experiment/src/generator.rs @@ -53,6 +53,7 @@ pub struct ModelGenerationProject { providers: Vec, part_context: PlayerPartProviderContext, textures: HashMap, + warnings: Vec, max_resolution: Vec2, image_io: I, } @@ -90,6 +91,7 @@ impl ModelGenerationProject { ] .to_vec(), part_context: context, + warnings: Vec::new(), textures: HashMap::new(), max_resolution: Vec2::ZERO, image_io, @@ -120,7 +122,8 @@ impl ModelGenerationProject { use nmsr_rendering::high_level::parts::provider::ears::PlayerPartEarsTextureType; if texture_type == PlayerPartTextureType::Skin { - if let Ok(Some(alfalfa)) = ears_rs::alfalfa::read_alfalfa(&texture) { + let alfalfa = ears_rs::alfalfa::read_alfalfa(&texture); + if let Ok(Some(ref alfalfa)) = alfalfa { if let Some(wings) = alfalfa.get_data(AlfalfaDataKey::Wings) { self.load_texture( PlayerPartEarsTextureType::Wings.into(), @@ -128,7 +131,7 @@ impl ModelGenerationProject { do_ears_processing, )?; } - + if let Some(cape) = alfalfa.get_data(AlfalfaDataKey::Cape) { self.load_texture( PlayerPartEarsTextureType::Cape.into(), @@ -139,7 +142,22 @@ impl ModelGenerationProject { } let features = EarsParser::parse(&texture)?; - + + if let (Some(features), Ok(None)) = (features, alfalfa) { + let wings_enabled = features.wing.is_some(); + let cape_enabled = features.cape_enabled; + + if wings_enabled { + self.insert_empty_texture(PlayerPartEarsTextureType::Wings.into())?; + self.warnings.push("Wings are enabled but no wings texture was found.".to_string()); + } + + if cape_enabled { + self.insert_empty_texture(PlayerPartEarsTextureType::Cape.into())?; + self.warnings.push("Cape is enabled but no cape texture was found.".to_string()); + } + } + self.part_context.ears_features = features; ears_rs::utils::process_erase_regions(&mut texture)?; @@ -163,6 +181,15 @@ impl ModelGenerationProject { Ok(()) } + fn insert_empty_texture(&mut self, texture_type: PlayerPartTextureType) -> Result<()> { + let (width, height) = texture_type.get_texture_size(); + let texture = RgbaImage::new(width, height); + + self.add_texture(texture_type, texture, false)?; + + Ok(()) + } + fn recompute_max_resolution(&mut self) { let max_resolution = self .textures @@ -275,4 +302,8 @@ impl ModelGenerationProject { pub(crate) fn filter_textures(&mut self, keys: &[PlayerPartTextureType]) { self.textures.retain(|k, _| keys.contains(k)); } + + pub fn warnings(&self) -> &[String] { + &self.warnings + } }