Painting a color(or texture) at runtime on Zylann HeightMap Plugin

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By siamak-s

Is it possible?!
I found hterrain_brush.gd file for painting functions, I instanciate that and call paint method, but I get Assertion Failed error.

siamak-s | 2019-08-05 17:40

It is possible (even without brush), but I never tested using the brush in game and maybe it’s not exactly fit to your needs. Which error are you getting?

Zylann | 2019-08-06 12:46

I use these two line for painting a color on terrain, but I get “Assertion Failed” on hterrain_brush.gd Line 536. It seems CHANNEL_COLOR is not loaded or accessible that momemt.

var brush = preload("res://addons/zylann.hterrain/hterrain_brush.gd").new()
brush.paint($HTerrain, collsioin_info.position.x, collsioin_info.position.z, brush.MODE_COLOR)

siamak-s | 2019-08-07 05:04

Looks like only the heights can be accessed at runtime, actually. Colors are not because most of the time it is not really needed so no point wasting a large amount of memory.

I need to add an option somewhere to make it so channels stay in memory at runtime.
At the moment, if want to access it, I think you should comment out the if located in hterrain_data.gd line 1077: https://github.com/Zylann/godot_heightmap_plugin/blob/30f0e6022903825aef2b006e5abb97065668ec49/addons/zylann.hterrain/hterrain_data.gd#L1077

Zylann | 2019-08-07 18:08

Another error on hterrain_brush.gd Line 283 occured.
Invalid call. Nonexistent function ‘get_width’ in base ‘Nil’.

siamak-s | 2019-08-08 16:04

The brush doesn’t initialize its shape by default. You need to specify it by calling set_radius(radius in pixels).

Zylann | 2019-08-08 18:09

Thanks Zylann! Finally It works!
For someone who read later, after commenting if located in line 1077 of hterrain_data.gd with following lines we could paint terrain at runtime.

var brush = preload("res://addons/zylann.hterrain/hterrain_brush.gd").new()
brush.set_color(Color.red)
brush.set_radius(10)
brush.paint($HTerrain, collsioin_info.position.x, collsioin_info.position.z, brush.MODE_COLOR)

I think if you add an option somewhere for loading channels to memory at runtime (so does not need to change addon source files), It could be a good temporal solution for https://forum.godotengine.org/49476/apply-objects-movement-effect-on-terrain (more specific on texture painting)

siamak-s | 2019-08-08 22:20

Good to hear it works fine :slight_smile:
However careful with the other question you linked, modifying the terrain to leave skidmarks is extremely expensive. Decals or simple mesh strips are often preferred to do this.

Zylann | 2019-08-08 22:24

Would you please give me some link or resources about them?
I found this https://github.com/Mr-Slurpy/Screen-Space-Decals, but I don’t know how actually its works., and are its known limitations serious or not?

siamak-s | 2019-08-10 06:15

I never used this in Godot yet, so I don’t know more than you do.

Zylann | 2019-08-10 14:36

Anyway very thanks Zylann!

siamak-s | 2019-08-10 18:11

hi Zylann, ive got a similar problem:
How can i modify the terrain while runtime?

theMX89 | 2021-07-15 12:33

:bust_in_silhouette: Reply From: siamak-s

Comment the if which is located in line 1077 of hterrain_data.gd and then use following lines:

var brush = preload("res://addons/zylann.hterrain/hterrain_brush.gd").new()
brush.set_color(Color.red)
brush.set_radius(10)
brush.paint($HTerrain, collsioin_info.position.x, collsioin_info.position.z, brush.MODE_COLOR)

For more info read above comments.