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

Indexing and aggregation.

This module provides *indexers*, which disambiguate geometry and produce
the minimal set of topological and geometric data. This is primarily used
to index streams of $n$-gons (`NGon`

, `Trigon`

, etc.) into raw buffers or
polygonal mesh data structures like `MeshBuffer`

.

Indexing produces an *index buffer* and *vertex buffer*. The index buffer
describes the topology of a mesh by providing ordered groups of indices
into the vertex buffer. Each group of indices represents a polygon. The
vertex buffer contains geometric data associated with a vertex, such as
positions or surface normals. Plexus supports both *structured* and *flat
index buffers*.

Flat index buffers directly store individual indices, such as `Vec<usize>`

.
Because there is no explicit structure, arity must by constant, but
arbitrarily sized $n$-gons are trivially supported. Flat index buffers tend
to be more useful for rendering pipelines, especially triangular buffers,
because rendering pipelines typically expect a simple contiguous buffer of
index data. See `MeshBuffer3`

and `Flat`

.

Structured index buffers contain sub-structures that explicitly group
indices, such as `Vec<Trigon<usize>>`

. Structured index buffers typically
contain `Trigon`

s, `Tetragon`

s, or `Polygon`

s. Notably, `Polygon`

can
describe the topology of a mesh even if its arity is non-constant.

The primary interface of this module is the `IndexVertices`

and
`CollectWithIndexer`

traits along with the `HashIndexer`

and `LruIndexer`

types.

# Examples

Indexing data for a cube to create raw buffers and a `MeshBuffer`

:

use decorum::N64; use nalgebra::Point3; use plexus::buffer::MeshBuffer3; use plexus::index::{Flat3, HashIndexer}; use plexus::prelude::*; use plexus::primitive::cube::Cube; use plexus::primitive::generate::Position; let (indices, positions) = Cube::new() .polygons::<Position<Point3<N64>>>() .triangulate() .index_vertices::<Flat3, _>(HashIndexer::default()); let buffer = MeshBuffer3::<u32, _>::from_raw_buffers(indices, positions).unwrap();

## Structs

Flat | Flat index buffer meta-grouping. |

HashIndexer | Hashing vertex indexer. |

LruIndexer | LRU caching vertex indexer. |

## Traits

CollectWithIndexer | Functions for collecting a stream of $n$-gons into a mesh data structure. |

FromIndexer | |

GroupedIndexVertices | Functions for collecting a stream of $n$-gons into raw index and vertex buffers. |

Grouping | |

IndexBuffer | Index buffer. |

IndexVertices | Functions for collecting a stream of $n$-gons into raw index and vertex buffers. |

Indexer | Vertex indexer. |

Push |

## Type Definitions

Flat3 | Alias for a flat and triangular index buffer. |

Flat4 | Alias for a flat and quadrilateral index buffer. |