View Single Post
# 13 26-12-2013 , 04:26 AM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
I quickly wrote up a script that should do what you want.

Select your blendshapes, then your target object. Move to the frame that you wish the animation to begin and run the script. This will create keyframes of each blendshape activated for a single key. You will probably need to space out the keys, but it should get you 99% of the way there.

Code:
// Multiple objects to keyframed blendshape - (C) John Mather (NextDesign) 2013
// Author page: https://www.creativecrash.com/users/john-mather
// Usage: 1) Select your blendshapes, then your target object. 
//        2) Move to the frame that you wish the animation to begin and run the script.

string $sel[] = `ls -sl`;

if (size($sel) > 0)
{
    string $blendshapes[] = `blendShape -origin "local"`;
    
    string $blendshape = $blendshapes[0];
    int $nWeights = `blendShape -q -wc $blendshape`;
    string $targets[] = `blendShape -q -t $blendshape`;
    int $t = `currentTime -q`;
    
    // create a keyframe with all attributes set to 0
    setKeyframe -t $t -ott "step" $blendshape;
    
    $t++;
    
    for ($weight = 0; $weight < $nWeights; $weight++)
    {
        string $bsAttr = $blendshape + "." + $targets[$weight];
        
        if ($weight == 0)
        {
            // set the first weight's value to 1. ignore anything before.
            setKeyframe -t ($t - 1) -v 0 -ott "step" $bsAttr;
            setKeyframe -t $t -v 1 -ott "step" $bsAttr;
        }
        else
        {
            // set the next weight's value to 1, and set the previous to 0. 
            string $lastbsAttr = $blendshape + "." + $targets[$weight - 1];
            
            setKeyframe -t ($t - 1) -v 0 -ott "step" $bsAttr;
            setKeyframe -t $t -v 1 -ott "step" $bsAttr;
            
            setKeyframe -t $t -v 0 -ott "step" $lastbsAttr;
        }
        
        $t++;
    }
}
Happy holidays!


Imagination is more important than knowledge.

Last edited by NextDesign; 26-12-2013 at 05:23 AM.