Struct truck_meshalgo::rexport_polymesh::PolygonMesh
source · pub struct PolygonMesh<V = StandardVertex, A = StandardAttributes> { /* private fields */ }
Expand description
Polygon mesh
The polygon data is held in a method compliant with wavefront obj. Position, uv (texture) coordinates, and normal vectors are held in separate arrays, and each face vertex accesses those values by an indices triple.
Implementations§
source§impl<V, A> PolygonMesh<V, A>where
V: Copy + Hash + Debug + Eq,
A: Attributes<V>,
impl<V, A> PolygonMesh<V, A>where
V: Copy + Hash + Debug + Eq,
A: Attributes<V>,
sourcepub fn expands<T>(
&self,
contraction: impl Fn(<A as Attributes<V>>::Output) -> T
) -> PolygonMesh<usize, Vec<T, Global>>where
T: Copy,
pub fn expands<T>(
&self,
contraction: impl Fn(<A as Attributes<V>>::Output) -> T
) -> PolygonMesh<usize, Vec<T, Global>>where
T: Copy,
Contract attributes and expand polygon.
Examples
use truck_polymesh::*;
let polygon = PolygonMesh::new(
StandardAttributes {
positions: vec![
Point3::new(0.0, 0.0, 0.0),
Point3::new(1.0, 0.0, 0.0),
Point3::new(0.0, 1.0, 0.0),
Point3::new(1.0, 1.0, 0.0),
],
normals: vec![
Vector3::new(0.0, 0.0, 1.0),
Vector3::new(0.0, 0.0, -1.0),
],
..Default::default()
},
Faces::from_iter(&[
&[(0, None, Some(0)), (1, None, Some(0)), (2, None, Some(0))],
&[(3, None, Some(1)), (1, None, Some(1)), (2, None, Some(1))],
])
);
let expands = polygon.expands(|attr| (attr.position, attr.normal.unwrap()));
assert_eq!(
expands,
PolygonMesh::<usize, Vec<(Point3, Vector3)>>::new(
vec![
(Point3::new(0.0, 0.0, 0.0), Vector3::new(0.0, 0.0, 1.0)),
(Point3::new(1.0, 0.0, 0.0), Vector3::new(0.0, 0.0, 1.0)),
(Point3::new(0.0, 1.0, 0.0), Vector3::new(0.0, 0.0, 1.0)),
(Point3::new(1.0, 1.0, 0.0), Vector3::new(0.0, 0.0, -1.0)),
(Point3::new(1.0, 0.0, 0.0), Vector3::new(0.0, 0.0, -1.0)),
(Point3::new(0.0, 1.0, 0.0), Vector3::new(0.0, 0.0, -1.0)),
],
Faces::from_iter(&[[0, 1, 2], [3, 4, 5]]),
)
);
source§impl<V, A> PolygonMesh<V, A>where
V: Copy + Debug,
A: Attributes<V>,
impl<V, A> PolygonMesh<V, A>where
V: Copy + Debug,
A: Attributes<V>,
sourcepub fn new(attributes: A, faces: Faces<V>) -> PolygonMesh<V, A>
pub fn new(attributes: A, faces: Faces<V>) -> PolygonMesh<V, A>
sourcepub fn try_new(
attributes: A,
faces: Faces<V>
) -> Result<PolygonMesh<V, A>, Error<V>>
pub fn try_new(
attributes: A,
faces: Faces<V>
) -> Result<PolygonMesh<V, A>, Error<V>>
complete constructor
Errors
Returns Error::OutOfRange
if there is an index is out of range.
Remarks
This method does not check whether the normal is normalized or not.
sourcepub const fn new_unchecked(attributes: A, faces: Faces<V>) -> PolygonMesh<V, A>
pub const fn new_unchecked(attributes: A, faces: Faces<V>) -> PolygonMesh<V, A>
constructor without boundary check
sourcepub fn debug_new(attributes: A, faces: Faces<V>) -> PolygonMesh<V, A>
pub fn debug_new(attributes: A, faces: Faces<V>) -> PolygonMesh<V, A>
constructor, boundary check is acrivated only in debug mode.
sourcepub const fn attributes(&self) -> &A
pub const fn attributes(&self) -> &A
Returns attributes
sourcepub const fn tri_faces(&self) -> &Vec<[V; 3], Global> ⓘ
pub const fn tri_faces(&self) -> &Vec<[V; 3], Global> ⓘ
Returns the vector of all triangles of the polygon.
sourcepub const fn quad_faces(&self) -> &Vec<[V; 4], Global> ⓘ
pub const fn quad_faces(&self) -> &Vec<[V; 4], Global> ⓘ
Returns the vector of all quadrangles.
sourcepub const fn other_faces(&self) -> &Vec<Vec<V, Global>, Global> ⓘ
pub const fn other_faces(&self) -> &Vec<Vec<V, Global>, Global> ⓘ
Returns the vector of n-gons (n > 4).
sourcepub fn face_iter(&self) -> impl Iterator<Item = &[V]>
pub fn face_iter(&self) -> impl Iterator<Item = &[V]>
Returns the iterator of the slice.
By the internal optimization, this iterator does not runs in the simple order
in which they are registered, but runs order: triangle, square, and the others.
cf: Faces::face_iter
sourcepub fn face_iter_mut(&mut self) -> impl Iterator<Item = &mut [V]>
pub fn face_iter_mut(&mut self) -> impl Iterator<Item = &mut [V]>
Returns the iterator of the slice.
By the internal optimization, this iterator does not runs in the simple order
in which they are registered, but runs order: triangle, square, and the others.
cf: Faces::face_iter
sourcepub fn editor(&mut self) -> PolygonMeshEditor<'_, V, A>
pub fn editor(&mut self) -> PolygonMeshEditor<'_, V, A>
Creates an editor that performs boundary checking on dropped.
sourcepub fn uncheck_editor(&mut self) -> PolygonMeshEditor<'_, V, A>
pub fn uncheck_editor(&mut self) -> PolygonMeshEditor<'_, V, A>
Creates an editor that does NOT perform boundary checking on dropped.
sourcepub fn debug_editor(&mut self) -> PolygonMeshEditor<'_, V, A>
pub fn debug_editor(&mut self) -> PolygonMeshEditor<'_, V, A>
Creates an editor that performs boundary checking on dropped ONLY in debug build.
source§impl PolygonMesh<StandardVertex, StandardAttributes>
impl PolygonMesh<StandardVertex, StandardAttributes>
sourcepub fn merge(&mut self, mesh: PolygonMesh<StandardVertex, StandardAttributes>)
pub fn merge(&mut self, mesh: PolygonMesh<StandardVertex, StandardAttributes>)
Returns polygonmesh merged self
and mesh
.
sourcepub fn bounding_box(&self) -> BoundingBox<Point3<f64>>
pub fn bounding_box(&self) -> BoundingBox<Point3<f64>>
Creates the bounding box of the polygon mesh.
source§impl PolygonMesh<StandardVertex, StandardAttributes>
impl PolygonMesh<StandardVertex, StandardAttributes>
sourcepub const fn positions(&self) -> &Vec<Point3<f64>, Global> ⓘ
pub const fn positions(&self) -> &Vec<Point3<f64>, Global> ⓘ
Returns the vector of all positions.
sourcepub fn positions_mut(&mut self) -> &mut [Point3<f64>]
pub fn positions_mut(&mut self) -> &mut [Point3<f64>]
Returns the mutable slice of all positions.
sourcepub fn push_position(&mut self, position: Point3<f64>)
pub fn push_position(&mut self, position: Point3<f64>)
Adds a position.
sourcepub fn extend_positions<I>(&mut self, iter: I)where
I: IntoIterator<Item = Point3<f64>>,
pub fn extend_positions<I>(&mut self, iter: I)where
I: IntoIterator<Item = Point3<f64>>,
Extend positions by iterator.
sourcepub const fn uv_coords(&self) -> &Vec<Vector2<f64>, Global> ⓘ
pub const fn uv_coords(&self) -> &Vec<Vector2<f64>, Global> ⓘ
Returns the vector of all uv (texture) coordinates.
sourcepub fn uv_coords_mut(&mut self) -> &mut [Vector2<f64>]
pub fn uv_coords_mut(&mut self) -> &mut [Vector2<f64>]
Returns the mutable slice of all uv (texture) coordinates.
sourcepub fn push_uv_coord(&mut self, uv_coord: Vector2<f64>)
pub fn push_uv_coord(&mut self, uv_coord: Vector2<f64>)
Adds a uv (texture) coordinate.
sourcepub fn extend_uv_coords<I>(&mut self, iter: I)where
I: IntoIterator<Item = Vector2<f64>>,
pub fn extend_uv_coords<I>(&mut self, iter: I)where
I: IntoIterator<Item = Vector2<f64>>,
Extend uv (texture) coordinates by iterator.
sourcepub fn normals_mut(&mut self) -> &mut [Vector3<f64>]
pub fn normals_mut(&mut self) -> &mut [Vector3<f64>]
Returns the mutable slice of all normals.
sourcepub fn extend_normals<I>(&mut self, iter: I)where
I: IntoIterator<Item = Vector3<f64>>,
pub fn extend_normals<I>(&mut self, iter: I)where
I: IntoIterator<Item = Vector3<f64>>,
Extend normals by iterator
Trait Implementations§
source§impl<V, A> Clone for PolygonMesh<V, A>where
V: Clone,
A: Clone,
impl<V, A> Clone for PolygonMesh<V, A>where
V: Clone,
A: Clone,
source§fn clone(&self) -> PolygonMesh<V, A>
fn clone(&self) -> PolygonMesh<V, A>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Collision for PolygonMesh
impl Collision for PolygonMesh
source§fn collide_with(&self, other: &PolygonMesh) -> Option<(Point3, Point3)>
fn collide_with(&self, other: &PolygonMesh) -> Option<(Point3, Point3)>
self
and other
collide, then returns only one interference line.
Otherwise, returns None
.source§fn extract_interference(&self, other: &PolygonMesh) -> Vec<(Point3, Point3)> ⓘ
fn extract_interference(&self, other: &PolygonMesh) -> Vec<(Point3, Point3)> ⓘ
source§impl<V, A> Default for PolygonMesh<V, A>where
A: Default,
impl<V, A> Default for PolygonMesh<V, A>where
A: Default,
source§fn default() -> PolygonMesh<V, A>
fn default() -> PolygonMesh<V, A>
source§impl<'de, V, A> Deserialize<'de> for PolygonMesh<V, A>where
V: Copy + Debug + Deserialize<'de>,
A: Attributes<V> + Deserialize<'de>,
impl<'de, V, A> Deserialize<'de> for PolygonMesh<V, A>where
V: Copy + Debug + Deserialize<'de>,
A: Attributes<V> + Deserialize<'de>,
source§fn deserialize<D>(
deserializer: D
) -> Result<PolygonMesh<V, A>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<PolygonMesh<V, A>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl FromIterator<STLFace> for PolygonMesh<StandardVertex, StandardAttributes>
impl FromIterator<STLFace> for PolygonMesh<StandardVertex, StandardAttributes>
source§fn from_iter<I>(iter: I) -> PolygonMesh<StandardVertex, StandardAttributes>where
I: IntoIterator<Item = STLFace>,
fn from_iter<I>(iter: I) -> PolygonMesh<StandardVertex, StandardAttributes>where
I: IntoIterator<Item = STLFace>,
source§impl IncludingPointInDomain for PolygonMesh
impl IncludingPointInDomain for PolygonMesh
source§fn signed_crossing_faces(&self, point: Point3, ray_direction: Vector3) -> isize
fn signed_crossing_faces(&self, point: Point3, ray_direction: Vector3) -> isize
point
and direction ray_direction
.
Counter increase if the dot product of the ray and the normal of a face is positive,
and decrease if it is negative. Read moresource§impl<'a> IntoSTLIterator for &'a PolygonMesh<StandardVertex, StandardAttributes>
impl<'a> IntoSTLIterator for &'a PolygonMesh<StandardVertex, StandardAttributes>
§type IntoIter = PolygonMeshSTLFaceIterator<'a>
type IntoIter = PolygonMeshSTLFaceIterator<'a>
source§fn into_iter(
self
) -> <&'a PolygonMesh<StandardVertex, StandardAttributes> as IntoSTLIterator>::IntoIter
fn into_iter(
self
) -> <&'a PolygonMesh<StandardVertex, StandardAttributes> as IntoSTLIterator>::IntoIter
source§impl Invertible for PolygonMesh<StandardVertex, StandardAttributes>
impl Invertible for PolygonMesh<StandardVertex, StandardAttributes>
source§fn inverse(&self) -> PolygonMesh<StandardVertex, StandardAttributes>
fn inverse(&self) -> PolygonMesh<StandardVertex, StandardAttributes>
source§impl NormalFilters for PolygonMesh
impl NormalFilters for PolygonMesh
source§fn normalize_normals(&mut self) -> &mut Self
fn normalize_normals(&mut self) -> &mut Self
None
to the nor
index of the vertices
that has irregular normals. Read moresource§fn make_face_compatible_to_normal(&mut self) -> &mut Self
fn make_face_compatible_to_normal(&mut self) -> &mut Self
source§fn make_normal_compatible_to_face(&mut self) -> &mut Self
fn make_normal_compatible_to_face(&mut self) -> &mut Self
source§impl OptimizingFilter for PolygonMesh
impl OptimizingFilter for PolygonMesh
source§fn remove_unused_attrs(&mut self) -> &mut Self
fn remove_unused_attrs(&mut self) -> &mut Self
source§fn remove_degenerate_faces(&mut self) -> &mut Self
fn remove_degenerate_faces(&mut self) -> &mut Self
source§fn put_together_same_attrs(&mut self) -> &mut Self
fn put_together_same_attrs(&mut self) -> &mut Self
source§impl<V, A> PartialEq<PolygonMesh<V, A>> for PolygonMesh<V, A>where
V: PartialEq<V>,
A: PartialEq<A>,
impl<V, A> PartialEq<PolygonMesh<V, A>> for PolygonMesh<V, A>where
V: PartialEq<V>,
A: PartialEq<A>,
source§fn eq(&self, other: &PolygonMesh<V, A>) -> bool
fn eq(&self, other: &PolygonMesh<V, A>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<V, A> Serialize for PolygonMesh<V, A>where
V: Serialize,
A: Serialize,
impl<V, A> Serialize for PolygonMesh<V, A>where
V: Serialize,
A: Serialize,
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
source§impl Splitting for PolygonMesh
impl Splitting for PolygonMesh
source§fn create_mesh_by_face_indices(&self, indices: &[usize]) -> PolygonMesh
fn create_mesh_by_face_indices(&self, indices: &[usize]) -> PolygonMesh
source§impl StructuringFilter for PolygonMesh
impl StructuringFilter for PolygonMesh
source§impl Subdivision for PolygonMesh
impl Subdivision for PolygonMesh
source§fn loop_subdivision(&mut self) -> &mut Self
fn loop_subdivision(&mut self) -> &mut Self
source§impl Topology for PolygonMesh
impl Topology for PolygonMesh
source§fn extract_boundaries(&self) -> Vec<Vec<usize>> ⓘ
fn extract_boundaries(&self) -> Vec<Vec<usize>> ⓘ
source§fn shell_condition(&self) -> ShellCondition
fn shell_condition(&self) -> ShellCondition
The complexity increases in proportion to the number of edges. Read more