newton.utils.rasterize_mesh_to_heightfield#
- newton.utils.rasterize_mesh_to_heightfield(mesh, resolution, *, max_cells_per_axis=4096)[source]#
Rasterize a triangle mesh into a heightfield elevation grid.
Rays are cast straight down onto the mesh on a regular grid spanning the mesh’s XY bounding box. The grid follows Newton’s heightfield convention (see
Heightfield):heights[row, col]samples the surface atx = x_min + col * dx(columns map to X) andy = y_min + row * dy(rows map to Y). Rays that miss the mesh fall back to the mesh’s minimum Z so that nothing collides in gaps. This is only meaningful for surfaces that are single-valued in Z (e.g. locomotion terrain).- Parameters:
mesh (Mesh) – Triangle mesh to rasterize. Its vertices are taken in their current frame; transform the mesh into world space beforehand if needed.
resolution (float) – Horizontal grid spacing [m]. Smaller values preserve more detail at the cost of a larger grid.
max_cells_per_axis (int) – Upper bound on grid rows/columns. If the mesh extent would exceed this, the effective resolution is coarsened to fit.
- Returns:
A tuple
(heights, bounds)whereheightsis a(nrow, ncol)float32 array of world-space elevations [m] andboundsis the mesh’s XY bounding box as(x_min, y_min, x_max, y_max)[m].- Return type: