-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.gd
110 lines (82 loc) · 2.81 KB
/
main.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
extends Control
var dir = ''
@export var player_canvas_path: NodePath
@export var file_button_path: NodePath
@export var position_ui_path: NodePath
@export var rotation_ui_path: NodePath
@export var scale_ui_path: NodePath
@export var menu_button_path : NodePath
var player_canvas: Control
var file_button: MenuButton
var menu_button : MenuButton
var position_ui: HBoxContainer
var rotation_ui: HBoxContainer
var scale_ui: HBoxContainer
var player_node: Node3D
var color_shader: ColorRect
var player_transform: Node3D
signal path_update
func _ready():
player_canvas = get_node(player_canvas_path)
file_button = get_node(file_button_path)
position_ui = get_node(position_ui_path)
rotation_ui = get_node(rotation_ui_path)
scale_ui = get_node(scale_ui_path)
menu_button = get_node(menu_button_path)
color_shader = player_canvas.find_child("ColorShader")
player_node = player_canvas.find_child("Player")
file_button.connect("model_load_triggered", _on_model_load_triggered)
player_transform = player_canvas.find_child("Player")
var c = Callable(self,"file_drop_path")
get_tree().get_root().connect('files_dropped',c)
update_player_transform(player_node)
func _on_background_shader_toggled(button_pressed):
if not button_pressed:
color_shader.hide()
else:
color_shader.show()
func _on_run_annimation_button_down():
render()
func render():
var arr : Array
menu_button.file_menu(1)
dir = await path_update
dir += '/'
arr = await player_canvas.get_all_animation_frames()
print(arr.size())
var anime_names = arr[1] as Array
var images = arr[0] as Array
for i in anime_names.size():
var img: Image
img = images[i]
var path = dir + anime_names[i] + ".png"
img.save_png(path)
func _on_model_load_triggered(path : String):
if path.ends_with(".gltf") or path.ends_with(".glb"):
var state = GLTFState.new()
var importer = GLTFDocument.new()
importer.append_from_file(path, state)
var node = importer.generate_scene(state)
node.transform = player_node.transform
var node_parent = player_node.get_parent()
player_node.queue_free()
node_parent.add_child(node)
node.set_owner(node_parent)
player_node = node
player_node.name = "Player"
update_player_transform(node)
func update_player_transform(node):
player_transform = node as Node3D
position_ui.transform = player_transform.position
rotation_ui.transform = player_transform.rotation_degrees
scale_ui.transform = player_transform.scale
func file_drop_path(files):
_on_model_load_triggered(files[0])
func _on_position_transform_changed(_transform):
player_transform.position=_transform
func _on_rotation_transform_changed(_transform):
player_transform.rotation_degrees=_transform
func _on_scale_transform_changed(_transform):
player_transform.scale=_transform
func _on_file_dialog_dir_selected(dir):
emit_signal('path_update',str(dir))