From 3a1282087ffb4bc634715c6d953b899532339e56 Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Sun, 31 Mar 2024 18:23:44 +0300 Subject: [PATCH] wip: load materials --- src/main.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index a92e12d..0b77260 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,6 +49,7 @@ use { // MAT // PAL // PIX +use bevy::app::AppExit; fn setup_cars( mut commands: Commands, @@ -58,16 +59,34 @@ fn setup_cars( mut materials: ResMut>, // mut textures: ResMut>, // mut texture_atlases: ResMut>, + mut exit: EventWriter, ) /*-> Result>*/ { // bevy @todo: load all textures into the texture atlas // TextureAtlasBuilder - let mats = - Material::load_many("assets/DecodedData/DATA/MATERIAL/CITYA.MAT").expect("Load materials"); - // for mat in mats { - // debug!("{:?}", mat); - // } + let mut mats = vec![]; + + let _ = visit_files("assets/DecodedData/DATA/MATERIAL", &mut |dir_entry| { + if let Ok(file_type) = dir_entry.file_type() { + let fname = String::from(dir_entry.path().to_str().unwrap()); + if file_type.is_file() && fname.ends_with(".MAT") { + mats.extend(Material::load_many(fname)?); + } + } + Ok(()) + }); + + mats.sort_by_key(|e| e.material.identifier.clone()); // NB + for mat in mats.iter() { + debug!("{:?}", mat.material.identifier); + } + debug!("{:?}", mats[0]); + debug!("{:?}", mats[1]); + debug!("Total {} materials", mats.len()); // 8014 without dedup + + exit.send(AppExit); + return; // models refer to materials to load! check that let models =