"""Bake supplied Mixamo clips onto both TokenRig skin variants for review.""" import json import sys from pathlib import Path import bpy root=Path(sys.argv[sys.argv.index('--')+1]) folder=root/'Tools/output/campguide_studio/rig_mixamo41' base=root/'AIClient/Assets/Bundles/Characters/Human/test/Boy_mixamo' manifest=[] for variant,filename in [('raw','tokenrig_mixamo41.blend'),('local','tokenrig_mixamo41_local.blend')]: for label in ['Walking','Breathing Idle','Happy Idle']: bpy.ops.wm.open_mainfile(filepath=str(folder/filename)) target=next(o for o in bpy.context.scene.objects if o.type=='ARMATURE') before=set(bpy.data.objects) bpy.ops.import_scene.fbx(filepath=str(base/('CampGuideStudio@'+label+'.fbx'))) source=next(o for o in bpy.data.objects if o not in before and o.type=='ARMATURE') first,last=map(int,source.animation_data.action.frame_range) for b in target.pose.bones: b.rotation_mode='QUATERNION' for frame in range(first,last+1): bpy.context.scene.frame_set(frame) bpy.context.view_layer.update() matrices={b.name:target.matrix_world.inverted()@source.matrix_world@b.matrix for b in source.pose.bones} for b in target.pose.bones: b.matrix=matrices[b.name] bpy.context.view_layer.update() b.keyframe_insert('location',frame=frame) b.keyframe_insert('rotation_quaternion',frame=frame) b.keyframe_insert('scale',frame=frame) action=target.animation_data.action action.name=variant+'_'+label.replace(' ','_') bpy.data.objects.remove(source,do_unlink=True) for a in list(bpy.data.actions): if a!=action: bpy.data.actions.remove(a) scene=bpy.context.scene scene.frame_start,scene.frame_end=first,last scene.render.fps=30 dst=folder/'animations'/variant/(label.replace(' ','_')+'.glb') dst.parent.mkdir(parents=True,exist_ok=True) bpy.ops.export_scene.gltf(filepath=str(dst),export_format='GLB',export_skins=True,export_animations=True, export_animation_mode='ACTIVE_ACTIONS',export_force_sampling=True,export_def_bones=False) manifest.append({'file':str(dst),'skin':variant,'frames':[first,last],'fps':30,'source_clip':str(base/('CampGuideStudio@'+label+'.fbx'))}) print('BAKED',dst) (folder/'animations/manifest.json').write_text(json.dumps(manifest,indent=2),encoding='utf-8')