class_name TerrainGeneration
extends Node

var mesh : MeshInstance3D
var planet_radius : float = 1

@export var noise : FastNoiseLite

# Called when the node enters the scene tree for the first time.
func _ready():
	generate()

func generate():
	var sphere_mesh = SphereMesh.new()
	sphere_mesh.material = preload("res://ProceduralGeneration/Materials/terrain.tres")

	
	var surface = SurfaceTool.new()
	var data = MeshDataTool.new()
	surface.create_from(sphere_mesh, 0)

	var plane_array = surface.commit()
	data.create_from_surface(plane_array, 0)

	for i in range(data.get_vertex_count()):
		var vert = data.get_vertex(i)
		data.set_vertex(i, vert)

	plane_array.clear_surfaces()
	data.commit_to_surface(plane_array)

	surface.begin(Mesh.PRIMITIVE_TRIANGLES)
	surface.create_from(plane_array, 0)
	surface.generate_normals()

	mesh = MeshInstance3D.new()
	mesh.mesh = surface.commit()
	mesh.create_trimesh_collision()
	mesh.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF

	mesh.add_to_group("NavSource")
	add_child(mesh)
