Skip to content

Instantly share code, notes, and snippets.

@gifguide2code
Last active April 8, 2018 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gifguide2code/78d168ee30296ab0242d5ee1b5e94733 to your computer and use it in GitHub Desktop.
Save gifguide2code/78d168ee30296ab0242d5ee1b5e94733 to your computer and use it in GitHub Desktop.
A function to automate setting shape keys for a mouth on a mesh in Blender.
import bpy
import random
def chat(speech, speed):
slist = list(speech)
mouth = bpy.data.objects['Mouth']
face = bpy.data.objects['Face']
f = 1
for x in slist:
if (x=="a") or (x=="e") or (x=="i") or (x=="o") or (x=="u") or (x=="y"):
mouth.select = True
bpy.data.shape_keys["Key.001"].key_blocks["Oh"].value = 1
mouth.data.shape_keys.key_blocks["Oh"].keyframe_insert("value",frame=f)
mouth.select = False
face.select = True
bpy.data.shape_keys["Key.002"].key_blocks["Chin"].value = 0
face.data.shape_keys.key_blocks["Chin"].keyframe_insert("value",frame=f)
face.select = False
f+=speed
else:
mouth.select = True
bpy.data.shape_keys["Key.001"].key_blocks["Oh"].value = 0
mouth.data.shape_keys.key_blocks["Oh"].keyframe_insert("value",frame=f)
mouth.select = False
face.select = True
bpy.data.shape_keys["Key.002"].key_blocks["Chin"].value = 1
face.data.shape_keys.key_blocks["Chin"].keyframe_insert("value",frame=f)
face.select = False
f+=speed
song = "heeello my daaaarliiiing heeello my hooonyyy heeello myyy raaagtiiimm gaaaaal"
chat(song, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment