Notebook source code: notebooks/how_to/00_load_mesh_from_file.ipynb
Run it yourself on binder Binder badge

How to load a mesh from a file?#

 In [1]:
import tempfile

import meshio

from geomfum.dataset import NotebooksDataset
from geomfum.shape import PointCloud, TriangleMesh
 In [2]:
dataset = NotebooksDataset()
path = dataset.get_filename("cat-00") #Here you should use the path to your mesh file
mesh = TriangleMesh.from_file(path)

mesh.n_vertices, mesh.n_faces
 Out [2]:
(7207, 14410)

Imagine instead of a mesh, you want to handle point clouds.

(We emulate this use case by writing the above mesh to disk.)

 In [3]:
filename = tempfile.NamedTemporaryFile(mode="w+t", delete=True, suffix=".ply").name

meshio.write(filename, meshio.Mesh(points=mesh.vertices, cells=[]))
 In [4]:
point_cloud = PointCloud.from_file(filename)

point_cloud.n_vertices
 Out [4]:
7207

Further reading#