pyblenderSDIC.meshes.TriangleMesh3D.from_meshio#

classmethod TriangleMesh3D.from_meshio(mesh: Mesh) TriangleMesh3D[source]#

Create a TriangleMesh3D instance from a meshio.Mesh object.

The following fields are extracted:

  • mesh.points → vertices

  • mesh.cells → triangles

  • mesh.point_data → vertex_normals

  • mesh.cell_data → triangle_normals, triangle_centroids, triangle_areas, uvmap

import meshio
from pyblenderSDIC.mesh import TriangleMesh3D

# Read the mesh from a file
mesh = meshio.read("path/to/mesh.vtk")
# Create a TriangleMesh3D instance from the meshio object
mesh = TriangleMesh3D.from_meshio(mesh)

Meshio Structure#

The points attribute of the meshio object is expected to be a NumPy array of shape (N, 3), where N is the number of vertices and each row contains the coordinates of a vertex in 3D space.

The cells attribute of the meshio object is expected to be a list with only one element, This element should be a dictionary with the triangle key and a NumPy array of shape (M, 3) as value, where M is the number of triangles and each row contains the indices of the vertices that form a triangle.

The point_data attribute of the meshio object can contain the normals of the vertices under the key "normals".

The cell_data attribute of the meshio object can contain the normals of the triangles under the key "normals", the centroids of the triangles under the key "centroids", the areas of the triangles under the key "areas", and the UV map under the key "uvmap".

param mesh:

A meshio.Mesh object containing the mesh data.

type mesh:

meshio.Mesh

returns:

A TriangleMesh3D instance created from the meshio object.

rtype:

TriangleMesh3D