Skip to main content

StlMesh

Struct StlMesh 

Source
pub struct StlMesh {
    pub triangles: Vec<StlTriangle>,
    pub name: String,
}
Expand description

An STL mesh consisting of named triangles.

Fields§

§triangles: Vec<StlTriangle>

The triangles that make up this mesh.

§name: String

The name of the solid (used in ASCII output).

Implementations§

Source§

impl StlMesh

Source

pub fn new(name: &str) -> Self

Create a new empty STL mesh with the given name.

Source

pub fn add_triangle(&mut self, v0: [f32; 3], v1: [f32; 3], v2: [f32; 3])

Add a triangle defined by three vertices; the normal is computed automatically.

Source

pub fn to_binary_bytes(&self) -> Vec<u8>

Serialize this mesh to binary STL bytes.

Layout: 80-byte header + 4-byte little-endian triangle count + (12 floats + 2-byte attribute) per triangle = 50 bytes each.

Source

pub fn from_binary_bytes(data: &[u8]) -> Result<Self, String>

Parse a binary STL byte slice into an StlMesh.

Source

pub fn to_ascii(&self) -> String

Serialize this mesh to ASCII STL text.

Source

pub fn from_ascii(s: &str) -> Result<Self, String>

Parse an ASCII STL string into an StlMesh.

Source

pub fn surface_area(&self) -> f32

Compute the total surface area of this mesh.

Source

pub fn bounding_box(&self) -> ([f32; 3], [f32; 3])

Compute the axis-aligned bounding box as (min, max).

Returns ([0.0;3], [0.0;3]) for an empty mesh.

Source

pub fn is_watertight(&self) -> bool

Return true if every edge is shared by exactly two triangles (watertight).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.