HeightMapShape3D

Hereda: Shape3D < Resource < RefCounted < Object

Una forma de mapa de altura 3D utilizada para la colisión física.

Descripción

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)

Propiedades

PackedFloat32Array

map_data

PackedFloat32Array(0, 0, 0, 0)

int

map_depth

2

int

map_width

2

Métodos

float

get_max_height() const

float

get_min_height() const

void

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


Descripciones de Propiedades

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

Datos del mapa de altura. El tamaño del array debe ser igual a map_width multiplicado por 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()

Número de vértices en la profundidad del mapa de altura. Cambiar esto redimensionará map_data.


int map_width = 2 🔗

  • void set_map_width(value: int)

  • int get_map_width()

Número de vértices en el ancho del mapa de altura. Cambiar esto redimensionará map_data.


Descripciones de Métodos

float get_max_height() const 🔗

Devuelve el valor de altura más grande encontrado en map_data. Se vuelve a calcular solo cuando cambia map_data.


float get_min_height() const 🔗

Devuelve el valor de altura más pequeño encontrado en map_data. Se vuelve a calcular solo cuando cambia map_data.


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

Updates map_data with data read from an Image reference. Automatically resizes heightmap map_width and map_depth to fit the full image width and height.

The image needs to be in either Image.FORMAT_RF (32 bit), Image.FORMAT_RH (16 bit), or Image.FORMAT_R8 (8 bit).

Each image pixel is read in as a float on the range from 0.0 (black pixel) to 1.0 (white pixel). This range value gets remapped to height_min and height_max to form the final height value.

Note: 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.