Skip to content

Commit b69a28f

Browse files
authored
Add preview panel to the right of the graph editor (#526)
* Preview panel changes from first branch * Add filesystem compatibility * Fix lost references * Add orbit camera * Add multi mesh * Add 3D render * Add overlay * Add better shader * Moved generation settings in the graph resource * Mouved pouches and add checkerboard background * Fix some lint issues * Update camera script and fix references * Test generator * Backup before breaking everything * Generate multiple chunks * Update stuff * Fix demo runtime * Stuff * Revert some changes * Revert change * cleanup * Moved code around * Removed GaeaPreviewGenerationSettings class * cleanup * It's working ! * Update style * Add multiple layer display * Cleanup camera movement * Cleanups and camera reset * Latest fix for review * Fix lint issues * Fix tests * Change sun direction * Revert changes to task pool * Update GaeaTaskPool init * Use thread generation * cleanup * Update camera position on reset * Init preview world size * Fix chunk limit * Fix rebase leaving old code
1 parent b07144e commit b69a28f

24 files changed

+1042
-61
lines changed

addons/gaea/editor/graph_editor/graph_edit.gd

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extends GraphEdit
88
## List of nodes attached to a frame (element, frame)
99
var attached_elements: Dictionary[StringName, StringName]
1010

11-
## Currently edited resource
11+
## Currently edited resource, use [method populate] to change the graph
1212
var graph: GaeaGraph :
1313
set(value):
1414
graph = value
@@ -62,6 +62,11 @@ func populate(new_graph: GaeaGraph) -> void:
6262
graph.layer_count_modified.connect(_update_output_node)
6363
_load_data()
6464

65+
if is_instance_valid(main_editor):
66+
# The Screenshotter don't have the main_editor reference
67+
main_editor.set_editor_visible(true)
68+
main_editor.preview_panel.reset()
69+
6570

6671
func unpopulate() -> void:
6772
if is_instance_valid(graph) and graph.layer_count_modified.is_connected(_update_output_node):
@@ -71,6 +76,11 @@ func unpopulate() -> void:
7176
for child in get_children():
7277
if child is GraphElement:
7378
child.queue_free()
79+
80+
if is_instance_valid(main_editor):
81+
# The Screenshotter don't have the main_editor reference
82+
main_editor.set_editor_visible(false)
83+
7484
graph = null
7585

7686

addons/gaea/editor/graph_editor/main_editor.gd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@tool
22
class_name GaeaMainEditor
3-
extends Control
3+
extends HSplitContainer
44

55
## Emitted when the about popup is requested.
66
@warning_ignore("unused_signal")
@@ -20,6 +20,7 @@ signal new_reroute_requested(connection: Dictionary)
2020

2121
@export var gaea_panel: GaeaPanel
2222
@export var graph_edit: GaeaGraphEdit
23+
@export var preview_panel: GaeaPreviewPanel
2324
@export var about_window: AcceptDialog
2425
@export var create_node_popup: GaeaPopupCreateNode
2526
@export var node_context_menu: GaeaPopupNodeContextMenu
@@ -69,3 +70,9 @@ static func _clamp_popup_in_rect(popup: Window, window_rect: Rect2i) -> void:
6970
popup.position.y = window_rect.position.y
7071
elif inner_rect.position.y + inner_rect.size.y > window_rect.position.y + window_rect.size.y:
7172
popup.position.y = window_rect.position.y + window_rect.size.y - inner_rect.size.y
73+
74+
75+
@warning_ignore("shadowed_variable_base_class")
76+
func set_editor_visible(visible: bool) -> void:
77+
graph_edit.visible = visible
78+
preview_panel.visible = visible

addons/gaea/editor/panel/panel.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extends Control
66
@export var main_editor: GaeaMainEditor
77
@export var graph_edit: GaeaGraphEdit
88
@export var file_list: GaeaFileList
9+
@export var preview_panel: GaeaPreviewPanel
910

1011
var plugin: GaeaEditorPlugin
1112

addons/gaea/editor/panel/panel.tscn

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=13 format=3 uid="uid://dngytsjlmkfg7"]
1+
[gd_scene load_steps=14 format=3 uid="uid://dngytsjlmkfg7"]
22

33
[ext_resource type="Script" uid="uid://dpbmowgfmnxe5" path="res://addons/gaea/editor/panel/panel.gd" id="1_afcqa"]
44
[ext_resource type="Script" uid="uid://bedt1m4gyyvyv" path="res://addons/gaea/editor/graph_editor/graph_edit.gd" id="2_cdav6"]
@@ -10,11 +10,12 @@
1010
[ext_resource type="Script" uid="uid://bybvolyg1u0v4" path="res://addons/gaea/editor/graph_editor/node_context_menu.gd" id="4_vtsfx"]
1111
[ext_resource type="Script" uid="uid://cqd2rkam5cs3d" path="res://addons/gaea/editor/graph_editor/create_node_popup.gd" id="5_nbnm7"]
1212
[ext_resource type="Script" uid="uid://btt4eqjkp5pyf" path="res://addons/gaea/editor/graph_editor/link_context_menu.gd" id="7_dhpru"]
13+
[ext_resource type="PackedScene" uid="uid://c0hkiofdk5jcx" path="res://addons/gaea/editor/panel/right_panel/right_panel.tscn" id="7_eht7w"]
1314
[ext_resource type="PackedScene" uid="uid://dcec3sivqmbjf" path="res://addons/gaea/editor/panel/about_window.tscn" id="9_affj1"]
1415

1516
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_dhpru"]
1617

17-
[node name="GaeaPanel" type="HSplitContainer" node_paths=PackedStringArray("main_editor", "graph_edit", "file_list")]
18+
[node name="GaeaPanel" type="HSplitContainer" node_paths=PackedStringArray("main_editor", "graph_edit", "file_list", "preview_panel")]
1819
custom_minimum_size = Vector2(0, 256)
1920
anchors_preset = 15
2021
anchor_right = 1.0
@@ -25,6 +26,7 @@ script = ExtResource("1_afcqa")
2526
main_editor = NodePath("MainEditor")
2627
graph_edit = NodePath("MainEditor/GraphEdit")
2728
file_list = NodePath("FileSystemContainer")
29+
preview_panel = NodePath("MainEditor/PreviewPanel")
2830

2931
[node name="FileSystemContainer" type="VBoxContainer" parent="." node_paths=PackedStringArray("graph_edit", "main_editor", "menu_bar", "file_list", "context_menu", "file_dialog")]
3032
clip_contents = true
@@ -63,25 +65,23 @@ size = Vector2i(960, 540)
6365
mode_overrides_title = false
6466
filters = PackedStringArray("*.tres;Resource Files")
6567

66-
[node name="MainEditor" type="Control" parent="." node_paths=PackedStringArray("gaea_panel", "graph_edit", "about_window", "create_node_popup", "node_context_menu", "link_context_menu")]
68+
[node name="MainEditor" type="HSplitContainer" parent="." node_paths=PackedStringArray("gaea_panel", "graph_edit", "preview_panel", "about_window", "create_node_popup", "node_context_menu", "link_context_menu")]
6769
layout_mode = 2
6870
size_flags_vertical = 3
71+
split_offset = 1000000
6972
script = ExtResource("4_gbl2m")
7073
gaea_panel = NodePath("..")
7174
graph_edit = NodePath("GraphEdit")
75+
preview_panel = NodePath("PreviewPanel")
7276
about_window = NodePath("AboutWindow")
7377
create_node_popup = NodePath("CreateNodePopup")
7478
node_context_menu = NodePath("NodeContextMenu")
7579
link_context_menu = NodePath("LinkContextMenu")
7680

7781
[node name="GraphEdit" type="GraphEdit" parent="MainEditor" node_paths=PackedStringArray("main_editor", "bottom_note_label")]
7882
visible = false
79-
layout_mode = 1
80-
anchors_preset = 15
81-
anchor_right = 1.0
82-
anchor_bottom = 1.0
83-
grow_horizontal = 2
84-
grow_vertical = 2
83+
custom_minimum_size = Vector2(50, 50)
84+
layout_mode = 2
8585
size_flags_vertical = 3
8686
theme_override_colors/connection_rim_color = Color(0.0784314, 0.0784314, 0.0784314, 1)
8787
grid_pattern = 1
@@ -117,6 +117,11 @@ text = "(0,0)"
117117
fit_content = true
118118
metadata/_edit_use_anchors_ = true
119119

120+
[node name="PreviewPanel" parent="MainEditor" node_paths=PackedStringArray("main_editor") instance=ExtResource("7_eht7w")]
121+
visible = false
122+
layout_mode = 2
123+
main_editor = NodePath("..")
124+
120125
[node name="AboutWindow" parent="MainEditor" node_paths=PackedStringArray("main_editor") instance=ExtResource("9_affj1")]
121126
visible = false
122127
exclusive = true
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
@tool
2+
class_name GaeaPreviewCamera
3+
extends Camera3D
4+
5+
const SCROLL_SPEED: float = 5.0 # Speed when use scroll mouse
6+
const ZOOM_SPEED: float = 50.0 # Speed use when is_zoom_in or is_zoom_out is true
7+
const DEFAULT_DISTANCE: float = 5.0 # Default distance of the Node
8+
const ROTATE_SPEED: float = 2.0
9+
const PAN_SPEED: float = 0.25
10+
11+
@export var _anchor_node: Node3D
12+
13+
# Use to add posibility to updated zoom with external script
14+
var is_zoom_in: bool
15+
var is_zoom_out: bool
16+
17+
# Event var
18+
var _current_rotate_input: Vector2
19+
var _current_pan_input: Vector2
20+
var _current_scroll_speed: float
21+
22+
# Transform var
23+
var _rotation: Vector3
24+
var _distance: float
25+
26+
func _ready():
27+
_distance = DEFAULT_DISTANCE
28+
_rotation = _anchor_node.transform.basis.get_rotation_quaternion().get_euler()
29+
30+
31+
func _process(delta: float):
32+
if is_zoom_in:
33+
_current_scroll_speed = -1 * ZOOM_SPEED
34+
if is_zoom_out:
35+
_current_scroll_speed = 1 * ZOOM_SPEED
36+
_process_transformation(delta)
37+
38+
39+
func _process_transformation(delta: float):
40+
# Update rotation
41+
_rotation.x += -_current_rotate_input.y * delta * ROTATE_SPEED
42+
_rotation.y += -_current_rotate_input.x * delta * ROTATE_SPEED
43+
if _rotation.x < -PI/2:
44+
_rotation.x = -PI/2
45+
if _rotation.x > PI/2:
46+
_rotation.x = PI/2
47+
_current_rotate_input = Vector2.ZERO
48+
49+
# Update distance
50+
_distance += _current_scroll_speed * delta
51+
if _distance < 1:
52+
_distance = 1
53+
_current_scroll_speed = 0
54+
55+
self.set_identity()
56+
self.translate_object_local(Vector3(0,0,_distance))
57+
58+
_anchor_node.transform.basis = Basis(Quaternion.from_euler(_rotation))
59+
60+
var pan_factor = delta * maxf(_distance, 1) * PAN_SPEED
61+
_anchor_node.position -= _anchor_node.transform.basis.x * _current_pan_input.x * pan_factor
62+
_anchor_node.position -= _anchor_node.transform.basis.y * -_current_pan_input.y * pan_factor
63+
_current_pan_input = Vector2.ZERO
64+
65+
66+
func input(event: InputEvent):
67+
if event is InputEventMouseMotion:
68+
_process_mouse_rotation_event(event)
69+
elif event is InputEventMouseButton:
70+
_process_mouse_scroll_event(event)
71+
72+
73+
func _process_mouse_rotation_event(e: InputEventMouseMotion):
74+
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
75+
_current_rotate_input = e.relative
76+
elif Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
77+
_current_pan_input = e.relative
78+
79+
80+
func _process_mouse_scroll_event(e: InputEventMouseButton):
81+
if e.button_index == MOUSE_BUTTON_WHEEL_UP:
82+
_current_scroll_speed = -maxf(_distance, 1) * SCROLL_SPEED
83+
elif e.button_index == MOUSE_BUTTON_WHEEL_DOWN:
84+
_current_scroll_speed = maxf(_distance, 1) * SCROLL_SPEED
85+
86+
87+
@warning_ignore("shadowed_variable_base_class")
88+
func set_camera_view(anchor_position: Vector3, rotation: Vector3, distance: float):
89+
_anchor_node.position = anchor_position
90+
_rotation = rotation
91+
_distance = distance
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://bobcj42guajf3
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://c5mn0qnqt78fj"]
2+
3+
[ext_resource type="Shader" uid="uid://6bf04rd28i71" path="res://addons/gaea/editor/panel/right_panel/cube_shader.gdshader" id="1_ci0if"]
4+
5+
[resource]
6+
render_priority = 0
7+
shader = ExtResource("1_ci0if")
8+
shader_parameter/metalic = 0.25
9+
shader_parameter/roughness = 1.0
10+
shader_parameter/grid_scale = 1.0
11+
shader_parameter/grid_width = 0.0150000007125
12+
shader_parameter/grid_color = Color(0.17254902, 0.24313726, 0.3137255, 0.78431374)
13+
shader_parameter/inside_scale = 3.0
14+
shader_parameter/inside_width = 0.0050000002375
15+
shader_parameter/inside_color = Color(0.12608984, 0.11347676, 0.022142986, 0.8)
16+
shader_parameter/checkered = false
17+
shader_parameter/sub_checkered_grid = false
18+
shader_parameter/checkered_color = Color(0.25, 0.25, 0.25, 1)
19+
shader_parameter/checkered_blend_color = 0.1
20+
shader_parameter/use_inside_uv = false
21+
shader_parameter/use_albedo_color = false
22+
shader_parameter/albedo_alpha = 0.5

0 commit comments

Comments
 (0)