Files
scorpion21211-cmd 965f0d7584 Initial commit
2026-10-03 23:29:41 -04:00

69 lines
2.2 KiB
GDScript

extends Node3D
## Earth impostor — from Luna you are always far; show a disc inside far plane.
@export var real_earth_path: NodePath = ^".."
@export var surface_path: NodePath = ^"../EarthSurface"
@export var impostor_mesh_path: NodePath = ^"ImposterSphere"
@export var switch_distance: float = 150000.0
@export var visual_distance: float = 120000.0
@export var real_radius: float = 637100.0
var _real: Node3D
var _surface: Node3D
var _mesh: MeshInstance3D
var _base_radius: float = 0.5
func _ready() -> void:
_real = get_node_or_null(real_earth_path) as Node3D
_surface = get_node_or_null(surface_path) as Node3D
_mesh = get_node_or_null(impostor_mesh_path) as MeshInstance3D
if _mesh and _mesh.mesh is SphereMesh:
_base_radius = maxf((_mesh.mesh as SphereMesh).radius, 0.5)
if _mesh:
_mesh.visible = false
# Keep YOUR material/texture; only force unshaded so it reads in space
var src_mat: Material = _mesh.get_active_material(0)
if src_mat is StandardMaterial3D:
var mat: StandardMaterial3D = (src_mat as StandardMaterial3D).duplicate()
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
_mesh.material_override = mat
print("EarthImposter ready | real=", _real, " surface=", _surface, " mesh=", _mesh)
set_process(true)
func _process(_delta: float) -> void:
if _real == null or _mesh == null:
return
var viewer: Node3D = FloatingOrigin.focus
if viewer == null or not is_instance_valid(viewer):
_mesh.visible = false
return
var to_body: Vector3 = _real.global_position - viewer.global_position
var dist: float = to_body.length()
if dist < 1.0:
_mesh.visible = false
return
# Close approach only: real surface
if dist < switch_distance:
_mesh.visible = false
if _surface:
_surface.visible = true
return
# Far (normal from Luna): impostor on
# Leave EarthSurface visible until you confirm the disc — then you can hide it
var dir: Vector3 = to_body / dist
_mesh.global_position = viewer.global_position + dir * visual_distance
var visual_radius: float = real_radius * (visual_distance / dist)
visual_radius = clampf(visual_radius, 8000.0, 150000.0)
_mesh.scale = Vector3.ONE * (visual_radius / _base_radius)
_mesh.visible = true