Quick Start¶
Get started with mmgpy in 5 minutes.
Your First Remesh¶
The simplest way to use mmgpy is to load a mesh, remesh it, and save the result:
import mmgpy
# Load a mesh from any supported format
mesh = mmgpy.read("input.mesh")
# Remesh with a target edge size
result = mesh.remesh(hmax=0.1)
# Check the results
print(f"Vertices: {result.vertices_before} -> {result.vertices_after}")
print(f"Quality: {result.quality_mean_before:.3f} -> {result.quality_mean_after:.3f}")
# Save to any supported format
mesh.save("output.vtk")
Using Options Objects¶
For more control, use typed options objects with IDE autocomplete:
Factory Presets¶
Options classes provide convenient factory methods for common use cases:
from mmgpy import Mmg3DOptions
# Fine mesh (small elements)
fine_opts = Mmg3DOptions.fine()
# Coarse mesh (large elements)
coarse_opts = Mmg3DOptions.coarse()
# Optimization only (no topology changes)
opt_opts = Mmg3DOptions.optimize_only()
Local Sizing Control¶
Refine the mesh in specific regions:
import mmgpy
mesh = mmgpy.read("input.mesh")
# Fine mesh in a spherical region
mesh.set_size_sphere(
center=[0.5, 0.5, 0.5],
radius=0.2,
size=0.01,
)
# Fine mesh in a box region
mesh.set_size_box(
bounds=[[0, 0, 0], [0.3, 0.3, 0.3]],
size=0.02,
)
# Remesh with global hmax, local sizing takes precedence
result = mesh.remesh(hmax=0.1, verbose=-1)
PyVista Visualization¶
Visualize meshes with the built-in plot() method:
import mmgpy
# Load and remesh
mesh = mmgpy.read("input.mesh")
mesh.remesh(hmax=0.1)
# Quick visualization with edges
mesh.plot()
# Or customize with PyVista options
mesh.plot(color="lightblue", opacity=0.8)
For custom plotters, use the vtk property:
import pyvista as pv
plotter = pv.Plotter()
plotter.add_mesh(mesh.vtk, show_edges=True)
plotter.show()
Load from PyVista:
import mmgpy
import pyvista as pv
# Create a PyVista mesh
sphere = pv.Sphere(radius=1.0)
# Convert to mmgpy mesh
mesh = mmgpy.from_pyvista(sphere, mesh_type="surface")
# Remesh and visualize
mesh.remesh(hmax=0.1)
mesh.plot()
Mesh Validation¶
Check mesh quality before and after remeshing:
import mmgpy
mesh = mmgpy.read("input.mesh")
# Quick validation (returns bool)
if mesh.validate():
print("Mesh is valid")
else:
print("Mesh has issues")
# Detailed validation report
report = mesh.validate(detailed=True)
print(f"Valid: {report.is_valid}")
print(f"Mean quality: {report.quality.mean:.3f}")
print(f"Min quality: {report.quality.min:.3f}")
for issue in report.issues:
print(f" {issue.severity}: {issue.message}")
Next Steps¶
- Core Concepts - Understand mesh types and remeshing strategies
- Basic Remeshing Tutorial - In-depth remeshing guide
- API Reference - Complete API documentation