Mesh

Struct Mesh 

Source
pub struct Mesh {
    pub vertices: Vec<Vertex>,
    pub triangles: Vec<Triangle>,
    pub beam_lattice: Option<BeamLattice>,
}
Expand description

A triangle mesh representing 3D geometry.

A mesh is the fundamental geometry container in 3MF, consisting of vertices (3D points) and triangles that connect those vertices. Meshes can optionally include beam lattice structures for lightweight, high-strength geometry.

§Examples

use lib3mf_core::model::Mesh;

let mut mesh = Mesh::new();
let v1 = mesh.add_vertex(0.0, 0.0, 0.0);
let v2 = mesh.add_vertex(1.0, 0.0, 0.0);
let v3 = mesh.add_vertex(0.0, 1.0, 0.0);
mesh.add_triangle(v1, v2, v3);
assert_eq!(mesh.triangles.len(), 1);

Fields§

§vertices: Vec<Vertex>

List of vertices (points in 3D space).

§triangles: Vec<Triangle>

List of triangles connecting vertices by their indices.

§beam_lattice: Option<BeamLattice>

Beam Lattice extension data for structural lattice geometry (optional).

Implementations§

Source§

impl Mesh

Source

pub fn new() -> Self

Creates a new empty mesh.

Source

pub fn add_vertex(&mut self, x: f32, y: f32, z: f32) -> u32

Adds a vertex to the mesh and returns its index.

§Arguments
  • x - X coordinate in model units
  • y - Y coordinate in model units
  • z - Z coordinate in model units
§Returns

The index of the newly added vertex, which can be used to reference this vertex in triangles.

Source

pub fn add_triangle(&mut self, v1: u32, v2: u32, v3: u32)

Adds a triangle to the mesh connecting three vertices.

§Arguments
  • v1 - Index of the first vertex
  • v2 - Index of the second vertex
  • v3 - Index of the third vertex

The vertex indices should be in counter-clockwise order when viewed from outside the mesh for correct normal orientation.

Source

pub fn compute_aabb(&self) -> Option<BoundingBox>

Computes the axis-aligned bounding box (AABB) of the mesh.

Returns None if the mesh has no vertices.

Source

pub fn compute_area_and_volume(&self) -> (f64, f64)

Computes the total surface area and volume of the mesh.

Uses triangle area calculation and signed tetrahedron volumes. Returns (0.0, 0.0) if the mesh has no triangles.

§Returns

A tuple of (surface_area, volume) in square and cubic model units respectively.

Source

pub fn compute_triangle_area(&self, triangle: &Triangle) -> f64

Computes the area of a single triangle.

§Arguments
  • triangle - Reference to the triangle whose area to compute
§Returns

The area of the triangle in square model units.

Trait Implementations§

Source§

impl Clone for Mesh

Source§

fn clone(&self) -> Mesh

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Mesh

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Mesh

Source§

fn default() -> Mesh

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

impl<'de> Deserialize<'de> for Mesh

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl MeshRepair for Mesh

Source§

fn repair(&mut self, options: RepairOptions) -> RepairStats

Attempts to repair the mesh in-place based on the provided options. Read more
Source§

impl PartialEq for Mesh

Source§

fn eq(&self, other: &Mesh) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Mesh

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Mesh

Auto Trait Implementations§

§

impl Freeze for Mesh

§

impl RefUnwindSafe for Mesh

§

impl Send for Mesh

§

impl Sync for Mesh

§

impl Unpin for Mesh

§

impl UnwindSafe for Mesh

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,