extends SceneTree

const REGION_SIZE := 256
const TERRAIN_SIZE := 512
const DATA_DIRECTORY := "res://terrain/jajce/data"


func _initialize() -> void:
	call_deferred("_run")


func _run() -> void:
	var camera := Camera3D.new()
	camera.current = true
	root.add_child(camera)

	var terrain := Terrain3D.new()
	terrain.region_size = REGION_SIZE
	root.add_child(terrain)
	terrain.set_camera(camera)
	await process_frame

	var height_map := Image.create_empty(TERRAIN_SIZE, TERRAIN_SIZE, false, Image.FORMAT_RF)
	height_map.fill(Color(0.0, 0.0, 0.0, 1.0))

	var images: Array[Image]
	images.resize(Terrain3DRegion.TYPE_MAX)
	images[Terrain3DRegion.TYPE_HEIGHT] = height_map

	terrain.data.import_images(
		images, Vector3(-TERRAIN_SIZE / 2.0, 0.0, -TERRAIN_SIZE / 2.0), 0.0, 1.0
	)
	terrain.data.save_directory(DATA_DIRECTORY)
	print("[TOOL] Generated flat Jajce Terrain3D seed data in ", DATA_DIRECTORY)
	quit(0)
