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.

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.

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