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 const
s for the most common cases:
-
GPU_LOAD_OPTIONS
– if you display meshes on the GPU/in realtime. -
OFFLINE_RENDERING_LOAD_OPTIONS
– if you’re rendering meshes with e.g. an offline path tracer or the like.
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 aInvalidLoadOptionConfig
error if both are set totrue
. -
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 anInvalidLoadOptionConfig
error if both are set totrue
. -
The resulting
Mesh
’snormal_indices
and/ortexcoord_indices
will be empty. -
Per-vertex normals and/or texture_coordinates will be reordered to match the
Mesh
’sindices
. -
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
andreorder_data
resp. and will lead to aInvalidLoadOptionConfig
error if both it and either of the two other are set totrue
. -
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
’snormal_indices
andtexcoord_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
orignore_lines
is/are set totrue
, resp. -
The resulting
Mesh
’sface_arities
will be empty as all faces are guranteed to have arity3
. -
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
impl LoadOptions
sourcepub fn is_valid(&self) -> bool
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
impl Clone for LoadOptions
source§fn clone(&self) -> LoadOptions
fn clone(&self) -> LoadOptions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more