Monday, July 14, 2014

Tip: Update Blendshape and keep its blendnode connections

Hi,

Tip updating a blendshape and keeping all its driven keys, connections etc.
(note for cleanup it does need a little work with nodes example disconnecting shape inmesh from blend node -- (i wrote a test script to clean up a meshes input its still a work in progress but may be helpful))

Suppose wanted to change l_brow_up with a new sculpt but its already connected up with a ui etc.  To update it with say new_l_brow_up, just plug  new_l_brow_up into l_brow_up as a blendshape and put blendweight at 1.  Then just delete new_l_brow_up. Now our l_brow_up should be updated with change and how its used with a blend node is preserved.


Here's the rough script i wrote to clean up a meshes input:
//07-14-2014 -- nate  -- initial release
//Modify at own risk
global proc na_cleanBlendshapeInput(){
    //clean blendshape input of selected, currently it assumes preserving shader on blendshape is not required
    //assumes shape selected assumes shape has exactly one blend node
    if(size(`ls -sl`) == 1){
        string $selAr[] = `ls -sl`;
        string $shape = "";
        
        //so it can work with selecting transform or shape
        if( `objectType $selAr[0]`  != "mesh" ){
            string $tryThisAr[] = `pickWalk -d down`;//ignoring if doesnt have shape
            if( `objectType $tryThisAr[0]` == "mesh"){$shape = $tryThisAr[0];}
            else{error("Requires single Shape selected");}
        }
        else{$shape = $selAr[0];}
        //
        
        string $allHistory[] = `listHistory $shape`;
        string $blendNodeAr[] = `ls -type blendShape $allHistory`;
        
        if(size($blendNodeAr) == 1){
            string $blendNode = $blendNodeAr[0];
            //cleanup blendshape input
            //disconnectAttr lipBlend_test2.outputGeometry[0] |r_brow_up_default|r_brow_up_defaultShape.inMesh;
            disconnectAttr ($blendNode+"."+"outputGeometry[0]") ($shape+"."+"inMesh");
            //remove blend node for cleanup this need to come after disconnecting
        //might need to verify this blendnode is coming from input only
            delete $blendNode;
        }
        else{error("Requires one blend shape node on selected shape!!!");}
    }
    
}



Hope you find this helpful.

cheers,
Nate