-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I add detail layer at runtime using GDScript? #442
Comments
I don't think you can do that in a straightforward way, there is no direct API to do this. It was only developped for in-editor usage, so you have to do several steps and investigate. godot_heightmap_plugin/addons/zylann.hterrain/tools/detail_editor/detail_editor.gd Line 106 in 9c6e5c6
The idea is that a detail layer is 2 things:
So adding a detail layer means to create a new map (texture) to HTerrainData in the The code might be this: var node := HTerrainDetailLayer.new()
var map_index := terrain.data._edit_add_map(HTerrainData.CHANNEL_DETAIL)
node.layer_index = map_index
terrain.add_child(node) But if you want to re-use an existing density map: var node := HTerrainDetailLayer.new()
node.layer_index = map_index
terrain.add_child(node) (untested) Note that this doesnt actually create a texture yet, but I think that will happen on the first call to |
So I created a scene containing only a HTerrainDetailLayer node, where I already set the grass texture. Then I have this code in my world generation script:
and I added this set_image function inside the hterrain_data.gd script:
But nothing happens so far. Do you have another hint for me, I think I'm still doing something wrong that I can't get? |
Not really sure what could be wrong here, other than the method you added to I tried the following with the current version and it worked: extends Node
const HTerrain = preload("res://addons/zylann.hterrain/hterrain.gd")
const HTerrainData = HTerrain.HTerrainData
const HTerrainDetailLayer = preload("res://addons/zylann.hterrain/hterrain_detail_layer.gd")
const HTerrainTextureSet = HTerrain.HTerrainTextureSet
func _ready():
var terrain_data := HTerrainData.new()
terrain_data.resize(513)
var detail_map_index := terrain_data._edit_add_map(HTerrainData.CHANNEL_DETAIL)
var detail_map_image := terrain_data.get_image(HTerrainData.CHANNEL_DETAIL, detail_map_index)
for y in detail_map_image.get_height():
for x in detail_map_image.get_width():
# Make some recognizable pattern to confirm that the result comes from here
var d := maxf(cos(x * 0.1) + sin(y * 0.1), 0.0)
detail_map_image.set_pixel(x, y, Color(d, d, d, 1.0))
var terrain := HTerrain.new()
terrain.set_data(terrain_data)
var texture_set := HTerrainTextureSet.new()
texture_set.insert_slot(0)
texture_set.set_texture(0, HTerrainTextureSet.TYPE_ALBEDO_BUMP, load("res://icon.svg"))
terrain.set_texture_set(texture_set)
var detail_layer := HTerrainDetailLayer.new()
detail_layer.layer_index = detail_map_index
terrain.add_child(detail_layer)
add_child(terrain) |
still using Godot 3 :)
The text was updated successfully, but these errors were encountered: