### Initialize MeshSet and Process Meshes Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/intro.rst Demonstrates how to instantiate a MeshSet, load a 3D model, apply a convex hull filter, and save the resulting mesh to a file. ```python import pymeshlab ms = pymeshlab.MeshSet() ms.load_new_mesh('airplane.obj') ms.generate_convex_hull() ms.save_current_mesh('convex_hull.ply') ``` -------------------------------- ### Query and List MeshLab Filters Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/intro.rst Shows how to list available filters, inspect specific filter parameters, and search for filters using keywords. ```python pymeshlab.print_filter_list() pymeshlab.print_filter_parameter_list('generate_surface_reconstruction_screened_poisson') pymeshlab.search('poisson') ``` -------------------------------- ### Run PyMeshLab Tests Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/intro.rst Provides the shell commands required to install the pytest framework and execute the built-in PyMeshLab test suite. ```shell pip3 install pytest pytest --pyargs pymeshlab ``` -------------------------------- ### Apply Filters and Retrieve Metrics Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/intro.rst Illustrates how to apply filters with custom parameters and extract geometric measurements from the returned dictionary. ```python ms.create_noisy_isosurface(resolution=128) out_dict = ms.get_geometric_measures() print(out_dict['surface_area']) ``` -------------------------------- ### Load Project Example in Python Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/tutorials/load_project.rst Demonstrates how to load a project file using the PyMeshLab library. This script requires the PyMeshLab library to be installed and a valid project file to be present. ```python import pymeshlab def load_project(file_path): """Loads a project file using pymeshlab. Args: file_path (str): The path to the project file. Returns: pymeshlab.MeshSet: The loaded MeshSet object. """ ms = pymeshlab.MeshSet() ms.load_project(file_path) return ms if __name__ == '__main__': # Example usage: # Replace 'path/to/your/project.json' with the actual path to your project file project_file = 'path/to/your/project.json' try: meshset = load_project(project_file) print(f"Project loaded successfully from {project_file}") # You can now work with the loaded meshset, e.g., print its layers # print(meshset.print_layers()) except FileNotFoundError: print(f"Error: Project file not found at {project_file}") except Exception as e: print(f"An error occurred: {e}") ``` -------------------------------- ### Run PyMeshLab Tests Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/tutorials.rst Executes the built-in test suite for PyMeshLab to verify the installation and functionality of the library. This command runs all tutorial-based tests provided within the package. ```bash pytest --pyargs pymeshlab ``` -------------------------------- ### Install PyMeshLab via Package Managers Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/README.md Commands to install the PyMeshLab library using either pip or Conda-Forge. These are the standard methods for setting up the environment. ```bash pip3 install pymeshlab ``` ```bash conda install -c conda-forge pymeshlab ``` -------------------------------- ### Install Target and Directories (CMake) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/src/pymeshlab/CMakeLists.txt Installs the PyMeshLab target and associated directories. The installation path is conditional on 'PYMESHLAB_BUILD_DUMMY_BIN_MAC_DEPLOY', placing the target within 'dummybin.app/Contents' on macOS or the root installation prefix otherwise. This also handles the installation of test files and Python modules. ```cmake if (PYMESHLAB_BUILD_DUMMY_BIN_MAC_DEPLOY) install(TARGETS ${PYMESHLAB_MODULE_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/dummybin.app/Contents) else() install(TARGETS ${PYMESHLAB_MODULE_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}) endif() if (NOT PYMESHLAB_BUILD_DUMMY_BIN_MAC_DEPLOY) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/tests" DESTINATION ${CMAKE_INSTALL_PREFIX}) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/__init__.py" DESTINATION ${CMAKE_INSTALL_PREFIX}) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/polyscope_functions.py" DESTINATION ${CMAKE_INSTALL_PREFIX}) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/replacer.py" DESTINATION ${CMAKE_INSTALL_PREFIX}) else() install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/tests" DESTINATION ${CMAKE_INSTALL_PREFIX}/dummybin.app/Contents) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/__init__.py" DESTINATION ${CMAKE_INSTALL_PREFIX}/dummybin.app/Contents) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/polyscope_functions.py" DESTINATION ${CMAKE_INSTALL_PREFIX}/dummybin.app/Contents) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/replacer.py" DESTINATION ${CMAKE_INSTALL_PREFIX}/dummybin.app/Contents) endif() ``` -------------------------------- ### Install PyMeshLab Wheel File using Pip Source: https://github.com/cnr-isti-vclab/pymeshlab/wiki/How-to-install-the-last-nightly-version This command installs the PyMeshLab wheel file after downloading it from the GitHub Actions artifacts. Ensure you are in the directory containing the .whl file and that the filename matches the pattern. ```shell pip install pymeshlab*.whl ``` -------------------------------- ### Apply Color and Geometric Filters in PyMeshLab Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/filter_list.rst Examples demonstrating how to invoke various color scattering, transfer, and coordinate transformation filters within a PyMeshLab workflow. ```python import pymeshlab ms = pymeshlab.MeshSet() ms.load_new_mesh("input.obj") # Apply random color scattering to layers ms.compute_color_scattering_per_mesh(seed=1) # Transfer color from face to vertex ms.compute_color_transfer_face_to_vertex() # Apply geometric function to vertices (e.g., sine wave deformation) ms.compute_coord_by_function(x='x', y='y', z='sin(x+y)', onselected=False) # Morph mesh towards another loaded mesh ms.compute_coord_linear_morphing(targetmesh=1, percentmorph=50.0) ``` -------------------------------- ### Execute Example Script: apply_filter_parameters_percentage Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/tutorials/apply_filter_parameters_percentage.rst This command executes the specific example script 'apply_filter_parameters_percentage' using pytest. It's used to test the functionality of applying ranged percentage parameters to filters. ```shell pytest --pyargs pymeshlab -k 'apply_filter_parameters_percentage' ``` -------------------------------- ### Create and Save a Cube Mesh with PyMeshLab Source: https://context7.com/cnr-isti-vclab/pymeshlab/llms.txt Demonstrates creating a cube mesh from vertex and face arrays using PyMeshLab. It shows how to initialize a Mesh object, add it to a MeshSet, and save it to a PLY file. It also includes an example of creating a mesh with per-vertex RGBA colors. ```python import pymeshlab import numpy as np # Create a cube from vertex and face arrays vertices = np.array([ [-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [-0.5, 0.5, -0.5], [0.5, 0.5, -0.5], [-0.5, -0.5, 0.5], [0.5, -0.5, 0.5], [-0.5, 0.5, 0.5], [0.5, 0.5, 0.5] ]) faces = np.array([ [2, 1, 0], [1, 2, 3], [4, 2, 0], [2, 4, 6], [1, 4, 0], [4, 1, 5], [6, 5, 7], [5, 6, 4], [3, 6, 7], [6, 3, 2], [5, 3, 7], [3, 5, 1] ]) # Create mesh from arrays m = pymeshlab.Mesh(vertices, faces) print(f"Vertices: {m.vertex_number()}, Faces: {m.face_number()}") # Add mesh to MeshSet with a name ms = pymeshlab.MeshSet() ms.add_mesh(m, "cube_mesh") ms.save_current_mesh("cube.ply") # Create mesh with per-vertex colors (RGBA, 0-1 float range) vertex_colors = np.array([ [1, 0, 0, 1], # red [0, 1, 0, 1], # green [0, 0, 1, 1], # blue [0.5, 0, 0, 1], [0, 0.5, 0, 1], [0, 0, 0.5, 1], [0.5, 0, 0.5, 1], [0, 0.5, 0.5, 1] ]) m_colored = pymeshlab.Mesh( vertex_matrix=vertices, face_matrix=faces, v_color_matrix=vertex_colors ) ms.add_mesh(m_colored, "colored_cube") ms.save_current_mesh("colored_cube.ply") ``` -------------------------------- ### Load and Save 3D Meshes Source: https://context7.com/cnr-isti-vclab/pymeshlab/llms.txt Shows how to import and export meshes using various file formats like OBJ and PLY. It includes examples of passing format-specific parameters such as binary encoding and attribute preservation. ```python import pymeshlab ms = pymeshlab.MeshSet() # Load a mesh with default parameters ms.load_new_mesh("model.obj") # Save the current mesh with default parameters ms.save_current_mesh("output.obj") # Save with specific options (disable face color export) ms.save_current_mesh("output.ply", save_face_color=False) # Save in binary PLY format with vertex colors ms.save_current_mesh("output_binary.ply", binary=True, save_vertex_color=True) # Load 3DS file with all meshes merged into single layer ms.load_new_mesh("model.3ds", load_in_a_single_layer=True) ``` -------------------------------- ### Deploy PyMeshLab with 2_deploy.sh Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/scripts/README.md Packages the previously built PyMeshLab into a self-contained module. It accepts an optional path argument specifying the installation directory. ```shell sh 2_deploy.sh sh 2_deploy.sh my/install/path ``` -------------------------------- ### Execute Base Module Tests Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/tutorials/base.rst Command-line instruction to run the PyMeshLab test suite specifically for the base module using pytest. This requires the pytest framework to be installed in the environment. ```bash pytest --pyargs pymeshlab -k 'base' ``` -------------------------------- ### Configure Library Output Directory (CMake) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/src/pymeshlab/CMakeLists.txt Sets the output directory for the PyMeshLab library during the build process. It conditionally directs the output to a 'dummybin.app/Contents' directory on macOS when 'PYMESHLAB_BUILD_DUMMY_BIN_MAC_DEPLOY' is enabled, otherwise, it uses the general distribution directory. ```cmake if (NOT PYMESHLAB_BUILD_DUMMY_BIN_MAC_DEPLOY) #set_property(TARGET ${PYMESHLAB_MODULE_NAME} # PROPERTY RUNTIME_OUTPUT_DIRECTORY ${PYMESHLAB_BUILD_DISTRIB_DIR}) set_property(TARGET ${PYMESHLAB_MODULE_NAME} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${PYMESHLAB_BUILD_DISTRIB_DIR}) else() set_property(TARGET ${PYMESHLAB_MODULE_NAME} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${PYMESHLAB_BUILD_DISTRIB_DIR}/dummybin.app/Contents) endif() ``` -------------------------------- ### POST /filters/rendering/gpu_filter_example Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/filter_list.rst A sample GPU filter demonstrating how to work with a GL render context. It's a basic filter for illustrative purposes. ```APIDOC ## POST /filters/rendering/gpu_filter_example ### Description A sample GPU filter demonstrating how to work with a GL render context. It's a basic filter for illustrative purposes. ### Method POST ### Endpoint /filters/rendering/gpu_filter_example ### Parameters #### Request Body - **imagebackgroundcolor** (Color) - Optional - The color used as image background. Defaults to [50; 50; 50; 255]. - **imagewidth** (integer) - Optional - The width in pixels of the produced image. Defaults to 512. - **imageheight** (integer) - Optional - The height in pixels of the produced image. Defaults to 512. - **imagefilename** (string) - Optional - The file name used to save the image. Defaults to 'gpu_generated_image.png'. ### Request Example ```json { "imagebackgroundcolor": [0, 0, 0, 255], "imagewidth": 1024, "imageheight": 768, "imagefilename": "rendered_scene.png" } ``` ### Response #### Success Response (200) - **message** (string) - Success message indicating the image was generated and saved. #### Response Example ```json { "message": "GPU generated image saved as rendered_scene.png." } ``` ``` -------------------------------- ### Explore and Search PyMeshLab Filters Source: https://context7.com/cnr-isti-vclab/pymeshlab/llms.txt Shows how to list all available filters, search for filters by keyword, and print parameter details for specific filters. It also demonstrates retrieving the filter list programmatically. ```python import pymeshlab # List all available filterspymeshlab.print_filter_list() # Search for filters by keywordpymeshlab.search('poisson') # Find Poisson reconstruction filterspymeshlab.search('smooth') # Find smoothing filterspymeshlab.search('boolean') # Find boolean operation filters # Print parameters for a specific filterpymeshlab.print_filter_parameter_list('generate_surface_reconstruction_screened_poisson')pymeshlab.print_filter_parameter_list('meshing_decimation_quadric_edge_collapse') # Get filter list programmatically filter_names = pymeshlab.filter_list() print(f"Total available filters: {len(filter_names)}") ``` -------------------------------- ### Configure RPATH for Shared Libraries (CMake) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/src/pymeshlab/CMakeLists.txt Configures the RPATH (Run-time Search Path) for the PyMeshLab target. On non-Apple platforms, it sets the RPATH to include the library's own directory and any specified installation RPATH. On Apple platforms, it enables RPATH usage from the link path and adds a custom command to embed '@loader_path/Frameworks' into the executable's RPATH. ```cmake if (NOT APPLE) set_target_properties(${PYMESHLAB_MODULE_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/lib:${INSTALL_RPATH}") else() set_target_properties(${PYMESHLAB_MODULE_NAME} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) add_custom_command( TARGET ${PYMESHLAB_MODULE_NAME} POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@loader_path/Frameworks" $) endif() ``` -------------------------------- ### Execute Example Custom Mesh Attributes Test (Shell) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/tutorials/custom_mesh_attributes.rst This command executes a specific example test for custom mesh attributes within the PyMeshLab project using pytest. The `--pyargs pymeshlab` flag tells pytest to look for tests within the pymeshlab package, and `-k 'example_custom_mesh_attributes'` filters to run only tests matching that keyword. ```shell pytest --pyargs pymeshlab -k 'example_custom_mesh_attributes' ``` -------------------------------- ### Save Mesh to WRL Format (Python) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/io_format_list.rst Saves a mesh to the WRL (VRML) file format. Options include saving vertex colors, wedge colors, and wedge texture coordinates. ```python import pymeshlab mshell = pymeshlab.MeshSet() mshell.load_new_mesh('input.obj') mshell.save_wrl(file_name='output.WRL', save_vertex_color=True, save_wedge_color=True, save_wedge_texcoord=True) ``` -------------------------------- ### Visualize Meshes with Polyscope Source: https://context7.com/cnr-isti-vclab/pymeshlab/llms.txt Demonstrates how to load multiple meshes using PyMeshLab and visualize them interactively using the Polyscope library. It includes applying a processing step before visualization. ```python import pymeshlab # Requires: pip install polyscope ms = pymeshlab.MeshSet() ms.load_new_mesh("model.obj") ms.load_new_mesh("another_model.ply") # Apply some processing ms.compute_color_from_scalar_per_vertex() # Show interactive 3D viewer with all meshes ms.show_polyscope() ``` -------------------------------- ### Copy Files During Build (CMake) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/src/pymeshlab/CMakeLists.txt Copies essential PyMeshLab files and directories, including tests, __init__.py, polyscope_functions.py, and replacer.py, to the distribution directory. The destination path is adjusted for macOS dummy binary deployment. ```cmake if (NOT PYMESHLAB_BUILD_DUMMY_BIN_MAC_DEPLOY) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/tests" DESTINATION ${PYMESHLAB_BUILD_DISTRIB_DIR}) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/__init__.py" DESTINATION ${PYMESHLAB_BUILD_DISTRIB_DIR}) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/polyscope_functions.py" DESTINATION ${PYMESHLAB_BUILD_DISTRIB_DIR}) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/replacer.py" DESTINATION ${PYMESHLAB_BUILD_DISTRIB_DIR}) else() file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/tests" DESTINATION ${PYMESHLAB_BUILD_DISTRIB_DIR}/dummybin.app/Contents) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/__init__.py" DESTINATION ${PYMESHLAB_BUILD_DISTRIB_DIR}/dummybin.app/Contents) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/polyscope_functions.py" DESTINATION ${PYMESHLAB_BUILD_DISTRIB_DIR}/dummybin.app/Contents) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/../../pymeshlab/replacer.py" DESTINATION ${PYMESHLAB_BUILD_DISTRIB_DIR}/dummybin.app/Contents) endif() ``` -------------------------------- ### Load Mesh into MeshSet using PyMeshLab Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/tutorials/load_mesh.rst Demonstrates how to initialize a MeshSet object and load a 3D mesh file into it. This is the fundamental step for performing further mesh processing tasks within the PyMeshLab framework. ```python import pymeshlab # Create a new MeshSet ms = pymeshlab.MeshSet() # Load a mesh file ms.load_mesh("path/to/your/mesh.obj") # Access the loaded mesh mesh = ms.current_mesh() print(f"Loaded mesh with {mesh.vertex_number()} vertices.") ``` -------------------------------- ### Extract Mesh Data with PyMeshLab Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/tutorials/get_mesh_values.rst Demonstrates how to access vertex coordinates and face-vertex incident indices from a mesh object. It utilizes the PyMeshLab library to interface with mesh data structures and returns the results as NumPy arrays. ```python import pymeshlab # Create a MeshSet and load a mesh ms = pymeshlab.MeshSet() ms.load_new_mesh("input_mesh.obj") mesh = ms.current_mesh() # Extract vertex coordinates as a numpy array vertex_matrix = mesh.vertex_matrix() # Extract face-vertex indices as a numpy array face_matrix = mesh.face_matrix() print("Vertex coordinates shape:", vertex_matrix.shape) print("Face-vertex indices shape:", face_matrix.shape) ``` -------------------------------- ### POST /mesh/generate_dust_accumulation Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/filter_list.rst Simulates dust accumulation over the mesh, generating a point cloud based on surface properties. ```APIDOC ## POST /mesh/generate_dust_accumulation ### Description Simulates dust accumulation over the mesh generating a cloud of points lying on the current mesh. ### Method POST ### Endpoint /mesh/generate_dust_accumulation ### Parameters #### Request Body - **dust_dir** (array) - Optional - Direction of the dust source (default: [0, 1, 0]). - **nparticles** (int) - Optional - Max number of dust particles to generate per face. - **slippiness** (float) - Optional - Surface slippiness (large values mean less sticky). - **adhesion** (float) - Optional - Factor to model general adhesion. - **draw_texture** (bool) - Optional - If true, creates a new texture saved in dirt_texture.png. ### Request Example { "dust_dir": [0, 1, 0], "nparticles": 3, "slippiness": 1.0, "adhesion": 0.2, "draw_texture": false } ``` -------------------------------- ### Execute PyMeshLab Load Mesh Test Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/tutorials/load_mesh.rst Command-line instruction to verify the mesh loading functionality using the pytest framework. This ensures the environment is correctly configured and the library is functioning as expected. ```bash pytest --pyargs pymeshlab -k 'load_mesh' ``` -------------------------------- ### Execute PyMeshLab Save Project Tests Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/tutorials/save_project.rst Command-line instruction to verify the save project functionality using the pytest framework. This ensures that the project saving logic is correctly integrated and functional within the environment. ```bash pytest --pyargs pymeshlab -k 'save_project' ``` -------------------------------- ### Define Platform-Specific Build and Install Directories Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/src/CMakeLists.txt Configures output paths for libraries and plugins based on the target operating system (Windows, macOS, or Linux). It handles the specific directory structure requirements for macOS application bundles versus standard library paths. ```cmake if (WIN32) set(MESHLAB_LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) set(MESHLAB_PLUGIN_INSTALL_DIR ${MESHLAB_LIB_INSTALL_DIR}/lib/plugins) elseif(NOT APPLE) set(MESHLAB_LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib) set(MESHLAB_PLUGIN_INSTALL_DIR ${MESHLAB_LIB_INSTALL_DIR}/plugins) else(APPLE) set(MESHLAB_LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/Frameworks) set(MESHLAB_PLUGIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/PlugIns) endif() ``` -------------------------------- ### Manage MeshSets in PyMeshLab Source: https://context7.com/cnr-isti-vclab/pymeshlab/llms.txt Demonstrates how to initialize a MeshSet, load multiple 3D models into distinct layers, switch between active meshes, and clear the set. This is the fundamental workflow for handling multiple geometry files simultaneously. ```python import pymeshlab # Create a new empty MeshSet ms = pymeshlab.MeshSet() # Load meshes into the MeshSet (each becomes a layer) ms.load_new_mesh("bone.ply") print(f"Meshes in set: {ms.mesh_number()}") # Output: 1 ms.load_new_mesh("airplane.obj") print(f"Meshes in set: {ms.mesh_number()}") # Output: 2 # Switch between meshes using their ID ms.set_current_mesh(0) # Select first mesh (bone.ply) print(f"Vertices in bone: {ms.current_mesh().vertex_number()}") # Output: 1872 ms.set_current_mesh(1) # Select second mesh (airplane.obj) print(f"Vertices in airplane: {ms.current_mesh().vertex_number()}") # Output: 7017 # Clear all meshes from the MeshSet ms.clear() ``` -------------------------------- ### Load external plugins Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/changelog.rst Demonstrates how to load custom or additional MeshLab plugins at runtime. ```python import pymeshlab # Load a specific plugin pymeshlab.load_plugin('my_plugin_path') ``` -------------------------------- ### Import Mesh from NumPy Arrays into MeshSet (Python) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/tutorials/import_mesh_from_arrays.rst This Python script shows how to create a mesh directly from NumPy arrays representing vertices and faces, and then add this mesh to a PyMeshLab MeshSet. It requires the PyMeshLab library and NumPy to be installed. The output is a MeshSet object containing the newly created mesh. ```python import pymeshlab import numpy as np def example_import_mesh_from_arrays(): # Create a MeshSet ms = pymeshlab.MeshSet() # Define vertices and faces using numpy arrays vertices = np.array([ [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0, 0.0] ], dtype=np.float32) faces = np.array([ [0, 1, 2], [1, 3, 2] ], dtype=np.int32) # Create a new mesh from the arrays m = pymeshlab.Mesh(vertex_matrix=vertices, face_matrix=faces) # Insert the mesh into the MeshSet ms.add_mesh(m, 'imported_mesh') # You can now work with the mesh in the MeshSet print(f"Mesh '{ms.current_mesh().name()}' added to MeshSet.") print(f"Number of vertices: {ms.current_mesh().vertex_number()}") print(f"Number of faces: {ms.current_mesh().face_number()}") if __name__ == '__main__': example_import_mesh_from_arrays() ``` -------------------------------- ### Configure Filter Parameters and Percentage Values Source: https://context7.com/cnr-isti-vclab/pymeshlab/llms.txt Demonstrates the use of specific parameter types including iteration counts, absolute values, and PercentageValue for relative mesh dimension operations. ```python import pymeshlab ms = pymeshlab.MeshSet() ms.load_new_mesh("noisy_scan.ply") # Apply smoothing with iteration count parameter ms.apply_coord_laplacian_smoothing(stepsmoothnum=10) # Use PercentageValue for size-relative operations # Remove components with diameter less than 50% of mesh diagonal p = pymeshlab.PercentageValue(50) ms.meshing_remove_connected_component_by_diameter(mincomponentdiag=p) # Alternatively use PureValue for absolute measurements av = pymeshlab.PureValue(0.5) # 0.5 units ms.meshing_remove_connected_component_by_diameter(mincomponentdiag=av) # Apply remeshing with multiple parameters ms.meshing_isotropic_explicit_remeshing() # Compute and colorize by quality ms.compute_scalar_by_aspect_ratio_per_face() ms.compute_color_from_scalar_per_face() ms.save_current_mesh("processed_mesh.ply") ``` -------------------------------- ### Configure OpenGL settings Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/changelog.rst Allows enabling CPU-based OpenGL rendering, which is useful for environments where hardware acceleration is unavailable. ```python import pymeshlab # Enable CPU OpenGL on Windows pymeshlab.use_cpu_opengl() ``` -------------------------------- ### Initialize and Process Meshes in Python Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/README.md Basic usage of the MeshSet class to load, manipulate, and save 3D meshes. It demonstrates importing the library, initializing the mesh set, and applying filters. ```python import pymeshlab ms = pymeshlab.MeshSet() ms.load_new_mesh('airplane.obj') ms.generate_convex_hull() ms.save_current_mesh('convex_hull.ply') ms.create_noisy_isosurface(resolution=128) ``` -------------------------------- ### Load and Process Meshes with MeshSet Source: https://context7.com/cnr-isti-vclab/pymeshlab/llms.txt Demonstrates loading an MLP project, processing all meshes by removing duplicate vertices, and saving the project. ```python import pymeshlab ms = pymeshlab.MeshSet() # Load MLP project (MeshLab project with more metadata) ms.load_project("full_project.mlp") print(f"Total meshes: {ms.mesh_number()}") # Process all meshes for i in range(ms.mesh_number()): ms.set_current_mesh(i) ms.meshing_remove_duplicate_vertices() # Save as MLP project ms.save_project("output_project.mlp") ``` -------------------------------- ### Load JPG Image (Python) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/io_format_list.rst Loads a JPG image file. Requires the file_name parameter specifying the path to the JPG image. ```python import pymeshlab mshell = pymeshlab.MeshSet() mshell.load_new_raster('image.JPG') ``` -------------------------------- ### Surface Reconstruction Algorithms Source: https://context7.com/cnr-isti-vclab/pymeshlab/llms.txt Demonstrates three surface reconstruction methods: Ball Pivoting Algorithm, Screened Poisson Reconstruction, and VCG Reconstruction, for converting point clouds to meshes. Each method is applied to a loaded point cloud and the result is saved. ```python import pymeshlab ms = pymeshlab.MeshSet() ms.load_new_mesh("point_cloud.ply") # Ball Pivoting Algorithm - good for clean point clouds ms.generate_surface_reconstruction_ball_pivoting() ms.save_current_mesh("ball_pivoting_result.ply") # Screened Poisson Reconstruction - good for noisy data with normals ms.set_current_mesh(0) # Go back to original point cloud ms.generate_surface_reconstruction_screened_poisson( depth=10, # Octree depth (higher = more detail) preclean=True # Clean duplicates before reconstruction ) ms.save_current_mesh("poisson_result.ply") # VCG Reconstruction ms.set_current_mesh(0) ms.generate_surface_reconstruction_vcg() ms.save_current_mesh("vcg_result.ply") ``` -------------------------------- ### Load TIF Image (Python) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/io_format_list.rst Loads a TIF image file. Requires the file_name parameter specifying the path to the TIF image. ```python import pymeshlab mshell = pymeshlab.MeshSet() mshell.load_new_raster('image.TIF') ``` -------------------------------- ### Load PNG Image (Python) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/io_format_list.rst Loads a PNG image file. Requires the file_name parameter specifying the path to the PNG image. ```python import pymeshlab mshell = pymeshlab.MeshSet() mshell.load_new_raster('image.PNG') ``` -------------------------------- ### Configure Depth Peeling Parameters Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/filter_list.rst Parameters used to control the depth peeling process, which determines how rays traverse mesh layers to calculate intersections. ```python peelingiteration = 10 peelingtolerance = 1e-07 coneangle = 120 removefalse = True removeoutliers = False ``` -------------------------------- ### Select Convex Hull Visible Points Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/filter_list.rst Selects visible points within the convex hull of a point cloud from a given viewpoint. It uses the Qhull library and an algorithm that determines visibility without explicit surface reconstruction. ```python import pymeshlab ms = pymeshlab.MeshSet() ms.load_new_mesh('input.ply') # Select visible points with default parameters ms.compute_selection_of_visible_convex_hull_per_vertex() # Select visible points with custom radius threshold and viewpoint custom_viewpoint = [1.0, 2.0, 3.0] ms.compute_selection_of_visible_convex_hull_per_vertex(radiusthreshold=0.5, viewpoint=custom_viewpoint) # Use camera viewpoint ms.compute_selection_of_visible_convex_hull_per_vertex(usecamera=True) ms.save_new_mesh('output.ply') ``` -------------------------------- ### Perform Mesh Element Sampling Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/filter_list.rst Creates a point cloud by sampling specific mesh elements (vertices, edges, or faces) uniformly. Users define the element type and the total number of samples to generate. ```python sampling = 'Vertex' # or 0, 1, 2 samplenum = 0 ``` -------------------------------- ### Load MeshLab Projects (MLP/ALN) with PyMeshLab Source: https://context7.com/cnr-isti-vclab/pymeshlab/llms.txt Shows how to load MeshLab project files, specifically ALN (alignment) projects, which can contain multiple meshes with associated transformations and metadata. This allows for loading complex scenes into PyMeshLab. ```python import pymeshlab ms = pymeshlab.MeshSet() # Load ALN project (contains multiple aligned meshes) ms.load_project("scan_alignment.aln") print(f"Meshes loaded from ALN: {ms.mesh_number()}") ``` -------------------------------- ### Save Mesh to U3D Format (Python) Source: https://github.com/cnr-isti-vclab/pymeshlab/blob/main/docs/io_format_list.rst Saves a mesh to the U3D file format. Supports saving vertex colors, face colors, and wedge texture coordinates. Compression and camera parameters can be configured. ```python import pymeshlab mshell = pymeshlab.MeshSet() mshell.load_new_mesh('input.obj') mshell.save_u3d(file_name='output.U3D', save_vertex_color=True, save_face_color=True, save_wedge_texcoord=True, compression_val=500) ```