Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions doc/classes/HeightMapShape3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
A 3D height map shape used for physics collision.
</brief_description>
<description>
A 3D heightmap shape, intended for use in physics. Usually used to provide a shape for a [CollisionShape3D]. This type is most commonly used for terrain with vertices placed in a fixed width grid. Due to the nature of the heightmap, it cannot be used to model overhangs or caves, which would require multiple vertices at the same vertical location. Holes can be punched through the collision by assigning [constant @GDScript.NAN] to the height of the desired vertices (this is supported in both GodotPhysics3D and Jolt Physics). You could then insert meshes with their own separate collision to provide overhangs, caves, and so on.
A 3D height map shape, intended for use in physics to provide a shape for a [CollisionShape3D]. This type is most commonly used for terrain with vertices placed in a fixed width grid.
The height map is represented as a 2D grid of height values, which represent the position of grid points on the Y axis. Grid points are spaced 1 unit apart on the X and Z axes, and the grid is centered on the origin of the [HeightMapShape3D] node. Internally, each grid square is divided into two triangles.
Due to the nature of the height map, it cannot be used to model overhangs or caves, which would require multiple vertices at the same vertical location. Holes can be punched through the collision by assigning [constant @GDScript.NAN] to the height of the desired vertices (this is supported in both GodotPhysics3D and Jolt Physics). You could then insert meshes with their own separate collision to provide overhangs, caves, and so on.
[b]Performance:[/b] [HeightMapShape3D] is faster to check collisions against than [ConcavePolygonShape3D], but it is significantly slower than primitive shapes like [BoxShape3D].
A heightmap collision shape can also be built by using an [Image] reference:
A height map collision shape can also be built by using an [Image] reference:
[codeblocks]
[gdscript]
var heightmap_texture = ResourceLoader.load("res://heightmap_image.exr")
var heightmap_image = heightmap_texture.get_image()
heightmap_image.convert(Image.FORMAT_RF)
var height_map_texture = ResourceLoader.load("res://height_map_image.exr")
var height_map_image = height_map_texture.get_image()
height_map_image.convert(Image.FORMAT_RF)

var height_min = 0.0
var height_max = 10.0

update_map_data_from_image(heightmap_image, height_min, height_max)
update_map_data_from_image(height_map_image, height_min, height_max)
[/gdscript]
[/codeblocks]
[b]Note:[/b] If you need to use a spacing different than 1 unit, you can adjust the [member Node3D.scale] of the shape. However, keep in mind that GodotPhysics3D does not support non-uniform scaling: you'll need to scale the Y axis by the same amount as the X and Z axes, which means the values in [member map_data] will need to be pre-scaled by the inverse of that scale. Also note that GodotPhysics3D does not support scaling at all for dynamic bodies (that is, non-frozen [RigidBody3D]); to use a scaled [HeightMapShape3D] with those, you will need to use Jolt Physics.
</description>
<tutorials>
</tutorials>
Expand All @@ -41,10 +44,10 @@
<param index="1" name="height_min" type="float" />
<param index="2" name="height_max" type="float" />
<description>
Updates [member map_data] with data read from an [Image] reference. Automatically resizes heightmap [member map_width] and [member map_depth] to fit the full image width and height.
Updates [member map_data] with data read from an [Image] reference. Automatically resizes height map [member map_width] and [member map_depth] to fit the full image width and height.
The image needs to be in either [constant Image.FORMAT_RF] (32 bit), [constant Image.FORMAT_RH] (16 bit), or [constant Image.FORMAT_R8] (8 bit).
Each image pixel is read in as a float on the range from [code]0.0[/code] (black pixel) to [code]1.0[/code] (white pixel). This range value gets remapped to [param height_min] and [param height_max] to form the final height value.
[b]Note:[/b] Using a heightmap with 16-bit or 32-bit data, stored in EXR or HDR format is recommended. Using 8-bit height data, or a format like PNG that Godot imports as 8-bit, will result in a terraced terrain.
[b]Note:[/b] Using a height map with 16-bit or 32-bit data, stored in EXR or HDR format is recommended. Using 8-bit height data, or a format like PNG that Godot imports as 8-bit, will result in a terraced terrain.
</description>
</method>
</methods>
Expand Down