pytuflow.XMDF.to_gltf

Contents

pytuflow.XMDF.to_gltf#

XMDF.to_gltf(output_path, mesh_geometry='', time=-1, vertex_colour=(), uv_projection_extent=(), location_ref=None)#

Exports the mesh to a glTF 2.0 file for visualisation in compatible software. Both .gltf and .glb formats are supported.

Experimental Feature

gLTF export is an experimental feature and may not work for all formats and drivers. It may also be modified without warning in future releases.

Parameters:
  • output_path (Path | str) – The output file path for the glTF file.

  • mesh_geometry (str, optional) – The data type to use for the mesh geometry, e.g. "water level". If not provided, the base mesh geometry will be used e.g. this will be the "Bed Elevation" for XMDF results.

  • time (float | datetime) – The time to export the data for.

  • vertex_colour (Array[str], optional) –

    The provided data types will be exported into the mesh vertex colours. This allows a maximum of 3 data types only, one in the red channel, blue channel, and green channel. Vector types require 2 channels and should use a suffix with either "-x" or "-y" (e.g. "Vector Velocity-x" for the x vector component).

    The data types will be re-mapped to the 0-1 range for the colour channels by using the following formula
    packed_value = (value - value_min) / (value_max - value_min).
    The value_min and value_max are obtained using the minimum() and maximum() methods.
    An example usage would be ["Depth", "Vector Velocity-x", "Vector Velocity-y"] to pack depth into the red channel, velocity x into green, and velocity y into blue.

  • uv_projection_extent (Array[float], optional) – The extent to use for UV projection of textures onto the mesh. The format is (min_x, min_y, max_x, max_y). If not provided, the mesh bounding box will be used except for TUFLOW HPC/Classic XMDF results which will use the model domain extent as defined in the .2dm.

  • location_ref (Mesh, optional) – The location reference to use when setting the geometry origin. By default, the mesh bounding box is used to set the geometry origin (it uses the centre of the bounding box). Another mesh result can be used to define the origin instead, which is useful when exporting multiple meshes that need to be aligned in 3D space.

Examples

The examples below show images of importing the exported glTF files into Blender for visualisation.

Export an XMDF bed elevation:

>>> from pytuflow import XMDF
>>> xmdf = XMDF('/path/to/result.xmdf')
>>> xmdf.to_gltf('/path/to/output/bed_elevation.glb')
XMDF Bed Elevation in Blender
Export the maximum water level with the depth results in the vertex colours:
>>> xmdf.to_gltf(
    output_path='/path/to/output/max_water_level.glb',
    mesh_geometry='max water level',
    vertex_colour=['max depth']
)
XMDF Max Water Level in Blender
Export DEM_Z check file and use the XMDF result as a location reference so that they will align in local space.
>>> from pytuflow import Grid
>>> dem_z = Grid('/path/to/check/DEM_Z.tif')
>>> dem_z.to_mesh().to_gltf(
    output_path='/path/to/check/dem_z.glb',
    location_ref=xmdf
)
XMDF DEM_Z and Max Water Level in Blender XMDF DEM_Z and Max Water Level in Blender