tweak map loading

This commit is contained in:
Quaternions 2023-10-02 15:27:41 -07:00
parent 79262ce3b4
commit d16404167b
3 changed files with 17 additions and 12 deletions

View File

@ -1,5 +1,3 @@
use crate::model::{IndexedModelInstances,ModelInstance};
use crate::primitives; use crate::primitives;
fn class_is_a(class: &str, superclass: &str) -> bool { fn class_is_a(class: &str, superclass: &str) -> bool {
@ -111,7 +109,7 @@ enum RobloxBasePartDescription{
Wedge(RobloxWedgeDescription), Wedge(RobloxWedgeDescription),
CornerWedge(RobloxCornerWedgeDescription), CornerWedge(RobloxCornerWedgeDescription),
} }
pub fn generate_indexed_models_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(IndexedModelInstances,glam::Vec3), Box<dyn std::error::Error>>{ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::IndexedModelInstances{
//IndexedModelInstances includes textures //IndexedModelInstances includes textures
let mut spawn_point=glam::Vec3::ZERO; let mut spawn_point=glam::Vec3::ZERO;
@ -335,15 +333,16 @@ pub fn generate_indexed_models_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(Inde
}); });
model_id model_id
}; };
indexed_models[model_id].instances.push(ModelInstance { indexed_models[model_id].instances.push(crate::model::ModelInstance {
transform:model_transform, transform:model_transform,
color:glam::vec4(color3.r as f32/255f32, color3.g as f32/255f32, color3.b as f32/255f32, 1.0-*transparency), color:glam::vec4(color3.r as f32/255f32, color3.g as f32/255f32, color3.b as f32/255f32, 1.0-*transparency),
}); });
} }
} }
} }
Ok((IndexedModelInstances{ crate::model::IndexedModelInstances{
textures:asset_id_from_texture_id.iter().map(|t|t.to_string()).collect(), textures:asset_id_from_texture_id.iter().map(|t|t.to_string()).collect(),
models:indexed_models, models:indexed_models,
},spawn_point)) spawn_point,
}
} }

View File

@ -769,6 +769,7 @@ impl framework::Example for GraphicsData {
let indexed_model_instances=model::IndexedModelInstances{ let indexed_model_instances=model::IndexedModelInstances{
textures:Vec::new(), textures:Vec::new(),
models:indexed_models, models:indexed_models,
spawn_point:glam::Vec3::Y*50.0,
}; };
graphics.generate_model_physics(&indexed_model_instances); graphics.generate_model_physics(&indexed_model_instances);
graphics.generate_model_graphics(&device,&queue,indexed_model_instances); graphics.generate_model_graphics(&device,&queue,indexed_model_instances);
@ -795,7 +796,7 @@ impl framework::Example for GraphicsData {
//.snf = "SNBF" //.snf = "SNBF"
if let (Ok(()),Ok(()))=(std::io::Read::read_exact(&mut input, &mut first_8),std::io::Seek::rewind(&mut input)){ if let (Ok(()),Ok(()))=(std::io::Read::read_exact(&mut input, &mut first_8),std::io::Seek::rewind(&mut input)){
// //
if let Some(Ok((indexed_model_instances,spawn_point)))={ if let Some(indexed_model_instances)={
match &first_8[0..4]{ match &first_8[0..4]{
b"<rob"=>{ b"<rob"=>{
match match &first_8[4..8]{ match match &first_8[4..8]{
@ -803,19 +804,23 @@ impl framework::Example for GraphicsData {
b"lox "=>rbx_xml::from_reader(input,rbx_xml::DecodeOptions::default()).map_err(|e|format!("{:?}",e)), b"lox "=>rbx_xml::from_reader(input,rbx_xml::DecodeOptions::default()).map_err(|e|format!("{:?}",e)),
other=>Err(format!("Unknown Roblox file type {:?}",other)), other=>Err(format!("Unknown Roblox file type {:?}",other)),
}{ }{
Ok(dom)=>Some(load_roblox::generate_indexed_models_roblox(dom)), Ok(dom)=>Some(load_roblox::generate_indexed_models(dom)),
Err(e)=>{ Err(e)=>{
println!("Error loading roblox file:{:?}",e); println!("Error loading roblox file:{:?}",e);
None None
}, },
} }
}, },
//b"VBSP"=>load_valve::generate_indexed_models_valve(input), //b"VBSP"=>Some(load_bsp::generate_indexed_models(input)),
//b"SNFM"=>sniffer::generate_indexed_models(input), //b"SNFM"=>Some(sniffer::generate_indexed_models(input)),
//b"SNFB"=>sniffer::load_bot(input), //b"SNFB"=>Some(sniffer::load_bot(input)),
_=>None, other=>{
println!("loser file {:?}",other);
None
},
} }
}{ }{
let spawn_point=indexed_model_instances.spawn_point;
//if generate_indexed_models succeeds, clear the previous ones //if generate_indexed_models succeeds, clear the previous ones
self.models.clear(); self.models.clear();
self.physics.models.clear(); self.physics.models.clear();

View File

@ -63,6 +63,7 @@ pub struct IndexedModelInstances{
pub textures:Vec<String>,//RenderPattern pub textures:Vec<String>,//RenderPattern
pub models:Vec<IndexedModel>, pub models:Vec<IndexedModel>,
//object_index for spawns, triggers etc? //object_index for spawns, triggers etc?
pub spawn_point:glam::Vec3,
} }
pub fn generate_indexed_model_list_from_obj(data:obj::ObjData,color:[f32;4]) -> Vec<IndexedModel>{ pub fn generate_indexed_model_list_from_obj(data:obj::ObjData,color:[f32;4]) -> Vec<IndexedModel>{