logo
pub struct MeshBuffer<R, G> where
    R: Grouping
{ /* private fields */ }
Expand description

Polygonal mesh composed of vertex and index buffers.

A MeshBuffer is a linear representation of a polygonal mesh that is composed of two separate but related linear buffers: an index buffer and a vertex buffer. The index buffer contains ordered indices into the data in the vertex buffer and describes the topology of the mesh. The vertex buffer contains arbitrary data that describes each vertex.

MeshBuffer only explicitly respresents vertices via the vertex buffer and surfaces via the index buffer. There is no explicit representation of structures like edges and faces.

The R type parameter specifies the Grouping of the index buffer. See the index module documention for more information.

Implementations

Creates an empty MeshBuffer.

Examples
use plexus::buffer::MeshBuffer;
use plexus::index::Flat3;

let buffer = MeshBuffer::<Flat3<u64>, (f64, f64, f64)>::new();

Converts a MeshBuffer into its index and vertex buffers.

Maps over the vertex data in a MeshBuffer.

Examples

Translating the position data in a buffer:

use decorum::N64;
use nalgebra::{Point3, Vector3};
use plexus::buffer::MeshBuffer3;
use plexus::prelude::*;
use plexus::primitive::generate::Position;
use plexus::primitive::sphere::UvSphere;

let buffer: MeshBuffer3<usize, Point3<f64>> = UvSphere::new(16, 8)
    .polygons::<Position<Point3<N64>>>()
    .triangulate()
    .collect();
// Translate the positions.
let translation = Vector3::<f64>::x() * 2.0;
let buffer = buffer.map_vertices(|position| position + translation);

Gets a slice over the index data.

Gets a slice over the vertex data.

Appends the contents of a flat MeshBuffer into another MeshBuffer. The source buffer is drained.

Errors

Returns an error if an index overflows.

Appends the contents of a structured MeshBuffer into another MeshBuffer. The source buffer is drained.

Errors

Returns an error if an index overflows.

Trait Implementations

Exposes a MeshBuilder that can be used to construct a MeshBuffer incrementally from surfaces and facets.

Note that the facet data for MeshBuffer is always the unit type ().

See the documentation for the builder module.

Examples

Creating a MeshBuffer from a triangle:

use nalgebra::Point2;
use plexus::buffer::MeshBuffer3;
use plexus::builder::Buildable;
use plexus::prelude::*;

let mut builder = MeshBuffer3::<usize, Point2<f64>>::builder();
let buffer = builder
    .surface_with(|builder| {
        let a = builder.insert_vertex((0.0, 0.0))?;
        let b = builder.insert_vertex((1.0, 0.0))?;
        let c = builder.insert_vertex((0.0, 1.0))?;
        builder.facets_with(|builder| builder.insert_facet(&[a, b, c], ()))
    })
    .and_then(|_| builder.build())
    .unwrap();

Vertex data. Read more

Facet data. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts to this type from the input type.

Creates a value from an iterator. Read more

Creates a structured MeshBuffer from raw index and vertex buffers.

Errors

Returns an error if the index data is out of bounds within the vertex buffer.

Examples
use nalgebra::Point3;
use plexus::buffer::MeshBufferN;
use plexus::prelude::*;
use plexus::primitive::generate::Position;
use plexus::primitive::sphere::UvSphere;

type E3 = Point3<f64>;

let sphere = UvSphere::new(8, 8);
let buffer = MeshBufferN::<usize, E3>::from_raw_buffers(
    sphere.indexing_polygons::<Position>(),
    sphere.vertices::<Position<E3>>(),
)
.unwrap();

Creates a flat MeshBuffer from raw index and vertex buffers.

Errors

Returns an error if the index data is out of bounds within the vertex buffer or if the number of indices disagrees with the arity of the index buffer.

Examples
use decorum::R64;
use nalgebra::Point3;
use plexus::buffer::MeshBuffer;
use plexus::geometry::Vector;
use plexus::index::{Flat3, HashIndexer};
use plexus::prelude::*;
use plexus::primitive;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::{Normal, Position};

type E3 = Point3<R64>;
type Vertex = (E3, Vector<E3>); // Position and normal.

let cube = Cube::new();
let (indices, vertices) = primitive::zip_vertices((
    cube.polygons::<Position<E3>>(),
    cube.polygons::<Normal<E3>>()
        .map_vertices(|normal| normal.into_inner()),
))
.triangulate()
.index_vertices::<Flat3, _>(HashIndexer::default());
let buffer = MeshBuffer::<Flat3, Vertex>::from_raw_buffers(indices, vertices).unwrap();

Converts the index buffer of a MeshBuffer from structured data into flat data.

Examples
use nalgebra::Point3;
use plexus::buffer::MeshBuffer;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;
use plexus::primitive::Trigon;

type E3 = Point3<f32>;

let cube = Cube::new();
let buffer = MeshBuffer::<Trigon<usize>, E3>::from_raw_buffers(
    cube.indexing_polygons::<Position>().triangulate(),
    cube.vertices::<Position<E3>>(),
)
.unwrap();
let buffer = buffer.into_flat_index();
for index in buffer.as_index_slice() {
    // ...
}

Converts the index buffer of a MeshBuffer from flat data into structured data.

Examples
use nalgebra::Point3;
use plexus::buffer::MeshBuffer;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;
use plexus::primitive::Tetragon;

type E3 = Point3<f64>;

let cube = Cube::new();
let buffer = MeshBuffer::<Tetragon<usize>, E3>::from_raw_buffers(
    cube.indexing_polygons::<Position>(),
    cube.vertices::<Position<E3>>(),
)
.unwrap();
let buffer = buffer.into_flat_index();
for index in buffer.as_index_slice() {
    // ...
}

Converts a triangular flat MeshBuffer into an iterator of Trigons containing vertex data.

Converts a quadrilateral flat MeshBuffer into an iterator of Tetragons containing vertex data.

Examples

Mapping over the polygons described by a flat buffer:

use decorum::R64;
use nalgebra::Point3;
use plexus::buffer::MeshBuffer;
use plexus::graph::MeshGraph;
use plexus::index::Flat4;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;

type E3 = Point3<R64>;

let buffer: MeshBuffer<Flat4, E3> = Cube::new().polygons::<Position<E3>>().collect();
let graph: MeshGraph<E3> = buffer
    .into_polygons()
    .map_vertices(|position| position * 2.0.into())
    .collect();

Converts a structured MeshBuffer into an iterator of polygons containing vertex data.

Examples

Mapping over the polygons described by a structured buffer:

use decorum::R64;
use nalgebra::Point3;
use plexus::buffer::MeshBuffer;
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::generate::Position;
use plexus::primitive::sphere::UvSphere;
use plexus::primitive::BoundedPolygon;

type E3 = Point3<R64>;

let buffer: MeshBuffer<BoundedPolygon<usize>, E3> =
    UvSphere::new(8, 8).polygons::<Position<E3>>().collect();
let graph: MeshGraph<E3> = buffer
    .into_polygons()
    .map_vertices(|position| position * 2.0.into())
    .triangulate()
    .collect();

Converts the index buffer of a MeshBuffer from flat data into structured data.

Examples
use nalgebra::Point3;
use plexus::buffer::MeshBuffer;
use plexus::index::Flat3;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;

type E3 = Point3<f64>;

let cube = Cube::new();
let buffer = MeshBuffer::<Flat3, E3>::from_raw_buffers(
    cube.indexing_polygons::<Position>()
        .triangulate()
        .vertices(),
    cube.vertices::<Position<E3>>(),
)
.unwrap();
let buffer = buffer.into_structured_index();
for trigon in buffer.as_index_slice() {
    // ...
}

Converts the index buffer of a MeshBuffer from flat data into structured data.

Examples
use nalgebra::Point3;
use plexus::buffer::MeshBuffer4;
use plexus::prelude::*;
use plexus::primitive::cube::Cube;
use plexus::primitive::generate::Position;

type E3 = Point3<f64>;

let cube = Cube::new();
let buffer = MeshBuffer4::<usize, E3>::from_raw_buffers(
    cube.indexing_polygons::<Position>(),
    cube.vertices::<Position<E3>>(),
)
.unwrap();
let buffer = buffer.into_structured_index();
for tetragon in buffer.as_index_slice() {
    // ...
}

Creates a MeshGraph from a flat MeshBuffer. The arity of the polygons in the index buffer must be known and constant.

Errors

Returns an error if a MeshGraph cannot represent the topology in the MeshBuffer.

Examples
use nalgebra::Point2;
use plexus::buffer::MeshBuffer;
use plexus::graph::MeshGraph;
use plexus::index::Flat4;
use plexus::prelude::*;
use std::convert::TryFrom;

type E2 = Point2<f64>;

let buffer = MeshBuffer::<Flat4, E2>::from_raw_buffers(
    vec![0u64, 1, 2, 3],
    vec![(0.0f64, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)],
)
.unwrap();
let mut graph = MeshGraph::<E2>::try_from(buffer).unwrap();

The type returned in the event of a conversion error.

Creates a MeshGraph from a structured MeshBuffer.

Errors

Returns an error if a MeshGraph cannot represent the topology in the MeshBuffer.

Examples
use nalgebra::Point2;
use plexus::buffer::MeshBuffer;
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::Tetragon;
use std::convert::TryFrom;

type E2 = Point2<f64>;

let buffer = MeshBuffer::<Tetragon<u64>, E2>::from_raw_buffers(
    vec![Tetragon::new(0u64, 1, 2, 3)],
    vec![(0.0f64, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)],
)
.unwrap();
let mut graph = MeshGraph::<E2>::try_from(buffer).unwrap();

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

Checks if self is actually part of its subset T (and can be converted to it).

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

The inclusion map: converts self to the equivalent element of its superset.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.