From a6626b9d600eebcba909183395e34c319e49369e Mon Sep 17 00:00:00 2001 From: Hoimar <36260114+Hoimar@users.noreply.github.com> Date: Wed, 26 Jul 2023 12:49:28 +0200 Subject: [PATCH] Fixed quadtree demo, disabled collisions for now. --- .../planet_presets/test_planet_settings.tres | 2 +- addons/hoimar.planetgen/scripts/constants.gd | 2 +- addons/hoimar.planetgen/scripts/gui/gui.gd | 15 +++++++++++---- .../scripts/terrain/terrain_patch.gd | 3 ++- .../hoimar.planetgen/scripts/utils/pg_globals.gd | 1 + demos/quadtree_terrain_demo.gd | 7 ++++--- demos/quadtree_terrain_demo.tscn | 12 ++++++++---- 7 files changed, 28 insertions(+), 14 deletions(-) diff --git a/addons/hoimar.planetgen/planet_presets/test_planet_settings.tres b/addons/hoimar.planetgen/planet_presets/test_planet_settings.tres index 6d9bb1d..2cb03a9 100644 --- a/addons/hoimar.planetgen/planet_presets/test_planet_settings.tres +++ b/addons/hoimar.planetgen/planet_presets/test_planet_settings.tres @@ -21,7 +21,7 @@ noise_generators = [SubResource("1")] [resource] script = ExtResource("1") -resolution = 100 +resolution = 10 radius = 100.0 has_water = false has_atmosphere = false diff --git a/addons/hoimar.planetgen/scripts/constants.gd b/addons/hoimar.planetgen/scripts/constants.gd index 6250ec3..20c9366 100644 --- a/addons/hoimar.planetgen/scripts/constants.gd +++ b/addons/hoimar.planetgen/scripts/constants.gd @@ -1,6 +1,6 @@ # Defines some constants for the quadtree and terrain patches. -const COLLISIONS_ENABLED := true # Whether planets generate collision shapes. +const COLLISIONS_ENABLED := false # Whether planets generate collision shapes. const GRAVITY_ENABLED := true # TODO: Implement gravity. const THREADS_ENABLED := true diff --git a/addons/hoimar.planetgen/scripts/gui/gui.gd b/addons/hoimar.planetgen/scripts/gui/gui.gd index ff9b394..b51b211 100644 --- a/addons/hoimar.planetgen/scripts/gui/gui.gd +++ b/addons/hoimar.planetgen/scripts/gui/gui.gd @@ -4,11 +4,14 @@ extends Node @onready var lbl_status := $Root/MarginContainer/HBoxContainer/LabelStatus @onready var lbl_speedscale := $Root/MarginContainer/HBoxContainer/Control/LabelSpeedScale @onready var slider_speedscale := $Root/MarginContainer/HBoxContainer/Control/HSlider -@onready var ship : Node3D = get_tree().get_nodes_in_group("player")[0] +var ship : Node3D func _ready(): - ship.connect("speed_scale_changed", Callable(self, "update_speed_scale")) + var player_nodes = get_tree().get_nodes_in_group("player") + if player_nodes.size() > 0: + ship = player_nodes[0] + ship.connect("speed_scale_changed", Callable(self, "update_speed_scale")) func _process(_delta): @@ -42,9 +45,13 @@ func check_input(): func _on_HSlider_value_changed(value): - lbl_speedscale.text = str(value) - ship.speed_scale = value + update_speed_scale(value) + if ship: + ship.speed_scale = value func update_speed_scale(value): + lbl_speedscale.text = str(value) slider_speedscale.value = value + PGGlobals.speed_scale = value + diff --git a/addons/hoimar.planetgen/scripts/terrain/terrain_patch.gd b/addons/hoimar.planetgen/scripts/terrain/terrain_patch.gd index eb2bbca..a073319 100644 --- a/addons/hoimar.planetgen/scripts/terrain/terrain_patch.gd +++ b/addons/hoimar.planetgen/scripts/terrain/terrain_patch.gd @@ -29,7 +29,7 @@ func _process(_delta): func _notification(what): - if what == NOTIFICATION_TRANSFORM_CHANGED: + if Const.COLLISIONS_ENABLED and what == NOTIFICATION_TRANSFORM_CHANGED: update_transform() # Manually update physics shape position. @@ -127,6 +127,7 @@ func init_physics(): func update_transform(): + print(_body_rid) var transform: Transform3D = data.settings._planet.global_transform PhysicsServer3D.body_set_state(_body_rid, PhysicsServer3D.BODY_STATE_TRANSFORM, transform) diff --git a/addons/hoimar.planetgen/scripts/utils/pg_globals.gd b/addons/hoimar.planetgen/scripts/utils/pg_globals.gd index 5d32c64..c8bb5d8 100644 --- a/addons/hoimar.planetgen/scripts/utils/pg_globals.gd +++ b/addons/hoimar.planetgen/scripts/utils/pg_globals.gd @@ -9,6 +9,7 @@ var colored_patches: bool # Colors patches of terrain randomly. var benchmark_mode: bool # re-generates planets even if there are still active threads. var solar_systems: Array = [] var job_queue := JobQueue.new() # Global queue for TerrainJobs. +var speed_scale: float = 0.001 func _ready(): diff --git a/demos/quadtree_terrain_demo.gd b/demos/quadtree_terrain_demo.gd index 7098c5c..0f2a097 100644 --- a/demos/quadtree_terrain_demo.gd +++ b/demos/quadtree_terrain_demo.gd @@ -3,21 +3,22 @@ extends Node3D @export var _play_in_editor: bool = true: set = set_play_in_editor -@export var _rotation_speed: float = 0.2 +@export var _rotation_speed: float = 200 @onready var _view_position_rig := $ViewPositionRig @onready var _view_position := $ViewPositionRig/ViewPosition -@onready var _planet := $TestPlanet +@onready var _planet := $SolarSystem/TestPlanet func _ready(): PGGlobals.wireframe = true + #PGGlobals.colored_patches = true _planet._terrain.set_viewer(_view_position) func _process(delta): if Engine.is_editor_hint() and not _play_in_editor: return - _view_position_rig.rotate_y(_rotation_speed*delta) + _view_position_rig.rotate_y(_rotation_speed * PGGlobals.speed_scale * delta) func set_play_in_editor(new: bool): diff --git a/demos/quadtree_terrain_demo.tscn b/demos/quadtree_terrain_demo.tscn index 167e259..9d50953 100644 --- a/demos/quadtree_terrain_demo.tscn +++ b/demos/quadtree_terrain_demo.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=11 format=3 uid="uid://cv3jth7u5rno3"] +[gd_scene load_steps=12 format=3 uid="uid://cv3jth7u5rno3"] [ext_resource type="Script" path="res://demos/quadtree_terrain_demo.gd" id="1"] [ext_resource type="PackedScene" uid="uid://btubuuiux53j4" path="res://addons/hoimar.planetgen/scenes/gui/gui.tscn" id="2"] +[ext_resource type="Script" path="res://addons/hoimar.planetgen/scripts/celestial_bodies/solar_system.gd" id="3_hi6yo"] [ext_resource type="PackedScene" uid="uid://dtmgyl1uf7auy" path="res://addons/hoimar.planetgen/scenes/celestial_bodies/planet.tscn" id="4"] [ext_resource type="Resource" uid="uid://kono1hjgsisy" path="res://addons/hoimar.planetgen/planet_presets/test_planet_settings.tres" id="6"] @@ -32,16 +33,19 @@ glow_blend_mode = 1 [node name="QuadTreeTerrainDemo" type="Node3D"] script = ExtResource("1") _play_in_editor = false -_rotation_speed = 0.1 [node name="Gui" parent="." instance=ExtResource("2")] -[node name="TestPlanet" parent="." instance=ExtResource("4")] +[node name="SolarSystem" type="Node3D" parent="."] +script = ExtResource("3_hi6yo") + +[node name="TestPlanet" parent="SolarSystem" instance=ExtResource("4")] settings = ExtResource("6") material = SubResource("3") +solar_system_path = NodePath("..") [node name="ViewPositionRig" type="Node3D" parent="."] -transform = Transform3D(1.00011, 0, 0, 0, 1, 0, 0, 0, 1.00011, 0, 0, 0) +transform = Transform3D(-0.786847, 0, -0.6176, 0, 1, 0, 0.6176, 0, -0.786847, 0, 0, 0) [node name="ViewPosition" type="MeshInstance3D" parent="ViewPositionRig"] transform = Transform3D(1, 0, 0, 0, 1, 0, -1.42109e-14, 0, 1, -105, 0, 0)