extends Node3D ## Keep the sun disc inside the cockpit far plane. Aim SunLight. ## Never leave the disc sitting on the Moon. @export var sun_disc_path: NodePath = ^"SunDisc" @export var sun_light_path: NodePath = ^"../SunLight" @export var sun_direction: Vector3 = Vector3(-0.82, 0.45, 0.35) @export var visual_distance: float = 220000.0 @export var visual_radius: float = 9000.0 var _mesh: MeshInstance3D var _light: DirectionalLight3D var _base_radius: float = 0.5 func _ready() -> void: _mesh = get_node_or_null(sun_disc_path) as MeshInstance3D if _mesh == null: _mesh = find_child("SunDisc", true, false) as MeshInstance3D if _mesh and _mesh.mesh is SphereMesh: _base_radius = maxf((_mesh.mesh as SphereMesh).radius, 0.5) _light = get_node_or_null(sun_light_path) as DirectionalLight3D if _light == null: _light = get_node_or_null("../SunLight") as DirectionalLight3D sun_direction = sun_direction.normalized() _aim_light() set_process(true) func _aim_light() -> void: if _light == null: return var target: Vector3 = _light.global_position - sun_direction if target.is_equal_approx(_light.global_position): return _light.look_at(target, Vector3.UP) func _process(_delta: float) -> void: if _mesh == null: return var viewer: Node3D = FloatingOrigin.focus var origin: Vector3 = viewer.global_position if viewer and is_instance_valid(viewer) else global_position _mesh.global_position = origin + sun_direction * visual_distance _mesh.scale = Vector3.ONE * (visual_radius / _base_radius) _mesh.visible = true _aim_light()