pointcache/tools/pack_res.gd

53 lines
1.7 KiB
GDScript
Executable File

#!/usr/bin/env -S godot -s --headless
# To be called with args "++ basename, basename, ..."
# Fragile script
# Relies on instantiating instead of using set_script
# Godot ignores exported properties unless you reload script
# Can't call methods directly because it's a parse error
# Also can't use .set() because then the properties aren't exported.
@tool
extends SceneTree
var bundle_name := "vertex_animations.scn"
var VertexAnimation = preload("VertexAnimation.gd")
var VertexAnimations = preload("VertexAnimations.gd")
func _init():
var basenames := OS.get_cmdline_user_args()
print(basenames)
var animations = VertexAnimations.new()
animations.name = "VertexAnimations"
for basename in basenames:
animations.animations.append(add_animation(basename))
var packed = PackedScene.new()
packed.pack(animations)
ResourceSaver.save(packed, "res://" + bundle_name, ResourceSaver.FLAG_CHANGE_PATH | ResourceSaver.FLAG_RELATIVE_PATHS)
# Was never added to the scene tree, must manually free
animations.free()
quit()
func add_animation(basename: String):
var animation_info: Dictionary = JSON.parse_string(FileAccess.open(basename + ".json", FileAccess.READ).get_as_text())
var animation = VertexAnimation.new()
var splitname: String = basename.split("/")[-1]
animation.name = splitname
animation.start_frame = animation_info["frame_start"]
animation.end_frame = animation_info["frame_end"]
animation.fps = animation_info["fps"]
var img := Image.new()
img.load(basename + ".exr")
animation.data = ImageTexture.create_from_image(img)
img = Image.new()
img.load(basename + "_mask.exr")
animation.mask = ImageTexture.create_from_image(img)
return animation