Moderator: joepal
Rhynedahll wrote:Just to verify, these are still in 0.27?
SonAmyFan362 wrote:Can someone tell me how to use each Viseme as a Shape Key, please?
import bpy
#===============================================================================
def zeroKeys(mesh):
for block in mesh.data.shape_keys.key_blocks:
block.value = 0
#assume mesh has already merged teeth, tongue, eye lashes, eye browses to the body mesh
def combineFaceKeys(scene, mesh, delete = False):
combineKey(scene, mesh, ['mouth_open'], [1], 'FACE-MOUTH_OPEN', delete) # really just a name change
combineKey(scene, mesh, ['mouth_wide_left', 'mouth_wide_right'], [1, 1], 'FACE-MOUTH_WIDE', delete)
combineKey(scene, mesh, ['mouth_up_left' , 'mouth_up_right' ], [1, 1], 'FACE-MOUTH_UP' , delete)
combineKey(scene, mesh, ['lips_mid_upper_up_left', 'lips_mid_upper_up_right'], [1, 1], 'FACE-LIPS_MID_UPPER_UP', delete)
combineKey(scene, mesh, ['lips_mid_lower_down_left', 'lips_mid_lower_down_right'], [1, 1], 'FACE-LIPS_MID_LOWER_DOWN', delete)
combineKey(scene, mesh, ['tongue_back_up', 'tongue_up'], [1, 1], 'FACE-TONGUE', delete)
# combineKey(scene, mesh, ['', ''], [1, 1], 'FALSE-', delete)
zeroKeys(mesh)
def combineKey(scene, mesh, keysToCombine, keyValues, finalName, delete = False):
# bpy.ops.object.shape_key_add will only work when mesh is the active object
scene.objects.active = mesh
# delete any key of the final name, so can be done more than once
deleteKey(scene, mesh, finalName)
# clear all the values of each shape key
zeroKeys(mesh)
# apply each of the keys to composite the new one
idx = 0
for shapeName in keysToCombine:
mesh.data.shape_keys.key_blocks[shapeName].value = keyValues[idx]
idx += 1
# create the new key from a mix
bpy.ops.object.shape_key_add(from_mix=True)
# name the new key
mesh.data.shape_keys.key_blocks[mesh.active_shape_key_index].name = finalName
# delete keys on request
if delete:
for shapeName in keysToCombine:
deleteKey(scene, mesh, shapeName)
def removeCombinedKeys(scene, mesh):
deleteKey(scene, mesh, 'FACE-MOUTH_OPEN')
deleteKey(scene, mesh, 'FACE-MOUTH_WIDE')
deleteKey(scene, mesh, 'FACE-MOUTH_UP')
deleteKey(scene, mesh, 'FACE-LIPS_MID_UPPER_UP')
deleteKey(scene, mesh, 'FACE-LIPS_MID_LOWER_DOWN')
deleteKey(scene, mesh, 'FACE-TONGUE')
def deleteKey(scene, mesh, shapeName):
scene.objects.active = mesh
bpy.ops.object.mode_set(mode='OBJECT')
# cannot just assign mesh.active_shape_key, since it is readonly, must set index
for idx in range(len(mesh.data.shape_keys.key_blocks)):
if mesh.data.shape_keys.key_blocks[idx].name == shapeName:
mesh.active_shape_key_index = idx
bpy.ops.object.shape_key_remove(all=False)
print('deleted ' + shapeName)
return
print('failed to delete key: ' + shapeName)
#===============================================================================
# add import_runtime_mhx2 to sys.path, so can be imported
mhxOnPath = False
def putMhxOnPath():
global mhxOnPath
if not mhxOnPath:
import os
import sys
addon_paths = bpy.utils.script_paths('addons')
for path in addon_paths:
lib_path = os.path.join(path, 'import_runtime_mhx2')
if os.path.exists(lib_path):
print('mhx2 found @ ' + lib_path)
sys.path.append(lib_path)
mhxOnPath = True
break
return mhxOnPath
def importMHShapes(human, filename):
if not putMhxOnPath():
raise 'mhx2 runtime could not be found'
from os import path
from import_runtime_mhx2.shapekeys import getScales, addTargets
from import_runtime_mhx2.load_json import loadJson
from import_runtime_mhx2.utils import getMhHuman
filePath = path.join(path.dirname(__file__), filename)
print('importing shapes from: ' + filePath)
mhHuman = getMhHuman()
struct = loadJson(filePath)
scales = getScales(human, struct["bounding_box"], mhHuman)
addTargets(human, struct["targets"], scales)
Return to MHX2 and other plugins developed outside MakeHuman
Users browsing this forum: No registered users and 1 guest