file loader multiplexer, pass dom to load_roblox
This commit is contained in:
parent
6da4c81826
commit
7c2666fdf5
@ -10,10 +10,8 @@ fn class_is_a(class: &str, superclass: &str) -> bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
pub fn get_objects<R: std::io::Read>(buf_thing: R, superclass: &str) -> Result<std::vec::Vec<rbx_dom_weak::Instance>, Box<dyn std::error::Error>> {
|
|
||||||
// Using buffered I/O is recommended with rbx_binary
|
|
||||||
let dom = rbx_binary::from_reader(buf_thing)?;
|
|
||||||
|
|
||||||
|
pub fn get_objects(dom:rbx_dom_weak::WeakDom, superclass: &str) -> Result<std::vec::Vec<rbx_dom_weak::Instance>, Box<dyn std::error::Error>> {
|
||||||
let mut objects = std::vec::Vec::<rbx_dom_weak::Instance>::new();
|
let mut objects = std::vec::Vec::<rbx_dom_weak::Instance>::new();
|
||||||
//move matching instances into objects
|
//move matching instances into objects
|
||||||
let (_,mut instances) = dom.into_raw();
|
let (_,mut instances) = dom.into_raw();
|
||||||
|
35
src/main.rs
35
src/main.rs
@ -161,9 +161,9 @@ impl GraphicsData {
|
|||||||
depth_texture.create_view(&wgpu::TextureViewDescriptor::default())
|
depth_texture.create_view(&wgpu::TextureViewDescriptor::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_modeldatas_roblox<R: std::io::Read>(&self,input:R) -> Vec<ModelData>{
|
fn generate_modeldatas_roblox(&self,dom:rbx_dom_weak::WeakDom) -> Vec<ModelData>{
|
||||||
let mut modeldatas=generate_modeldatas(self.handy_unit_cube.clone(),ModelData::COLOR_FLOATS_WHITE);
|
let mut modeldatas=generate_modeldatas(self.handy_unit_cube.clone(),ModelData::COLOR_FLOATS_WHITE);
|
||||||
match load_roblox::get_objects(input, "BasePart") {
|
match load_roblox::get_objects(dom, "BasePart") {
|
||||||
Ok(objects)=>{
|
Ok(objects)=>{
|
||||||
for object in objects.iter() {
|
for object in objects.iter() {
|
||||||
if let (
|
if let (
|
||||||
@ -830,13 +830,40 @@ impl framework::Example for GraphicsData {
|
|||||||
println!("opening file: {:?}", &path);
|
println!("opening file: {:?}", &path);
|
||||||
//oh boy! let's load the map!
|
//oh boy! let's load the map!
|
||||||
if let Ok(file)=std::fs::File::open(path){
|
if let Ok(file)=std::fs::File::open(path){
|
||||||
let input = std::io::BufReader::new(file);
|
let mut input = std::io::BufReader::new(file);
|
||||||
let modeldatas=self.generate_modeldatas_roblox(input);
|
let mut first_8=[0u8;8];
|
||||||
|
//.rbxm roblox binary = "<roblox!"
|
||||||
|
//.rbxmx roblox xml = "<roblox "
|
||||||
|
//.bsp = "VBSP"
|
||||||
|
//.vmf =
|
||||||
|
//.snf = "SNMF"
|
||||||
|
//.snf = "SNBF"
|
||||||
|
if let (Ok(()),Ok(()))=(std::io::Read::read_exact(&mut input, &mut first_8),std::io::Seek::rewind(&mut input)){
|
||||||
|
//
|
||||||
|
if let Some(modeldatas)={
|
||||||
|
if &first_8==b"<roblox!"{
|
||||||
|
if let Ok(dom) = rbx_binary::from_reader(input){
|
||||||
|
Some(self.generate_modeldatas_roblox(dom))
|
||||||
|
}else{
|
||||||
|
None
|
||||||
|
}
|
||||||
|
//}else if &first_8[0..4]==b"VBSP"{
|
||||||
|
// self.generate_modeldatas_valve(input)
|
||||||
|
}else{
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}{
|
||||||
//if generate_modeldatas succeeds, clear the previous ones
|
//if generate_modeldatas succeeds, clear the previous ones
|
||||||
self.models.clear();
|
self.models.clear();
|
||||||
self.physics.models.clear();
|
self.physics.models.clear();
|
||||||
self.generate_model_physics(&modeldatas);
|
self.generate_model_physics(&modeldatas);
|
||||||
self.generate_model_graphics(device,modeldatas);
|
self.generate_model_graphics(device,modeldatas);
|
||||||
|
}else{
|
||||||
|
println!("No modeldatas were generated");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
println!("Failed ro read first 8 bytes and seek back to beginning of file.");
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
println!("Could not open file");
|
println!("Could not open file");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user