# [−][src]Module plexus::buffer

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 example, a 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.

# Examples

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();

Converting a MeshGraph to a structured MeshBuffer:

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();

## Structs

 MeshBuffer Polygonal mesh composed of vertex and index buffers.

## Enums

 BufferError Errors concerning raw buffers and MeshBuffers.

## Traits

 FromRawBuffers Conversion from raw buffers. FromRawBuffersWithArity Conversion from raw buffers that do not encode their arity. IntoFlatIndex IntoStructuredIndex

## Type Definitions

 MeshBuffer3 Triangular MeshBuffer. MeshBuffer4 Quadrilateral MeshBuffer. MeshBufferN MeshBuffer that supports polygons with arbitrary arity.