Skip to content

Instantly share code, notes, and snippets.

@nmfisher
Created August 2, 2023 00:54
Show Gist options
  • Save nmfisher/4e92efb4be3700a1fde75d455e3462a6 to your computer and use it in GitHub Desktop.
Save nmfisher/4e92efb4be3700a1fde75d455e3462a6 to your computer and use it in GitHub Desktop.
Generate shape keys from frame poses in Blender
# this assumes that every 10th frame is the pose corresponding to the shape key, ordered according to the variable arkit
# adjust frame_increment if this isn't correct (e.g. if each pose is on consecutive frames, set frame_increment to 1)
# reorder arkit to match the order of poses in your action if needed
# select the mesh in the viewport, then run this script
import bpy
rig_name="rig"
frame = -1
frame_increment = 10
arkit=["browInnerUp","browDownLeft","browDownRight","browOuterUpLeft","browOuterUpRight","eyeLookUpLeft","eyeLookUpRight","eyeLookDownLeft","eyeLookDownRight","eyeLookInLeft","eyeLookInRight","eyeLookOutLeft","eyeLookOutRight","eyeBlinkLeft","eyeBlinkRight","eyeSquintRight","eyeSquintLeft","eyeWideLeft","eyeWideRight","cheekPuff","cheekSquintLeft","cheekSquintRight","noseSneerLeft","noseSneerRight","jawOpen","jawForward","jawLeft","jawRight","mouthFunnel","mouthPucker","mouthLeft","mouthRight","mouthRollUpper","mouthRollLower","mouthShrugUpper","mouthShrugLower","mouthClose","mouthSmileLeft","mouthSmileRight","mouthFrownLeft","mouthFrownRight","mouthDimpleLeft","mouthDimpleRight","mouthUpperUpLeft","mouthUpperUpRight","mouthLowerDownLeft","mouthLowerDownRight","mouthPressLeft","mouthPressRight","mouthStretchLeft","mouthStretchRight"]
for key in arkit:
frame += frame_increment
bpy.context.scene.frame_set(frame)
bpy.ops.object.modifier_apply_as_shapekey(keep_modifier=True,modifier=rig_name)
bpy.context.object.data.shape_keys.key_blocks["rig"].name = key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment