HeightMapShape3D

继承: Shape3D < Resource < RefCounted < Object

用于物理碰撞的3D高度图形状。

描述

一个用于物理的3D高度图形状。通常用于为ColliderShape提供形状。这对于地形很有用,但它有局限性,因为悬垂部分(如洞穴)无法存储。HeightMapShape3D中的孔洞是通过在所需区域的点上赋予非常低的值来创建的。

性能:HeightMapShape3D在检查碰撞时比ConcavePolygonShape3D更快,但比基本形状如BoxShape3D慢得多。

使用Image引用也可以构建高度图碰撞形状:

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)

属性

PackedFloat32Array

map_data

PackedFloat32Array(0, 0, 0, 0)

int

map_depth

2

int

map_width

2

方法

float

get_max_height() const

float

get_min_height() const

void

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


属性说明

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

高度映射数据。数组的大小必须等于map_width乘以map_depth

提示: 返回的数组是副本,对其进行的任何修改都不会更新原始属性值。有关更多详细信息,请参阅 PackedFloat32Array .


int map_depth = 2 🔗

  • void set_map_depth(value: int)

  • int get_map_depth()

高度图深度的顶点数。更改此项将调整map_data的大小。


int map_width = 2 🔗

  • void set_map_width(value: int)

  • int get_map_width()

高度图宽度的顶点数。更改此项将调整map_data的大小。


方法说明

float get_max_height() const 🔗

返回map_data中的最大高度值。仅在map_data更改时重新计算。


float get_min_height() const 🔗

返回map_data中的最小高度值。仅在map_data更改时重新计算。


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

使用从Image引用读取的数据更新map_data。自动调整高度图map_widthmap_depth以适应完整的图像宽度和高度。

图像需要在Image.FORMAT_RF(32位)、Image.FORMAT_RH(16位)或Image.FORMAT_R8(8位)。

每个图像像素在0.0(黑色像素)到1.0(白色像素)的范围内作为浮点数读入。该范围值被重新映射到height_minheight_max以形成最终的高度值。