// =========================================================================== // 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. // =========================================================================== // // // // global proc float[] getIKFKJointRotations(string $handle) // // Description: // When switching from IK to FK, set the joint rotations so they // do not jump. // { string $joints[] = `ikHandle -q -jl $handle`; string $j; float $rot[]; int $rotIndex = 0; for ($j in $joints) { float $r[] = `getAttr ($j+".r")`; $rot[$rotIndex++] = $r[0]; $rot[$rotIndex++] = $r[1]; $rot[$rotIndex++] = $r[2]; } return $rot; } global proc setIKFKJointRotations(string $handle, float $rot[]) { string $joints[] = `ikHandle -q -jl $handle`; string $j; int $rotIndex = 0; for ($j in $joints) { setAttr ($j+".r") $rot[$rotIndex++] $rot[$rotIndex++] $rot[$rotIndex++]; } } global proc updateIKFKState() // // { int $oldMode = `optionVar -q ikFKSwitchState`; int $ikFKSetting = (! $oldMode); optionVar -intValue ikFKSwitchState $ikFKSetting; if (`menuItem -exists ikFKStateItem`) { menuItem -edit -checkBox $ikFKSetting ikFKStateItem; } int $count; string $sel[] = `ls -sl`; string $handles[] = `ls -sl -type "ikHandle"`; string $jointList[] = `ls -sl -type "joint"`; if (size($sel) != (size($handles)+size($jointList))) { // check if any of the selected objects are connected to fk/ik // for ($obj in $sel) { string $attrName; if (size(`ls ($obj+".ikBlend")`)) { $attrName = ".ikBlend"; } else if (size(`ls ($obj+".solverEnable")`)) { $attrName = ".solverEnable"; } if (size($attrName)) { string $cnx[] = `listConnections -d 0 ($obj+$attrName)`; // This only makes sense if an ikHandle is at the other end of the // object. // if (size($cnx) > 0 && (nodeType($cnx[0]) == "ikHandle")) { $handles[size($handles)] = $cnx[0]; } } } } if (size($handles) > 0) { string $h; for ($h in $handles) { float $rot[] = getIKFKJointRotations($h); setAttr ($h + ".ikBlend") $ikFKSetting; setIKFKJointRotations($h, $rot); $count++; } } if (size($jointList) > 0) { int $found = false; string $handle; string $handles[] = `ls -type ikHandle`; string $h; for ($h in $handles) { string $joints[] = `ikHandle -q -jl $h`; int $nJoints = size($joints); $joints[$nJoints] = `ikHandle -q -sj $h`; string $j; for ($j in $joints) { string $sj; for ($sj in $jointList) { if (size(`match $sj $j`) > 0 && size(`match ($sj+"|") $j`) == 0) { float $rot[] = getIKFKJointRotations($h); setAttr ($h + ".ikBlend") $ikFKSetting; setIKFKJointRotations($h, $rot); $count++; } } } } } if ($count == 1) { print((uiRes("m_updateIKFKState.kUpdatedOneHandle"))); } else if ($count > 1) { string $printMsg = (uiRes("m_updateIKFKState.kUpdatedHandles")); print(`format -s $count $printMsg`); } else { error((uiRes("m_updateIKFKState.kSelectAHandle"))); } }