Struct MeshSurface

Source
pub struct MeshSurface { /* private fields */ }
Expand description

A distribution for sampling points uniformly on the surface of a 3d model

Samples the surface of a model by first randomly picking a triangle with probability proportional to its area, and then uniformly samples a point within that triangle.

§Example

use mesh_rand::MeshSurface;
use rand::distributions::Distribution;

let verticies = [
    [1.0, 0.0, 0.0],
    [0.0, 1.0, 0.0],
    [0.0, 0.0, 1.0],
    [1.0, 2.0, 0.0],
];
let faces = [[0, 1, 2], [0, 1, 3]];
let mesh_dist = MeshSurface::new(&verticies, &faces)?;
let mut rng = rand::thread_rng();
let sample = mesh_dist.sample(&mut rng);
println!(
    "generated point on mesh at {:?} located on face with index {:?} with normal {:?}",
    sample.position, sample.face_index, sample.normal
);

Implementations§

Source§

impl MeshSurface

Source

pub fn new(verts: &[[f32; 3]], faces: &[[usize; 3]]) -> Result<Self, MError>

Initializes a new mesh surface distribution given verticies and faces (triangles)

§Result

Returns an error if:

  • An index defining a face is out of range of the verticies collection
  • The area of one of the triangles provided is very close to 0 (f32::is_normal(area) == false)
  • The collection of faces is empty

Trait Implementations§

Source§

impl Clone for MeshSurface

Source§

fn clone(&self) -> MeshSurface

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MeshSurface

Source§

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

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

impl Distribution<SurfSample> for MeshSurface

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> SurfSample

Samples the model surface uniformly, returning an instance of the SurfSample struct

Source§

fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more

Auto Trait Implementations§

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> 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 = 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>,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V