Struct plexus::buffer::MeshBuffer
source · [−]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
sourceimpl<R, G> MeshBuffer<R, G> where
R: Grouping,
Vec<R::Group>: IndexBuffer<R>,
impl<R, G> MeshBuffer<R, G> where
R: Grouping,
Vec<R::Group>: IndexBuffer<R>,
sourceimpl<R, G> MeshBuffer<R, G> where
R: Grouping,
impl<R, G> MeshBuffer<R, G> where
R: Grouping,
sourcepub fn into_raw_buffers(self) -> (Vec<R::Group>, Vec<G>)
pub fn into_raw_buffers(self) -> (Vec<R::Group>, Vec<G>)
Converts a MeshBuffer
into its index and vertex buffers.
sourcepub fn map_vertices<H, F>(self, f: F) -> MeshBuffer<R, H> where
F: FnMut(G) -> H,
pub fn map_vertices<H, F>(self, f: F) -> MeshBuffer<R, H> where
F: FnMut(G) -> H,
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);
sourcepub fn as_index_slice(&self) -> &[R::Group]
pub fn as_index_slice(&self) -> &[R::Group]
Gets a slice over the index data.
sourceimpl<T, G, const N: usize> MeshBuffer<Flat<T, N>, G> where
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + NumCast + Unsigned,
impl<T, G, const N: usize> MeshBuffer<Flat<T, N>, G> where
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + NumCast + Unsigned,
sourcepub fn append<R, H>(
&mut self,
buffer: &mut MeshBuffer<R, H>
) -> Result<(), BufferError> where
G: FromGeometry<H>,
R: Grouping,
R::Group: Into<<Flat<T, N> as Grouping>::Group>,
pub fn append<R, H>(
&mut self,
buffer: &mut MeshBuffer<R, H>
) -> Result<(), BufferError> where
G: FromGeometry<H>,
R: Grouping,
R::Group: Into<<Flat<T, N> as Grouping>::Group>,
Appends the contents of a flat MeshBuffer
into another MeshBuffer
.
The source buffer is drained.
Errors
Returns an error if an index overflows.
sourceimpl<P, G> MeshBuffer<P, G> where
P: Grouping + Polygonal,
P::Vertex: Copy + Integer + NumCast + Unsigned,
impl<P, G> MeshBuffer<P, G> where
P: Grouping + Polygonal,
P::Vertex: Copy + Integer + NumCast + Unsigned,
sourcepub fn append<R, H>(
&mut self,
buffer: &mut MeshBuffer<R, H>
) -> Result<(), BufferError> where
G: FromGeometry<H>,
R: Grouping,
R::Group: Into<<P as Grouping>::Group>,
<P as Grouping>::Group: Map<P::Vertex, Output = <P as Grouping>::Group> + Topological<Vertex = P::Vertex>,
pub fn append<R, H>(
&mut self,
buffer: &mut MeshBuffer<R, H>
) -> Result<(), BufferError> where
G: FromGeometry<H>,
R: Grouping,
R::Group: Into<<P as Grouping>::Group>,
<P as Grouping>::Group: Map<P::Vertex, Output = <P as Grouping>::Group> + Topological<Vertex = P::Vertex>,
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
sourceimpl<R, G> Buildable for MeshBuffer<R, G> where
R: Grouping,
Vec<R::Group>: IndexBuffer<R>,
BufferBuilder<R, G>: MeshBuilder<Error = BufferError, Commit = Self, Vertex = G, Facet = ()>,
impl<R, G> Buildable for MeshBuffer<R, G> where
R: Grouping,
Vec<R::Group>: IndexBuffer<R>,
BufferBuilder<R, G>: MeshBuilder<Error = BufferError, Commit = Self, Vertex = G, Facet = ()>,
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();
sourceimpl<R, G> Default for MeshBuffer<R, G> where
R: Grouping,
Vec<R::Group>: IndexBuffer<R>,
impl<R, G> Default for MeshBuffer<R, G> where
R: Grouping,
Vec<R::Group>: IndexBuffer<R>,
sourceimpl<T, G, const N: usize> DynamicArity for MeshBuffer<Flat<T, N>, G> where
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + Unsigned,
impl<T, G, const N: usize> DynamicArity for MeshBuffer<Flat<T, N>, G> where
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + Unsigned,
sourceimpl<P, G> DynamicArity for MeshBuffer<P, G> where
P: Grouping + Monomorphic + Polygonal,
P::Vertex: Copy + Integer + Unsigned,
impl<P, G> DynamicArity for MeshBuffer<P, G> where
P: Grouping + Monomorphic + Polygonal,
P::Vertex: Copy + Integer + Unsigned,
sourceimpl<N, G> DynamicArity for MeshBuffer<BoundedPolygon<N>, G> where
N: Copy + Integer + Unsigned,
impl<N, G> DynamicArity for MeshBuffer<BoundedPolygon<N>, G> where
N: Copy + Integer + Unsigned,
sourceimpl<N, G> DynamicArity for MeshBuffer<UnboundedPolygon<N>, G> where
N: Copy + Integer + Unsigned,
impl<N, G> DynamicArity for MeshBuffer<UnboundedPolygon<N>, G> where
N: Copy + Integer + Unsigned,
sourceimpl<P, Q, T, R, N, G> From<P> for MeshBuffer<R, G> where
P: IntoIndexed<N, Indexed = Q> + Polygonal,
Q: Clone + Map<G, Output = T> + Map<N, Output = R> + Polygonal<Vertex = (N, P::Vertex)>,
T: Polygonal<Vertex = G>,
R: Grouping<Group = R> + Polygonal<Vertex = N>,
N: Copy + Integer + NumCast + Unsigned,
G: FromGeometry<P::Vertex>,
impl<P, Q, T, R, N, G> From<P> for MeshBuffer<R, G> where
P: IntoIndexed<N, Indexed = Q> + Polygonal,
Q: Clone + Map<G, Output = T> + Map<N, Output = R> + Polygonal<Vertex = (N, P::Vertex)>,
T: Polygonal<Vertex = G>,
R: Grouping<Group = R> + Polygonal<Vertex = N>,
N: Copy + Integer + NumCast + Unsigned,
G: FromGeometry<P::Vertex>,
sourceimpl<E, P, G> FromEncoding<E> for MeshBuffer<P, G> where
E: FaceDecoder<Face = ()> + VertexDecoder,
E::Index: AsRef<[P::Vertex]>,
P: Polygonal<Vertex = usize>,
G: FromGeometry<E::Vertex>,
Self: FromRawBuffers<P, G, Error = BufferError>,
impl<E, P, G> FromEncoding<E> for MeshBuffer<P, G> where
E: FaceDecoder<Face = ()> + VertexDecoder,
E::Index: AsRef<[P::Vertex]>,
P: Polygonal<Vertex = usize>,
G: FromGeometry<E::Vertex>,
Self: FromRawBuffers<P, G, Error = BufferError>,
type Error = <MeshBuffer<P, G> as FromRawBuffers<P, G>>::Error
fn from_encoding(
vertices: <E as VertexDecoder>::Output,
faces: <E as FaceDecoder>::Output
) -> Result<Self, Self::Error>
sourceimpl<R, P, G> FromIndexer<P, P> for MeshBuffer<R, G> where
R: Grouping,
G: FromGeometry<P::Vertex>,
P: Map<<Vec<<R as Grouping>::Group> as IndexBuffer<R>>::Index> + Topological,
P::Output: Topological<Vertex = <Vec<<R as Grouping>::Group> as IndexBuffer<R>>::Index>,
Vec<<R as Grouping>::Group>: Push<R, P::Output>,
<Vec<<R as Grouping>::Group> as IndexBuffer<R>>::Index: NumCast,
Self: FromRawBuffers<R::Group, G>,
impl<R, P, G> FromIndexer<P, P> for MeshBuffer<R, G> where
R: Grouping,
G: FromGeometry<P::Vertex>,
P: Map<<Vec<<R as Grouping>::Group> as IndexBuffer<R>>::Index> + Topological,
P::Output: Topological<Vertex = <Vec<<R as Grouping>::Group> as IndexBuffer<R>>::Index>,
Vec<<R as Grouping>::Group>: Push<R, P::Output>,
<Vec<<R as Grouping>::Group> as IndexBuffer<R>>::Index: NumCast,
Self: FromRawBuffers<R::Group, G>,
type Error = <MeshBuffer<R, G> as FromRawBuffers<<R as Grouping>::Group, G>>::Error
fn from_indexer<I, M>(input: I, indexer: M) -> Result<Self, Self::Error> where
I: IntoIterator<Item = P>,
M: Indexer<P, P::Vertex>,
sourceimpl<R, P, G> FromIterator<P> for MeshBuffer<R, G> where
R: Grouping,
G: FromGeometry<P::Vertex>,
P: Topological,
P::Vertex: Copy + Eq + Hash,
Vec<<R as Grouping>::Group>: IndexBuffer<R>,
Self: FromIndexer<P, P>,
impl<R, P, G> FromIterator<P> for MeshBuffer<R, G> where
R: Grouping,
G: FromGeometry<P::Vertex>,
P: Topological,
P::Vertex: Copy + Eq + Hash,
Vec<<R as Grouping>::Group>: IndexBuffer<R>,
Self: FromIndexer<P, P>,
sourcefn from_iter<I>(input: I) -> Self where
I: IntoIterator<Item = P>,
fn from_iter<I>(input: I) -> Self where
I: IntoIterator<Item = P>,
Creates a value from an iterator. Read more
sourceimpl<P, Q, G, H> FromRawBuffers<Q, H> for MeshBuffer<P, G> where
P: From<Q> + Grouping<Group = P> + Polygonal,
P::Vertex: Copy + Integer + NumCast + Unsigned,
G: FromGeometry<H>,
impl<P, Q, G, H> FromRawBuffers<Q, H> for MeshBuffer<P, G> where
P: From<Q> + Grouping<Group = P> + Polygonal,
P::Vertex: Copy + Integer + NumCast + Unsigned,
G: FromGeometry<H>,
sourcefn from_raw_buffers<I, J>(indices: I, vertices: J) -> Result<Self, BufferError> where
I: IntoIterator<Item = Q>,
J: IntoIterator<Item = H>,
fn from_raw_buffers<I, J>(indices: I, vertices: J) -> Result<Self, BufferError> where
I: IntoIterator<Item = Q>,
J: IntoIterator<Item = H>,
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();
type Error = BufferError
sourceimpl<T, U, G, H, const N: usize> FromRawBuffers<U, H> for MeshBuffer<Flat<T, N>, G> where
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + NumCast + Unsigned,
U: Copy + Integer + NumCast + Unsigned,
G: FromGeometry<H>,
impl<T, U, G, H, const N: usize> FromRawBuffers<U, H> for MeshBuffer<Flat<T, N>, G> where
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + NumCast + Unsigned,
U: Copy + Integer + NumCast + Unsigned,
G: FromGeometry<H>,
sourcefn from_raw_buffers<I, J>(indices: I, vertices: J) -> Result<Self, BufferError> where
I: IntoIterator<Item = U>,
J: IntoIterator<Item = H>,
fn from_raw_buffers<I, J>(indices: I, vertices: J) -> Result<Self, BufferError> where
I: IntoIterator<Item = U>,
J: IntoIterator<Item = H>,
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();
type Error = BufferError
sourceimpl<N, G> IntoFlatIndex<G, 3_usize> for MeshBuffer<Trigon<N>, G> where
N: Copy + Integer + Unsigned,
impl<N, G> IntoFlatIndex<G, 3_usize> for MeshBuffer<Trigon<N>, G> where
N: Copy + Integer + Unsigned,
sourcefn into_flat_index(self) -> MeshBuffer<Flat<Self::Item, 3>, G>
fn into_flat_index(self) -> MeshBuffer<Flat<Self::Item, 3>, G>
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() {
// ...
}
type Item = N
sourceimpl<N, G> IntoFlatIndex<G, 4_usize> for MeshBuffer<Tetragon<N>, G> where
N: Copy + Integer + Unsigned,
impl<N, G> IntoFlatIndex<G, 4_usize> for MeshBuffer<Tetragon<N>, G> where
N: Copy + Integer + Unsigned,
sourcefn into_flat_index(self) -> MeshBuffer<Flat<Self::Item, 4>, G>
fn into_flat_index(self) -> MeshBuffer<Flat<Self::Item, 4>, G>
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() {
// ...
}
type Item = N
sourceimpl<T, G, const N: usize> IntoFlatIndex<G, N> for MeshBuffer<Flat<T, N>, G> where
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + Unsigned,
impl<T, G, const N: usize> IntoFlatIndex<G, N> for MeshBuffer<Flat<T, N>, G> where
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + Unsigned,
type Item = T
fn into_flat_index(self) -> MeshBuffer<Flat<Self::Item, N>, G>
sourceimpl<N, G> IntoPolygons for MeshBuffer<Flat3<N>, G> where
N: Copy + Integer + NumCast + Unsigned,
G: Clone,
Trigon<N>: Grouping<Group = Trigon<N>>,
impl<N, G> IntoPolygons for MeshBuffer<Flat3<N>, G> where
N: Copy + Integer + NumCast + Unsigned,
G: Clone,
Trigon<N>: Grouping<Group = Trigon<N>>,
sourcefn into_polygons(self) -> Self::Output
fn into_polygons(self) -> Self::Output
Converts a triangular flat MeshBuffer
into an iterator of Trigon
s
containing vertex data.
type Output = IntoIter<<MeshBuffer<Flat<N, 3_usize>, G> as IntoPolygons>::Polygon, Global>
type Polygon = NGon<G, 3_usize>
sourceimpl<N, G> IntoPolygons for MeshBuffer<Flat4<N>, G> where
N: Copy + Integer + NumCast + Unsigned,
G: Clone,
Trigon<N>: Grouping<Group = Trigon<N>>,
impl<N, G> IntoPolygons for MeshBuffer<Flat4<N>, G> where
N: Copy + Integer + NumCast + Unsigned,
G: Clone,
Trigon<N>: Grouping<Group = Trigon<N>>,
sourcefn into_polygons(self) -> Self::Output
fn into_polygons(self) -> Self::Output
Converts a quadrilateral flat MeshBuffer
into an iterator of
Tetragon
s 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();
type Output = IntoIter<<MeshBuffer<Flat<N, 4_usize>, G> as IntoPolygons>::Polygon, Global>
type Polygon = NGon<G, 4_usize>
sourceimpl<P, G> IntoPolygons for MeshBuffer<P, G> where
P: Grouping + Polygonal,
P::Group: Map<G> + Polygonal,
<P::Group as Map<G>>::Output: Polygonal<Vertex = G>,
<P::Group as Topological>::Vertex: NumCast,
P::Vertex: Copy + Integer + NumCast + Unsigned,
G: Clone,
impl<P, G> IntoPolygons for MeshBuffer<P, G> where
P: Grouping + Polygonal,
P::Group: Map<G> + Polygonal,
<P::Group as Map<G>>::Output: Polygonal<Vertex = G>,
<P::Group as Topological>::Vertex: NumCast,
P::Vertex: Copy + Integer + NumCast + Unsigned,
G: Clone,
sourcefn into_polygons(self) -> Self::Output
fn into_polygons(self) -> Self::Output
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();
type Output = IntoIter<<MeshBuffer<P, G> as IntoPolygons>::Polygon, Global>
type Polygon = <<P as Grouping>::Group as Map<G>>::Output
sourceimpl<P, G> IntoStructuredIndex<G> for MeshBuffer<P, G> where
P: Grouping + Polygonal,
P::Vertex: Copy + Integer + Unsigned,
impl<P, G> IntoStructuredIndex<G> for MeshBuffer<P, G> where
P: Grouping + Polygonal,
P::Vertex: Copy + Integer + Unsigned,
type Item = P
fn into_structured_index(self) -> MeshBuffer<Self::Item, G>
sourceimpl<N, G> IntoStructuredIndex<G> for MeshBuffer<Flat3<N>, G> where
N: Copy + Integer + Unsigned,
Trigon<N>: Grouping<Group = Trigon<N>>,
impl<N, G> IntoStructuredIndex<G> for MeshBuffer<Flat3<N>, G> where
N: Copy + Integer + Unsigned,
Trigon<N>: Grouping<Group = Trigon<N>>,
sourcefn into_structured_index(self) -> MeshBuffer<Self::Item, G>
fn into_structured_index(self) -> MeshBuffer<Self::Item, G>
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() {
// ...
}
type Item = NGon<N, 3_usize>
sourceimpl<N, G> IntoStructuredIndex<G> for MeshBuffer<Flat4<N>, G> where
N: Copy + Integer + Unsigned,
Tetragon<N>: Grouping<Group = Tetragon<N>>,
impl<N, G> IntoStructuredIndex<G> for MeshBuffer<Flat4<N>, G> where
N: Copy + Integer + Unsigned,
Tetragon<N>: Grouping<Group = Tetragon<N>>,
sourcefn into_structured_index(self) -> MeshBuffer<Self::Item, G>
fn into_structured_index(self) -> MeshBuffer<Self::Item, G>
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() {
// ...
}
type Item = NGon<N, 4_usize>
sourceimpl<R, G> StaticArity for MeshBuffer<R, G> where
R: Grouping,
impl<R, G> StaticArity for MeshBuffer<R, G> where
R: Grouping,
sourceimpl<T, H, G, const A: usize> TryFrom<MeshBuffer<Flat<T, A>, H>> for MeshGraph<G> where
Constant<A>: ToType,
TypeOf<A>: NonZero,
T: Copy + Integer + NumCast + Unsigned,
H: Clone,
G: GraphData,
G::Vertex: FromGeometry<H>,
impl<T, H, G, const A: usize> TryFrom<MeshBuffer<Flat<T, A>, H>> for MeshGraph<G> where
Constant<A>: ToType,
TypeOf<A>: NonZero,
T: Copy + Integer + NumCast + Unsigned,
H: Clone,
G: GraphData,
G::Vertex: FromGeometry<H>,
sourcefn try_from(buffer: MeshBuffer<Flat<T, A>, H>) -> Result<Self, Self::Error>
fn try_from(buffer: MeshBuffer<Flat<T, A>, H>) -> Result<Self, Self::Error>
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();
type Error = GraphError
type Error = GraphError
The type returned in the event of a conversion error.
sourceimpl<P, H, G> TryFrom<MeshBuffer<P, H>> for MeshGraph<G> where
P: Grouping<Group = P> + IntoVertices + Polygonal,
P::Vertex: Copy + Integer + NumCast + Unsigned,
H: Clone,
G: GraphData,
G::Vertex: FromGeometry<H>,
impl<P, H, G> TryFrom<MeshBuffer<P, H>> for MeshGraph<G> where
P: Grouping<Group = P> + IntoVertices + Polygonal,
P::Vertex: Copy + Integer + NumCast + Unsigned,
H: Clone,
G: GraphData,
G::Vertex: FromGeometry<H>,
sourcefn try_from(buffer: MeshBuffer<P, H>) -> Result<Self, Self::Error>
fn try_from(buffer: MeshBuffer<P, H>) -> Result<Self, Self::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();
type Error = GraphError
type Error = GraphError
The type returned in the event of a conversion error.
impl<R, G> Monomorphic for MeshBuffer<R, G> where
R: Grouping + Monomorphic,
Auto Trait Implementations
impl<R, G> RefUnwindSafe for MeshBuffer<R, G> where
G: RefUnwindSafe,
<R as Grouping>::Group: RefUnwindSafe,
impl<R, G> Send for MeshBuffer<R, G> where
G: Send,
<R as Grouping>::Group: Send,
impl<R, G> Sync for MeshBuffer<R, G> where
G: Sync,
<R as Grouping>::Group: Sync,
impl<R, G> Unpin for MeshBuffer<R, G> where
G: Unpin,
<R as Grouping>::Group: Unpin,
impl<R, G> UnwindSafe for MeshBuffer<R, G> where
G: UnwindSafe,
<R as Grouping>::Group: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> FromGeometry<T> for T
impl<T> FromGeometry<T> for T
fn from_geometry(other: T) -> T
sourceimpl<T, E> FromPly<E> for T where
T: FromEncoding<E>,
E: FaceElementDecoder + FacePropertyDecoder + VertexPropertyDecoder + VertexElementDecoder,
impl<T, E> FromPly<E> for T where
T: FromEncoding<E>,
E: FaceElementDecoder + FacePropertyDecoder + VertexPropertyDecoder + VertexElementDecoder,
sourceimpl<T, U> IntoGeometry<U> for T where
U: FromGeometry<T>,
impl<T, U> IntoGeometry<U> for T where
U: FromGeometry<T>,
fn into_geometry(self) -> U
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.