extends Node3D

@onready var terrain: Terrain3D = $TerrainRoot/Terrain3D


func _ready() -> void:
	call_deferred("_initialize_world_presentation")


func _initialize_world_presentation() -> void:
	var active_camera := get_viewport().get_camera_3d()
	if active_camera != null:
		terrain.set_camera(active_camera)
	var groups_to_snap: Array[Node] = []
	groups_to_snap.append_array($FoliageRoot.get_children())
	if has_node("FortressBlockout"):
		groups_to_snap.append($FortressBlockout)
	for child in $VillageRoot.get_children():
		groups_to_snap.append(child)
	for item in groups_to_snap:
		var pos: Vector3 = item.global_position
		var h: float = terrain.data.get_height(pos)
		if not is_nan(h):
			item.global_position.y = h
