HeightMapShape3D

Hérite de : Shape3D < Resource < RefCounted < Object

A 3D height map shape used for physics collision.

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 @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.

Performance: 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:

var heightmap_texture = ResourceLoader.load("res://heightmap_image.exr")
var heightmap_image = heightmap_texture.get_image()
heightmap_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)

Propriétés

PackedFloat32Array

map_data

PackedFloat32Array(0, 0, 0, 0)

int

map_depth

2

int

map_width

2

Méthodes

float

get_max_height() const

float

get_min_height() const

void

update_map_data_from_image(image: Image, height_min: float, height_max: float)


Descriptions des propriétés

PackedFloat32Array map_data = PackedFloat32Array(0, 0, 0, 0) 🔗

Height map data. The array's size must be equal to map_width multiplied by map_depth.

Note: The returned array is copied and any changes to it will not update the original property value. See PackedFloat32Array for more details.


int map_depth = 2 🔗

  • void set_map_depth(value: int)

  • int get_map_depth()

Number of vertices in the depth of the height map. Changing this will resize the map_data.


int map_width = 2 🔗

  • void set_map_width(value: int)

  • int get_map_width()

Number of vertices in the width of the height map. Changing this will resize the map_data.


Descriptions des méthodes

float get_max_height() const 🔗

Renvoie la plus grande valeur de hauteur trouvée dans map_data. Recalcule seulement lorsque map_data change.


float get_min_height() const 🔗

Renvoie la plus petite valeur de hauteur trouvée dans map_data. Recalcule seulement lorsque map_data change.


void update_map_data_from_image(image: Image, height_min: float, height_max: float) 🔗

Met à jour map_data avec les données lues à partir d'une référence Image. Redimensionne automatiquement map_width et map_depth de la heightmap pour faire correspondre à la largeur et à la hauteur complètes de l'image.

L'image doit être en format Image.FORMAT_RF (32 bit), Image.FORMAT_RH (16 bits), ou Image.FORMAT_R8 (8 bits).

Chaque pixel d'image est lu comme un flottant sur une plage de 0.0 (pixel noir) à 1.0 (pixel blanc). Cette valeur de plage est réaffectée à height_min et height_max pour former la valeur de hauteur finale.

Note : Il est recommandé d'utiliser une heightmap avec des données 16 bits ou 32 bits, stockées en format EXR ou HDR. L'utilisation de données de hauteur de 8 bits, ou un format comme le PNG que Godot importe en 8 bits, entraînera un terrain en terrasses.