newton.geometry.compute_sdf#

newton.geometry.compute_sdf(mesh_src, shape_type, shape_scale=(1.0, 1.0, 1.0), shape_thickness=0.0, narrow_band_distance=(-0.1, 0.1), margin=0.05, target_voxel_size=None, max_resolution=64, bake_scale=False, verbose=False)[source]#

Compute sparse and coarse SDF volumes for a mesh.

The SDF is computed in the mesh’s unscaled local space. Scale is intentionally NOT a parameter - the collision system handles scaling at runtime, ensuring the SDF and mesh BVH stay consistent and allowing dynamic scale changes.

Parameters:
  • mesh_src (Mesh) – Mesh source with vertices and indices.

  • shape_type (int) – Type of the shape.

  • shape_scale (Sequence[float]) – Scale factors for the mesh. Applied before SDF generation if bake_scale is True.

  • shape_thickness (float) – Thickness offset to subtract from SDF values.

  • narrow_band_distance (Sequence[float]) – Tuple of (inner, outer) distances for narrow band.

  • margin (float) – Margin to add to bounding box. Must be > 0.

  • target_voxel_size (float | None) – Target voxel size for sparse SDF grid. If None, computed as max_extent/max_resolution.

  • max_resolution (int) – Maximum dimension for sparse SDF grid when target_voxel_size is None. Must be divisible by 8.

  • bake_scale (bool) – If True, bake shape_scale into the SDF. If False, use (1,1,1) scale.

  • verbose (bool) – Print debug info.

Returns:

  • sdf_data: SDFData struct with pointers and extents

  • sparse_volume: wp.Volume object for sparse SDF (keep alive for reference counting)

  • coarse_volume: wp.Volume object for coarse SDF (keep alive for reference counting)

  • block_coords: List of wp.vec3us tile coordinates for allocated blocks in the sparse volume

Return type:

Tuple of (sdf_data, sparse_volume, coarse_volume, block_coords) where

Raises:

RuntimeError – If CUDA is not available.