12个版本
0.0.11 | 2019年3月1日 |
---|---|
0.0.10 | 2018年8月30日 |
0.0.9 | 2018年1月21日 |
0.0.8 | 2017年11月25日 |
0.0.1 | 2017年8月20日 |
#675 在 数据结构
39 每月下载量
用于 bismuth
405KB
10K SLoC
Plexus 是一个用于2D和3D网格处理的Rust库。
原始数据和迭代器表达式
可以通过迭代器表达式从立方体和球体等原始数据生成几何数据流。原始数据发出拓扑结构如 Triangle
或 Quad
,它们在其顶点中包含任意数据。这些可以通过细分和其他操作进行转换和分解。
use nalgebra::Point3;
use plexus::buffer::MeshBuffer3;
use plexus::prelude::*;
use plexus::primitive::sphere::UvSphere;
// Example module in the local crate that provides basic rendering.
use render::{self, Color, Vertex};
// Construct a linear buffer of index and vertex data from a sphere primitive.
let buffer = UvSphere::new(16, 16)
.polygons_with_position()
.map_vertices(|position| -> Point3<f64> { position.into() })
.map_vertices(|position| Vertex::new(position, Color::white()))
.triangulate()
.collect::<MeshBuffer3<u32, Vertex>>();
render::draw(buffer.as_index_slice(), buffer.as_vertex_slice());
有关渲染的示例,请参阅 viewer示例。
半边图网格
MeshGraph
以半边图的形式表示,支持顶点、弧(半边)、边和面的任意几何形状。图是持久的,并且可以通过迭代器表达式和线性缓冲区无法执行的方式遍历和操作,例如循环、挤压、合并和连接。
use nalgebra::Point3;
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::sphere::{Bounds, UvSphere};
// Construct a mesh from a sphere primitive. The vertex geometry is convertible
// to `Point3` via the `FromGeometry` trait in this example.
let mut graph = UvSphere::new(8, 8)
.polygons_with_position_from(Bounds::unit_width())
.collect::<MeshGraph<Point3<f64>>>();
// Extrude a face in the mesh.
let abc = graph.faces().nth(0).unwrap().key();
if let Ok(face) = graph.face_mut(abc).unwrap().extrude(1.0) {
// ...
}
Plexus避免暴露非常基本的拓扑操作,如插入单个顶点,因为这些操作很容易出错。相反,网格通常使用更高级的操作,如分割和连接来操作。
几何特性
通过可选特性,图支持顶点、弧、边和面(包括没有任何几何形状)的任意几何形状。实现这些特性可以启用几何功能,但只需要一个特性:Geometry
。
use decorum::R64;
use nalgebra::{Point3, Vector3};
use plexus::geometry::convert::AsPosition;
use plexus::geometry::Geometry;
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct VertexGeometry {
pub position: Point3<R64>,
pub normal: Vector3<R64>,
}
impl Geometry for VertexGeometry {
type Vertex = Self;
type Arc = ();
type Edge = ();
type Face = ();
}
impl AsPosition for VertexGeometry {
type Target = Point3<R64>;
fn as_position(&self) -> &Self::Target {
&self.position
}
fn as_position_mut(&mut self) -> &mut Self::Target {
&mut self.position
}
}
几何操作是基于顶点的。通过实现 AsPosition
以从顶点公开位置数据,并为该位置数据实现几何特性,可以公开挤压等操作。
几何特征可选地实现了在 cgmath、mint 和 nalgebra 包中,以便可以使用通用类型进行顶点几何。请参阅 geometry-cgmath
、geometry-mint
和 geometry-nalgebra
包功能。默认情况下,启用了 geometry-nalgebra
功能。网格操作支持 2D 和 3D 几何。
依赖项
~3–4.5MB
~92K SLoC