New visible celestial bodies

This commit is contained in:
olof.pettersson
2025-11-14 10:58:45 +01:00
parent 27ce796898
commit 1342ca2610
27 changed files with 138 additions and 242 deletions

View File

@ -31,14 +31,7 @@ func initialize(body: OrbitalBody3D):
body_reference = body
name_label.text = body.name
if body is Star:
dot_color = Color.GOLD
elif body is Planet:
dot_color = Color.DODGER_BLUE
elif body is Moon:
dot_color = Color.PURPLE
else:
dot_color = Color.CYAN
dot_color = Color.CYAN
self.tooltip_text = _generate_tooltip_text()
@ -98,7 +91,7 @@ func _on_mouse_exited():
func _generate_tooltip_text() -> String:
var info = [body_reference.name]
if body_reference is Planet:
if body_reference is CelestialBody:
var planet_system = body_reference.get_parent() as Barycenter
var period_seconds = OrbitalMechanics.get_orbital_time_in_seconds(planet_system, GameManager.get_system_data().star)
@ -106,18 +99,11 @@ func _generate_tooltip_text() -> String:
var moon_count = 0
for child in planet_system.get_internal_attractors():
if child is Moon:
if child is CelestialBody:
moon_count += 1
if moon_count > 0:
info.append("Moons: %d" % moon_count)
if body_reference is Moon:
var planet_system = body_reference.get_parent() as Barycenter
var period_seconds = OrbitalMechanics.get_orbital_time_in_seconds(body_reference as Moon, planet_system)
info.append("Orbital Period: %s" % _format_seconds_to_mmss(period_seconds))
if body_reference is Module:
info.append("Class: Player Vessel")
info.append("Mass: %.0f kg" % body_reference.mass)

View File

@ -1,19 +0,0 @@
class_name Asteroid
extends OrbitalBody3D
# The orbital radius for this asteroid.
var orbital_radius: float
func get_class_name() -> String:
return "Asteroid"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# An Asteroid has negligible mass for physics calculations.
#mass = 0.001
#radius = 5.0
# You can set a default texture here.
# texture = preload("res://assets/asteroid_texture.png")
super._ready()

View File

@ -1 +0,0 @@
uid://c816xae77cbmq

View File

@ -1,8 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://bawsujtlpmh5r"]
[ext_resource type="Script" uid="uid://0isnsk356que" path="res://scripts/orbital_body_2d.gd" id="1_4q05e"]
[node name="Asteroid" type="Node2D"]
script = ExtResource("1_4q05e")
base_mass = 50000.0
metadata/_custom_type_script = "uid://0isnsk356que"

View File

@ -0,0 +1,13 @@
class_name CelestialBody extends OrbitalBody3D
@export var radius: float = 100.0
func set_radius(value: float):
radius = value
if $Surface.mesh is SphereMesh:
$Surface.mesh.radius = radius
$Surface.mesh.height = radius * 2.0
if $CollisionShape3D.shape is SphereShape3D:
$CollisionShape3D.shape.radius = radius

View File

@ -0,0 +1 @@
uid://dok35h0q4pseh

View File

@ -0,0 +1,27 @@
[gd_scene load_steps=5 format=3 uid="uid://dv18eg4xrlefe"]
[ext_resource type="Script" uid="uid://dok35h0q4pseh" path="res://scenes/celestial_bodies/celestial_body.gd" id="1_uxu4s"]
[ext_resource type="Material" uid="uid://de0xnmjf12ted" path="res://scenes/celestial_bodies/materials/sun_mat.tres" id="2_vi0nt"]
[sub_resource type="SphereMesh" id="SphereMesh_vi0nt"]
resource_local_to_scene = true
material = ExtResource("2_vi0nt")
radius = 2000.0
height = 4000.0
[sub_resource type="SphereShape3D" id="SphereShape3D_uxu4s"]
[node name="CelestialBody" type="RigidBody3D"]
script = ExtResource("1_uxu4s")
metadata/_custom_type_script = "uid://dok35h0q4pseh"
[node name="Surface" type="MeshInstance3D" parent="."]
mesh = SubResource("SphereMesh_vi0nt")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_uxu4s")
[node name="OmniLight3D" type="OmniLight3D" parent="."]
light_color = Color(0.958646, 0.7997282, 0.55087835, 1)
omni_range = 200000.0
omni_attenuation = 2.0

View File

@ -0,0 +1,52 @@
// https://godotshaders.com/shader/3d-sun-shader/
shader_type spatial;
render_mode specular_schlick_ggx;
uniform float Glow_Power : hint_range(0,10) = 3;
uniform float Lightness_Difference : hint_range(0,10) = 3;
uniform vec4 Sun_Color: source_color;
uniform sampler2D voronoi_noise;
uniform sampler2D emission_noise;
varying vec3 vertex_pos;
uniform float waveSpeed : hint_range(0,1) = 0.1;
uniform float fresnel : hint_range(0,2) = 1.0;
uniform float scale : hint_range(0,2) = 0.01;
uniform float blendSharpness : hint_range(0,2) = 0.0;
// TRIPLANAR FUNCTION
vec4 triplanar_texture(vec3 position, vec3 normal, vec2 offset, sampler2D noise) {
vec4 colX = texture(noise, position.xy * scale + offset);
vec4 colY = texture(noise, position.xz * scale + offset);
vec4 colZ = texture(noise, position.zy * scale + offset);
vec3 blendWeight = abs(normal);
blendWeight = vec3(pow(blendWeight.x, blendSharpness), pow(blendWeight.y, blendSharpness), pow(blendWeight.z, blendSharpness));
blendWeight /= (blendWeight.x + blendWeight.y + blendWeight.z);
return colX * blendWeight.x + colY * blendWeight.y + colZ * blendWeight.z;
}
void vertex() {
vertex_pos = VERTEX;
}
void fragment() {
// Fresnel
float fresnel_out = pow(fresnel - clamp(dot(NORMAL, VIEW), 0.0, fresnel), fresnel);
vec2 waveOffsetA = vec2(TIME * waveSpeed, TIME * waveSpeed * 0.8);
vec2 waveOffsetB = vec2(TIME * waveSpeed * - 0.8, TIME * waveSpeed * -0.3);
vec2 result_offset = waveOffsetA + waveOffsetB;
vec3 cloud_tex = triplanar_texture(vertex_pos, NORMAL, result_offset, voronoi_noise).rgb;
vec3 cloud_tex_with_light = cloud_tex * vec3(Lightness_Difference);
vec3 cloud_tex_with_light_with_color = cloud_tex_with_light * Sun_Color.rgb;
vec3 cloud_tex_with_light_with_color_with_glow = vec3(Glow_Power) * cloud_tex_with_light_with_color;
vec3 noise_tex = triplanar_texture(vertex_pos, NORMAL, result_offset, emission_noise).rgb;
vec3 result = cloud_tex_with_light_with_color_with_glow * noise_tex;
EMISSION = vec3(fresnel_out) * result;
}

View File

@ -0,0 +1 @@
uid://0cjdd62t25g1

View File

@ -0,0 +1,27 @@
[gd_resource type="ShaderMaterial" load_steps=6 format=3 uid="uid://de0xnmjf12ted"]
[ext_resource type="Shader" uid="uid://0cjdd62t25g1" path="res://scenes/celestial_bodies/materials/sun_mat.gdshader" id="1_f1bp4"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_f1bp4"]
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_1eyo5"]
noise = SubResource("FastNoiseLite_f1bp4")
[sub_resource type="FastNoiseLite" id="FastNoiseLite_6484p"]
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_oxjal"]
noise = SubResource("FastNoiseLite_6484p")
in_3d_space = true
[resource]
render_priority = 0
shader = ExtResource("1_f1bp4")
shader_parameter/Glow_Power = 10.0
shader_parameter/Lightness_Difference = 4.26400020254
shader_parameter/Sun_Color = Color(0.90528274, 0.8164857, 0.6356678, 1)
shader_parameter/voronoi_noise = SubResource("NoiseTexture2D_oxjal")
shader_parameter/emission_noise = SubResource("NoiseTexture2D_1eyo5")
shader_parameter/waveSpeed = 0.1
shader_parameter/fresnel = 1.0
shader_parameter/scale = 0.01
shader_parameter/blendSharpness = 0.0

View File

@ -1,17 +0,0 @@
class_name Moon
extends OrbitalBody3D
# The orbital radius for this moon.
var orbital_radius: float
func get_class_name() -> String:
return "Moon"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# A Moon has a smaller mass than a planet.
# You can set a default texture here.
# texture = preload("res://assets/moon_texture.png")
super._ready()

View File

@ -1 +0,0 @@
uid://b1xsx7er22nxn

View File

@ -1,8 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://74ppvxcw8an4"]
[ext_resource type="Script" uid="uid://b1xsx7er22nxn" path="res://scenes/celestial_bodies/moon.gd" id="1_530pw"]
[node name="Moon" type="Node2D"]
script = ExtResource("1_530pw")
base_mass = 1e+06
metadata/_custom_type_script = "uid://0isnsk356que"

View File

@ -1,15 +0,0 @@
class_name Planet
extends OrbitalBody3D
# The orbital radius for this planet.
var orbital_radius: float
func get_class_name() -> String:
return "Planet"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# You can set a default texture here.
# texture = preload("res://assets/planet_texture.png")
super._ready()

View File

@ -1 +0,0 @@
uid://5f6ipgu65urb

View File

@ -1,10 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://clt4qlsjcfgln"]
[ext_resource type="Script" uid="uid://5f6ipgu65urb" path="res://scenes/celestial_bodies/planet.gd" id="1_cktii"]
[node name="Planet" type="Node2D"]
script = ExtResource("1_cktii")
base_mass = 2.5e+07
metadata/_custom_type_script = "uid://0isnsk356que"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]

View File

@ -1,14 +0,0 @@
class_name Star
extends OrbitalBody3D
func get_class_name() -> String:
return "Star"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# A Star has no primary and a very large mass.
# You can set a default texture here, or assign it in the Inspector.
# texture = preload("res://assets/star_texture.png")
super._ready()

View File

@ -1 +0,0 @@
uid://um2sfghmii42

View File

@ -1,15 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://5uqp4amjj7ww"]
[ext_resource type="Script" uid="uid://um2sfghmii42" path="res://scenes/celestial_bodies/star.gd" id="1_mcqwg"]
[sub_resource type="CircleShape2D" id="CircleShape2D_508pf"]
radius = 200.0
[node name="Star" type="Node2D"]
script = ExtResource("1_mcqwg")
base_mass = 5e+08
metadata/_custom_type_script = "uid://0isnsk356que"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_508pf")
debug_color = Color(0.863865, 0.471779, 0.162305, 1)

View File

@ -1,17 +0,0 @@
class_name Station
extends OrbitalBody3D
# The orbital radius for this station.
var orbital_radius: float
func get_class_name() -> String:
return "Station"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# A Station has negligible mass for physics calculations.
# You can set a default texture here.
# texture = preload("res://assets/station_texture.png")
super._ready()

View File

@ -1 +0,0 @@
uid://ulw61oxppwdu

View File

@ -1,8 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://dm3s33o4xhqfv"]
[ext_resource type="Script" uid="uid://ulw61oxppwdu" path="res://scenes/celestial_bodies/station.gd" id="1_rod8h"]
[node name="Station" type="Node2D"]
script = ExtResource("1_rod8h")
base_mass = 5000.0
metadata/_custom_type_script = "uid://0isnsk356que"

View File

@ -1,82 +0,0 @@
[gd_scene load_steps=4 format=3 uid="uid://c77wxeb7gpplw"]
[ext_resource type="Script" uid="uid://6co67nfy8ngb" path="res://scenes/ship/builder/module.gd" id="1_mtskc"]
[ext_resource type="PackedScene" uid="uid://bho8x10x4oab7" path="res://scenes/ship/builder/pieces/hullplate.tscn" id="2_aovrk"]
[ext_resource type="PackedScene" uid="uid://d3hitk62fice4" path="res://scenes/ship/builder/pieces/bulkhead.tscn" id="4_dwgsg"]
[node name="Module" type="Node2D"]
position = Vector2(-50, 50)
script = ExtResource("1_mtskc")
metadata/_custom_type_script = "uid://0isnsk356que"
[node name="StructuralContainer" type="Node2D" parent="."]
[node name="Hullplate" parent="StructuralContainer" instance=ExtResource("2_aovrk")]
[node name="@StaticBody2D@31031" parent="StructuralContainer" instance=ExtResource("2_aovrk")]
position = Vector2(0, 100)
[node name="@StaticBody2D@31033" parent="StructuralContainer" instance=ExtResource("2_aovrk")]
position = Vector2(100, 100)
[node name="@StaticBody2D@31035" parent="StructuralContainer" instance=ExtResource("2_aovrk")]
position = Vector2(100, 0)
[node name="@StaticBody2D@31037" parent="StructuralContainer" instance=ExtResource("2_aovrk")]
position = Vector2(100, -100)
[node name="@StaticBody2D@31039" parent="StructuralContainer" instance=ExtResource("2_aovrk")]
position = Vector2(100, -200)
[node name="@StaticBody2D@31041" parent="StructuralContainer" instance=ExtResource("2_aovrk")]
position = Vector2(0, -200)
[node name="@StaticBody2D@31043" parent="StructuralContainer" instance=ExtResource("2_aovrk")]
position = Vector2(0, -100)
[node name="Bulkhead" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(-50, 100)
[node name="@StaticBody2D@31046" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(-50, 0)
[node name="@StaticBody2D@31048" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(-50, -100)
[node name="@StaticBody2D@31050" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(-50, -200)
[node name="@StaticBody2D@31052" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(150, -200)
[node name="@StaticBody2D@31054" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(150, -100)
[node name="@StaticBody2D@31056" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(150, 0)
[node name="@StaticBody2D@31058" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(150, 100)
[node name="@StaticBody2D@31060" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(0, 150)
rotation = 1.5708
[node name="@StaticBody2D@31062" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(100, 150)
rotation = 1.5708
[node name="@StaticBody2D@31064" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(0, -250)
rotation = 1.5708
[node name="@StaticBody2D@31066" parent="StructuralContainer" instance=ExtResource("4_dwgsg")]
position = Vector2(100, -250)
rotation = 1.5708
[node name="HullVolumeContainer" type="Node2D" parent="."]
[node name="AtmosphereVisualizer" type="Node2D" parent="."]
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(50, -50)

View File

@ -76,12 +76,12 @@ func _draw() -> void:
draw_projected_orbits(star_orbiters)
for body in icon_map:
if body is Asteroid: continue
#if body is Asteroid: continue
var icon = icon_map[body]
if not icon.visible: continue
var path_points = []
if body is Planet:
if body is CelestialBody:
var planet_system = body.get_parent() as Barycenter
draw_projected_orbits(planet_system.get_internal_attractors())
else: continue

View File

@ -44,6 +44,7 @@ top_level = true
spring_length = 3.0
[node name="Camera3D" type="Camera3D" parent="CameraPivot/SpringArm"]
far = 200000.0
[node name="GripDetector" type="Area3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1)

View File

@ -36,7 +36,7 @@ func get_planetary_systems() -> Array[Barycenter]:
func get_orbital_bodies() -> Array[OrbitalBody3D]:
var bodies: Array[OrbitalBody3D] = []
for child in get_children():
if child is Star or child is Barycenter:
if child is CelestialBody or child is Barycenter:
continue
if child is OrbitalBody3D:
bodies.append(child)

View File

@ -11,12 +11,16 @@ const MAX_PLANETS = 8
const MAX_MOONS_PER_PLANET = 5
const ORBIT_SAFETY_FACTOR = 5
func generate(star_system: StarSystem) -> SystemData:
var CelestialBodyScene: PackedScene = preload("res://scenes/celestial_bodies/celestial_body.tscn")
func generate(star_system: StarSystem) -> SystemData:
var system_data = SystemData.new()
var star = Star.new()
var star: CelestialBody = CelestialBodyScene.instantiate()
system_data.star = star
star.name = "Star"
star.set_radius(2000.0)
star.base_mass = STAR_MASS
star_system.add_child(star)
@ -28,7 +32,8 @@ func generate(star_system: StarSystem) -> SystemData:
planet_barycenter.name = "PlanetSystem_%d" % (i + 1)
star_system.add_child(planet_barycenter)
var planet = Planet.new()
var planet: CelestialBody = CelestialBodyScene.instantiate()
planet.set_radius(randf_range(50.0, 200.0))
system_data.planets.append(planet)
planet.name = "Planet_%d" % (i + 1)
planet.base_mass = randf_range(PLANET_MASS * 0.2, PLANET_MASS * 5.0)
@ -63,7 +68,8 @@ func _generate_moons(planet: OrbitalBody3D, planet_barycenter: Barycenter, syste
var current_orbit_radius = 200.0
for i in range(num_moons):
var moon = Moon.new()
var moon = CelestialBodyScene.instantiate()
moon.set_radius(10.0)
system_data.moons.append(moon)
planet_barycenter.add_child(moon)
planet_barycenter.recalculate_total_mass()