HeightMapShape3D
继承: Shape3D
< Resource
< RefCounted
< Object
A 3D height map shape used for physics collision.
描述
A 3D heightmap shape, intended for use in physics. Usually used to provide a shape for a CollisionShape3D
. This is useful for terrain, but it is limited as overhangs (such as caves) cannot be stored. Holes in a HeightMapShape3D are created by assigning very low values to points in the desired area.
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 build by using an Image
reference:
var heightmap_texture: Texture = ResourceLoader.load("res://heightmap_image.exr")
var heightmap_image: Image = heightmap_texture.get_image()
heightmap_image.convert(Image.FORMAT_RF)
var height_min: float = 0.0
var height_max: float = 10.0
update_map_data_from_image(heightmap_image, height_min, height_max)
属性
方法
float | get_max_height ( ) const1 |
float | get_min_height ( ) const1 |
void | update_map_data_from_image ( image: Image , height_min: float , height_max: float ) |
属性说明
PackedFloat32Array
map_data = PackedFloat32Array(0, 0, 0, 0)
void
set_map_data ( value:PackedFloat32Array
)PackedFloat32Array
get_map_data ( )
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
Number of vertices in the depth of the height map. Changing this will resize the map_data
.
int
map_width = 2
Number of vertices in the width of the height map. Changing this will resize the map_data
.
方法说明
float
get_max_height ( ) const1
Returns the largest height value found in map_data
. Recalculates only when map_data
changes.
float
get_min_height ( ) const1
Returns the smallest height value found in map_data
. Recalculates only when map_data
changes.
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.
本方法通常需要用户覆盖才能生效。
本方法无副作用,不会修改该实例的任何成员变量。
本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。
本方法用于构造某个类型。
调用本方法无需实例,可直接使用类名进行调用。
本方法描述的是使用本类型作为左操作数的有效运算符。
这个值是由下列位标志构成位掩码的整数。
无返回值。