// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // Procedure Name: // blendShapeChangeInBetweenWeight // // Description: // change the weight of an in-between target // // Input Arguments: // bs - Blend shape name; // targetIndex - Hero target index of the in-between target; // oldIbWeight - Current weight of the in-between target; // $newIbWeight - New weight of the in-between target; // global proc int blendShapeChangeInBetweenWeight(string $bs, int $targetIndex, float $oldIbWeight, float $newIbWeight) { int $newIbIndex = $newIbWeight * 1000 + 5000; int $oldIbIndex = $oldIbWeight * 1000 + 5000; if($newIbIndex == 6000) { error( (uiRes("m_blendShapeChangeInBetweenWeight.kInBetweenErrorWeightEqualsToOne"))); return 0; } string $baseGeomNames[]=`blendShape -q -g $bs`; int $baseGeomIndices[]=`blendShape -q -gi $bs`; if( size($baseGeomNames) == 0 || size($baseGeomNames) != size($baseGeomIndices) ) return 0; string $targetGeomNames[]; for ($baseIndex in $baseGeomIndices) { string $attr = $bs + ".inputTarget[" + $baseIndex + "].inputTargetGroup[" + $targetIndex + "].inputTargetItem"; int $ibIndices[] = `getAttr -mi $attr`; if (intArrayContains($newIbIndex, $ibIndices)) { //IB already exist, revert error( (uiRes("m_blendShapeChangeInBetweenWeight.kInBetweenErrorWeightDuplicate"))); return 0; } $attr += "[" + $oldIbIndex + "].inputGeomTarget"; string $targetGeomName[] = `listConnections -sh 1 $attr`; // Get the physical geom shape if the in-between has target shape connected. if (size($targetGeomName)) $targetGeomNames[size($targetGeomNames)] = $targetGeomName[0]; else $targetGeomNames[size($targetGeomNames)] = ""; // Currently when add inbetweens by UI it will always be added for every base geom // if there are multiple bases. So no need to loop them all. // If this changes in the future, we may need to adjust this logic too. } string $ibTypeAttr = $bs + ".inbetweenInfoGroup[" + $targetIndex + "].inbetweenInfo[" + $oldIbIndex + "].inbetweenTargetType"; int $ibType = `getAttr $ibTypeAttr`; // Re-add the in-between targets to each base geom with the new weight. string $addCmd = "doBlendShapeAddInBetweenTargetWithSpecifiedBaseAndTarget " + $bs + " on " + $targetIndex + " " + $newIbWeight + " " + $ibType; // Construct the base and target geoms string. $addCmd += " {"; for ($i = 0; $i