{"id":10113,"library":"pymeshfix","title":"PyMeshFix","description":"PyMeshFix is a Python library that provides bindings to the MeshFix C++ library, enabling robust repair of triangular meshes. It can fix common mesh issues such as holes, self-intersections, and non-manifold edges. The current version is 0.18.0, and it generally sees several releases per year, often aligning with updates to the broader PyVista ecosystem.","status":"active","version":"0.18.0","language":"en","source_language":"en","source_url":"https://github.com/pyvista/pymeshfix","tags":["mesh","3d","repair","geometry","pyvista","cad"],"install":[{"cmd":"pip install pymeshfix","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for array manipulation of mesh vertices and faces.","package":"numpy","optional":false}],"imports":[{"symbol":"MeshFix","correct":"from pymeshfix import MeshFix"}],"quickstart":{"code":"import numpy as np\nfrom pymeshfix import MeshFix\n\n# Create a simple mesh with a known issue (e.g., open boundary)\n# A triangle pointing up, but with a missing top vertex to create a hole\nv = np.array([\n    [0.0, 0.0, 0.0], # Base left\n    [1.0, 0.0, 0.0], # Base right\n    [0.5, 1.0, 0.0]  # Top (would create a closed triangle)\n], dtype=np.float64)\nf = np.array([\n    [0, 1, 2] # A single triangle\n], dtype=np.int32)\n\n# To demonstrate repair, let's create a small hole by removing a vertex\n# For a true 'hole fix', typically you'd have an open boundary that isn't manifold\n# In this minimal example, we'll just demonstrate the API with a valid mesh\n# Real-world usage involves meshes with actual defects.\n\n# Initialize MeshFix with vertices and faces\nmfx = MeshFix(v, f)\n\n# Repair the mesh (e.g., fill holes, remove self-intersections)\n# Common options include verbose=False, joincomp=True, remove_self_intersections=True\nmfx.repair(verbose=False, joincomp=True, remove_self_intersections=True)\n\n# Get the repaired mesh\nv_repaired = mfx.v\nf_repaired = mfx.f\n\nprint(f\"Original vertices shape: {v.shape}\")\nprint(f\"Original faces shape: {f.shape}\")\nprint(f\"Repaired vertices shape: {v_repaired.shape}\")\nprint(f\"Repaired faces shape: {f_repaired.shape}\")\n# Often, repair might add or remove vertices/faces depending on the issues found\n\n# Example of creating a mesh with a hole more explicitly (requires more complex setup)\n# v_hole = np.array([[0,0,0], [1,0,0], [0,1,0], [1,1,0], [0.5,0.5,1]])\n# f_hole = np.array([[0,1,2], [1,3,2], [0,2,4], [1,3,4]]) # missing [0,1,4] & [2,3,4] faces to make it a pyramid with a hole\n# mfx_hole = MeshFix(v_hole, f_hole)\n# mfx_hole.repair()\n# print(\"Hole repaired:\", mfx_hole.v.shape, mfx_hole.f.shape)\n","lang":"python","description":"This quickstart demonstrates how to import `MeshFix`, initialize it with NumPy arrays for vertices and faces, and perform a basic repair operation. Note that `pymeshfix` is typically used to fix complex meshes loaded from files, and this example uses a simple mesh to illustrate the API. The `repair` method can take various parameters to control the fixing process."},"warnings":[{"fix":"Ensure your build environment is compatible with Nanobind requirements if compiling from source. If using pre-built wheels, simply update `pymeshfix` and its dependencies.","message":"Version 0.18.0 replaced the internal Cython bindings with Nanobind. While the public Python API is intended to remain stable, this change in the underlying C++ binding technology might affect environments with custom build pipelines or those implicitly relying on Cython internals. Users might experience different build requirements or subtle runtime behavior changes.","severity":"breaking","affected_versions":">=0.18.0"},{"fix":"When creating or loading face arrays, explicitly cast them to an integer type: `faces = np.array(..., dtype=np.int32)`.","message":"Mesh face arrays (indices) must be of an integer dtype, specifically `numpy.int32` or `numpy.int64`. Providing float dtypes will lead to `TypeError` or `ArgumentError` from the underlying C++ extension.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you are using a Python interpreter version within the supported range (e.g., 3.10, 3.11, 3.12, 3.13, 3.14). Consider using a virtual environment manager like `conda` or `venv` to manage Python versions.","message":"PyMeshFix has strict Python version requirements, currently supporting `Python >=3.10` and `<3.15`. Using an incompatible Python version will prevent installation or lead to 'No matching distribution' errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the GPL license terms carefully to understand its implications for your project before incorporating PyMeshFix.","message":"PyMeshFix is licensed under the GNU General Public License (GPL). This is an important consideration for commercial or proprietary projects, as it imposes requirements on derivative works.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install pymeshfix` in your terminal to install the library.","cause":"The pymeshfix library has not been installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'pymeshfix'"},{"fix":"Ensure your face array is explicitly cast to `numpy.int32` or `numpy.int64`. Example: `faces = np.array([[0, 1, 2]], dtype=np.int32)`.","cause":"The array provided for mesh faces (indices) has an incorrect data type, typically a float type instead of an integer type.","error":"TypeError: an integer is required (got type numpy.float64) / ArgumentError: Python argument types to meshfix.MeshFix.set_meshfix_faces did not match C++ signature:"},{"fix":"Verify your Python version. PyMeshFix currently supports `Python >=3.10, <3.15`. Install a compatible Python version or use a virtual environment with a supported Python version.","cause":"Your Python interpreter version is not compatible with any available pymeshfix wheels on PyPI, or you are on an unsupported platform.","error":"ERROR: Could not find a version that satisfies the requirement pymeshfix (from versions: none) / ERROR: No matching distribution found for pymeshfix"}]}