Importing & exporting#

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 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

Some file formats may contain more than one element type (e.g., a combination of triangular and quadrilateral elements). Only elements of a single type will be included in the resulting Mesh object, meaning that only part of the original mesh will be imported.

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 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.

  • 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.

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 options, you can specify the format explicitly using the binary argument:

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

By default, binary=True. So if you want a binary file, there is no need to set this argument.

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 and sets#

HelloTriangle meshes can contain fields (data associated with nodes or elements) and sets (groups of nodes or elements). Both can be exported along with the mesh for use in other applications such as finite element solvers or visualization tools.

Exporting fields#

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

Exporting node and element sets#

Meshes can contain sets, which may be either:

  • node sets (groups of node indices), or

  • element sets (groups of element indices)

Sets are stored directly on the Mesh object and are exported by default if the selected file format supports them.

# Export all sets (default behavior)
save(mymesh, "mymesh.inp")
# Export only selected sets
save(
    mymesh,
    "mymesh.inp",
    sets=["left_boundary", "solid_material"]
)
# Export no sets
save(mymesh, "mymesh.inp", sets=None)

Accepted values for sets:

  • "all" → export all available sets (default)

  • list of set names → export selected sets

  • None or [] → export no sets

Both node sets and element sets are handled automatically; no distinction is required when exporting.

Note

For file formats that do not support fields or sets, these arguments are silently ignored.

Supported file formats and element types#

The table below summarizes the 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