newton.geometry.heightfield_to_mesh#

newton.geometry.heightfield_to_mesh(heightfield, extent_x, extent_y, center_x=0.0, center_y=0.0, ground_z=0.0)[source]#

Convert a 2D heightfield array to a watertight triangle mesh.

Creates a closed mesh with top surface (from heightfield), bottom surface (at ground_z), and side walls connecting them. Each grid cell becomes two triangles.

Parameters:
  • heightfield (ndarray) – (grid_size_x, grid_size_y) array of Z heights for top surface

  • extent_x (float) – Physical size in X direction (meters)

  • extent_y (float) – Physical size in Y direction (meters)

  • center_x (float) – Center X coordinate (default: 0.0)

  • center_y (float) – Center Y coordinate (default: 0.0)

  • ground_z (float) – Z coordinate of bottom surface (default: 0.0)

Returns:

tuple of (vertices, indices) where vertices is (N, 3) float32 array and indices is (M,) int32 array of triangle indices (flattened)

Raises:
  • ValueError – If heightfield is not a 2D array

  • ValueError – If heightfield dimensions are smaller than 2x2

  • ValueError – If extent_x or extent_y are not positive

Return type:

tuple[ndarray, ndarray]