1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00

Optimize the export dialog by caching all of the blended frames

No more slowness when changing the export settings. The only setting that causes the frames to be blended again is changing the layers.
This commit is contained in:
Emmanouil Papadeas 2024-09-05 04:50:36 +03:00
parent 9650dae678
commit a0c7dd4527
3 changed files with 19 additions and 3 deletions

View file

@ -46,6 +46,9 @@ var custom_exporter_generators := {}
var current_tab := ExportTab.IMAGE var current_tab := ExportTab.IMAGE
## All frames and their layers processed/blended into images ## All frames and their layers processed/blended into images
var processed_images: Array[ProcessedImage] = [] var processed_images: Array[ProcessedImage] = []
## Dictionary of [Frame] and [Image] that contains all of the blended frames.
## Changes when [method cache_blended_frames] is called.
var blended_frames := {}
var export_json := false var export_json := false
var split_layers := false var split_layers := false
var trim_sprite := false var trim_sprite := false
@ -137,6 +140,7 @@ func remove_custom_file_format(id: int) -> void:
func external_export(project := Global.current_project) -> void: func external_export(project := Global.current_project) -> void:
cache_blended_frames(project)
process_data(project) process_data(project)
export_processed_images(true, Global.export_dialog, project) export_processed_images(true, Global.export_dialog, project)
@ -149,6 +153,15 @@ func process_data(project := Global.current_project) -> void:
process_spritesheet(project) process_spritesheet(project)
func cache_blended_frames(project := Global.current_project) -> void:
blended_frames.clear()
var frames := _calculate_frames(project)
for frame in frames:
var image := Image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8)
_blend_layers(image, frame)
blended_frames[frame] = image
func process_spritesheet(project := Global.current_project) -> void: func process_spritesheet(project := Global.current_project) -> void:
processed_images.clear() processed_images.clear()
# Range of frames determined by tags # Range of frames determined by tags
@ -252,7 +265,8 @@ func process_spritesheet(project := Global.current_project) -> void:
origin.y = project.size.y * tag_origins[0] origin.y = project.size.y * tag_origins[0]
origin.x = 0 origin.x = 0
tag_origins[0] += 1 tag_origins[0] += 1
_blend_layers(whole_image, frame, origin) whole_image.blend_rect(blended_frames[frame], Rect2i(Vector2i.ZERO, project.size), origin)
#_blend_layers(whole_image, frame, origin)
processed_images.append(ProcessedImage.new(whole_image, 0)) processed_images.append(ProcessedImage.new(whole_image, 0))
@ -271,7 +285,7 @@ func process_animation(project := Global.current_project) -> void:
) )
else: else:
var image := Image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8) var image := Image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8)
_blend_layers(image, frame) image.copy_from(blended_frames[frame])
if trim_sprite: if trim_sprite:
image = image.get_region(image.get_used_rect()) image = image.get_region(image.get_used_rect())
var duration := frame.duration * (1.0 / project.fps) var duration := frame.duration * (1.0 / project.fps)

View file

@ -290,6 +290,7 @@ func _on_ExportDialog_about_to_show() -> void:
path_dialog_popup.current_dir = project.export_directory_path path_dialog_popup.current_dir = project.export_directory_path
file_line_edit.text = project.file_name file_line_edit.text = project.file_name
file_format_options.selected = project.file_format file_format_options.selected = project.file_format
Export.cache_blended_frames()
show_tab() show_tab()
# Set the size of the preview checker # Set the size of the preview checker
@ -472,6 +473,7 @@ func _on_Frames_item_selected(id: int) -> void:
func _on_Layers_item_selected(id: int) -> void: func _on_Layers_item_selected(id: int) -> void:
Export.export_layers = id Export.export_layers = id
Export.cache_blended_frames()
Export.process_data() Export.process_data()
set_preview() set_preview()

View file

@ -82,8 +82,8 @@ mouse_default_cursor_shape = 2
selected = 0 selected = 0
item_count = 4 item_count = 4
popup/item_0/text = "Columns" popup/item_0/text = "Columns"
popup/item_0/id = 1
popup/item_1/text = "Rows" popup/item_1/text = "Rows"
popup/item_1/id = 1
popup/item_2/text = "Tags by column" popup/item_2/text = "Tags by column"
popup/item_2/id = 2 popup/item_2/id = 2
popup/item_3/text = "Tags by row" popup/item_3/text = "Tags by row"