[−][src]Function tobj::load_obj_buf
pub fn load_obj_buf<B, ML>(reader: &mut B, material_loader: ML) -> LoadResult where
B: BufRead,
ML: Fn(&Path) -> MTLLoadResult,
Load the various meshes in an OBJ buffer of some kind, e.g. a network stream, text file already in memory or so on.
You must pass a "material loader" function, which will return a material
given a name. A trivial material loader may just look at the file
name and then call load_mtl_buf
with the in-memory MTL file source.
Alternatively it could pass an MTL file in memory to load_mtl_buf
to
parse materials from some buffer.
Example
The test for load_obj_buf
includes the OBJ and MTL files as strings
and uses a Cursor
to provide a BufRead
interface on the buffer.
use std::env; use std::fs::File; use std::io::BufReader; let dir = env::current_dir().unwrap(); let mut cornell_box_obj = dir.clone(); cornell_box_obj.push("cornell_box.obj"); let mut cornell_box_file = BufReader::new(File::open(cornell_box_obj.as_path()).unwrap()); let mut cornell_box_mtl1 = dir.clone(); cornell_box_mtl1.push("cornell_box.mtl"); let mut cornell_box_mtl2 = dir.clone(); cornell_box_mtl2.push("cornell_box2.mtl"); let m = tobj::load_obj_buf(&mut cornell_box_file, |p| { match p.file_name().unwrap().to_str().unwrap() { "cornell_box.mtl" => { let f = File::open(cornell_box_mtl1.as_path()).unwrap(); tobj::load_mtl_buf(&mut BufReader::new(f)) }, "cornell_box2.mtl" => { let f = File::open(cornell_box_mtl2.as_path()).unwrap(); tobj::load_mtl_buf(&mut BufReader::new(f)) }, _ => unreachable!(), } });