-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathViewportRecorder.gd
38 lines (28 loc) · 904 Bytes
/
ViewportRecorder.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
extends Node
#The viewport to record
export(String, DIR) var target_directory = "./recordings/"
var target_viewport = null
var image_index = 0
var scene_name = null
func _ready():
#Get the active viewport for recording
#TODO: Allow for user-specified viewports
target_viewport = get_viewport()
#Reset the image index for naming
image_index = 0
#Get the current scene name
scene_name = get_tree().get_current_scene().get_name()
#Process every frame
set_process(true)
pass
func _process(delta):
#We want to get the viewport's image data
var texture = target_viewport.get_texture()
#Get the image data for this texture
var image = texture.get_data()
#Now build the file path
var file_path = target_directory + "image_" + str(image_index) + ".png"
image_index += 1
#Write the image to that file
var result = image.save_png(file_path)
print("Recording... " + str(result))