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
impl MeshSurface
Sourcepub fn new(verts: &[[f32; 3]], faces: &[[usize; 3]]) -> Result<Self, MError>
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
impl Clone for MeshSurface
Source§fn clone(&self) -> MeshSurface
fn clone(&self) -> MeshSurface
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for MeshSurface
impl Debug for MeshSurface
Source§impl Distribution<SurfSample> for MeshSurface
impl Distribution<SurfSample> for MeshSurface
Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> SurfSample
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>
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
Create an iterator that generates random values of
T
, using rng
as
the source of randomness. Read moreAuto Trait Implementations§
impl Freeze for MeshSurface
impl RefUnwindSafe for MeshSurface
impl Send for MeshSurface
impl Sync for MeshSurface
impl Unpin for MeshSurface
impl UnwindSafe for MeshSurface
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more