MB-Lab Release for Blender 2.80

I got the muscle rig working with rigify rig - kind of. There are some issues I could not solve. The knee IK targets are crossed. The feet are rolled in. This makes the feet go unter the ground.

I’m posting here, so more people can see this. For bug reports etc. please post here to not spam this thread with half off-topic posts!


This code is for testing only! Don’t damage your work!

  1. Select the “MBlab_sk_” rig and run this to get the rigify rig:
    This takes a long time.
import bpy
from mathutils import Vector

mblab_rig = None
rigify_rig = None
muscle_rig = None

muscle_parents = {}

subtargets = {}

bpy.ops.object.mode_set(mode='OBJECT')

# Duplicate MB-lab rig
bpy.ops.object.duplicate()
mblab_rig = bpy.context.active_object

# EDIT MODE
bpy.ops.object.mode_set(mode='EDIT')

# Fix disconnected toe
bpy.context.active_object.data.edit_bones['toes_R'].use_connect = True

# Disconnect upperarms
bpy.context.active_object.data.edit_bones['upperarm_L'].use_connect = False
bpy.context.active_object.data.edit_bones['upperarm_R'].use_connect = False

# re-parent thumbs
bpy.context.active_object.data.edit_bones['thumb01_L'].parent = bpy.context.active_object.data.edit_bones['index00_L']
bpy.context.active_object.data.edit_bones['thumb01_R'].parent = bpy.context.active_object.data.edit_bones['index00_R']

# Connect spine with neck
bpy.context.active_object.data.edit_bones['spine03'].tail = bpy.context.active_object.data.edit_bones[
    'neck'].head.copy()
bpy.context.active_object.data.edit_bones['neck'].use_connect = True

# Create heels
for ext in ["_L", "_R"]:
    bone_name = "heel" + ext
    bone_heel = bpy.context.active_object.data.edit_bones.new(bone_name)
    bone_heel.bbone_x = 0.01
    bone_heel.bbone_z = 0.01
    foot_bone = bpy.context.active_object.data.edit_bones["foot" + ext]
    # heel x location relative to foot head
    bone_heel.tail.x = 0.1 if ext == "_L" else -0.1
    heel_head_x = (bone_heel.tail.x - foot_bone.head.x) / 2 + foot_bone.head.x
    heel_tail_x = (foot_bone.head.x - bone_heel.tail.x) / 2 + foot_bone.head.x
    bone_heel.head = Vector((heel_head_x, mblab_rig.location.y, mblab_rig.location.z))
    bone_heel.tail = Vector((heel_tail_x, mblab_rig.location.y, mblab_rig.location.z))
    # parent
    bone_heel.use_connect = False
    bone_heel.parent = foot_bone

# Rename muscle bones on layer 1
for name, bone in bpy.context.active_object.data.edit_bones.items():
    if "rot_helper" in name:
        bone.name = "MCH-" + name
        bone.use_deform = False
    if "muscle" in name:
        if "_H" in name or "_T" in name:
            bone.name = "MCH-" + name
            bone.use_deform = False
        else:
            bone.name = "DEF-" + name

bpy.ops.object.mode_set(mode='POSE')

# Subtargets
for name, bone in bpy.context.active_object.pose.bones.items():
    if "rot_helper" in name or "muscle" in name:
        temp_constraints = {}
        for c_name, constraint in bone.constraints.items():
            sub_name = constraint.subtarget
            if "MCH" not in constraint.subtarget:
                sub_name = "DEF-" + sub_name
            temp_constraints[c_name] = sub_name
        subtargets[name] = temp_constraints

bpy.ops.object.mode_set(mode='EDIT')
# Save the parents
for name, bone in bpy.context.active_object.data.edit_bones.items():
    if "rot_helper" in name or "muscle" in name:
        if "MCH" not in bone.parent.name and "DEF" not in bone.parent.name:
            parent_name = "DEF-" + bone.parent.name
        else:
            parent_name = bone.parent.name
        muscle_parents[name] = parent_name

for name, bone in bpy.context.active_object.data.edit_bones.items():
    if "rot_helper" in name or "muscle" in name:
        bone.parent = None

bpy.ops.object.mode_set(mode='POSE')

# Unlock transforms
for name, bone in bpy.context.active_object.pose.bones.items():
    bone.lock_location[0] = False
    bone.lock_location[1] = False
    bone.lock_location[2] = False
    bone.lock_scale[0] = False
    bone.lock_scale[1] = False
    bone.lock_scale[2] = False

# set rigify types
bpy.context.object.pose.bones["pelvis"].rigify_type = "spines.super_spine"
bpy.context.object.pose.bones["pelvis"].rigify_parameters['neck_pos'] = 5

bpy.context.object.pose.bones["clavicle_L"].rigify_type = "basic.super_copy"
bpy.context.object.pose.bones["clavicle_R"].rigify_type = "basic.super_copy"

bpy.context.object.pose.bones["breast_L"].rigify_type = "basic.super_copy"
bpy.context.object.pose.bones["breast_R"].rigify_type = "basic.super_copy"

for ext in ["_L", "_R"]:
    bone_name = 'thigh' + ext
    bpy.context.object.pose.bones[bone_name].rigify_type = "limbs.super_limb"
    bpy.context.object.pose.bones[bone_name].rigify_parameters.limb_type = 'leg'
    bpy.context.object.pose.bones[bone_name].rigify_parameters.segments = 1
    bpy.context.object.pose.bones[bone_name].rigify_parameters.rotation_axis = 'x'

    bone_name = 'upperarm' + ext
    bpy.context.object.pose.bones[bone_name].rigify_type = "limbs.super_limb"
    bpy.context.object.pose.bones[bone_name].rigify_parameters.limb_type = 'arm'
    bpy.context.object.pose.bones[bone_name].rigify_parameters.segments = 1

    bpy.context.object.pose.bones["index00" + ext].rigify_type = "limbs.super_palm"

    for name in ['thumb01', 'index01', 'middle01', 'ring01', 'pinky01']:
        bone_name = name + ext
        bpy.context.object.pose.bones[bone_name].rigify_type = "limbs.simple_tentacle"

    bpy.context.object.data.bones["breast" + ext].hide = False

bpy.ops.object.mode_set(mode='OBJECT')

# Duplicate MB-lab rig
bpy.ops.object.duplicate()
muscle_rig = bpy.context.active_object

bpy.ops.object.select_all(action='DESELECT')

bpy.context.view_layer.objects.active = muscle_rig

# Delete bones on layer 1
bpy.ops.object.mode_set(mode='EDIT')

bpy.context.object.data.layers[0] = True
bpy.context.object.data.layers[1] = True
for name, bone in bpy.context.active_object.data.edit_bones.items():
    if bone.layers[0]:
        bone.select = True
    else:
        bone.select = False
bpy.ops.armature.delete()

# Move bones to layer 3
for name, bone in bpy.context.active_object.data.edit_bones.items():
    bone.layers[2] = True
for name, bone in bpy.context.active_object.data.edit_bones.items():
    bone.layers[1] = False

bpy.ops.object.mode_set(mode='OBJECT')

# generate rigify rig
bpy.ops.object.select_all(action='DESELECT')
bpy.context.view_layer.objects.active = mblab_rig
bpy.ops.pose.rigify_generate()
rigify_rig = bpy.context.active_object

# add copy rig to rigify rig
muscle_rig.select_set(True)
rigify_rig.select_set(True)
bpy.context.view_layer.objects.active = rigify_rig
bpy.ops.object.join()

bpy.ops.object.mode_set(mode='EDIT')

for bone_name, parent_name in muscle_parents.items():

    # re-parent bones
    bpy.context.active_object.data.edit_bones[bone_name].parent = bpy.context.active_object.data.edit_bones[parent_name]

    # reconnect muscle bones
    if "muscle" in bone_name:
        if not ("_H" in bone_name or "_T" in bone_name):
            bpy.context.active_object.data.edit_bones[bone_name].use_connect = True

bpy.ops.object.mode_set(mode='POSE')

# Subtargets
for bone_name, constraint in subtargets.items():
    for c_name, sub_name in constraint.items():
        bpy.context.object.pose.bones[bone_name].constraints[c_name].subtarget = sub_name

bpy.ops.object.mode_set(mode='OBJECT')

  1. Select the mesh “MBlab_bd_” and run this for renaming the vertex groups:
import bpy

for name, v_group in bpy.context.active_object.vertex_groups.items():
    new_name = "DEF-" + name
    v_group.name = new_name
  1. Replace rig in “mbastlab_armature” modifier.
2 Likes