Struct tobj::LoadOptions

source ·
pub struct LoadOptions {
    pub merge_identical_points: bool,
    pub reorder_data: bool,
    pub single_index: bool,
    pub triangulate: bool,
    pub ignore_points: bool,
    pub ignore_lines: bool,
}
Expand description

Options for processing the mesh during loading.

Passed to load_obj(), load_obj_buf() and load_obj_buf_async().

By default, all of these are false. With those settings, the data you get represents the original data in the input file/buffer as closely as possible.

Use the init struct pattern to set individual options:

LoadOptions {
    single_index: true,
    ..Default::default()
}

There are convenience consts for the most common cases:

Fields§

§merge_identical_points: bool

Merge identical positions.

This is usually what you want if you intend to use the mesh in an offline rendering context or to do further processing with topological operators.

  • This flag is mutually exclusive with single_index and will lead to a InvalidLoadOptionConfig error if both are set to true.

  • If adjacent faces share vertices that have separate indices but the same position in 3D they will be merged into a single vertex and the resp. indices changed.

  • Topolgy may change as a result (faces may become connected in the index).

§reorder_data: bool

Normal & texture coordinates will be reordered to allow omitting their indices.

  • This flag is mutually exclusive with single_index and will lead to an InvalidLoadOptionConfig error if both are set to true.

  • The resulting Mesh’s normal_indices and/or texcoord_indices will be empty.

  • Per-vertex normals and/or texture_coordinates will be reordered to match the Mesh’s indices.

  • Per-vertex-per-face normals and/or texture coordinates indices will be [0, 1, 2, ..., n]. I.e.:

    // If normals where specified per-vertex-per-face:
    assert!(mesh.indices.len() == mesh.normals.len() / 3);
    
    for index in 0..mesh.indices.len() {
        println!("Normal n is {}, {}, {}",
            mesh.normals[index * 3 + 0],
            mesh.normals[index * 3 + 1],
            mesh.normals[index * 3 + 2]
        );
    }
§single_index: bool

Create a single index.

This is usually what you want if you are loading the mesh to display in a realtime (GPU) context.

  • This flag is mutually exclusive with both merge_identical_points and reorder_data resp. and will lead to a InvalidLoadOptionConfig error if both it and either of the two other are set to true.

  • Vertices may get duplicated to match the granularity (per-vertex-per-face) of normals and/or texture coordinates.

  • Topolgy may change as a result (faces may become disconnected in the index).

  • The resulting Mesh’s normal_indices and texcoord_indices will be empty.

§triangulate: bool

Triangulate all faces.

  • Points (one point) and lines (two points) are blown up to zero area triangles via point duplication. Except if ignore_points or ignore_lines is/are set to true, resp.

  • The resulting Mesh’s face_arities will be empty as all faces are guranteed to have arity 3.

  • Only polygons that are trivially convertible to triangle fans are supported. Arbitrary polygons may not behave as expected. The best solution would be to convert your mesh to solely consist of triangles in your modeling software.

§ignore_points: bool

Ignore faces containing only a single vertex (points).

This is usually what you want if you do not intend to make special use of the point data (e.g. as particles etc.).

Polygon meshes that contain faces with one vertex only usually do so because of bad topology.

§ignore_lines: bool

Ignore faces containing only two vertices (lines).

This is usually what you want if you do not intend to make special use of the line data (e.g. as wires/ropes etc.).

Polygon meshes that contains faces with two vertices only usually do so because of bad topology.

Implementations§

source§

impl LoadOptions

source

pub fn is_valid(&self) -> bool

Checks if the given LoadOptions do not contain mutually exclusive flag settings.

This is called by load_obj()/load_obj_buf() in any case. This method is only exposed for scenarios where you want to do this check yourself.

Trait Implementations§

source§

impl Clone for LoadOptions

source§

fn clone(&self) -> LoadOptions

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for LoadOptions

source§

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

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

impl Default for LoadOptions

source§

fn default() -> LoadOptions

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

impl Copy for LoadOptions

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.