From dd977bc9464757629d9071fa45eeeddce8d04029 Mon Sep 17 00:00:00 2001 From: cakipaul Date: Fri, 17 Jan 2025 23:43:36 +0800 Subject: [PATCH] =?UTF-8?q?gif=20importer=20=E6=8F=92=E4=BB=B6=E4=B8=8E?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/gif-importer/importer_plugin.gd | 74 ++++++++++++++++++ addons/gif-importer/plugin.cfg | 7 ++ addons/gif-importer/plugin.gd | 23 ++++++ ...【胖小孩背着残疾小孩】-侧面呼吸.gif.import | 5 +- .../【胖小孩背着残疾小孩】-呼吸.gif.import | 5 +- ...【胖小孩背着残疾小孩】-正面呼吸.gif.import | 5 +- ...【胖小孩背着残疾小孩】-正面抖肩.gif.import | 5 +- .../【胖小孩背着残疾小孩】-画画.gif.import | 5 +- asset/art/gif/右1跑动男孩.gif.import | 5 +- asset/art/gif/右1跑动男孩ceshi.gif | Bin 7998 -> 0 bytes asset/art/gif/右1跑动男孩ceshi.gif.import | 15 ---- config/animation/gif_importer.gd | 41 ++++++++++ config/animation/gif_importer.tscn | 15 ++++ project.godot | 7 +- 14 files changed, 174 insertions(+), 38 deletions(-) create mode 100644 addons/gif-importer/importer_plugin.gd create mode 100644 addons/gif-importer/plugin.cfg create mode 100644 addons/gif-importer/plugin.gd delete mode 100644 asset/art/gif/右1跑动男孩ceshi.gif delete mode 100644 asset/art/gif/右1跑动男孩ceshi.gif.import create mode 100644 config/animation/gif_importer.gd create mode 100644 config/animation/gif_importer.tscn diff --git a/addons/gif-importer/importer_plugin.gd b/addons/gif-importer/importer_plugin.gd new file mode 100644 index 00000000..23cab3ce --- /dev/null +++ b/addons/gif-importer/importer_plugin.gd @@ -0,0 +1,74 @@ +# Derived from https://github.com/jegor377/godot-gdgifexporter + +@tool +extends EditorImportPlugin + + +func _can_import_threaded(): + return false + + +func _get_priority(): + return 100 + + +func _get_import_order(): + # 数字越小越提前 + return ResourceImporter.IMPORT_ORDER_DEFAULT - 100 + + +func _get_importer_name(): + return "gif.animated.texture.plugin" + + +func _get_visible_name(): + return "Sprite Frames (Thread Safe)" + + +func _get_recognized_extensions(): + return ["gif"] + + +func _get_save_extension(): + return "tres" + + +func _get_resource_type(): + return "SpriteFrames" + + +func _get_preset_count(): + return 0 + + +func _get_preset_name(i): + return "" + + +func _get_import_options(_path, _i): + return [] + + +func _get_option_visibility(path: String, option_name: StringName, options: Dictionary) -> bool: + return false + + +# 防止同时加载多个文件时卡死 +static var MUTEX = Mutex.new() + + +func _import(source_file, save_path, options, platform_variants, gen_files): + if GifManager == null: + printerr("GifManager is not available!") + return FAILED + var file = FileAccess.open(source_file, FileAccess.READ) + var buffer = file.get_buffer(file.get_length()) + file.close() + MUTEX.lock() + var frames = GifManager.sprite_frames_from_buffer(buffer, 0, 30) + var filename = save_path + "." + _get_save_extension() + var code = ResourceSaver.save(frames, filename) + # await get_tree().create_timer(0.1).timeout + MUTEX.unlock() + print_debug("Imported GIF frames: ", frames.get_frame_count("gif"), " from ", source_file) + return code diff --git a/addons/gif-importer/plugin.cfg b/addons/gif-importer/plugin.cfg new file mode 100644 index 00000000..0b3b15a4 --- /dev/null +++ b/addons/gif-importer/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="GIF Importer" +description="GifManger 的线程安全修正版本" +author="cakipaul" +version="1.0" +script="plugin.gd" diff --git a/addons/gif-importer/plugin.gd b/addons/gif-importer/plugin.gd new file mode 100644 index 00000000..7227133c --- /dev/null +++ b/addons/gif-importer/plugin.gd @@ -0,0 +1,23 @@ +@tool +extends EditorPlugin + +var import_sprite_frames_plugin +# var post_import_plugin + + +func _enter_tree(): + if GifManager == null: + printerr( + "GifManager is not available, please make sure you have the gif-importer plugin installed." + ) + import_sprite_frames_plugin = preload("importer_plugin.gd").new() + # post_import_plugin = preload("post_import.gd").new() + add_import_plugin(import_sprite_frames_plugin, true) + # add_scene_format_importer_plugin(post_import_plugin) + + +func _exit_tree(): + remove_import_plugin(import_sprite_frames_plugin) + import_sprite_frames_plugin = null + # remove_scene_format_importer_plugin(post_import_plugin) + # post_import_plugin = null diff --git a/asset/art/gif/【胖小孩背着残疾小孩】-侧面呼吸.gif.import b/asset/art/gif/【胖小孩背着残疾小孩】-侧面呼吸.gif.import index 774dbf23..02b2f98e 100644 --- a/asset/art/gif/【胖小孩背着残疾小孩】-侧面呼吸.gif.import +++ b/asset/art/gif/【胖小孩背着残疾小孩】-侧面呼吸.gif.import @@ -1,8 +1,8 @@ [remap] -importer="import_gif_to_sprite_frames" +importer="gif.animated.texture.plugin" type="SpriteFrames" -uid="uid://bgfi4y5vrdv3" +uid="uid://c365bkp2y53f3" path="res://.godot/imported/【胖小孩背着残疾小孩】-侧面呼吸.gif-41cf8f62c31ce34b394d9506a4d3fb39.tres" [deps] @@ -12,4 +12,3 @@ dest_files=["res://.godot/imported/【胖小孩背着残疾小孩】-侧面呼 [params] -frames_per_second=30 diff --git a/asset/art/gif/【胖小孩背着残疾小孩】-呼吸.gif.import b/asset/art/gif/【胖小孩背着残疾小孩】-呼吸.gif.import index 0899d2e2..3e9a2e95 100644 --- a/asset/art/gif/【胖小孩背着残疾小孩】-呼吸.gif.import +++ b/asset/art/gif/【胖小孩背着残疾小孩】-呼吸.gif.import @@ -1,8 +1,8 @@ [remap] -importer="import_gif_to_sprite_frames" +importer="gif.animated.texture.plugin" type="SpriteFrames" -uid="uid://cubcamrofhvtr" +uid="uid://cqi3cn2mbebj" path="res://.godot/imported/【胖小孩背着残疾小孩】-呼吸.gif-c79ab4a31a499090e54afdff7675adfe.tres" [deps] @@ -12,4 +12,3 @@ dest_files=["res://.godot/imported/【胖小孩背着残疾小孩】-呼吸.gif- [params] -frames_per_second=30 diff --git a/asset/art/gif/【胖小孩背着残疾小孩】-正面呼吸.gif.import b/asset/art/gif/【胖小孩背着残疾小孩】-正面呼吸.gif.import index ef96fdf4..98c3bc0d 100644 --- a/asset/art/gif/【胖小孩背着残疾小孩】-正面呼吸.gif.import +++ b/asset/art/gif/【胖小孩背着残疾小孩】-正面呼吸.gif.import @@ -1,8 +1,8 @@ [remap] -importer="import_gif_to_sprite_frames" +importer="gif.animated.texture.plugin" type="SpriteFrames" -uid="uid://77k8twghlrj6" +uid="uid://deor6xh8ho3fh" path="res://.godot/imported/【胖小孩背着残疾小孩】-正面呼吸.gif-9675740292b31deb89f7a836f70478f0.tres" [deps] @@ -12,4 +12,3 @@ dest_files=["res://.godot/imported/【胖小孩背着残疾小孩】-正面呼 [params] -frames_per_second=30 diff --git a/asset/art/gif/【胖小孩背着残疾小孩】-正面抖肩.gif.import b/asset/art/gif/【胖小孩背着残疾小孩】-正面抖肩.gif.import index 78e39412..d8011785 100644 --- a/asset/art/gif/【胖小孩背着残疾小孩】-正面抖肩.gif.import +++ b/asset/art/gif/【胖小孩背着残疾小孩】-正面抖肩.gif.import @@ -1,8 +1,8 @@ [remap] -importer="import_gif_to_sprite_frames" +importer="gif.animated.texture.plugin" type="SpriteFrames" -uid="uid://j15catnhfmwg" +uid="uid://xk4fvx44lu7e" path="res://.godot/imported/【胖小孩背着残疾小孩】-正面抖肩.gif-4259b71a0f04bca96bf0e07177319913.tres" [deps] @@ -12,4 +12,3 @@ dest_files=["res://.godot/imported/【胖小孩背着残疾小孩】-正面抖 [params] -frames_per_second=30 diff --git a/asset/art/gif/【胖小孩背着残疾小孩】-画画.gif.import b/asset/art/gif/【胖小孩背着残疾小孩】-画画.gif.import index 5675cd0f..627a197c 100644 --- a/asset/art/gif/【胖小孩背着残疾小孩】-画画.gif.import +++ b/asset/art/gif/【胖小孩背着残疾小孩】-画画.gif.import @@ -1,8 +1,8 @@ [remap] -importer="import_gif_to_sprite_frames" +importer="gif.animated.texture.plugin" type="SpriteFrames" -uid="uid://p6158w0210vj" +uid="uid://bivlhoec73pq" path="res://.godot/imported/【胖小孩背着残疾小孩】-画画.gif-3b458561a577cef811ccd651b4b69272.tres" [deps] @@ -12,4 +12,3 @@ dest_files=["res://.godot/imported/【胖小孩背着残疾小孩】-画画.gif- [params] -frames_per_second=30 diff --git a/asset/art/gif/右1跑动男孩.gif.import b/asset/art/gif/右1跑动男孩.gif.import index 04717a70..c650f831 100644 --- a/asset/art/gif/右1跑动男孩.gif.import +++ b/asset/art/gif/右1跑动男孩.gif.import @@ -1,8 +1,8 @@ [remap] -importer="import_gif_to_sprite_frames" +importer="gif.animated.texture.plugin" type="SpriteFrames" -uid="uid://doonfsppjqmj6" +uid="uid://deniyxsdbrt1p" path="res://.godot/imported/右1跑动男孩.gif-9079138d4476d9c9b2c631defe192e44.tres" [deps] @@ -12,4 +12,3 @@ dest_files=["res://.godot/imported/右1跑动男孩.gif-9079138d4476d9c9b2c631de [params] -frames_per_second=30 diff --git a/asset/art/gif/右1跑动男孩ceshi.gif b/asset/art/gif/右1跑动男孩ceshi.gif deleted file mode 100644 index ea3e938811c6d2d8c1b598a432ba9206a9924308..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7998 zcmeI0X;>45T{aBRhI!%qbqxRv!v`xnP)tO;|`vC{^p%<@M=E9q(I9Xa#dX^zJqo@_#*8zONS9KjfaH^!J4VX>w}oGFHg{Cc3o0eMWe=}xPyU&D#d%upWw{(h#$ z#({x>=s-N0%X2rzlF4La49*ybGZNP@;s^Ws(}RqB`C8w4uwwDucpN`}4%ZjC)FYk2 zJ>+kO5)by*S@`(b+5MwqUq1TFoX~DuALAgppD`AVG4}CUn%bAzeE*%Se-7ghYx8#n z`>~97viRIXJU5oOy4JVG;@kJ{11(h)kH+)|9!LCK=-yUbw?jTGUw<1bGnDuWn#p0B zk_b2!gG?tFk;&_sMg%eeV?=UW&o&|xNDLyGj-z8R#BcrlQF}6pY=PfmVPQqE#9^^p zwvw=z_2vY!37$YOCz)Uf-`d*v^8M+)Zme&yIpWw~+nWE|wx*Um7TurA+r{O2e@g^= z53WC#@4@v$;)rN04yotF@nv!Y`T9!_>DM`1v3Q&S7IQ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