works
This commit is contained in:
parent
cc792cfb1b
commit
5d3b7051a4
|
@ -10,87 +10,41 @@
|
|||
@tool
|
||||
extends SceneTree
|
||||
|
||||
var bundle_name := "bundle.res"
|
||||
var bundle_name := "vertex_animations.scn"
|
||||
var VertexAnimation = preload("VertexAnimation.gd")
|
||||
var VertexAnimations = preload("VertexAnimations.gd")
|
||||
|
||||
|
||||
func _init():
|
||||
var script := GDScript.new()
|
||||
var basenames := OS.get_cmdline_user_args()
|
||||
script.source_code = make_all_headers(basenames, true)
|
||||
script.reload()
|
||||
var res: Resource = script.new()
|
||||
|
||||
res.basenames = basenames
|
||||
var animations = VertexAnimations.new()
|
||||
animations.name = "VertexAnimations"
|
||||
for basename in basenames:
|
||||
add_images(res, basename)
|
||||
animations.animations.append(add_animation(basename))
|
||||
|
||||
var packed = PackedScene.new()
|
||||
packed.pack(animations)
|
||||
|
||||
var shader := ShaderInclude.new()
|
||||
for basename in basenames:
|
||||
shader.code += make_shader(basename)
|
||||
|
||||
script.source_code = make_all_headers(basenames, false)
|
||||
|
||||
|
||||
# Cannot use built-in scripts
|
||||
# See: https://github.com/godotengine/godot/issues/85876
|
||||
script.resource_path = "res://bundle/bundle.gd"
|
||||
ResourceSaver.save(script, "res://bundle/bundle.gd")
|
||||
res.shader = shader
|
||||
res.shader.resource_name = "shader"
|
||||
shader.resource_path = "res://bundle/bundle.gdshaderinc"
|
||||
ResourceSaver.save(shader, "res://bundle/bundle.gdshaderinc", ResourceSaver.FLAG_CHANGE_PATH)
|
||||
ResourceSaver.save(res, "res://bundle/" + bundle_name, ResourceSaver.FLAG_CHANGE_PATH)
|
||||
ResourceSaver.save(packed, "res://" + bundle_name, ResourceSaver.FLAG_CHANGE_PATH)
|
||||
|
||||
# Was never added to the scene tree, must manually free
|
||||
animations.free()
|
||||
quit()
|
||||
|
||||
|
||||
func make_all_shaders(basenames):
|
||||
for basename in basenames:
|
||||
pass
|
||||
|
||||
func make_shader(basename: String):
|
||||
var code = "\nuniform sampler2D image_" + basename + ": repeat_disable;\n"
|
||||
code += "uniform sampler2D image_mask_" + basename + ": repeat_disable;\n"
|
||||
code += "uniform bool enabled_" + basename + " = false;\n"
|
||||
code += "uniform int start_time_" + basename + ";\n"
|
||||
return code
|
||||
|
||||
func make_all_headers(basenames, include_setters):
|
||||
var header := "extends Resource\n"
|
||||
header += "@export var basenames: PackedStringArray\n"
|
||||
header += "@export var shader: ShaderInclude\n"
|
||||
for basename in basenames:
|
||||
header += make_header(basename)
|
||||
if include_setters:
|
||||
header += make_setters(basename)
|
||||
return header + attach_code(basenames)
|
||||
|
||||
func attach_code(basenames):
|
||||
var code := "\nfunc attach(mat: ShaderMaterial):\n"
|
||||
for basename in basenames:
|
||||
code += " mat.set_shader_parameter('image_"+basename+"', image_"+basename+")\n"
|
||||
code += " mat.set_shader_parameter('image_mask_"+basename+"', image_mask_"+basename+")\n"
|
||||
return code
|
||||
|
||||
func make_header(basename: String):
|
||||
var header := "@export var image_" + basename + ": Texture2D\n"
|
||||
header += "@export var image_mask_" + basename + ": Texture2D\n"
|
||||
return header
|
||||
|
||||
func make_setters(basename: String):
|
||||
var body := """
|
||||
func set_image_"""+basename+"""(image):\n image_""" + basename + """ = image
|
||||
func set_image_mask_"""+basename+"""(image):\n image_mask_""" + basename + """ = image
|
||||
"""
|
||||
return body
|
||||
|
||||
|
||||
func add_images(res, basename: String):
|
||||
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()
|
||||
animation.name = basename
|
||||
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")
|
||||
var tex := ImageTexture.create_from_image(img)
|
||||
res.call("set_image_"+basename, tex)
|
||||
animation.data = ImageTexture.create_from_image(img)
|
||||
img = Image.new()
|
||||
img.load(basename + "_mask.exr")
|
||||
tex = ImageTexture.create_from_image(img)
|
||||
res.call("set_image_mask_"+basename, tex)
|
||||
animation.mask = ImageTexture.create_from_image(img)
|
||||
|
||||
return animation
|
||||
|
|
|
@ -108,7 +108,7 @@ fn write_point_image(
|
|||
}
|
||||
|
||||
// Not used because blender always starts frame frame zero so this info is useless
|
||||
fn write_animation_info(filename: &str, info: AnimationInfo) -> Result<(), Box<dyn Error>> {
|
||||
fn _write_animation_info(filename: &str, info: AnimationInfo) -> Result<(), Box<dyn Error>> {
|
||||
let data = format!(
|
||||
"{{ \"total_frames\": {}, \"total_points\": {}, \"start_frame\": {}, \"end_frame\": {}, \"fps\": {} }}\n",
|
||||
info.total_frames, info.total_points, info.start_frame, info.end_frame, info.fps
|
||||
|
@ -138,6 +138,7 @@ impl PointState {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let basename = std::env::args()
|
||||
.nth(1)
|
||||
|
@ -223,5 +224,4 @@ fn main() {
|
|||
"Total {} varying points of {} total points",
|
||||
total_varying, info.total_points
|
||||
);
|
||||
println!("{:?}", info);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue