Plexus is a Rust library for 2D and 3D mesh processing.
Primitives and Iterator Expressions
Streams of geometric data can be generated from primitives like cubes and
spheres using iterator expressions. Primitives emit topological structures like
Triangle
s or Quad
s, which contain arbitrary data in their vertices. These
can be transformed and decomposed via tessellation and other operations.
use Point3;
use MeshBuffer3;
use *;
use UvSphere;
// Example module in the local crate that provides basic rendering.
use ;
// Construct a linear buffer of index and vertex data from a sphere primitive.
let buffer = new
.polygons_with_position
.map_vertices
.map_vertices
.triangulate
.;
draw;
For an example of rendering, see the viewer example.
Half-Edge Graph Meshes
MeshGraph
, represented as a half-edge
graph, supports
arbitrary geometry for vertices, arcs (half-edges), edges, and faces. Graphs
are persistent and can be traversed and manipulated in ways that iterator
expressions and linear buffers cannot, such as circulation, extrusion, merging,
and joining.
use Point3;
use MeshGraph;
use *;
use ;
// Construct a mesh from a sphere primitive. The vertex geometry is convertible
// to `Point3` via the `FromGeometry` trait in this example.
let mut graph = new
.polygons_with_position_from
.;
// Extrude a face in the mesh.
let abc = graph.faces.nth.unwrap.key;
if let Ok = graph.face_mut.unwrap.extrude
Plexus avoids exposing very basic topological operations like inserting individual vertices, because they can easily be done incorrectly. Instead, meshes are typically manipulated with higher-level operations like splitting and joining.
Geometric Traits
Graphs support arbitrary geometry for vertices, arcs, edges, and faces
(including no geometry at all) via optional traits. Implementing these traits
enables geometric features, but only one trait is required: Geometry
.
use R64;
use ;
use AsPosition;
use Geometry;
Geometric operations are vertex-based. By implementing AsPosition
to expose
positional data from vertices and implementing geometric traits for that
positional data, operations like extrusion are exposed.
Geometric traits are optionally implemented for types in the
cgmath,
mint, and
nalgebra crates so that common types can be
used out-of-the-box for vertex geometry. See the geometry-cgmath
,
geometry-mint
, and geometry-nalgebra
crate features. By default, the
geometry-nalgebra
feature is enabled. Both 2D and 3D geometry are supported
by mesh operations.