MeshTrimmer
Classο
The MeshTrimmer
class provides functionalities for manipulating 3D meshes (typically in STL format) and trimming
lattice structures using these meshes. It can be used to load, save, scale, move, and perform geometric checks on
meshes. Additionally, it allows for cutting lattice beams that intersect with a mesh surface.
π¦ Featuresο
Load and save
.stl
mesh filesAutomatically reposition mesh to origin
Check whether a point or a lattice cell is inside the mesh
Trim beams that intersect the mesh surface
Use with a lattice generation process for geometrically conforming trimming
π§° Dependenciesο
Internal dependencies:
Beam
,Point
,Cell
class
π§± Class Usageο
Typically used in conjunction with the Lattice
class:
from data.inputs.mesh_file.mesh_trimmer import MeshTrimmer
from pyLattice.lattice import Lattice
trimmer = MeshTrimmer("example_mesh.stl")
lattice = Lattice(..., mesh_trimmer=trimmer)
π§© Methodsο
__init__(mesh_name: str = None)
ο
Initializes a MeshTrimmer
object. Optionally loads a mesh at initialization.
load_mesh(mesh_name: str)
ο
Loads a mesh from the Mesh/
directory (STL format). Automatically handles extension and path formatting.
save_mesh(output_name: str)
ο
Saves the current mesh to the Mesh/
directory, with automatic .stl
extension handling.
scale_mesh(scale: float)
ο
Scales the mesh uniformly and moves its minimum corner to the origin.
move_mesh_to_origin()
ο
Translates the mesh so that its minimum bounding box corner is at the origin.
is_inside_mesh(point: array-like) -> bool
ο
Checks if a given 3D point is located inside the mesh volume.
is_cell_in_mesh(cell: Cell) -> bool
ο
Returns True
if at least one corner of the given Cell
object is inside the mesh. Used to filter cells during lattice generation.
cut_beams_at_mesh_intersection(cells: list[Cell])
ο
Cuts or removes beams in the provided Cell
list depending on their intersection with the mesh surface.
Fully outside: removed
Partially intersecting: shortened
Inside: unchanged
find_intersection_with_mesh(beam: Beam) -> tuple[float, float, float] | None
ο
Uses pyembree
acceleration to find the first intersection between a beam and the mesh surface. Returns intersection point or None
if no hit.
plot_mesh()
ο
Visualizes the current mesh using matplotlib
in a 3D view.
The mesh is displayed with translucent cyan faces and black edges.
The camera is centered around the mesh centroid, with equal zoom in all directions.
The 3D axes and background are hidden for a cleaner visualization.
𧬠Integration with Lattice
ο
When passed to the Lattice
class via the mesh_trimmer
argument, MeshTrimmer
is automatically used during cell generation to:
Filter out cells not intersecting with the mesh
Optionally trim beams based on the geometry
from data.inputs.mesh_file.mesh_trimmer import MeshTrimmer
from pyLattice.lattice import Lattice
trimmer = MeshTrimmer("example_mesh.stl")
lattice = Lattice(..., mesh_trimmer=trimmer)
lattice.cut_beam_with_mesh_trimmer() # Use the trimmer to cut beams at mesh intersection
π File Structure Conventionο
Mesh files are expected to be stored under a
Mesh/
folder.STL format is enforced.
π οΈ Limitationsο
Only beams that havenβt already been modified (beam_mod == False) can be trimmed, due to the lack of implementation for simulating trimmed lattice structures.