Struct mesh_loader::Loader

source ·
pub struct Loader<B = Vec<u8>> { /* private fields */ }

Implementations§

source§

impl<B: AsRef<[u8]>> Loader<B>

source

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

source

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)
    }
});
source

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)?) });
source

pub fn load<P: AsRef<Path>>(&self, path: P) -> Result<Scene>

source

pub fn load_with_reader<P: AsRef<Path>, F: FnMut(&Path) -> Result<B>>( &self, path: P, reader: F ) -> Result<Scene>

source

pub fn load_from_slice<P: AsRef<Path>>( &self, bytes: &[u8], path: P ) -> Result<Scene>

source

pub fn load_from_slice_with_reader<P: AsRef<Path>, F: FnMut(&Path) -> Result<B>>( &self, bytes: &[u8], path: P, reader: F ) -> Result<Scene>

source

pub fn load_stl<P: AsRef<Path>>(&self, path: P) -> Result<Scene>

source

pub fn load_stl_from_slice<P: AsRef<Path>>( &self, bytes: &[u8], path: P ) -> Result<Scene>

source

pub fn stl_parse_color(self, enable: bool) -> Self

source

pub fn load_collada<P: AsRef<Path>>(&self, path: P) -> Result<Scene>

source

pub fn load_collada_from_slice<P: AsRef<Path>>( &self, bytes: &[u8], path: P ) -> Result<Scene>

source

pub fn load_obj<P: AsRef<Path>>(&self, path: P) -> Result<Scene>

source

pub fn load_obj_from_slice<P: AsRef<Path>>( &self, bytes: &[u8], path: P ) -> Result<Scene>

source

pub fn load_obj_with_reader<P: AsRef<Path>, F: FnMut(&Path) -> Result<B>>( &self, path: P, reader: F ) -> Result<Scene>

source

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§

source§

impl Debug for Loader

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Loader<Vec<u8>>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.