Display#
Classes to define mesh for display use. Display mesh do not require good aspect ratios on elements.
- class volmdlr.display.CompoundMesh3D(meshes: list[Mesh3D | CompoundMesh3D], name: str = '')#
Bases:
Primitive3DA group of 3D triangle mesh that can contain both Mesh3D and other CompoundMesh3D objects.
- apply_transform(matrix: list[list[float]]) CompoundMesh3D#
Transform all meshes (including nested compounds) by a homogeneous transformation matrix.
- Parameters:
matrix – (4, 4) float Homogeneous transformation matrix
- Returns:
The transformed CompoundMesh3D.
- babylon_data(merge_meshes: bool = True, show_curves: bool = False, ocaf=None)#
Get babylonjs data.
- Returns:
Dictionary with babylon data.
- property bounding_box: BoundingBox#
Return the bounding box enclosing all the meshes (including nested compounds).
- count_meshes() int#
Count the total number of Mesh3D objects in the hierarchy.
- Returns:
Total count of Mesh3D objects.
- find_meshes_by_name(name: str) list[tuple[list[int], Mesh3D | CompoundMesh3D]]#
Find all meshes with a specific name and return their paths.
- Parameters:
name – The name to search for
- Returns:
List of tuples (path, mesh) for all matching meshes
- find_path(target_mesh: Mesh3D | CompoundMesh3D) list[int] | None#
Find the path (as indices) to reach a specific mesh in the hierarchy.
- Parameters:
target_mesh – The mesh to find in the hierarchy
- Returns:
List of indices to reach the mesh, or None if not found
- frame_mapping(frame: Frame3D, side: str) CompoundMesh3D#
Transform a CompoundMesh3D (including all nested compounds) from the current reference frame to a new one.
side=’new’: consider the mesh in global frame and transforms in local given frame. side=’old’: consider the mesh in local given frame and transforms in global frame.
- Parameters:
frame – The input reference frame.
side – Choose between ‘old’ and ‘new’.
- Returns:
A frame mapped CompoundMesh3D object.
- get_all_meshes() list[Mesh3D]#
Flatten the hierarchy and return all Mesh3D objects contained in this compound.
- Returns:
A flat list of all Mesh3D objects.
- static get_babylon_data(shape: CompoundMesh3D, merge_meshes=True, show_curves: bool = False, ocaf=None)#
Get babylonjs data.
- Returns:
Dictionary with babylon data.
- get_depth() int#
Get the maximum depth of the hierarchy.
- Returns:
The maximum depth of nested CompoundMesh3D objects.
- get_depth_of_mesh(target_mesh: Mesh3D | CompoundMesh3D) int | None#
Get the depth of a specific mesh in the hierarchy.
- Parameters:
target_mesh – The mesh to find the depth of
- Returns:
The depth of the mesh (0 for direct children), or None if not found
- get_mesh_at_path(path: list[int]) Mesh3D | CompoundMesh3D | None#
Get a mesh at a specific path in the hierarchy.
- Parameters:
path – List of indices representing the path to the mesh.
- Returns:
The mesh at the specified path, or None if path is invalid.
- get_parent_compound(target_mesh: Mesh3D | CompoundMesh3D) CompoundMesh3D | None#
Find the parent CompoundMesh3D of a specific mesh.
- Parameters:
target_mesh – The mesh to find the parent of
- Returns:
The parent CompoundMesh3D, or None if not found or if target is a direct child
- print_hierarchy(indent: int = 0) None#
Print a visual representation of the mesh hierarchy.
- Parameters:
indent – Current indentation level (used for recursion)
- replace_mesh_at_path(path: list[int], new_mesh: Mesh3D | CompoundMesh3D) CompoundMesh3D#
Replace a mesh at a specific path with a new mesh.
- Parameters:
path – List of indices representing the path to the mesh to replace
new_mesh – The new mesh to insert at the specified path
- Returns:
A new CompoundMesh3D with the mesh replaced
- rotation(center: Point3D, axis: Vector3D, angle: float) CompoundMesh3D#
Rotate all the meshes around the specified center, axis, and angle.
- Parameters:
center – The center point of rotation.
axis – The rotation axis.
angle – The rotation angle in radians.
- Returns:
A new CompoundMesh3D object resulting from the rotation.
- translation(offset: Vector3D) CompoundMesh3D#
Translate all the meshes by the specified offset.
- Parameters:
offset – The translation offset.
- Returns:
A new CompoundMesh3D object resulting from the translation.
- class volmdlr.display.Mesh2D(vertices: list[list[float]], triangles: list[list[int]], color: tuple[float, float, float] | None = None, alpha: float = 1.0, name: str = '')#
Bases:
MeshMixin,DessiaObject2D triangle mesh.
- area() float#
Calculate the total area of the 2D mesh as the sum of areas of triangles.
- Returns:
The total area of the mesh.
- Return type:
float
- class volmdlr.display.Mesh3D(vertices: list[list[float]], triangles: list[list[int]], color: tuple[float, float, float] | None = None, alpha: float = 1.0, name: str = '', normals: list[list[float]] | None = None, metadata: dict | None = None)#
Bases:
MeshMixin,Primitive3D3D triangle mesh.
- alpha_shape_reconstruction(n_sample_points: int = 5000, alpha: float | None = None, alpha_multiplier: float = 4.2) Mesh3D#
Reconstructs the mesh using the Alpha Shape algorithm.
https://www.open3d.org/docs/latest/tutorial/Advanced/surface_reconstruction.html
- Parameters:
n_sample_points – Number of points to sample from the mesh using Poisson disk sampling.
alpha – Alpha parameter controlling the level of detail. Lower values capture finer features. If not provided, it is automatically estimated as (alpha_multiplier × average nearest neighbor distance) for a tight fit.
alpha_multiplier – Multiplier used to estimate alpha when not provided. Default is 4.20, tuned for a detailed, tight-fitting reconstruction.
- Returns:
A new Mesh3D instance representing the reconstructed mesh using the Alpha Shape algorithm.
- apply_transform(matrix: list[list[float]]) Mesh3D#
Transform mesh by a homogeneous transformation matrix.
- Parameters:
matrix – (4, 4) float Homogeneous transformation matrix
- Returns:
The transformed Mesh.
- area() float#
Calculate the total surface area of the 3D mesh as the sum of areas of triangles.
- Returns:
The total surface area of the 3D mesh.
- Return type:
float
- ball_pivoting_reconstruction(n_sample_points: int = 5000, radii: list[float] | None = None) Mesh3D#
Reconstruction of the mesh using the Ball Pivoting algorithm.
https://www.open3d.org/docs/latest/tutorial/Advanced/surface_reconstruction.html
- Parameters:
n_sample_points – Number of points to sample from the mesh.
radii – List of radii for the ball pivoting algorithm. If None, it will be computed based on the average distance.
- Returns:
A new Mesh3D instance representing the reconstructed mesh using the Ball Pivoting algorithm.
- property bounding_box: BoundingBox#
Bounding box of current mesh.
- compute_len_edges()#
Compute the lengths of edges for each triangle in the mesh.
- Returns:
Lengths of edges (3 edges per triangles) of dimensions n_simplices x 3 and edges of dimensions n_simplices x 3 x 2
- Return type:
tuple[np.ndarray, np.ndarray]
- convex_hull() Mesh3D#
Compute the convex hull of the mesh.
- Returns:
A new Mesh3D instance representing the convex hull of the original mesh.
- crop_to_bounding_box(bounding_box: BoundingBox) Mesh3D#
Crop a mesh to a bounding box by slicing with planes.
- property debug_info: str#
Get comprehensive debug information about the mesh.
Useful for diagnosing mesh issues without sharing the actual mesh data.
- Returns:
Formatted debug information string
- decimate(target_count: int, update_rate: int = 5, aggressiveness: float = 7.0, max_iterations: int = 100, verbose: bool = False, lossless: bool = False, threshold_lossless: float = 0.001, alpha: float = 1e-09, k: int = 3, preserve_border: bool = True) Mesh3D#
Decimate the Mesh3D, and return it as a new instance.
Vertices of the mesh should be merged (and maybe rounded) for efficient decimation.
Note: threshold = alpha * pow(iteration + k, aggressiveness)
- Parameters:
target_count (int) – Target number of triangles.
update_rate (int) – Number of iterations between each update. If lossless flag is set to True, rate is 1.
aggressiveness (float) – Parameter controlling the growth rate of the threshold at each iteration when lossless is False.
max_iterations (int) – Maximal number of iterations.
verbose (bool) – Control verbosity.
lossless (bool) – Flag for using the lossless simplification method. Sets the update rate to 1.
threshold_lossless (float) – Maximal error after which a vertex is not deleted. Only for lossless method.
alpha (float) – Parameter for controlling the threshold growth.
k (int) – Parameter for controlling the threshold growth.
preserve_border (bool) – Flag for preserving vertices on open border.
- Returns:
The decimated mesh.
- Return type:
- distance_to_points(points_array: ndarray[Any, dtype[_ScalarType_co]], return_points: bool = False, sign_type: SignedDistanceType = SignedDistanceType.UNSIGNED) ndarray[Any, dtype[_ScalarType_co]] | tuple[ndarray[Any, dtype[_ScalarType_co]], ndarray[Any, dtype[_ScalarType_co]]]#
Compute the exact minimum distances between the mesh and the given points using IGL.
- Parameters:
points_array – A numpy array representing the 3D points.
return_points – A flag to indicate whether to return the closest points.
sign_type – Method for computing distance sign: “pseudonormal”, “winding_number”, “unsigned”, “fast_winding_number”, or “default”
- Returns:
The minimum distances to the points, and optionally, the closest points.
- distance_to_points_approximate(points_array: ndarray[Any, dtype[_ScalarType_co]], return_points: bool = False) ndarray[Any, dtype[_ScalarType_co]] | tuple[ndarray[Any, dtype[_ScalarType_co]], ndarray[Any, dtype[_ScalarType_co]]]#
Compute the approximate minimum distances between the mesh (using only its vertices) and the given points using a KDTree.
- Parameters:
points_array – A numpy array representing the 3D points.
return_points – A flag to indicate whether to return the closest points.
- Returns:
The minimum distances to the points, and optionally, the closest points.
- exclude_triangles_outside_bounding_box(bounding_box: BoundingBox) Mesh3D#
Exclude triangles that are clearly outside the bounding box (all vertices on one side of a bbox face).
This method removes triangles where all vertices are beyond one of the bbox boundaries: - All vertices have x > xmax or all have x < xmin - All vertices have y > ymax or all have y < ymin - All vertices have z > zmax or all have z < zmin
- Parameters:
bounding_box – The bounding box to use for filtering
- Returns:
A new Mesh3D with triangles clearly outside the bbox removed
- property faces#
Get the mesh faces as Triangle3D objects.
- Returns:
The triangles composing the mesh.
- Return type:
list[Triangle3D]
- fill_holes() Mesh3D#
Fill single triangle and single quad holes in the current mesh.
- Returns:
A new Mesh3D instance with holes filled.
- filter_smooth(method: Literal['Simple', 'Laplacian', 'Taubin'] = 'Simple', iterations: int = 1) Mesh3D#
Apply a smoothing filter to the mesh.
https://www.open3d.org/docs/release/tutorial/geometry/mesh.html#Mesh-filtering
- Parameters:
method – The smoothing method to use. Options are ‘Simple’, ‘Laplacian’, or ‘Taubin’.
iterations – The number of iterations to apply the smoothing filter.
- Returns:
A new Mesh3D instance representing the smoothed mesh.
- filter_triangles_by_bounding_box(bounding_box: BoundingBox, mode: Literal['fully_inside', 'partially_inside'] = 'fully_inside') Mesh3D#
Filter triangles based on their position relative to a bounding box.
- Parameters:
bounding_box – The bounding box to use as filter
mode – Filtering mode: - ‘fully_inside’: keep only triangles with all vertices inside the bbox - ‘partially_inside’: keep triangles with at least one vertex inside the bbox
- Returns:
A new Mesh3D containing filtered triangles
- frame_mapping(frame: Frame3D, side: str)#
Transform a Mesh3D from the current reference frame to a new one.
side=’new’: consider the mesh in global frame and transforms in local given frame. side=’old’: consider the mesh in local given frame and transforms in global frame.
- Parameters:
frame – The input reference frame.
side – Choose between ‘old’ and ‘new’.
- Returns:
A frame mapped Mesh3D object.
- classmethod from_3mf_file(filepath: str, scale_factor: float = 0.001, merge_meshes: bool = True)#
Create a 3D mesh from an 3MF file.
- Parameters:
filepath (str) – The path to the 3MF file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
merge_meshes (bool) – A flag to choose to merge all the 3MF meshes in one, or return a list of meshes.
- Returns:
A new 3D mesh instance if merge_meshes is True, or a list of 3D mesh instances if merge_meshes is False.
- Return type:
- classmethod from_3mf_stream(stream: BinaryFile, scale_factor: float = 0.001, merge_meshes: bool = True)#
Create a 3D mesh from an 3MF stream.
- Parameters:
stream (BinaryFile) – A binary stream containing 3MF data.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
merge_meshes (bool) – A flag to choose to merge all the 3MF meshes in one, or return a list of meshes.
- Returns:
A new 3D mesh instance if merge_meshes is True, or a list of 3D mesh instances if merge_meshes is False.
- Return type:
- classmethod from_glb_file(filepath: str, scale_factor: float = 0.001, merge_meshes: bool = True)#
Create a 3D mesh from a GLB file.
- Parameters:
filepath (str) – The path to the GLB file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
merge_meshes (bool) – A flag to choose to merge all the GLB meshes in one, or return a list of meshes.
- Returns:
A new 3D mesh instance if merge_meshes is True, or a list of 3D mesh instances if merge_meshes is False.
- Return type:
- classmethod from_glb_stream(stream: BinaryFile, scale_factor: float = 0.001, merge_meshes: bool = True)#
Create a 3D mesh from a GLB stream.
- Parameters:
stream (BinaryFile) – A binary stream containing GLB data.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
merge_meshes (bool) – A flag to choose to merge all the GLB meshes in one, or return a list of meshes.
- Returns:
A new 3D mesh instance if merge_meshes is True, or a list of 3D mesh instances if merge_meshes is False.
- Return type:
- classmethod from_obj_file(filepath: str, scale_factor: float = 0.001) Mesh3D#
Create a 3D mesh from an OBJ file.
- Parameters:
filepath (str) – The path to the OBJ file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
- Returns:
A new 3D mesh instance.
- Return type:
- classmethod from_obj_stream(stream: BinaryFile, scale_factor: float = 0.001) Mesh3D#
Create a 3D mesh from an OBJ stream.
- Parameters:
stream (BinaryFile) – A binary stream containing OBJ data.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
- Returns:
A new 3D mesh instance.
- Return type:
- classmethod from_off_file(filepath: str, scale_factor: float = 0.001) Mesh3D#
Create a 3D mesh from an OFF file.
- Parameters:
filepath (str) – The path to the OFF file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
- Returns:
A new 3D mesh instance.
- Return type:
- classmethod from_off_stream(stream: BinaryFile, scale_factor: float = 0.001) Mesh3D#
Create a 3D mesh from an OFF stream.
- Parameters:
stream (BinaryFile) – A binary stream containing OFF data.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
- Returns:
A new 3D mesh instance.
- Return type:
- classmethod from_open3d(mesh: TriangleMesh, name: str = '') Mesh3D#
Create a 3D mesh from an Open3D TriangleMesh object.
- Parameters:
mesh – An Open3D TriangleMesh object representing the 3D mesh.
name – A name for the mesh, optional.
- Returns:
A new 3D mesh instance.
- classmethod from_ply_file(filepath: str, scale_factor: float = 0.001) Mesh3D#
Create a 3D mesh from an PLY file.
- Parameters:
filepath (str) – The path to the PLY file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
- Returns:
A new 3D mesh instance.
- Return type:
- classmethod from_ply_stream(stream: BinaryFile, scale_factor: float = 0.001) Mesh3D#
Create a 3D mesh from an PLY stream.
- Parameters:
stream (BinaryFile) – A binary stream containing PLY data.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
- Returns:
A new 3D mesh instance.
- Return type:
- classmethod from_point_cloud_alpha_shape(points_array: ndarray[Any, dtype[_ScalarType_co]], alpha: float | None = None, alpha_multiplier: float = 4.2, name: str = '') Mesh3D#
Create a 3D mesh from a point cloud using the Alpha Shape algorithm to reconstruct the surface.
https://www.open3d.org/docs/latest/tutorial/Advanced/surface_reconstruction.html
- Parameters:
points_array – A numpy array representing the 3D points.
alpha – Alpha parameter controlling the level of detail. Lower values capture finer features. If not provided, it is automatically estimated as (alpha_multiplier × average nearest neighbor distance) for a tight fit.
alpha_multiplier – Multiplier used to estimate alpha when not provided. Default is 4.20, tuned for a detailed, tight-fitting reconstruction.
name – A name for the mesh, optional.
- Returns:
A new 3D mesh instance created from the point cloud using the Alpha Shape algorithm.
- classmethod from_stl_file(filepath: str, scale_factor: float = 0.001, merge_meshes: bool = True)#
Create a 3D mesh from an STL file.
- Parameters:
filepath (str) – The path to the STL file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
merge_meshes (bool) – A flag to choose to merge all the STL meshes in one, or return a list of meshes.
- Returns:
A new 3D mesh instance if merge_meshes is True, or a list of 3D mesh instances if merge_meshes is False.
- Return type:
- classmethod from_stl_stream(stream: BinaryFile, scale_factor: float = 0.001, merge_meshes: bool = True)#
Create a 3D mesh from an STL stream.
- Parameters:
stream (BinaryFile) – A binary stream containing STL data.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
merge_meshes (bool) – A flag to choose to merge all the STL meshes in one, or return a list of meshes.
- Returns:
A new 3D mesh instance if merge_meshes is True, or a list of 3D mesh instances if merge_meshes is False.
- Return type:
- classmethod from_trimesh(trimesh_: Trimesh, name: str | None = None) Mesh3D#
Create a 3D mesh from a Trimesh object.
- Parameters:
trimesh – A Trimesh object representing the 3D mesh.
name – A name for the mesh, optional.
- Returns:
A new 3D mesh instance.
- classmethod from_trimesh_scene(trimesh_scene: Scene, scale_factor: float = 0.001) Mesh3D#
Create a 3D mesh from a Trimesh Scene.
- Parameters:
trimesh_scene (trimesh.Scene) – A Trimesh Scene containing multiple geometry objects.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
- Returns:
A new 3D mesh instance.
- Return type:
- get_edges_triangles()#
Compute lengths edges of triangles.
- Returns:
A 3D numpy array representing edges of triangles. The dimensions are n_triangles x 3 x 2, where each entry contains the start and end points of an edge.
- Return type:
np.ndarray
- get_mesh_border()#
Retrieve the topological border of a triangle mesh.
This function identifies and returns the edges that belong to only one triangle, effectively representing the border of the mesh.
- Returns:
A tuple of two numpy arrays. The first array contains the unique border edges, and the second array includes all edges of the mesh.
- Return type:
tuple[np.ndarray, np.ndarray]
- property has_duplicate_indices: bool#
Check if any triangle has duplicate vertex indices.
- property has_inf_triangles: bool#
Check if triangles contain Inf values.
- property has_inf_vertices: bool#
Check if vertices contain Inf values.
- property has_nan_triangles: bool#
Check if triangles contain NaN values.
- property has_nan_vertices: bool#
Check if vertices contain NaN values.
- line_segment_intersection(segment_start: ndarray[Any, dtype[_ScalarType_co]], segment_end: ndarray[Any, dtype[_ScalarType_co]], bbox_margin: float = 1e-06) ndarray[Any, dtype[_ScalarType_co]]#
Compute intersections between a line segment and the mesh with automatic spatial optimization.
This method automatically crops the mesh to the segment’s bounding box before computing intersections, and filters results to only include intersections within the segment bounds.
- Parameters:
segment_start – Start point of the segment, shape (3,) with coordinates [x, y, z]
segment_end – End point of the segment, shape (3,) with coordinates [x, y, z]
bbox_margin – Margin to add around the segment’s bounding box for mesh cropping (default: 1e-6)
- Returns:
Array of intersection points, shape (n_intersections, 3). Empty array if no intersections.
- minimum_distance(other_mesh: Mesh3D, return_points: bool = False, method: Literal['Approximate', 'Exact'] = 'Approximate') float | tuple[float, Point3D, Point3D]#
Compute the minimum distance between this 3D mesh and another 3D mesh.
This method can compute an approximate distance (only based on vertices) or an exact distance (using IGL).
- Parameters:
other_mesh – The other 3D mesh to compare against.
return_points – Whether to return the closest points.
method – The method to use for distance computation (‘Approximate’ or ‘Exact’). If ‘Exact’, the exact distance is computed using IGL.
- Returns:
The minimum distance between the two meshes, and optionally, the closest points.
- Return type:
float or (float, ndarray[float], ndarray[float])
- property nbytes: int#
Get the total memory size in bytes of the mesh data (vertices + triangles).
- poisson_surface_reconstruction(n_sample_points: int = 5000, depth: int = 8, width: float = 0, scale: float = 1.1, linear_fit: bool = False) Mesh3D#
Reconstruction of the mesh using the Poisson Surface algorithm.
https://www.open3d.org/docs/latest/tutorial/Advanced/surface_reconstruction.html
- Parameters:
n_sample_points – Number of points to sample from the mesh.
depth – Maximum depth of the tree that will be used for surface reconstruction. Running at depth d corresponds to solving on a grid whose resolution is no larger than 2^d x 2^d x 2^d. Note that since the reconstructor adapts the octree to the sampling density, the specified reconstruction depth is only an upper bound.
width – Specifies the target width of the finest level octree cells. This parameter is ignored if depth is specified.
scale – Specifies the ratio between the diameter of the cube used for reconstruction and the diameter of the samples’ bounding cube.
linear_fit – If true, the reconstructor will use linear interpolation to estimate the positions of iso-vertices.
- Returns:
A new Mesh3D instance representing the reconstructed mesh using the Poisson Surface algorithm.
- project_vertices_on_mesh(mesh: Mesh3D, method: Literal['Exact', 'Approximate'] = 'Exact', maximum_translation: float | None = None) Mesh3D#
Project the vertices of the mesh onto another mesh.
This method computes the closest points on the target mesh for each vertex of the current mesh and translates the vertices accordingly. The translation can be limited by a maximum distance.
- Parameters:
mesh – The target mesh to project onto.
method – The method to use for closest vertices computation (‘Exact’ or ‘Approximate’).
maximum_translation – The maximum distance for translation. If None, no limit is applied.
- Returns:
A new Mesh3D instance with the projected vertices.
- ray_intersection(ray_origins: ndarray[Any, dtype[_ScalarType_co]], ray_directions: ndarray[Any, dtype[_ScalarType_co]]) tuple[ndarray[Any, dtype[_ScalarType_co]], ndarray[Any, dtype[_ScalarType_co]], ndarray[Any, dtype[_ScalarType_co]]]#
Compute intersections between rays and the mesh.
- Parameters:
ray_origins – A numpy array of shape (n_rays, 3) representing ray origins.
ray_directions – A numpy array of shape (n_rays, 3) representing ray directions (need not be normalized).
- Returns:
A tuple of (locations, ray_indices, face_indices) where: - locations: Array of shape (n_intersections, 3) with intersection points - ray_indices: Array of shape (n_intersections,) indicating which ray each intersection belongs to - face_indices: Array of shape (n_intersections,) indicating which face was intersected
- remove_large_triangles(threshold_edge_length: float) Mesh3D#
Remove triangles from the mesh whose edge lengths exceed the specified threshold.
- Parameters:
threshold_edge_length (float) – The maximum allowed edge length for a triangle to remain in the mesh.
- Returns:
A new Mesh3D instance with large triangles removed.
- Return type:
- rotation(center: Point3D, axis: Vector3D, angle: float) Mesh3D#
Rotate the mesh around the specified center, axis, and angle.
- Parameters:
center – The center point of rotation.
axis – The rotation axis.
angle – The rotation angle in radians.
- Returns:
A new Mesh3D object resulting from the rotation.
- sample_points_poisson_disk(n_sample_points: int = 5000) ndarray[Any, dtype[_ScalarType_co]]#
Sample points using Poisson disk sampling on the mesh surface, using Open3D.
Ensures a minimum distance between points for a more even distribution.
- Parameters:
n_sample_points – The number of points to sample from the mesh.
- Returns:
A numpy array of shape (n_sample_points, 3) representing the sampled points.
- sample_points_uniformly(n_sample_points: int = 5000) ndarray[Any, dtype[_ScalarType_co]]#
Sample points uniformly on the mesh surface, using Open3D.
All areas of the surface have equal sampling probability. Fast but may cluster points.
- Parameters:
n_sample_points – The number of points to sample from the mesh.
- Returns:
A numpy array of shape (n_sample_points, 3) representing the sampled points.
- save_to_3mf_file(filepath: str, scale_factor: float = 1000.0)#
Save the 3D mesh to a 3MF file.
Deprecated since version v1: This method will be removed in v1. Use export decorators with save_export_to_file instead.
- Parameters:
filepath (str) – The path to the 3MF file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 1000.0).
- save_to_3mf_stream#
Implementation of a tag for exports.
- save_to_glb_stream#
Implementation of a tag for exports.
- save_to_obj_file(filepath: str, scale_factor: float = 1000.0)#
Save the 3D mesh to an OBJ file.
Deprecated since version v1: This method will be removed in v1. Use export decorators with save_export_to_file instead.
- Parameters:
filepath (str) – The path to the OBJ file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 1000.0).
- save_to_obj_stream#
Implementation of a tag for exports.
- save_to_off_file(filepath: str, scale_factor: float = 1000.0)#
Save the 3D mesh to an OFF file.
Deprecated since version v1: This method will be removed in v1. Use export decorators with save_export_to_file instead.
- Parameters:
filepath (str) – The path to the OFF file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 1000.0).
- save_to_off_stream#
Implementation of a tag for exports.
- save_to_ply_file(filepath: str, scale_factor: float = 1000.0)#
Save the 3D mesh to a PLY file.
Deprecated since version v1: This method will be removed in v1. Use export decorators with save_export_to_file instead.
- Parameters:
filepath (str) – The path to the PLY file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 1000.0).
- save_to_ply_stream#
Implementation of a tag for exports.
- save_to_stl_file(filepath: str, scale_factor: float = 1000.0)#
Save the 3D mesh to an STL file.
Deprecated since version v1: This method will be removed in v1. Use export decorators with save_export_to_file instead.
- Parameters:
filepath (str) – The path to the STL file.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 1000.0).
- save_to_stl_stream#
Implementation of a tag for exports.
- slice_plane(plane_origin: Point3D, plane_normal: Vector3D) Mesh3D#
Slice the mesh with a plane, returning a new mesh that is the portion of the original mesh to the positive normal side of the plane.
- Parameters:
plane_origin – Point on plane to intersect with mesh.
plane_normal – Normal vector of plane to intersect with mesh.
- Returns:
A new Mesh3D instance representing the sliced mesh.
- to_babylon()#
Convert the mesh to the Babylon.js format.
This method rounds the vertices to 6 decimal places and returns the mesh in a Babylon.js compatible format. https://doc.babylonjs.com/how_to/custom
- Returns:
A dictionary representing the mesh in Babylon.js format with ‘positions’ and ‘indices’ keys.
- Return type:
dict
- to_closed_shell()#
Convert the Mesh3D object to a closed triangle shell.
- Returns:
A closed triangle shell representation of the Mesh3D object.
- Return type:
ClosedTriangleShell3D
- to_open3d() TriangleMesh#
Convert the Mesh3D instance to an Open3D TriangleMesh object.
- Returns:
An Open3D TriangleMesh object representing the 3D mesh.
- to_open_shell()#
Convert the Mesh3D object to an open triangle shell.
- Returns:
An open triangle shell representation of the Mesh3D object.
- Return type:
OpenTriangleShell3D
- to_triangles3d(tol: float = 1e-10)#
Export the mesh faces as Triangle3D objects.
- Parameters:
tol – A float value representing the smallest area for considering a not degenerated triangle.
- Returns:
The triangles comosing the mesh.
- Return type:
list[Triangle3D]
- to_trimesh(process: bool = True) Trimesh#
Convert the Mesh3D instance to a Trimesh object.
- Parameters:
process – if True, Nan and Inf values will be removed immediately and vertices will be merged.
- Returns:
A Trimesh object representing the 3D mesh.
- Return type:
trimesh.Trimesh
- translation(offset: Vector3D)#
Translate the mesh by the specified offset.
- Parameters:
offset – The translation offset.
- Returns:
A new Mesh3D object resulting from the translation.
- triangular_faces()#
Export the mesh faces as Triangle3D objects.
- Returns:
The triangles comosing the mesh.
- Return type:
list[Triangle3D]
- classmethod trimesh_scene_to_meshes(trimesh_scene: Scene, scale_factor: float = 0.001) list[Mesh3D]#
Create a 3D mesh from a Trimesh Scene.
- Parameters:
trimesh_scene (trimesh.Scene) – A Trimesh Scene containing multiple geometry objects.
scale_factor (float, optional) – The scale factor to apply to the mesh (default is 0.001).
- Returns:
A list of new 3D mesh instance.
- Return type:
list[Mesh3D]
- property wrapped: Any#
Return a Solid composed of planar faces equivalent to the mesh for compatibility with OCAF.
- Returns:
- class volmdlr.display.MeshMixin#
Bases:
objectMixin class for 2D and 3D meshes.
This is an abstract class.
- MeshType = ~MeshType#
- check_consistency() bool#
Check the consistency of the Mesh instance.
This method verifies that all vertices referenced by triangles are within the valid range of vertex indices.
- Returns:
True if the mesh is consistent, False otherwise.
- Return type:
bool
- classmethod dict_to_object(dict_: Dict[str, Any], *args, **kwargs) MeshType#
Overload of ‘dict_to_object’ for numpy usage and memory perf.
- property dimension: int#
Get the dimension of the mesh (“2” for 2D mesh or “3” for 3D mesh).
- classmethod from_meshes(meshes: list[MeshType], merge_vertices: bool = False, merge_triangles: bool = False, name: str = '') MeshType#
Merge multiple meshes into a single mesh.
- Parameters:
meshes – A list of Mesh instance to merge all together.
merge_vertices – Flag to indicate whether to merge vertices.
merge_triangles – Flag to indicate whether to merge triangles.
name – A name for the mesh, optional (default is an empty string).
- Returns:
A new Mesh instance representing the merged meshes.
- Return type:
MeshType
- merge(other: MeshType, merge_vertices: bool = False, merge_triangles: bool = False) MeshType#
Merge two meshes.
- Parameters:
other (MeshType) – Another Mesh instance to merge with this instance.
merge_vertices (bool, optional) – Flag to indicate whether to merge vertices.
merge_triangles (bool, optional) – Flag to indicate whether to merge triangles.
- Returns:
A new Mesh instance representing the merged meshes.
- Return type:
MeshType
- merge_triangles() MeshType#
Merge duplicated triangles in the Mesh instance.
This method identifies and removes duplicate triangles, resulting in a Mesh with unique triangles.
- Returns:
A new Mesh instance with merged triangles.
- Return type:
MeshType
- merge_vertices() MeshType#
Merge duplicated vertices in the Mesh instance and remap triangles accordingly.
This method identifies duplicate vertices and combines them into a single unique set of vertices, updating the triangles to use the unique vertices.
- Returns:
A new Mesh instance with merged vertices and updated triangles.
- Return type:
MeshType
- property n_triangles: int#
Get number of triangles in the mesh.
- property n_vertices: int#
Get number of vertices in the mesh.
- plot(ax=None, numbering: bool = False)#
Plot the mesh with Matplotlib.
- remove_degenerate_triangles(tol: float = 1e-10) MeshType#
Remove degenerate triangles from the Mesh instance.
Degenerate triangles are triangles with zero or near-zero area, including flat triangles with three distinct points.
- Parameters:
tol (float, optional) – The tolerance value for the triangle area (default is 0.0).
- Returns:
A new Mesh instance with degenerate triangles removed.
- Return type:
MeshType
- resize(scale_factor: float) MeshType#
Resize the Mesh instance by scaling its vertices.
- Parameters:
scale_factor (float) – The factor by which to scale the mesh.
- Returns:
A new Mesh instance representing the scaled mesh.
- Return type:
MeshType
- round_vertices(decimals: int = 9) MeshType#
Round the vertices of the Mesh instance to a given number of decimals.
- Parameters:
decimals (int, optional) – The number of decimal places to round the vertices to (default is 9).
- Returns:
A new Mesh instance with rounded vertices.
- Return type:
MeshType
Split the shared vertices between triangles in the Mesh instance.
This method recreates distinct vertices for each triangle, effectively unmerging shared vertices. The resulting mesh will have three times the number of vertices as the number of triangles.
- Returns:
A new Mesh instance with unmerged vertices and original triangles.
- Return type:
MeshType
- to_dict(*args, **kwargs)#
Overload of ‘to_dict’ for numpy usage and memory perf.
- triangles_cross_products()#
Compute the cross products of edges for each triangle in the mesh.
- Returns:
An array containing the cross products of edges for each triangle.
- Return type:
np.ndarray[float]
- triangles_vertices()#
Get the actual triangles of the mesh represented by their vertices (not indices).
- Returns:
An array containing the vertices of the triangles.
- Return type:
np.ndarray[float]