Documentation
¶
Overview ¶
A 3D heightmap shape, intended for use in physics. Usually used to provide a shape for a graphics.gd/classdb/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: graphics.gd/classdb/HeightMapShape3D is faster to check collisions against than graphics.gd/classdb/ConcavePolygonShape3D, but it is significantly slower than primitive shapes like graphics.gd/classdb/BoxShape3D.
A heightmap collision shape can also be built by using an graphics.gd/classdb/Image reference:
package main import ( "graphics.gd/classdb/HeightMapShape3D" "graphics.gd/classdb/Image" "graphics.gd/classdb/Resource" "graphics.gd/classdb/Texture2D" "graphics.gd/variant/Float" ) func ExampleHeightMapShape3D(shape HeightMapShape3D.Instance) { var heightmap_texture = Resource.Load[Texture2D.Instance]("res://heightmap_image.exr") var heightmap_image = heightmap_texture.GetImage() heightmap_image.Convert(Image.FormatRf) var height_min Float.X = 0.0 var height_max Float.X = 10.0 shape.UpdateMapDataFromImage(heightmap_image, height_min, height_max) }
Index ¶
- type Advanced
- type Any
- type Extension
- type ID
- type Instance
- func (self Instance) AsHeightMapShape3D() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsResource() Resource.Instance
- func (self Instance) AsShape3D() Shape3D.Instance
- func (self Instance) GetMaxHeight() Float.X
- func (self Instance) GetMinHeight() Float.X
- func (self Instance) ID() ID
- func (self Instance) MapData() []float32
- func (self Instance) MapDepth() int
- func (self Instance) MapWidth() int
- func (self Instance) SetMapData(value []float32)
- func (self Instance) SetMapDepth(value int)
- func (self Instance) SetMapWidth(value int)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) UpdateMapDataFromImage(image Image.Instance, height_min Float.X, height_max Float.X)
- func (self Instance) Virtual(name string) reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsHeightMapShape3D ¶
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
func (*Extension[T]) AsResource ¶
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.HeightMapShape3D
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsHeightMapShape3D ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsResource ¶
func (Instance) GetMaxHeight ¶
Returns the largest height value found in Instance.MapData. Recalculates only when Instance.MapData changes.
func (Instance) GetMinHeight ¶
Returns the smallest height value found in Instance.MapData. Recalculates only when Instance.MapData changes.
func (Instance) SetMapData ¶
func (Instance) SetMapDepth ¶
func (Instance) SetMapWidth ¶
func (Instance) UpdateMapDataFromImage ¶
func (self Instance) UpdateMapDataFromImage(image Image.Instance, height_min Float.X, height_max Float.X)
Updates Instance.MapData with data read from an graphics.gd/classdb/Image reference. Automatically resizes heightmap Instance.MapWidth and Instance.MapDepth to fit the full image width and height.
The image needs to be in either [Image.FormatRf] (32 bit), [Image.FormatRh] (16 bit), or [Image.FormatR8] (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.