Plexus is a Rust library for generating and manipulating 2D and 3D meshes.
Generation and Iterator Expressions
Streams of topological and 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 into other topologies and
geometric data via triangulation, tesselation, and other operations.
use Point3;
use MeshBuffer;
use *;
use UvSphere;
// Example module in the local crate that provides basic rendering.
use ;
// Construct a buffer of index and vertex data from a sphere primitive.
let buffer = new
.polygons_with_position
.map_vertices
.map_vertices
.map_vertices
.;
draw;
For an example of rendering, see the viewer example.
Half-Edge Graph Meshes
Generators produce an ephemeral stream of topology and vertex geometry. A
Mesh
, represented as a half-edge
graph, supports
arbitrary geometry for vertices, edges, and faces. The graph can also be
traversed and manipulated in ways that generators and iterator expressions
cannot, such as circulation, extrusion, merging, and joining.
use Point3;
use Mesh;
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 mesh = new
.polygons_with_position_from
.;
// Extrude a face in the mesh.
let key = mesh.faces.nth.unwrap.key;
if let Ok = mesh.face_mut.unwrap.extrude
Plexus avoids exposing very basic topological operations like inserting individual vertices, because they can easily be done incorrectly and lead to invalid topologies. Instead, meshes are manipulated with higher-level operations like extrusion and joining.
Geometric Traits
Meshes support arbitrary geometry for vertices, edges, and faces (including no
geometry at all) via optional traits. Implementing these traits enables more
operations and features, but only two basic traits are required: Geometry
and
Attribute
.
use ;
use AsPosition;
use ;
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, splitting, etc. are exposed.
Geometric traits are optionally implemented for types in the
nalgebra and
cgmath crates so that common types can be
used right away for vertex geometry. See the geometry-cgmath
and
geometry-nalgebra
(enabled by default) crate features. Both 2D and 3D
geometry are supported by mesh operations.