plexus 0.0.2

3D mesh generation and manipulation.
Documentation

Plexus

Plexus is a Rust library for generating and manipulating 3D meshes.

Build Status Documentation Crate

Generation and Iterator Expressions

Meshes can be generated from primitives like cubes and spheres using iterator expressions. Primitives emit topological structures like Triangles or Quads, which contain arbitrary geometric data in their vertices. These can be transformed and decomposed into other topologies and geometric data via triangulation, tesselation, and conversion into rendering pipeline data.

use plexus::buffer::conjoint::ConjointBuffer;
use plexus::generate::{sphere, HashConjugate};
use plexus::generate::prelude::*; // Common generator traits.

// Example module in the local crate that provides rendering.
use render::{self, Vertex};

// Construct a buffer of index and vertex data from a sphere primitive.
// `HashConjugate` is used to convert vertex geometry into a conjugate type
// that supports `Hash` via the `into_hash` function. That type is convertible
// to `Vertex` via the `From` trait in this example.
let buffer = sphere::UVSphere::<f32>::with_unit_radius(16, 16)
    .polygons_with_position()
    .map_vertices(|(x, y, z)| (x * 10.0, y * 10.0, z * 10.0))
    .map_vertices(|vertex| vertex.into_hash())
    .collect::<ConjointBuffer<u64, Vertex>>();
render::draw(buffer.as_index_slice(), buffer.as_vertex_slice());

Half-Edge Graph Meshes

Generators are flexible and easy to use, but only represent vertex geometry and are difficult to query and manipulate once complete. A Mesh, represented as a half-edge graph, supports arbitrary geometry for vertices, edges, and faces. The graph can also be queried and manipulated in ways that generators and iterator expressions cannot.

use nalgebra::Point3;
use plexus::r32;
use plexus::generate::{sphere, HashConjugate};
use plexus::generate::prelude::*;
use plexus::graph::{FaceKey, IntoGeometry, Mesh};

// Construct a mesh from a sphere primitive. Note that the `(r32, r32, r32)`
// geometry is convertible to `Point3<f32>` via the `FromGeometry` trait in
// this example.
let mesh: Mesh<Point3<f32>> = sphere::UVSphere::<f32>::with_unit_radius(3, 2)
    .polygons_with_position()
    .map_vertices(|vertex| vertex.into_hash())
    .collect::<Mesh<(r32, r32, r32)>>()
    .into_geometry();
// Extrude a face in the mesh.
let face = mesh.face_mut(FaceKey::default()).unwrap();
let face = face.extrude(1.0).unwrap();