Importing & exporting meshes#

Working with meshes and point clouds often involves exchanging data with other software tools. For example, a mesh may be created from medical images using dedicated 3D reconstruction software and then imported into HelloTriangle for further manipulation or analysis. Conversely, HelloTriangle can be used to generate new meshes, either from scratch or starting from imported models, which users may then want to export for use in other applications such as finite element simulation packages or 3D printing workflows. This section explains how to import and export meshes in HelloTriangle.

How to import a mesh?#

To read a mesh file, you first need to manually upload the specific file to the online HelloTriangle application. Once the file is uploaded, it can be imported into your online script as follows:

mymesh = load('mymesh.stl')

This returns a Mesh or HybridMesh object, which can then be rendered using:

draw(mymesh)

The table in section Supported file formats and element types shows the file formats currently supported for import. Some file formats may contain element types that HelloTriangle does not yet support. In this case, an error will be raised.

Warning

Rendering a HybridMesh is not possible if some included element types have a different level or dimensionality (e.g. combination of triangles (=2D) and hexahedral (=3D) elements).

Warning

There is a file size limit of 50 MB for uploads to the platform.

Importing fields#

When a mesh is imported, any fields stored in the file are automatically attached to the resulting Mesh or HybridMesh object. Fields can store per-node or per-element data, such as distances, temperatures, or stresses.

mymesh = load("mymesh.vtu")

# List all available fields
print(mymesh.fields)

# Access a specific field
print(mymesh.fields["distance"])

# Retrieve the raw data array of a field
data = mymesh.fields["distance"].data
print(data)
  • Node fields (type node) have one value per node.

  • Element fields (type elem) have one value per element.

  • Element-nodal fields (type elemn) have one value per node for each element.

  • The printed field object shows its type, shape, and other metadata, e.g.:

    Field ‘distance’, type ‘node’, shape (98,), n_nodes=98, n_elems=96, nplex=4 [0. 0.25 0.5 0.75 1. …]

Note

If the file does not contain any fields, the mesh object will have an empty fields dictionary.

Note

In case of HybridMesh objects, only fields of type node or elem are supported. In addition, the field data needs to be available for all nodes and all elements. If not, the field data will not be available.

How to export a mesh?#

To export a mesh, you can use the following command in your script:

save(mymesh, "mymesh.vtk")

Here, mymesh is the Mesh object that you created, and “mymesh.vtk” is the name of the file to be saved. Once generated, the file can be downloaded from the platform.

For file formats that support both ASCII and binary output, you may specify the output mode explicitly using the binary argument:

save(mymesh, "mymesh.stl", binary=False)

If the binary argument is omitted, binary output is used when supported by the file format; otherwise ASCII output is used.

Important

If you explicitly request a binary or ASCII mode that is not supported by the selected file format, an error is raised.

Important

You must include the appropriate file extension in the file name (e.g., .vtk or .stl). Omitting the extension will result in an error.

Exporting fields#

HelloTriangle meshes can contain fields (data associated with nodes or elements). By default, all fields are exported when saving a mesh.

You can restrict or disable field export using the fields argument.

# Export only selected fields
save(
    mymesh,
    "mymesh.vtu",
    fields=["temperature", "stress"]
)
# Export all available fields (default behavior)
save(mymesh, "mymesh.vtu", fields="all")
# Export no fields
save(mymesh, "mymesh.vtu", fields=None)

Accepted values for fields:

  • "all" → export all fields (default)

  • list of field names → export selected fields

  • None or [] → export no fields

Supported file formats and element types#

The table below summarizes the mesh file formats that can currently be imported into or exported from HelloTriangle, as well as the associated element type(s) that are supported for that file format.

Some file formats exist in both ASCII and binary versions (e.g., STL). Both variants are supported where indicated. ASCII formats are human-readable and generally easier to inspect or edit, while binary formats are more compact and faster to load.

For more detailed information about the different element types supported in HelloTriangle, see the Element types.

File Format

point

line2

tri3

quad4

tet4

wedge6

hex8

INP (ASCII)

NA

Yes

Yes

Yes

Yes

Yes

Yes

OFF (ASCII)

Yes

NA

Yes

NA

NA

NA

NA

OBJ (ASCII)

Yes

NA

Yes

Yes

NA

NA

NA

PLY (ASCII & binary)

Yes

Yes

Yes

Yes

NA

NA

NA

STL (ASCII & binary)

NA

NA

Yes

NA

NA

NA

NA

VTK (binary)

NA

Yes

Yes

Yes

Yes

Yes

Yes

VTU (binary)

NA

Yes

Yes

Yes

Yes

Yes

Yes