mohsenph69 / Godot-MTerrain-plugin

A GDExtension plugin which give godot the ability to produce highly optimized Terrain for Open world games
MIT License
372 stars 19 forks source link

Editing terrain in-game #30

Open matthewhilton opened 3 months ago

matthewhilton commented 3 months ago

I want to be able to edit the terrain in-game. I see some useful methods, such as:

But after calling set_height_by_pixel, nothing seems to happen. Is there another update function I need to call to apply this change ?

mohsenph69 commented 3 months ago

You know All of these is possible but these need more work I explain down here!

So about this, you can use the set_height_by_pixel to update a heightmap pixel! but the problem now is that this data will updated only on RAM, for sending this information to GPU, you need to call a function which is not expose yet, that is update_all_dirty_image_texture ! This method exist in MGrid class and basically any image in a region which is dirty (its pixel is changed) will be updated after you call this function! I will expose that in future version of MTerrain! you can use that even in your game, but this is not something which you want to call every frame, this is heavy, but for some terrain change which is not every frame is OK! (The best way to optimize this is to make region size smaller, By this every update a smaller piece of heightmap will pass to GPU memory)

Also in MTerrian there is a layer system, basically you can change the heightmap on and editable layer without touching main heightmap! so you can put the layer data directory path in the save folder of game, also before each change in pixel you should activate the layer which you want to change by set_active_layer_by_name!

And beside this we should also update collission shape for terrain which has been changed! This is not something difficult I can add this also in future version, But I am not sure if godot physcis system can handle that and how heavy that will become!

At last I think this will be possible I will work on it in close future!

mohsenph69 commented 3 months ago

Almost done!

https://github.com/mohsenph69/Godot-MTerrain-plugin/assets/52196206/ca48749b-464f-4996-8dea-b985a3270e7e