How to use a heightmap on a collision sibling

Godot Version

4.3

Question

I am using a noise texture to apply a height map to a mesh in order to have procedurally generate terrain. I am able to affect the mesh, but I do not know how to make this height map apply work on the collision sibling. So far, I have made a HeightMapShapd3D, but I do not know how to pass the actual height map into it. Is there anywhere I can find this in documentation?

On the MeshInstance3D if it has the exact same shape as the intended heightmap, you can create a StaticBody3D or CollisionShape3D node of it in the editor. Or in code you can create StaticBody3D nodes based off it:

$MeshInstance3D.create_trimesh_collision()
or
$MeshInstance3D.create_convex_collision()
or
$MeshInstance3D.create_multiple_convex_collisions()

And then you could convert to CollisionShape3D if you don’t want to use them as StaticBody3D nodes:

func make_heightmap_collision(heightmap_mesh: MeshInstance3D) -> void:
    var heightmap_collision: CollisionShape3D = CollisionShape3D.new()
    heightmap_collision.shape = heightmap_mesh.mesh.create_trimesh_shape()
    heightmap_mesh.get_parent().add_child(heightmap_collision) #Prevent orphaning

With HeightMapShape3D you assign the same procgen texture as the mesh in al update_map_data_from_image() call and then do similar CollisionShape3D code handling as above except instead of setting the CollisionShape3D’s shape property to a MeshInstance3D, you set it to the HeightMapShape3D.

Here is the documentation, you can give it a image and call update_map_data_from_image