Get Mesh ValuesΒΆ

This example shows how to extract informations like vertex coordinates or vertex index incident to a face from a Mesh contained in a MeshSet, through numpy arrays.

This script can be executed by running the following command:

pytest --pyargs pymeshlab -k 'get_mesh_values'


import pymeshlab

def example_get_mesh_values():
    # lines needed to run this specific example
    from . import samples_common
    base_path = samples_common.samples_absolute_path()
    output_path = samples_common.test_output_path()

    # create a new MeshSet
    ms = pymeshlab.MeshSet()

    ms.load_new_mesh(base_path + 'chameleon.pts')

    # applying some filters...
    ms.apply_filter('parametrization_trivial_per_triangle', textdim=1024)
    ms.save_current_mesh(output_path + 'chameleon_simplified.obj')
    ms.apply_filter('transfer_vertex_color_to_texture', textname='chameleon_simplified.png')

    # get a reference to the current mesh
    m = ms.current_mesh()

    # get numpy arrays of vertices and faces of the current mesh
    vertex_array_matrix = m.vertex_matrix()
    face_array_matrix = m.face_matrix()