Skip to main content

Keep

Struct Keep 

Source
#[non_exhaustive]
pub struct Keep {
Show 13 fields pub animations: bool, pub skins: bool, pub morph_targets: bool, pub materials: bool, pub textures: bool, pub image_bytes: bool, pub cameras: bool, pub lights: bool, pub extras: bool, pub max_triangles: usize, pub lines_and_points: bool, pub max_points: usize, pub threads: usize, /* private fields */
}
Expand description

Which parts of a model a load keeps. Meshes and the node hierarchy are always kept; each switch here drops one kind of data on top of that. Keep::default keeps everything. Keep::max_triangles caps how big a model a load takes at all, and Keep::max_points how many points and lines Document::flatten draws.

Readers skip reading what isn’t kept, so a narrow Keep also makes a load faster: no texture files, embedded images or (without materials) material libraries and shaders are read, nor animations, skins, morph targets, cameras or lights where the format keeps them apart. What a reader did read and Document::prune then dropped leaves its buffer views and accessors behind, unreferenced.

Without textures, a material’s factors are its own: a reader that would have found a color texture doesn’t turn the base color white for it.

A Keep is built from Keep::ALL (or Keep::MESHES, Keep::LIGHT) with a with_ setter for each switch, which chain and work in consts:

use polysmelt::Keep;
// Static meshes for an engine that animates nothing, but still skins them.
let keep = Keep::ALL.with_animations(false);
// A 100-million-triangle scan, past the default limit.
let keep = Keep::ALL.with_max_triangles(120_000_000);
// A 40-million-point lidar scan, drawn as points, read on every core.
const SCAN: Keep = Keep::ALL.with_max_points(40_000_000).with_threads(0);
// Only the surfaces: no points or lines in the flattened mesh.
let keep = Keep::ALL.with_lines_and_points(false);

New switches may come in later versions, each keeping by default what it switches, so a Keep can’t be written out field by field.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§animations: bool

Animations.

§skins: bool

Skins: skeletons, their inverse bind matrices, and the joints and weights on vertices. The joint nodes stay either way, as part of the hierarchy.

§morph_targets: bool

Morph targets and their weights (and animation channels that set them).

§materials: bool

Materials; without them every primitive takes the default material, and textures go too.

§textures: bool

Textures, their images and samplers, and where materials use them.

§image_bytes: bool

The images’ bytes. Without them, kept textures’ images are found but not read or converted: each is a glTF image with a uri, and Document::images has a handle on it that says where it is (its file, if it’s in one) and reads it on request. Document::embed_images reads them all. Document::prune leaves images as they are: once read, they stay read. Images a reader must look into to make a texture (an OBJ’s roughness and metalness maps packed into one) are read all the same, so the textures match.

§cameras: bool

Cameras.

§lights: bool

Lights (KHR_lights_punctual).

§extras: bool

extras everywhere: custom properties and each format’s own details. What the file says about itself in the keys SourceInfo reads (units, up axis, author…) stays in asset.extras.source, and the document’s facts stay, either way.

§max_triangles: usize

The most triangles a load accepts, against hostile or runaway files: a model that draws more is refused (and Document::flatten refuses to draw more). Defaults to MAX_TRIANGLES; raise it for big scans. Values past TRIANGLE_CEILING are clamped to it.

§lines_and_points: bool

Points and lines (glTF’s POINTS, LINES, LINE_LOOP and LINE_STRIP primitives) in what Document::flatten draws: point clouds, wireframes, curves. Without them it draws only triangles, and a model of points and lines alone flattens to nothing. The document keeps them either way.

§max_points: usize

The most points and line segments Document::flatten draws, against huge point clouds: a model that draws more is refused (unless Keep::lines_and_points leaves them out). Counted apart from triangles. Defaults to MAX_POINTS; raise it for big scans. Values past TRIANGLE_CEILING are clamped to it.

§threads: usize

Threads a reader may split its work over, where it can: OBJ text and SPZ, so far. 1, the default, reads on the calling thread; 0 takes one per core. The model read is the same either way. Where threads can’t be had (WebAssembly without shared memory, or a platform that refuses to start one), it reads on the calling thread.

Implementations§

Source§

impl Keep

Source

pub const ALL: Keep

Everything.

Source

pub const MESHES: Keep

The meshes and what shapes or shades them (skins, morph targets, materials, textures, extras), without animations, cameras or lights.

Source

pub const LIGHT: Keep

Keep::MESHES without reading the images: textures stay, as references to their images (see Keep::image_bytes).

Source

pub const fn with_animations(self, animations: bool) -> Self

With Keep::animations set to animations.

Source

pub const fn with_skins(self, skins: bool) -> Self

With Keep::skins set to skins.

Source

pub const fn with_morph_targets(self, morph_targets: bool) -> Self

With Keep::morph_targets set to morph_targets.

Source

pub const fn with_materials(self, materials: bool) -> Self

With Keep::materials set to materials.

Source

pub const fn with_textures(self, textures: bool) -> Self

With Keep::textures set to textures.

Source

pub const fn with_image_bytes(self, image_bytes: bool) -> Self

With Keep::image_bytes set to image_bytes.

Source

pub const fn with_cameras(self, cameras: bool) -> Self

With Keep::cameras set to cameras.

Source

pub const fn with_lights(self, lights: bool) -> Self

With Keep::lights set to lights.

Source

pub const fn with_extras(self, extras: bool) -> Self

With Keep::extras set to extras.

Source

pub const fn with_max_triangles(self, max_triangles: usize) -> Self

With Keep::max_triangles set to max_triangles.

Source

pub const fn with_lines_and_points(self, lines_and_points: bool) -> Self

With Keep::lines_and_points set to lines_and_points.

Source

pub const fn with_max_points(self, max_points: usize) -> Self

With Keep::max_points set to max_points.

Source

pub const fn with_threads(self, threads: usize) -> Self

With Keep::threads set to threads.

Source

pub const fn with_crease_angle(self, degrees: f32) -> Self

With Keep::crease_angle set to degrees: from 0 to 180, and anything past either end is that end. A value that isn’t a number leaves the default, 30.

use polysmelt::Keep;
// Every face flat, as a file without normals is drawn where nothing smooths it.
const FACETED: Keep = Keep::ALL.with_crease_angle(0.0);
// Smooth across every shared vertex, whatever the edge.
let smooth = Keep::ALL.with_crease_angle(180.0);
assert_eq!((FACETED.crease_angle(), smooth.crease_angle()), (0.0, 180.0));
assert_eq!(Keep::ALL.crease_angle(), 30.0);
Source

pub const fn crease_angle(&self) -> f32

The crease angle, in degrees, of the normals a reader makes for a file that has none and says nothing of its own about smoothing: two faces that meet at a vertex share a normal there when they turn less than this from each other, and the vertex is split where they turn more. 30 by default, so a box keeps its hard edges and a finely cut curved surface is smooth; 0 makes every face flat, with normals of its own, and 180 smooths across every vertex the file’s faces share.

A file’s own normals and smoothing data always win: this is only for what has neither (an STL, a 3MF, an OBJ with no vn and no s). A glTF file is read as it is, without normals if it has none. Set with Keep::with_crease_angle.

Trait Implementations§

Source§

impl Clone for Keep

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Keep

Source§

impl Debug for Keep

Source§

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

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

impl Default for Keep

Source§

fn default() -> Self

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

impl Eq for Keep

Source§

impl Hash for Keep

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Keep

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Keep

Auto Trait Implementations§

§

impl Forget for Keep

§

impl Freeze for Keep

§

impl Move for Keep

§

impl RefUnwindSafe for Keep

§

impl Send for Keep

§

impl Sync for Keep

§

impl Unpin for Keep

§

impl UnsafeUnpin for Keep

§

impl UnwindSafe for Keep

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.