[−][src]Module plexus::buffer
Linear representation of meshes.
This module provides a MeshBuffer
that can be read by graphics pipelines
to render meshes. MeshBuffer
combines an index buffer and vertex buffer,
which are exposed as slices.
Vertex Buffers
Vertex buffers describe the geometry of a MeshBuffer
.
MeshBuffer
s use composite vertex buffers (as opposed to component
buffers). Each index in the buffer refers to a datum in the vertex buffer
that completely describes that vertex. For example, if each vertex is
described by a position and color attribute, then each element in the
vertex buffer contains both attributes within a single structure.
Index Buffers
Index buffers describe the topology of a MeshBuffer
. Both structured
(polygonal) and unstructured (flat) index buffers are supported. See
Flat
and Structured
.
Structured index buffers store indices as Triangle
s, Quad
s, or
Polygon
s, all of which preserve the topology of a mesh even if its arity
is non-constant. These types only support triangles and quads; higher arity
N-gons are not supported.
Flat index buffers store individual indices. Because there is no structure, arity must by constant, but arbitrary N-gons are supported. Flat buffers tend to be more useful for rendering, especially triangular flat buffers.
The MeshBuffer3
and MeshBufferN
type aliases avoid verbose type
parameters and provide the most common index buffer configurations.
Examples
Generating a flat MeshBuffer
from a primitive:
use nalgebra::Point3; use plexus::buffer::MeshBuffer3; use plexus::prelude::*; use plexus::primitive::sphere::UvSphere; let buffer = UvSphere::new(16, 16) .polygons_with_position() .triangulate() .collect::<MeshBuffer3<u32, Point3<f32>>>(); let indices = buffer.as_index_slice(); let positions = buffer.as_vertex_slice();
Converting a MeshGraph
to a flat MeshBuffer
:
use nalgebra::Point3; use plexus::buffer::U4; use plexus::graph::MeshGraph; use plexus::prelude::*; use plexus::primitive::cube::Cube; let graph = Cube::new() .polygons_with_position() .collect::<MeshGraph<Point3<f32>>>(); let buffer = graph .to_mesh_buffer_by_vertex::<U4, u32, Point3<f32>>() .unwrap();
Structs
Flat | Flat index buffer. |
MeshBuffer | Linear representation of a mesh. |
Structured | Structured index buffer. |
Enums
BufferError |
Traits
IndexBuffer | Index buffer. |
IntoFlatIndex | |
IntoStructuredIndex |
Type Definitions
Flat3 | Alias for a flat and triangular index buffer. |
Flat4 | Alias for a flat and quadrilateral index buffer. |
MeshBuffer3 | Alias for a flat and triangular |
MeshBuffer4 | Alias for a flat and quadrilateral |
MeshBufferN | Alias for a structured and polygonal |
Structured3 | Alias for a structured and triangular index buffer. |
Structured4 | Alias for a structured and quadrilateral index buffer. |
StructuredN | Alias for a structured and polygonal (variable arity) index buffer. |
U3 | |
U4 |