#mesh #surface #random #distribution #sample #3d-model

mesh-rand

provides methods of generating random points on the surface of 3d models

1 unstable release

0.1.0 Mar 3, 2023

#2038 in Algorithms

MIT/Apache

10KB
124 lines

mesh-rand

Rust library for generating random points on the surface of a mesh

Example

use mesh_rand::{MeshSurface, SurfSample};
use rand::distributions::Distribution;
// Verticies and faces for a non-regular tetrahedron:
 let verticies = [
    [0.0, 0.0, 0.0],
    [1.0, 0.0, 0.0],
    [0.0, 1.0, 0.0],
    [0.0, 0.0, 1.0],
];
let faces = [[1, 0, 2], [2, 0, 3], [0, 1, 3], [1, 2, 3]];
let mesh_dist = MeshSurface::new(&verticies, &faces)?;
let mut rng = rand::thread_rng();
let SurfSample { position, .. } = mesh_dist.sample(&mut rng);
println!("generated point on mesh at {position:?}");

Future Additions

  • edge/curve distribution
  • Poisson distributed surface points
  • Randomly sample mesh volume

lib.rs:

This crate provides methods of generating random points on the surface of 3d models.

use mesh_rand::{MeshSurface, SurfSample};
use rand::distributions::Distribution;

// Verticies for a non-regular tetrahedron:
let verticies = [
    [0.0, 0.0, 0.0],
    [1.0, 0.0, 0.0],
    [0.0, 1.0, 0.0],
    [0.0, 0.0, 1.0],
];
// Faces, oriented to be pointing outwards:
let faces = [[1, 0, 2], [2, 0, 3], [0, 1, 3], [1, 2, 3]];
let mesh_dist = MeshSurface::new(&verticies, &faces)?;
let mut rng = rand::thread_rng();
let SurfSample { position, .. } = mesh_dist.sample(&mut rng);
println!("generated point on mesh at {position:?}");

Dependencies

~1.3–1.9MB
~39K SLoC