Skip to main content

Positions

Struct Positions 

Source
pub struct Positions<'a>(/* private fields */);
Expand description

Checked borrowed XYZ view, preserving all supplied vertices, including unused ones.

Layout constructors do not scan values. Geometric operations reject non-finite components before changing destinations.

Implementations§

Source§

impl<'a> Positions<'a>

Source

pub const fn from_packed(data: &'a [[f32; 3]]) -> Self

Borrow tightly packed XYZ components without allocation.

Examples found in repository?
examples/meshlets.rs (line 9)
6fn main() -> Result<(), Error> {
7    let positions = [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [1., 1., 0.]];
8    let indices = [0, 1, 2, 2, 1, 3];
9    let view = Positions::from_packed(&positions);
10    let mut workspace = Workspace::default();
11    let built = build_meshlets(
12        &indices,
13        view,
14        MeshletSettings::default(),
15        0.25,
16        &mut workspace,
17    )?;
18    let positions = BoundsPositions::new(view);
19    for m in &built.meshlets {
20        let v = m.vertex_offset as usize;
21        let t = m.triangle_offset as usize;
22        let bounds = compute_meshlet_bounds_with_positions(
23            &built.vertices[v..v + m.vertex_count as usize],
24            &built.triangles[t..t + m.triangle_count as usize * 3],
25            positions,
26            &mut workspace,
27        )?;
28        println!("center {:?}, radius {}", bounds.center, bounds.radius);
29    }
30    Ok(())
31}
More examples
Hide additional examples
examples/lod_chain.rs (line 9)
6fn main() -> Result<(), Error> {
7    let positions = [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [1., 1., 0.]];
8    let indices = [0, 1, 2, 2, 1, 3];
9    let view = Positions::from_packed(&positions);
10    let mut workspace = Workspace::default();
11    let scale = simplify_scale(view)?;
12    let mut current = indices.to_vec();
13    for target_index_count in [6, 3, 0] {
14        let settings = SimplifySettings {
15            target_index_count,
16            target_error: 0.01,
17            options: SimplifyOptions::EMPTY,
18        };
19        let lod = simplify(&current, view, settings, &mut workspace)?;
20        let cached = optimize_vertex_cache(&lod.indices, positions.len(), &mut workspace)?;
21        current = optimize_overdraw(&cached, view, 1.05, &mut workspace)?;
22        println!(
23            "{} indices, absolute error {}",
24            current.len(),
25            lod.error * scale
26        );
27    }
28    Ok(())
29}
Source

pub fn from_interleaved( data: &'a [f32], count: usize, stride: usize, offset: usize, ) -> Result<Self, Error>

Borrow interleaved floats; stride and offset are in f32 elements. The stride must be between 3 and 64 elements.

§Errors

InvalidLayout for an unsupported width, stride, offset or buffer length; SizeOverflow if view size arithmetic overflows.

Source

pub fn from_bytes( data: &'a [u8], count: usize, stride: usize, offset: usize, order: ByteOrder, ) -> Result<Self, Error>

Borrow initialized bytes; stride and offset are in bytes, with an explicit byte order. Stride must be a multiple of four between 12 and 256 bytes.

§Errors

InvalidLayout for an unsupported width, stride, offset or buffer length; SizeOverflow if view size arithmetic overflows.

Source

pub const fn len(self) -> usize

Number of supplied vertices.

Source

pub const fn is_empty(self) -> bool

Whether there are no supplied vertices.

Source

pub fn get(self, index: usize) -> Option<[f32; 3]>

Read XYZ for a vertex, or None if its index is outside this view.

Trait Implementations§

Source§

impl<'a> Clone for Positions<'a>

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<'a> Copy for Positions<'a>

Source§

impl<'a> Debug for Positions<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Positions<'a>

§

impl<'a> RefUnwindSafe for Positions<'a>

§

impl<'a> Send for Positions<'a>

§

impl<'a> Sync for Positions<'a>

§

impl<'a> Unpin for Positions<'a>

§

impl<'a> UnsafeUnpin for Positions<'a>

§

impl<'a> UnwindSafe for Positions<'a>

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> 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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.