[][src]Trait plexus::primitive::index::IndexVertices

pub trait IndexVertices<P>: Sized where
    P: Map<usize> + Topological
{ fn index_vertices_with<N, K, F>(
        self,
        indexer: N,
        f: F
    ) -> (Vec<<P as Map<usize>>::Output>, Vec<P::Vertex>)
    where
        N: Indexer<P, K>,
        F: Fn(&P::Vertex) -> &K
; fn index_vertices<N>(
        self,
        indexer: N
    ) -> (Vec<<P as Map<usize>>::Output>, Vec<P::Vertex>)
    where
        N: Indexer<P, P::Vertex>
, { ... } }

Functions for collecting a topology stream into raw index and vertex buffers.

Produces structured index buffers with arbitrary arity. The buffers may contain Triangles, Quads, Polygons, etc. For flat buffers with constant arity, see FlatIndexVertices.

See HashIndexer and LruIndexer.

Examples

Note that using an indexer is not always the most effecient method to create buffers or meshes from a topology stream. Primitives provide per-attribute indeces that may be less expensive to generate than using an indexer. For iterator expressions operating on a single attribute (position, normal, etc.), this can be more effecient.

use plexus::prelude::*;
use plexus::primitive::index::HashIndexer;
use plexus::primitive::sphere::UvSphere;

// Detailed UV-sphere.
let sphere = UvSphere::new(64, 32);

// Using a positional index is more efficient.
let (indices, positions) = (
    sphere
        .indices_for_position()
        .triangulate()
        .collect::<Vec<_>>(),
    sphere.vertices_with_position().collect::<Vec<_>>(),
);

// Using an indexer is less efficient.
let (indices, positions) = sphere
    .polygons_with_position()
    .triangulate()
    .index_vertices(HashIndexer::default());

Required methods

fn index_vertices_with<N, K, F>(
    self,
    indexer: N,
    f: F
) -> (Vec<<P as Map<usize>>::Output>, Vec<P::Vertex>) where
    N: Indexer<P, K>,
    F: Fn(&P::Vertex) -> &K, 

Indexes a topology stream into a structured index buffer and vertex buffer using the given indexer and keying function.

Loading content...

Provided methods

fn index_vertices<N>(
    self,
    indexer: N
) -> (Vec<<P as Map<usize>>::Output>, Vec<P::Vertex>) where
    N: Indexer<P, P::Vertex>, 

Indexes a topology stream into a structured index buffer and vertex buffer using the given indexer.

Examples

use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::index::HashIndexer;

// `indices` contains `Triangle`s with index data.
let (indices, positions) = Cube::new()
    .polygons_with_position()
    .subdivide()
    .triangulate()
    .index_vertices(HashIndexer::default());
Loading content...

Implementors

impl<P, I> IndexVertices<P> for I where
    I: Iterator<Item = P>,
    P: Map<usize> + Topological
[src]

fn index_vertices<N>(
    self,
    indexer: N
) -> (Vec<<P as Map<usize>>::Output>, Vec<P::Vertex>) where
    N: Indexer<P, P::Vertex>, 
[src]

Loading content...