// =========================================================================== // 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. // =========================================================================== // Flag that if the neutral poses creation dialog will pop up // Three states: // -1 - the dialog should pop up; // 0 - the dialog should not pop up, and not create neutral pose when driver are controlled // 1 - the dialog should not pop up, and create neutral pose when driver are controlled global int $gCreateNeutralPoseWhenControlled = -1; global proc createNeutralPosesQueryDialogDismiss(int $noMore, int $status) { global int $gCreateNeutralPoseWhenControlled; if ($noMore != 0) $gCreateNeutralPoseWhenControlled = $status; if ($status) layoutDialog -dismiss "yes"; else layoutDialog -dismiss "no"; } global proc createNeutralPosesQueryDialog() { string $warningText = getPluginResource("poseInterpolator", "kNeutralPoseAddIssue"); string $yes = getPluginResource("poseInterpolator", "kYes"); string $no = getPluginResource("poseInterpolator", "kNo"); string $dontDisplayAgainText = getPluginResource("poseInterpolator", "kNotDisplayAgain"); columnLayout -columnAttach "both" 10 -rowSpacing 10 -columnWidth 450; string $text = `text -h 120 -al "left" -ww true -l $warningText`; rowLayout -numberOfColumns 2 -columnAttach2 "right" "left" -columnOffset2 20 20 -columnWidth2 225 225; string $noButton = `button -w 80 -l $no`; string $yesButton = `button -w 80 -l $yes`; setParent ..; string $dontDisplayAgainCheckBox = `checkBox -h 40 -l $dontDisplayAgainText -v 0`; setParent ..; string $callbackCmd = "createNeutralPosesQueryDialogDismiss(eval(\"checkBox -q -value " + $dontDisplayAgainCheckBox + "\"),0)"; button -e -c $callbackCmd $noButton; $callbackCmd = "createNeutralPosesQueryDialogDismiss(eval(\"checkBox -q -value " + $dontDisplayAgainCheckBox + "\"),1)"; button -e -c $callbackCmd $yesButton; } proc int createNeutralPosesWhenControlled() { global int $gCreateNeutralPoseWhenControlled; string $res; if ($gCreateNeutralPoseWhenControlled == -1) { string $title = getPluginResource("poseInterpolator", "kAddNeutralPoses"); $res = `layoutDialog -title $title -ui ("createNeutralPosesQueryDialog")`; } if ($gCreateNeutralPoseWhenControlled == 1 || $res == "yes") return 1; else return 0; } global proc string createPoseInterpolatorNode(string $nodeName, int $flagCreateNeutralPose, int $flagDriverTwistAxis) // // Description: // To create a poseInterpolator given a name. // Neutral poses will be created too if $flagCreateNeutralPose > 0. // // Return value: "" if fail to create a poseInterpolator, else the name of the poseInterpolator. // { string $resultName[] = `poseInterpolator -name $nodeName`; string $tpl = $resultName[0]; select $tpl; if ($flagCreateNeutralPose > 0) { // Check if drivers are controlled by other attributes string $attributes[6] = {"rotateX", "rotateY", "rotateZ", "translateX", "translateY", "translateZ"}; int $controlled = 0; string $drivers[] = poseInterpolatorDrivers( $tpl ); for ($driver in $drivers) { for($i = 0; $i < 6; $i++) { string $attribute = $driver + "." + $attributes[$i]; string $connectList[] = `listConnections -d off -scn on $attribute`; if (size($connectList)) { if( !isAnimCurve($connectList[0]) ) { $controlled = 1; break; } } } if($controlled) break; } if(!$controlled) { createNeutralPoses( $tpl ); } else { int $createWhenControlled = createNeutralPosesWhenControlled(); if($createWhenControlled) createNeutralPoses( $tpl ); } } // set driver twist axis string $tplShape = poseInterpolatorShape( $tpl ); string $attrName = $tplShape + ".driver"; int $indices[] = `getAttr -multiIndices $attrName`; for( $index in $indices ) { string $twistAxisAttr = $attrName + "[" + $index + "].driverTwistAxis"; setAttr $twistAxisAttr $flagDriverTwistAxis; } return $tpl; }