Hi!
I use Trunk to serve my app, and I use Tobj crate toparse my obj. file.
After I loaded my file, I try to parse it like this
let ( models, materials ) = load_model_from_slice( &buffer, "vokselia_spawn", &tobj::GPU_LOAD_OPTIONS ).await.expect( "Failed to load OBJ file" );
async fn load_model_from_slice( obj_buffer : &[ u8 ], material_folder : &str, load_options : &tobj::LoadOptions ) -> tobj::LoadResult
{
let obj_cursor = Cursor::new( obj_buffer );
let mut obj_reader = BufReader::new( obj_cursor );
tobj::load_obj_buf_async
(
&mut obj_reader,
load_options,
move | p |
{
async move
{
gl::console::time_with_label( "Load mtl" );
// This just fetches the file from the server and returns Vec<u8>
let mtl = gl::file::load( &format!( "{}/{}", material_folder, p ) ).await;
if mtl.is_err()
{
gl::log::error!( "{:#?}", mtl );
return Err( tobj::LoadError::OpenFileFailed );
}
let mtl = mtl.unwrap();
let mtl_cursor = Cursor::new( mtl );
let m = tobj::load_mtl_buf( &mut BufReader::new( mtl_cursor ) );
gl::console::time_end_with_label( "Load mtl" );
m
}
}
)
.await
}
The code above in WebAssembly take 44 seconds to parse a file, while the native version takes only 8 to parse the same file. Any idea why there is such a big difference in performance?