From 23ae2d33215696c24a225fe3ea103d446a919686 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 8 Jan 2024 20:53:59 -0800 Subject: [PATCH] attempt to load textures --- src/load_bsp.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/load_bsp.rs b/src/load_bsp.rs index 96c8bcd..9c86833 100644 --- a/src/load_bsp.rs +++ b/src/load_bsp.rs @@ -17,6 +17,8 @@ pub fn generate_indexed_models(input:&mut R)->Res .map(|vertex|<[f32;3]>::from(vertex.position)) .collect(); + let mut name_from_texture_id=Vec::new(); + let mut texture_id_from_name=std::collections::HashMap::new(); let models=bsp.models().map(|world_model|{ //non-deduplicated @@ -32,13 +34,23 @@ pub fn generate_indexed_models(input:&mut R)->Res let (s,t)=(glam::Vec3A::from_slice(&face_texture.texture_transforms_u[0..3]),glam::Vec3A::from_slice(&face_texture.texture_transforms_v[0..3])); let (s0,t0)=(face_texture.texture_transforms_u[3],face_texture.texture_transforms_v[3]); + //texture + let texture_id=if let Some(&texture_id)=texture_id_from_name.get(face_texture_data.name()){ + texture_id + }else{ + let texture_id=name_from_texture_id.len() as u32; + texture_id_from_name.insert(face_texture_data.name(),texture_id); + name_from_texture_id.push(face_texture_data.name().to_string()); + texture_id + }; + //normal let normal=face.normal(); let normal_idx=spam_normal.len() as u32; spam_normal.push(crate::integer::Planar64Vec3::try_from([normal.x,normal.z,normal.y]).unwrap()); crate::model::IndexedGroup{ - texture:None, + texture:Some(texture_id), polys:vec![crate::model::IndexedPolygon{vertices:face.vertex_indexes().map(|vertex_index|{ let pos=glam::Vec3A::from_array(vertices[vertex_index as usize]); let pos_idx=spam_pos.len(); @@ -75,7 +87,7 @@ pub fn generate_indexed_models(input:&mut R)->Res }).collect(); Ok(crate::model::IndexedModelInstances{ - textures:Vec::new(), + textures:name_from_texture_id, models, spawn_point, modes:Vec::new(),