pub struct Loader<B = Vec<u8>> { /* private fields */ }
Implementations§
Source§impl<B: AsRef<[u8]>> Loader<B>
impl<B: AsRef<[u8]>> Loader<B>
Sourcepub fn merge_meshes(self, enable: bool) -> Self
pub fn merge_meshes(self, enable: bool) -> Self
Sets whether or not to merge meshes at load time.
If set to true
, it is guaranteed that there is exactly one mesh in the
loaded Scene
(i.e., scene.meshes.len() == 1
).
Default: false
Sourcepub fn custom_reader(self, reader: fn(_: &Path) -> Result<B>) -> Self
pub fn custom_reader(self, reader: fn(_: &Path) -> Result<B>) -> Self
Use the given function as a file reader of this loader.
Default: std::fs::read
§Example
This is useful if you want to load a mesh from a location that the default reader does not support.
use std::fs;
use mesh_loader::Loader;
let loader = Loader::default().custom_reader(|path| {
match path.to_str() {
Some(url) if url.starts_with("https://") || url.starts_with("http://") => {
// Fetch online file
// ...
}
_ => fs::read(path), // Otherwise, read from a file (same as the default reader)
}
});
Sourcepub fn with_custom_reader(reader: fn(_: &Path) -> Result<B>) -> Self
pub fn with_custom_reader(reader: fn(_: &Path) -> Result<B>) -> Self
Creates a new loader with the given file reader.
This is similar to Loader::default().custom_reader()
,
but the reader can return a non-Vec<u8>
type.
§Example
This is useful when using mmap.
use std::fs::File;
use memmap2::Mmap;
use mesh_loader::Loader;
let loader = Loader::with_custom_reader(|path| unsafe { Mmap::map(&File::open(path)?) });
pub fn load<P: AsRef<Path>>(&self, path: P) -> Result<Scene>
pub fn load_with_reader<P: AsRef<Path>, F: FnMut(&Path) -> Result<B>>( &self, path: P, reader: F, ) -> Result<Scene>
pub fn load_from_slice<P: AsRef<Path>>( &self, bytes: &[u8], path: P, ) -> Result<Scene>
pub fn load_from_slice_with_reader<P: AsRef<Path>, F: FnMut(&Path) -> Result<B>>( &self, bytes: &[u8], path: P, reader: F, ) -> Result<Scene>
pub fn load_stl<P: AsRef<Path>>(&self, path: P) -> Result<Scene>
pub fn load_stl_from_slice<P: AsRef<Path>>( &self, bytes: &[u8], path: P, ) -> Result<Scene>
pub fn stl_parse_color(self, enable: bool) -> Self
pub fn load_collada<P: AsRef<Path>>(&self, path: P) -> Result<Scene>
pub fn load_collada_from_slice<P: AsRef<Path>>( &self, bytes: &[u8], path: P, ) -> Result<Scene>
pub fn load_obj<P: AsRef<Path>>(&self, path: P) -> Result<Scene>
pub fn load_obj_from_slice<P: AsRef<Path>>( &self, bytes: &[u8], path: P, ) -> Result<Scene>
pub fn load_obj_with_reader<P: AsRef<Path>, F: FnMut(&Path) -> Result<B>>( &self, path: P, reader: F, ) -> Result<Scene>
pub fn load_obj_from_slice_with_reader<P: AsRef<Path>, F: FnMut(&Path) -> Result<B>>( &self, bytes: &[u8], path: P, reader: F, ) -> Result<Scene>
Trait Implementations§
Auto Trait Implementations§
impl<B> Freeze for Loader<B>
impl<B> RefUnwindSafe for Loader<B>
impl<B> Send for Loader<B>
impl<B> Sync for Loader<B>
impl<B> Unpin for Loader<B>
impl<B> UnwindSafe for Loader<B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more