TokisanGames / Terrain3D

A high performance, editable terrain system for Godot 4.
MIT License
2.01k stars 114 forks source link

Implement Non-destructive layer #129

Open SlashScreen opened 1 year ago

SlashScreen commented 1 year ago

I have a somewhat-functional tool for nondestructive terrain editing using stamps, similar to that of the Microverse unity plugin, currently interfacing (buggily) with HTerrain. It generates a heightmap as the process' output. Could there be ways to set regions / update an entire heightmap from GDScript?

TokisanGames commented 1 year ago

Cool. Microverse looks interesting.

Yes. Look at importer.gd which imports user files into the terrain via gdscript.

SlashScreen commented 1 year ago

you mean via img = Terrain3DStorage.load_image(height_file_name, ResourceLoader.CACHE_MODE_IGNORE, r16_range, r16_size) (line 62)? Also, the brush tool must only update a region, right? I'd like to be able to offer real-time feedback in the editor as the user drags the stamps around. How bad of an idea would it be to import an entire new heightmap as the user drags the stamp around, or would it only be possible if I were to calculate diffs somehow between the old heightmap and the new and only update that region? I know that's the Proper way to do it, but that's difficult.

TokisanGames commented 1 year ago

Look at the online help in godot (Shift+F1) for Terrain3DStorage or look at the functions exposed in _bind_methods here: https://github.com/outobugi/Terrain3D/blob/d42c79a47db40db9c2dfce2eedf822ec3203b8df/src/terrain_3d_storage.cpp#L1563

load_image loads a file off disk and returns an image.

import_images receives an image in memory and places it on the terrain. You can import as small as one 1k region. It currently expects a full set of height/color/control maps though they can be null, and it overwrites what is there. We can change that to only import what is provided leaving the unspecified maps (#130).

get/set_map_region will allow you to retreive and set a 1k region image at a time. If you're going to do it non-destructively you'll have to retain what was there before. Our sculpt tools work on whatever is in these images. It will be challenging to do it this way.

Also you need to work across region boundaries.

It will probably be easier to incorporate a non-destructive data layer in C++ for stamps and curves by design.

TokisanGames commented 1 year ago

Currently on each edit update, we consolidate all heightmaps into one array to be sent to the shader.

Non-destructive editing could look like this:

SlashScreen commented 1 year ago

Data is sent to the GPU here?

TokisanGames commented 1 year ago

Yes, for the height/control/color maps. Actually sent when we set the material parameter.

dev-bre commented 8 months ago

is there any date when this would be available in the plugin?

TokisanGames commented 8 months ago

Whenever someone needs it and implements it. We don't need it for Out of the Ashes, so it's not on my personal task list anytime soon. There are far more pressing issues. I can provide guidance.