33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
import bpy, sys, os
|
|
# args: <dir> <base_clip_file> <out.glb> <clip1,clip2,...> (clips = @names)
|
|
argv = sys.argv[sys.argv.index("--")+1:]
|
|
DIR, BASE, OUT, CLIPS = argv[0], argv[1], argv[2], argv[3].split(",")
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
bpy.ops.import_scene.gltf(filepath=os.path.join(DIR, BASE))
|
|
arm = next(o for o in bpy.data.objects if o.type == "ARMATURE")
|
|
arm.animation_data_create()
|
|
base_actions = list(bpy.data.actions)
|
|
for a in base_actions:
|
|
a.name = BASE.split("@")[1].replace(".glb", "")
|
|
def stash(action, name):
|
|
action.name = name
|
|
tr = arm.animation_data.nla_tracks.new()
|
|
tr.name = name
|
|
tr.strips.new(name, 1, action)
|
|
tr.mute = True
|
|
for a in base_actions:
|
|
stash(a, a.name)
|
|
for clip in CLIPS:
|
|
f = os.path.join(DIR, f"Sci_Fi_Hands_mesh_Empty@{clip}.glb")
|
|
pre_a = set(bpy.data.actions); pre_o = set(bpy.data.objects)
|
|
bpy.ops.import_scene.gltf(filepath=f)
|
|
for o in [o for o in bpy.data.objects if o not in pre_o]:
|
|
bpy.data.objects.remove(o, do_unlink=True)
|
|
for a in [a for a in bpy.data.actions if a not in pre_a]:
|
|
stash(a, clip)
|
|
arm.animation_data.action = None
|
|
exec(open("/tmp/tex_bind.py").read()); bind()
|
|
bpy.ops.export_scene.gltf(filepath=OUT, export_format="GLB", export_animations=True)
|
|
import json
|
|
print("MERGED", OUT, os.path.getsize(OUT)//1024, "KB, clips:", [t.name for t in arm.animation_data.nla_tracks])
|