Blender pipeline needs to optionally prevent bone length distortions

On human realistic characters during rigify:

I want to prevent character limbs (and other items) from stretching when rigified IKs are positioned past normal limits:

Perhaps there’s a way to accomplish this lockdown withing CC itself in a global way?

Here’s an example script (WARNING: incomplete and not thoroughly tested) that would accomplish this in blender:

import bpy

for obj in bpy.data.objects:
if obj.type==‘ARMATURE’:
for bone in obj.pose.bones:

        # make all bones rotation Euler 
        bone.rotation_mode = 'XYZ'
        
        if bone.name.find("MCH") > -2:  # >-2 accepts all bones
            for cnst in bone.constraints:
                if cnst.type=="IK":
                    cnst.use_stretch = False
                    print( 'disable stretch on', bone.name, cnst.name )
                    
        if bone.name.find("DEF") > -2:  # >-2 accepts all bones
            hasStretchTo = False
            hasLimitScale = False
            for cnst in bone.constraints:
                if cnst.type=='STRETCH_TO':
                    hasStretchTo = True
                if cnst.type=='LIMIT_SCALE':
                    hasLimitScale = True
            if hasStretchTo and not hasLimitScale:
                lsCnst = bone.constraints.new('LIMIT_SCALE')                    
                lsCnst.use_min_y = True
                lsCnst.use_max_y = True               
                lsCnst.min_y = 1.0
                lsCnst.max_y = 1.03
                
    # lock some bone scales
    for bc in obj.data.collections:
        if bc.name.find('IK') > -1: # IK bones
            for b in bc.bones:
                bone = obj.pose.bones[ b.name ]
                bone.lock_scale = [True,True,True]

Please let me know if I’m overlooking the obvious solution during the pipeline/rigify process! If not, I’ll share again a more complete and well tested script in the future.

blender import after running the script:

You can control the stretch on each limb in the rigify Rig Main Properties:
rigmainprops

And I also put these together for quick access in the Rig Controls section of the Rigging and Animation panel:

1 Like