5 个版本 (2 个稳定版)
使用旧的 Rust 2015
1.0.1 | 2021 年 2 月 13 日 |
---|---|
1.0.0 | 2020 年 4 月 6 日 |
0.1.2 | 2017 年 6 月 20 日 |
0.1.1-pre | 2017 年 6 月 20 日 |
0.1.0 | 2017 年 6 月 20 日 |
#46 in 数据格式
21KB
407 代码行
mash
3D 网格操作库。
支持的格式
当将 mash
作为依赖项包含时,默认启用所有格式。
为了选择性地启用支持的格式,请明确设置要启用的功能。
[dependencies]
mash = { version = "1.0", default-features = false, features = ["wavefront"]}
架构
模型首先以特定格式的结构加载到内存中,以允许最大灵活性。您可以在相关的 load/<format>
模块中找到这些类型的文档。
一旦分离出相关的对象/组/三角形,模型就可以转换为独立于格式的表示 - mash::Model
。
基本工作流程如下所示
extern crate mash;
use mash::load;
type Vertex = mash::Vector;
type Index = u32;
type Model = mash::Model<Vertex, Index>;
fn main() {
// Load the shape into a wavefront-specific data structure.
let world = load::wavefront::from_path("res/world.obj").unwrap();
// Rather than converting the entire world into a single model, let's extract
// every object labelled 'door'.
let doors: Vec<Model> = world.objects().filter(|o| o.name().contains("door")).map(|object| {
// Convert each object into its own mesh.
Model::new(object).unwrap()
}).collect();
// We can also load the entire world into a single model if we wanted.
let entire_world = Model::new(world).unwrap();
// Skip every second triangle if that's your kind of thing.
let half_triangles = entire_world.mesh.triangles().enumerate().filter(|&(idx,_)| idx%2 == 0).map(|(_,t)| t);
let half_world: Model = Model { mesh: half_triangles.collect() };
}
依赖项
~2.5–3.5MB
~74K SLoC