2024-10-20 21:47:57 +00:00
|
|
|
@tool
|
|
|
|
extends Terrain3D
|
|
|
|
|
|
|
|
|
|
|
|
@export var clear_all: bool = false : set = reset_settings
|
|
|
|
@export var clear_terrain: bool = false : set = reset_terrain
|
|
|
|
@export var update_height_range: bool = false : set = update_heights
|
|
|
|
|
|
|
|
|
|
|
|
func reset_settings(p_value) -> void:
|
|
|
|
if p_value:
|
|
|
|
height_file_name = ""
|
|
|
|
control_file_name = ""
|
|
|
|
color_file_name = ""
|
2024-11-17 19:47:37 +00:00
|
|
|
destination_directory = ""
|
|
|
|
import_position = Vector2i.ZERO
|
|
|
|
height_offset = 0.0
|
2024-10-20 21:47:57 +00:00
|
|
|
import_scale = 1.0
|
|
|
|
r16_range = Vector2(0, 1)
|
|
|
|
r16_size = Vector2i(1024, 1024)
|
|
|
|
material = null
|
|
|
|
assets = null
|
|
|
|
|
|
|
|
|
|
|
|
func reset_terrain(p_value) -> void:
|
2024-11-17 19:47:37 +00:00
|
|
|
data_directory = ""
|
2024-10-20 21:47:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
func update_heights(p_value) -> void:
|
2024-11-17 19:47:37 +00:00
|
|
|
if p_value and data:
|
|
|
|
data.update_height_range()
|
2024-10-20 21:47:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
@export_group("Import File")
|
|
|
|
@export_global_file var height_file_name: String = ""
|
|
|
|
@export_global_file var control_file_name: String = ""
|
|
|
|
@export_global_file var color_file_name: String = ""
|
2024-11-17 19:47:37 +00:00
|
|
|
@export var import_position: Vector2i = Vector2i(0, 0) : set = set_import_position
|
2024-10-20 21:47:57 +00:00
|
|
|
@export var import_scale: float = 1.0
|
2024-11-17 19:47:37 +00:00
|
|
|
@export var height_offset: float = 0.0
|
2024-10-20 21:47:57 +00:00
|
|
|
@export var r16_range: Vector2 = Vector2(0, 1)
|
2024-11-17 19:47:37 +00:00
|
|
|
@export var r16_size: Vector2i = Vector2i(1024, 1024) : set = set_r16_size
|
2024-10-20 21:47:57 +00:00
|
|
|
@export var run_import: bool = false : set = start_import
|
|
|
|
|
2024-11-17 19:47:37 +00:00
|
|
|
@export_dir var destination_directory: String = ""
|
|
|
|
@export var save_to_disk: bool = false : set = save_data
|
|
|
|
|
|
|
|
|
|
|
|
func set_import_position(p_value: Vector2i) -> void:
|
|
|
|
import_position.x = clamp(p_value.x, -8192, 8192)
|
|
|
|
import_position.y = clamp(p_value.y, -8192, 8192)
|
|
|
|
|
|
|
|
|
|
|
|
func set_r16_size(p_value: Vector2i) -> void:
|
|
|
|
r16_size.x = clamp(p_value.x, 0, 16384)
|
|
|
|
r16_size.y = clamp(p_value.y, 0, 16384)
|
|
|
|
|
|
|
|
|
2024-10-20 21:47:57 +00:00
|
|
|
func start_import(p_value: bool) -> void:
|
|
|
|
if p_value:
|
|
|
|
print("Terrain3DImporter: Importing files:\n\t%s\n\t%s\n\t%s" % [ height_file_name, control_file_name, color_file_name])
|
|
|
|
|
|
|
|
var imported_images: Array[Image]
|
2024-11-17 19:47:37 +00:00
|
|
|
imported_images.resize(Terrain3DRegion.TYPE_MAX)
|
2024-10-20 21:47:57 +00:00
|
|
|
var min_max := Vector2(0, 1)
|
|
|
|
var img: Image
|
|
|
|
if height_file_name:
|
|
|
|
img = Terrain3DUtil.load_image(height_file_name, ResourceLoader.CACHE_MODE_IGNORE, r16_range, r16_size)
|
|
|
|
min_max = Terrain3DUtil.get_min_max(img)
|
2024-11-17 19:47:37 +00:00
|
|
|
imported_images[Terrain3DRegion.TYPE_HEIGHT] = img
|
2024-10-20 21:47:57 +00:00
|
|
|
if control_file_name:
|
|
|
|
img = Terrain3DUtil.load_image(control_file_name, ResourceLoader.CACHE_MODE_IGNORE)
|
2024-11-17 19:47:37 +00:00
|
|
|
imported_images[Terrain3DRegion.TYPE_CONTROL] = img
|
2024-10-20 21:47:57 +00:00
|
|
|
if color_file_name:
|
|
|
|
img = Terrain3DUtil.load_image(color_file_name, ResourceLoader.CACHE_MODE_IGNORE)
|
2024-11-17 19:47:37 +00:00
|
|
|
imported_images[Terrain3DRegion.TYPE_COLOR] = img
|
2024-10-20 21:47:57 +00:00
|
|
|
if assets.get_texture_count() == 0:
|
|
|
|
material.show_checkered = false
|
|
|
|
material.show_colormap = true
|
2024-11-17 19:47:37 +00:00
|
|
|
var pos := Vector3(import_position.x, 0, import_position.y)
|
|
|
|
data.import_images(imported_images, pos, height_offset, import_scale)
|
2024-10-20 21:47:57 +00:00
|
|
|
print("Terrain3DImporter: Import finished")
|
|
|
|
|
|
|
|
|
2024-11-17 19:47:37 +00:00
|
|
|
func save_data(p_value: bool) -> void:
|
|
|
|
if destination_directory.is_empty():
|
|
|
|
push_error("Set destination directory first")
|
|
|
|
return
|
|
|
|
data.save_directory(destination_directory)
|
|
|
|
|
|
|
|
|
2024-10-20 21:47:57 +00:00
|
|
|
@export_group("Export File")
|
|
|
|
enum { TYPE_HEIGHT, TYPE_CONTROL, TYPE_COLOR }
|
|
|
|
@export_enum("Height:0", "Control:1", "Color:2") var map_type: int = TYPE_HEIGHT
|
|
|
|
@export var file_name_out: String = ""
|
|
|
|
@export var run_export: bool = false : set = start_export
|
|
|
|
|
|
|
|
func start_export(p_value: bool) -> void:
|
2024-11-17 19:47:37 +00:00
|
|
|
var err: int = data.export_image(file_name_out, map_type)
|
2024-10-20 21:47:57 +00:00
|
|
|
print("Terrain3DImporter: Export error status: ", err, " ", error_string(err))
|
|
|
|
|