pub struct TriMesh {
pub vertices: Vec<Vec3>,
pub triangles: Vec<Triangle>,
}Expand description
A simple triangle mesh.
Fields§
§vertices: Vec<Vec3>Vertices of the mesh.
triangles: Vec<Triangle>Triangles defined by vertex indices.
Implementations§
Source§impl TriMesh
impl TriMesh
Sourcepub fn face_normal(&self, tri_idx: usize) -> Vec3
pub fn face_normal(&self, tri_idx: usize) -> Vec3
Compute the face normal for triangle at tri_idx.
Returns cross(v1-v0, v2-v0).normalize().
Sourcepub fn signed_volume(&self) -> f64
pub fn signed_volume(&self) -> f64
Volume of a closed mesh using the divergence theorem (signed volume sum).
Assumes a watertight mesh with consistent winding.
V = (1/6) * Σ (v0 · (v1 × v2))
Sourcepub fn surface_area(&self) -> f64
pub fn surface_area(&self) -> f64
Surface area of the mesh.
Sum of triangle areas = 0.5 * |cross(e1, e2)|.
Sourcepub fn vertex_normals(&self) -> Vec<Vec3> ⓘ
pub fn vertex_normals(&self) -> Vec<Vec3> ⓘ
Compute vertex normals by averaging adjacent face normals.
Sourcepub fn contains_point(&self, point: Vec3) -> bool
pub fn contains_point(&self, point: Vec3) -> bool
Check if a point is inside the mesh using ray casting in the +Z direction.
Counts intersections; odd count means inside. Assumes watertight mesh.
Sourcepub fn uv_sphere(radius: f64, rings: u32, sectors: u32) -> Self
pub fn uv_sphere(radius: f64, rings: u32, sectors: u32) -> Self
Generate a UV sphere mesh for testing purposes.
rings is the number of latitude rings (excluding poles),
sectors is the number of longitude sectors.
Sourcepub fn bounding_box(&self) -> (Vec3, Vec3)
pub fn bounding_box(&self) -> (Vec3, Vec3)
Compute the axis-aligned bounding box of the mesh.
Returns (min, max) corners. Panics if the mesh has no vertices.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TriMesh
impl RefUnwindSafe for TriMesh
impl Send for TriMesh
impl Sync for TriMesh
impl Unpin for TriMesh
impl UnsafeUnpin for TriMesh
impl UnwindSafe for TriMesh
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.