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
impl Mesh
Sourcepub fn add_triangle(&mut self, v1: u32, v2: u32, v3: u32)
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 vertexv2- Index of the second vertexv3- Index of the third vertex
The vertex indices should be in counter-clockwise order when viewed from outside the mesh for correct normal orientation.
Sourcepub fn compute_aabb(&self) -> Option<BoundingBox>
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.
Sourcepub fn compute_area_and_volume(&self) -> (f64, f64)
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.