Linear representations of polygonal meshes.
This module provides types and traits that describe polygonal meshes as
buffers of vertex data and buffers of indices into that vertex data. These
buffers are called the vertex buffer and index buffer, respectively, and
are typically used for indexed drawing. The
MeshBuffer type unifies
vertex and index buffers and maintains their consistency.
Note that only composite vertex buffers are supported, in which each element of a vertex buffer completely describes all attributes of a vertex. Plexus does not support component buffers, in which each attribute of a vertex is stored in a dedicated buffer.
Plexus refers to independent vertex and index buffers as raw buffers. For
Vec of index data is a raw buffer and can be modified without
regard to consistency with any particular vertex buffer. The
FromRawBuffers trait provides a way to construct mesh data structures
from such raw buffers.
Index buffers may contain either flat or structured data. See the
index module for more about these buffers and how they are defined.
Generating a flat
MeshBuffer from a $uv$-sphere:
use decorum::N32; use nalgebra::Point3; use plexus::buffer::MeshBuffer3; use plexus::prelude::*; use plexus::primitive::generate::Position; use plexus::primitive::sphere::UvSphere; let buffer: MeshBuffer3<u32, Point3<f32>> = UvSphere::new(16, 16) .polygons::<Position<Point3<N32>>>() .triangulate() .collect(); let indices = buffer.as_index_slice(); let positions = buffer.as_vertex_slice();
MeshGraph to a structured
use decorum::R64; use nalgebra::Point3; use plexus::buffer::MeshBufferN; use plexus::graph::MeshGraph; use plexus::prelude::*; use plexus::primitive::cube::Cube; use plexus::primitive::generate::Position; type E3 = Point3<R64>; let graph: MeshGraph<E3> = Cube::new().polygons::<Position<E3>>().collect(); let buffer: MeshBufferN<usize, E3> = graph.to_mesh_by_vertex().unwrap();
Polygonal mesh composed of vertex and index buffers.
Errors concerning raw buffers and
Conversion from raw buffers.
Conversion from raw buffers that do not encode their arity.
MeshBuffer that supports polygons with arbitrary arity.