porescene.io module

Reading and writing of mesh and geometry files.

porescene.io.mesh2obj(pth_obj, mesh)[source]

Writes one or more meshes to a Wavefront .obj file in text format.

Parameters:
  • pth_obj (Path) – Output path of the OBJ file.

  • mesh (Union[Mesh, Mapping[int, Mesh], Sequence[Mesh]]) – The mesh(es) to write. Pass a single Mesh, or a collection of them to store as separate OBJ objects in one file – e.g. the {label: Mesh} mapping returned by volume2mesh(..., per_label=True). A mapping is written in ascending key order; a sequence keeps its order. Each mesh’s name becomes an o record, and vertices are concatenated with the running index offset that OBJ’s shared, file-global vertex numbering requires. Faces hold 0-based vertex indices (as produced by volume2mesh()); OBJ indices are 1-based, so the values are offset accordingly on write.

Returns:

File path of the written OBJ file.

Return type:

Path

porescene.io.mesh2ply(pth_ply, mesh, binary=True)[source]

Writes a mesh to a Stanford .ply file.

Parameters:
  • pth_ply (Path) – Output path of the PLY file.

  • mesh (Mesh) – The mesh to write. Its faces hold 0-based vertex indices (e.g. from porescene.utility.volume2mesh()); PLY indices are 0-based too, so they are written unchanged. The mesh name is written as a PLY comment.

  • binary (bool) – If True (default), the vertex and face data are written as packed little-endian binary – far smaller and faster to load than the ascii variant produced when False. Defaults to True.

Returns:

File path of the written PLY file.

Return type:

Path