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

mesh-rand

提供在3D模型表面生成随机点的功能

1 个不稳定版本

0.1.0 2023年3月3日

#2114算法

MIT/Apache

10KB
124

mesh-rand

用于在网格表面生成随机点的Rust库

示例

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:?}");

未来添加功能

  • 边缘/曲线分布
  • 泊松分布表面点
  • 随机采样网格体积

lib.rs:

此crate提供在3D模型表面生成随机点的方法。

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:?}");

依赖项

~1.3–1.9MB
~39K SLoC