maya xform不解

1900 | |被浏览1661次| 0
|2016-08-12 22:23:25

三套骨骼中的时候 ikfk match 时使用 xform有不解 ;
问题模型是这样设置 c2 为joint3子物体,然后使用
$c2=`xform -q -ws -t c2`;
xform -ws -t $fk1[0] $fk1[1] $fk1[2] c1;
结果c1 c2出现在不同地方,
然后使用
xform -q -ws -t c2;
xform -q -ws -t c1;查询空间坐标一致。

分享到: 更多

满意回答

2018-08-14 21:42:10

我是小白  没怎么看懂 但是其实想要一致 用吸附就可以了啊 。。 下面是MG 吸附的 单独代码
POSnap 1;
print ("//Rain: ========吸附完成!========");

//===================Animation Snap codes=====================================================
global proc POSnap (int $snapmode)
{
string $nodes[];
global int $testSupportPythonOrNotForMGtools;
$nodes = `ls -sl -l`;
int $number=`size $nodes`;
if ($number !=2)
{
confirmDialog -title `MG_DualLan "footStepSnap.warnSelect.title"`
-message `MG_DualLan "snapLoc.POsnap.war.message"`
-button `MG_DualLan "snapLoc.POsnap.war.ok"`;
}
else
{

string $sel []=`ls -sl -l`;
string $copy[];
if($testSupportPythonOrNotForMGtools)
{
$copy= `duplicate -po $sel[1]`;
}
else
{
$copy= `duplicate $sel[1]`;
}
$copyedSlave=$copy[0];
if($snapmode==1||$snapmode==4)
{
arr_snap ($sel[0],$copyedSlave);
keyedSnap ($copyedSlave,$sel[1]);
}
if($snapmode==2||$snapmode==5)
{
pointsnap ($sel[0],$copyedSlave);
pointkeyedSnap ($copyedSlave,$sel[1]);
}
if($snapmode==3||$snapmode==6)
{
orientsnap ($sel[0],$copyedSlave);
orientkeyedSnap ($copyedSlave,$sel[1]);
}

delete $copyedSlave;
}
}


//==========================parent snap==================================
global proc int tempToggleOffConstraintBackup ()
{
int $result = 0;
if(`exists animRescue`)
{
if(`animRescue -q -ctt`)
{
animRescue -e -ctt 0;
$result=1;
}
}
return $result;
}

global proc tempToggleOnConstraintBackup ()
{
if(`exists animRescue`)
{
if(!`animRescue -q -ctt`)
{
animRescue -e -ctt 1;
}
}
}
global proc makeMultiplySnapLoc(int $mode)
{
global string $gPlayBackSlider;
string $selectrange = `timeControl -q -range   $gPlayBackSlider`;
string $buffer[];
   $numTokens = `tokenize $selectrange ":" $buffer`;
int $size1=`size $buffer[0]`;
int $size2=`size $buffer[1]`;
int $start = `substring $buffer[0] 2 $size1`;
int $end =`substring $buffer[1] 1 ($size2-1)`;
//print ($start+" "+$end);
string $selections []= `ls -sl`;
if(size ($selections)==0){return;}
if(($end -$start)==1)
{
for ($each in $selections)
{
if (!`gmatch $each "*SnapLoc_f*"`)
{select $each;snapLoc 1;}
}
select $selections;
}
else
{
for ($each in $selections)
{
if (!`gmatch $each "*SnapLoc_f*"`)
{
select $each; string $keyTicks[];string $nextKey;int $nextKeyStart;
if($mode==0)
{ $nextKey=`findKeyframe -time ($start-1)  -which "next" -at "translateX" -at "translateY"  -at "translateZ"  -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
$nextKeyStart =`findKeyframe -time ($start-1)  -which "next" -at "translateX" -at "translateY"  -at "translateZ"  -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
}
if($mode==1)
{ $nextKey=`findKeyframe -time ($start-1)  -which "next" -at "translateX" -at "translateY"  -at "translateZ"  $each`;
$nextKeyStart =`findKeyframe -time ($start-1)  -which "next" -at "translateX" -at "translateY"  -at "translateZ"  $each`;
}
if($mode==2)
{ $nextKey=`findKeyframe -time ($start-1)  -which "next"   -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
$nextKeyStart =`findKeyframe -time ($start-1)  -which "next"  -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
}
if ($nextKeyStart <=$end&&$nextKeyStart>=$start)
{ //print ("The first key is in "+$nextKey+"\n");
$keyTicks[size($keyTicks)]=$nextKey;
int $runTimes = ( $end -$start);
for ($i=0; $i<$runTimes; $i++)
{ int $newStart = $nextKeyStart ;
if($mode==0)
{ $nextKey=`findKeyframe -time $newStart -which "next" -at "translateX" -at "translateY"  -at "translateZ"   -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
$nextKeyStart =`findKeyframe -time $newStart -which "next" -at "translateX" -at "translateY"  -at "translateZ"  -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
}
if($mode==1)
{ $nextKey=`findKeyframe -time $newStart -which "next" -at "translateX" -at "translateY"  -at "translateZ"  $each`;
$nextKeyStart =`findKeyframe -time $newStart -which "next" -at "translateX" -at "translateY"  -at "translateZ"  $each`;
}
if($mode==2)
{ $nextKey=`findKeyframe -time $newStart -which "next"   -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
$nextKeyStart =`findKeyframe -time $newStart -which "next" -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
}


//print  ("The second Key is  "+$nextKey);
if ($nextKeyStart <=$end&&$nextKeyStart>=$start)
{$keyTicks[size($keyTicks)]=$nextKey;}
else {break;}
}
}
//print $keyTicks;
string $shorterTicks[] = stringArrayRemoveDuplicates($keyTicks);
if($mode==0){print `MG_DualLanFormat_1 "snapLoc.snapLocMode.rep0" $each`;}
if($mode==1){print `MG_DualLanFormat_1 "snapLoc.snapLocMode.rep1" $each`;}
if($mode==2){print `MG_DualLanFormat_1 "snapLoc.snapLocMode.rep2" $each`;}
//print $shorterTicks;
for ($eachInc in $shorterTicks)
{ print (" "+$eachInc);
currentTime -edit $eachInc;
snapLoc 1;
select $each;

}
$keyTicks={};
}
}
select $selections;
}
int $locNum = size(`ls -transforms "*SnapLoc_f*"`);
print "\n";
print `MG_DualLanFormat_1 "snapLoc.snapLocNum.rep" $locNum`;
}

global proc string snapLoc (int $mode)
{
global string   $gPlayBackSlider;
string $selectrange = `timeControl -q -range   $gPlayBackSlider`;
string $buffer[];
   $numTokens = `tokenize $selectrange ":" $buffer`;
int $size1=`size $buffer[0]`;
int $size2=`size $buffer[1]`;
int $start = `substring $buffer[0] 2 $size1`;
int $end =`substring $buffer[1] 1 ($size2-1)`;
//print ($start+" "+$end);
int $number = size(`ls -l -sl`);
if (size(`ls -l -sl`) == 0)
{
   confirmDialog -title `MG_DualLan "footStepSnap.warnSelect.title"`
-message  `MG_DualLan "footStepSnap.warnSelect.message"`
-button `MG_DualLan "footStepSnap.warnSelect.ok"` ;
}
else if (size(`ls -l -sl`) > 1)
{
string $test =`layoutDialog -ui "createMultipleSnapLocPrompt"`;
if ($test=="Next")
{
makeMultiplySnapLoc 0;
}
else
{return "";}

}
else
{
string $nodes[];
$nodes=`ls -sl`;
string $buffer[];
int $num =`tokenize $nodes[0] ":" $buffer`;
string $theNode;
if(size($buffer[1])==0) {$theNode = $buffer[0];}
else {$theNode = $buffer[0]+"_"+$buffer[1];}
string $frame =`currentTime -q`;
string $nodes01 [];
if(`objExists ($theNode+"_SnapLoc_f"+$frame)`)
{
$nodes01[0]=($theNode+"_SnapLoc_f"+$frame);
select -r $nodes;
select -add $nodes01;
POSnap 1;

  }
else{
$nodes01=`spaceLocator -p 0 0 0 -n ($theNode+"_SnapLoc_f"+$frame)`;
select -r $nodes;
select -add $nodes01;
POSnap 1;
}

select -r $nodes01[0];
string $grptest[]=`pickWalk -d up`;
if($grptest[0]!="snapLocsGrp")
{
if(`objExists "snapLocsGrp"`)
{parent $nodes01[0] snapLocsGrp;}
else {group -n "snapLocsGrp" $nodes01[0];}
}

if($mode==1)
{select -r $nodes[0];}
if($mode==2){select -r $nodes01[0]  $nodes[0];}
return $nodes01[0];

}
//int $locNum = size(`ls -transforms "SnapLoc_f*"`);
//print "\n";
//print ("There are now "+$locNum +" snapLocators in your scenes :)");
}


global proc invertSelectSnapLocItems ()
{
string $itemsSelected []=`textScrollList -q -selectItem myTSL`;
string $allItems []=`textScrollList -q -allItems myTSL`;
for ($eachAllItems in $allItems)
{textScrollList -e -selectItem $eachAllItems myTSL;}
for ($eachItemtoDeselect in $itemsSelected)
{textScrollList -e -deselectItem $eachItemtoDeselect myTSL;}
selectSnapLocItem;
}


global proc selectSameObjSnapLocItem ()
{
string $itemsSelected []=`textScrollList -q -selectItem myTSL`;
select -cl;
for ($theItem in $itemsSelected)
{
string $buffer[];
//string $theItem="pCube3_SnapLoc_f2";
$numTokens = `tokenize $theItem "_" $buffer`;
// string $newToken =($buffer[0]+"_"+$buffer[1]+"_");
//int $startNum = size($newToken)+1;
int $endNum = size ($buffer[($numTokens-1)]);
$endNum=size($theItem)-$endNum;
string $objName =`substring $theItem 1 $endNum`;
string $objSets[] = `ls -transforms ($objName+"f*")`;
select -add $objSets;
for ($eachObj in $objSets)
{textScrollList -e -selectItem $eachObj myTSL;}
}
}

global proc selectSnapLocItem ()
{
string $itemsSelected []=`textScrollList -q -selectItem myTSL`;
select -cl;
for ($theItem in $itemsSelected)
{select -add $theItem;}
}


global proc hideSnapLocItem (int $mode)
{

string $itemsSelected []=`textScrollList -q -selectItem myTSL`;
if($mode==2)
{ hide `ls "*SnapLoc_f*"`;
selectSnapLocItem;
return;
}
if($mode==3)
{ showHidden `ls "*SnapLoc_f*"`;
selectSnapLocItem;
return;
}
for ($theItem in $itemsSelected)
{
if($mode==0)
{hide $theItem;selectSnapLocItem;}
if($mode==1)
{showHidden $theItem;selectSnapLocItem;}

}
}


global proc appendSnapLocTsl()
{
string $formerSelected []=`ls -sl -l`;
string $thelocs []=`ls "*SnapLoc_f*"`;
if (`size $thelocs `==0)
{
confirmDialog -title `MG_DualLan "footStepSnap.warnSelect.title"`
-message `MG_DualLan "snapLoc.appendNoMarker.war"`
-button `MG_DualLan "footStepSnap.warnSelect.ok"`;
deleteUI snapLocListUI;
}
else
{
select -r "*SnapLoc_f*";
string $snapLocs[] =`ls -sl`;
string $snapTrans[];
for ($eachName in $snapLocs)
{
if (`objectType $eachName`=="transform" )
{
$snapTrans [`size $snapTrans`]=$eachName;
}
}
textScrollList -e  -removeAll myTSL ;
for ($eachLoc in $snapTrans)
{textScrollList -e -append $eachLoc myTSL;}
}
select -r $formerSelected ;
}

global proc delecteSelectedSnapLocTsl ()
{
string $forDelete[]=`textScrollList -q -selectItem myTSL `;
for ($eachItem in $forDelete)
{
delete $eachItem;
textScrollList -e -removeItem $eachItem myTSL;
}
}

global proc goToSelectedSnapLocFrame ()
{
string $selectedItem[]=`textScrollList -q -selectItem myTSL `;
select $selectedItem[0];
if (`size $selectedItem`!=0)
{
string $buffer[];
  $numTokens = `tokenize $selectedItem[0] "_" $buffer`;
string $frameIndi= $buffer[(size($buffer)-1)];
int $size = `size $frameIndi`;
string $timeString=`substring $frameIndi 2 $size`;
int $timeCode=$timeString;
currentTime $timeCode ;
}
}


global proc deleteAllSnaploc ()
{
if(`objExists "*SnapLoc_f*"`)
{
string $exlocs[]=`ls -transforms "*SnapLoc_f*"`;
int $size=size($exlocs);
int $leftSize=0;
for($each in $exlocs)
{
string $list[] = `listConnections -s 0 $each`;
if(size($list)==0)
{delete $each;}
else{$leftSize=$leftSize+1;}
}
print `MG_DualLanFormat_2 "snapLoc.sweepMarker.rep" ($size-$leftSize) $leftSize`;
//print (($size-$leftSize)+" snapLocators swept, "+$leftSize+" snapLocators skiped because of their/its output connections :P");
}
if(`window -exists snapLocListUI`){deleteUI snapLocListUI;}
if(`objExists "*_RelativeLoc"`) {$exRelocs =`ls -transforms "*_RelativeLoc"`;delete $exRelocs; }
if(`objExists "*:*_RelativeLoc"`) {$exRelocs =`ls -transforms "*:*_RelativeLoc"`;delete $exRelocs; }
if(`objExists "*:*:*_RelativeLoc"`) {$exRelocs =`ls -transforms "*:*:*_RelativeLoc"`;delete $exRelocs; }
if(`objExists "snapLocsGrp"`)
{
string $locs []=`listRelatives "snapLocsGrp"`;
if (size($locs)==0)
{delete "snapLocsGrp"; }
}
}

global proc createMultipleSnapLocPrompt()
  {
  // Get the dialog's formLayout.
  //
  string $form = `setParent -q`;

  // layoutDialog's are not resizable, so hard code a size here,
  // to make sure all UI elements are visible.
  //
  formLayout -e -width 300 $form;
  string $annoText=`MG_DualLan "snapLoc.multiMarker.message"`;
  string $btn1Text=`MG_DualLan "snapLoc.multiMarker.No.btn"`;
  string $btn1Text1=`MG_DualLan "snapLoc.multiMarker.Yes.btn"`;

  string $t = `text -l $annoText`;
  
  string $b1 = `button -l $btn1Text -c "layoutDialog -dismiss \"Cancel\""`;
  string $b2 = `button -l $btn1Text1 -c "layoutDialog -dismiss \"Next\""`;


  formLayout -edit
  -attachForm $t "top" 2
  -attachForm $t "left" 5
  -attachNone $t "bottom"
  -attachForm $t "right" 5
  
  -attachControl $b1 "top" 5 $t
  -attachForm $b1 "left" 5
  -attachNone $b1 "bottom"
  -attachPosition $b1 "right" 0 48
  
  -attachControl $b2 "top" 5 $t
  -attachControl $b2 "left" 3 $b1
  -attachNone $b2 "bottom"
  -attachForm        $b2 "right" 5
  

  $form;
  }

global proc arr_snap(string $master,string $slave)
{
string $s[]=`ls -sl -l`;
if ($master=="" || $slave=="")
{
$master = $s[0];
$slave = $s[1];
}

string $command = "parentConstraint -n pConstrainForSnap ";

int $lockX  = `getAttr -lock ($slave+".translateX")`;
int $lockY  = `getAttr -lock ($slave+".translateY")`;
int $lockZ  = `getAttr -lock ($slave+".translateZ")`;
int $lockrX  = `getAttr -lock ($slave+".rotateX")`;
int $lockrY  = `getAttr -lock ($slave+".rotateY")`;
int $lockrZ  = `getAttr -lock ($slave+".rotateZ")`;

if ($lockX==1)
{
$command=($command+" -skipTranslate x ");
}
if ($lockY==1)
{
$command=($command+" -skipTranslate y ");
}

if ($lockZ==1)
{
$command=($command+" -skipTranslate z ");
}

if ($lockrX==1)
{
$command=($command+" -skipRotate x ");
}

if ($lockrY==1)
{
$command=($command+" -skipRotate y ");
}
  
if($lockrZ==1)
{
$command=($command+" -skipRotate z ");
}

$command=($command+" "+$master+" "+$slave   );

int $needReON = tempToggleOffConstraintBackup();   
if(`objExists pConstrainForSnap`)delete pConstrainForSnap;
//catch(`eval ("delete pConstrainForSnap")`);
//refresh;
catch(`eval($command)`);
setAttr "pConstrainForSnap.interpType" 2;
//refresh;
catch(`eval ("delete pConstrainForSnap")`);
if($needReON)tempToggleOnConstraintBackup;
//refresh;

}


global proc keyedSnap(string $master,string $slave)
{
string $s[] = `ls -sl -l`;
if ($master=="" || $slave=="")
{
$master = $s[0];
$slave = $s[1];
}

float $xt[] = `getAttr ($master+".translate")`;
float $xr[] = `getAttr ($master+".rotate")`;

int $lockX  = `getAttr -lock ($slave+".translateX")`;
int $lockY  = `getAttr -lock ($slave+".translateY")`;
int $lockZ  = `getAttr -lock ($slave+".translateZ")`;
int $lockrX  = `getAttr -lock ($slave+".rotateX")`;
int $lockrY  = `getAttr -lock ($slave+".rotateY")`;
int $lockrZ  = `getAttr -lock ($slave+".rotateZ")`;

if ($lockX==0)
{
setAttr ($slave+".translateX") $xt[0];
}
if ($lockY==0)
{
setAttr ($slave+".translateY") $xt[1];
}

if ($lockZ==0)
{
setAttr ($slave+".translateZ") $xt[2];
}

if ($lockrX==0)
{
setAttr ($slave+".rotateX") $xr[0];
}

if ($lockrY==0)
{
setAttr ($slave+".rotateY") $xr[1];
}
  
if($lockrZ==0)
{
setAttr ($slave+".rotateZ") $xr[2];
}
}

//==========================point snap==================================
global proc pointsnap(string $master,string $slave)
{
string $s[]=`ls -sl -l`;
if ($master=="" || $slave=="")
{
$master = $s[0];
$slave = $s[1];
}
string $command = "pointConstraint -n pConstrainForSnap ";

int $lockX  = `getAttr -lock ($slave+".translateX")`;
int $lockY  = `getAttr -lock ($slave+".translateY")`;
int $lockZ  = `getAttr -lock ($slave+".translateZ")`;


if ($lockX==1)
{
$command=($command+" -skip x ");
}
if ($lockY==1)
{
$command=($command+" -skip y ");
}

if ($lockZ==1)
{
$command=($command+" -skip z ");
}



$command=($command+" "+$master+" "+$slave   );
int $needReON = tempToggleOffConstraintBackup();  
catch(`eval($command)`);
catch(`eval ("delete pConstrainForSnap")`);
//refresh;
if($needReON)tempToggleOnConstraintBackup;

}


global proc pointkeyedSnap(string $master,string $slave)
{
string $s[] = `ls -sl -l`;
if ($master=="" || $slave=="")
{
$master = $s[0];
$slave = $s[1];
}

float $xt[] = `getAttr ($master+".translate")`;

int $lockX  = `getAttr -lock ($slave+".translateX")`;
int $lockY  = `getAttr -lock ($slave+".translateY")`;
int $lockZ  = `getAttr -lock ($slave+".translateZ")`;


if ($lockX==0)
{
setAttr ($slave+".translateX") $xt[0];
}
if ($lockY==0)
{
setAttr ($slave+".translateY") $xt[1];
}

if ($lockZ==0)
{
setAttr ($slave+".translateZ") $xt[2];
}


}
//==========================orient snap==================================

global proc orientsnap(string $master,string $slave)
{
string $s[]=`ls -sl -l`;
if ($master=="" || $slave=="")
{
$master = $s[0];
$slave = $s[1];
}
string $command = "orientConstraint -n pConstrainForSnap ";

int $lockX  = `getAttr -lock ($slave+".rotateX")`;
int $lockY  = `getAttr -lock ($slave+".rotateY")`;
int $lockZ  = `getAttr -lock ($slave+".rotateZ")`;


if ($lockX==1)
{
$command=($command+" -skip x ");
}
if ($lockY==1)
{
$command=($command+" -skip y ");
}

if ($lockZ==1)
{
$command=($command+" -skip z ");
}



$command=($command+" "+$master+" "+$slave   );
int $needReON = tempToggleOffConstraintBackup();  
catch(`eval($command)`);
setAttr "pConstrainForSnap.interpType" 2;
catch(`eval ("delete pConstrainForSnap")`);
//refresh;
if($needReON)tempToggleOnConstraintBackup;
}


global proc orientkeyedSnap(string $master,string $slave)
{
string $s[] = `ls -sl -l`;
if ($master=="" || $slave=="")
{
$master = $s[0];
$slave = $s[1];
}

float $xt[] = `getAttr ($master+".rotate")`;

int $lockX  = `getAttr -lock ($slave+".rotateX")`;
int $lockY  = `getAttr -lock ($slave+".rotateY")`;
int $lockZ  = `getAttr -lock ($slave+".rotateZ")`;


if ($lockX==0)
{
setAttr ($slave+".rotateX") $xt[0];
}
if ($lockY==0)
{zz
setAttr ($slave+".rotateY") $xt[1];
}

if ($lockZ==0)
{
setAttr ($slave+".rotateZ") $xt[2];
}

}

Rain

 |采纳率:17%

全部回答(3)

  • 2018-08-14 21:42:10

    我是小白  没怎么看懂 但是其实想要一致 用吸附就可以了啊 。。 下面是MG 吸附的 单独代码
    POSnap 1;
    print ("//Rain: ========吸附完成!========");

    //===================Animation Snap codes=====================================================
    global proc POSnap (int $snapmode)
    {
    string $nodes[];
    global int $testSupportPythonOrNotForMGtools;
    $nodes = `ls -sl -l`;
    int $number=`size $nodes`;
    if ($number !=2)
    {
    confirmDialog -title `MG_DualLan "footStepSnap.warnSelect.title"`
    -message `MG_DualLan "snapLoc.POsnap.war.message"`
    -button `MG_DualLan "snapLoc.POsnap.war.ok"`;
    }
    else
    {

    string $sel []=`ls -sl -l`;
    string $copy[];
    if($testSupportPythonOrNotForMGtools)
    {
    $copy= `duplicate -po $sel[1]`;
    }
    else
    {
    $copy= `duplicate $sel[1]`;
    }
    $copyedSlave=$copy[0];
    if($snapmode==1||$snapmode==4)
    {
    arr_snap ($sel[0],$copyedSlave);
    keyedSnap ($copyedSlave,$sel[1]);
    }
    if($snapmode==2||$snapmode==5)
    {
    pointsnap ($sel[0],$copyedSlave);
    pointkeyedSnap ($copyedSlave,$sel[1]);
    }
    if($snapmode==3||$snapmode==6)
    {
    orientsnap ($sel[0],$copyedSlave);
    orientkeyedSnap ($copyedSlave,$sel[1]);
    }

    delete $copyedSlave;
    }
    }


    //==========================parent snap==================================
    global proc int tempToggleOffConstraintBackup ()
    {
    int $result = 0;
    if(`exists animRescue`)
    {
    if(`animRescue -q -ctt`)
    {
    animRescue -e -ctt 0;
    $result=1;
    }
    }
    return $result;
    }

    global proc tempToggleOnConstraintBackup ()
    {
    if(`exists animRescue`)
    {
    if(!`animRescue -q -ctt`)
    {
    animRescue -e -ctt 1;
    }
    }
    }
    global proc makeMultiplySnapLoc(int $mode)
    {
    global string $gPlayBackSlider;
    string $selectrange = `timeControl -q -range   $gPlayBackSlider`;
    string $buffer[];
       $numTokens = `tokenize $selectrange ":" $buffer`;
    int $size1=`size $buffer[0]`;
    int $size2=`size $buffer[1]`;
    int $start = `substring $buffer[0] 2 $size1`;
    int $end =`substring $buffer[1] 1 ($size2-1)`;
    //print ($start+" "+$end);
    string $selections []= `ls -sl`;
    if(size ($selections)==0){return;}
    if(($end -$start)==1)
    {
    for ($each in $selections)
    {
    if (!`gmatch $each "*SnapLoc_f*"`)
    {select $each;snapLoc 1;}
    }
    select $selections;
    }
    else
    {
    for ($each in $selections)
    {
    if (!`gmatch $each "*SnapLoc_f*"`)
    {
    select $each; string $keyTicks[];string $nextKey;int $nextKeyStart;
    if($mode==0)
    { $nextKey=`findKeyframe -time ($start-1)  -which "next" -at "translateX" -at "translateY"  -at "translateZ"  -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
    $nextKeyStart =`findKeyframe -time ($start-1)  -which "next" -at "translateX" -at "translateY"  -at "translateZ"  -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
    }
    if($mode==1)
    { $nextKey=`findKeyframe -time ($start-1)  -which "next" -at "translateX" -at "translateY"  -at "translateZ"  $each`;
    $nextKeyStart =`findKeyframe -time ($start-1)  -which "next" -at "translateX" -at "translateY"  -at "translateZ"  $each`;
    }
    if($mode==2)
    { $nextKey=`findKeyframe -time ($start-1)  -which "next"   -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
    $nextKeyStart =`findKeyframe -time ($start-1)  -which "next"  -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
    }
    if ($nextKeyStart <=$end&&$nextKeyStart>=$start)
    { //print ("The first key is in "+$nextKey+"n");
    $keyTicks[size($keyTicks)]=$nextKey;
    int $runTimes = ( $end -$start);
    for ($i=0; $i<$runTimes; $i++)
    { int $newStart = $nextKeyStart ;
    if($mode==0)
    { $nextKey=`findKeyframe -time $newStart -which "next" -at "translateX" -at "translateY"  -at "translateZ"   -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
    $nextKeyStart =`findKeyframe -time $newStart -which "next" -at "translateX" -at "translateY"  -at "translateZ"  -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
    }
    if($mode==1)
    { $nextKey=`findKeyframe -time $newStart -which "next" -at "translateX" -at "translateY"  -at "translateZ"  $each`;
    $nextKeyStart =`findKeyframe -time $newStart -which "next" -at "translateX" -at "translateY"  -at "translateZ"  $each`;
    }
    if($mode==2)
    { $nextKey=`findKeyframe -time $newStart -which "next"   -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
    $nextKeyStart =`findKeyframe -time $newStart -which "next" -at "rotateX" -at "rotateY" -at "rotateZ"  $each`;
    }


    //print  ("The second Key is  "+$nextKey);
    if ($nextKeyStart <=$end&&$nextKeyStart>=$start)
    {$keyTicks[size($keyTicks)]=$nextKey;}
    else {break;}
    }
    }
    //print $keyTicks;
    string $shorterTicks[] = stringArrayRemoveDuplicates($keyTicks);
    if($mode==0){print `MG_DualLanFormat_1 "snapLoc.snapLocMode.rep0" $each`;}
    if($mode==1){print `MG_DualLanFormat_1 "snapLoc.snapLocMode.rep1" $each`;}
    if($mode==2){print `MG_DualLanFormat_1 "snapLoc.snapLocMode.rep2" $each`;}
    //print $shorterTicks;
    for ($eachInc in $shorterTicks)
    { print (" "+$eachInc);
    currentTime -edit $eachInc;
    snapLoc 1;
    select $each;

    }
    $keyTicks={};
    }
    }
    select $selections;
    }
    int $locNum = size(`ls -transforms "*SnapLoc_f*"`);
    print "n";
    print `MG_DualLanFormat_1 "snapLoc.snapLocNum.rep" $locNum`;
    }

    global proc string snapLoc (int $mode)
    {
    global string   $gPlayBackSlider;
    string $selectrange = `timeControl -q -range   $gPlayBackSlider`;
    string $buffer[];
       $numTokens = `tokenize $selectrange ":" $buffer`;
    int $size1=`size $buffer[0]`;
    int $size2=`size $buffer[1]`;
    int $start = `substring $buffer[0] 2 $size1`;
    int $end =`substring $buffer[1] 1 ($size2-1)`;
    //print ($start+" "+$end);
    int $number = size(`ls -l -sl`);
    if (size(`ls -l -sl`) == 0)
    {
       confirmDialog -title `MG_DualLan "footStepSnap.warnSelect.title"`
    -message  `MG_DualLan "footStepSnap.warnSelect.message"`
    -button `MG_DualLan "footStepSnap.warnSelect.ok"` ;
    }
    else if (size(`ls -l -sl`) > 1)
    {
    string $test =`layoutDialog -ui "createMultipleSnapLocPrompt"`;
    if ($test=="Next")
    {
    makeMultiplySnapLoc 0;
    }
    else
    {return "";}

    }
    else
    {
    string $nodes[];
    $nodes=`ls -sl`;
    string $buffer[];
    int $num =`tokenize $nodes[0] ":" $buffer`;
    string $theNode;
    if(size($buffer[1])==0) {$theNode = $buffer[0];}
    else {$theNode = $buffer[0]+"_"+$buffer[1];}
    string $frame =`currentTime -q`;
    string $nodes01 [];
    if(`objExists ($theNode+"_SnapLoc_f"+$frame)`)
    {
    $nodes01[0]=($theNode+"_SnapLoc_f"+$frame);
    select -r $nodes;
    select -add $nodes01;
    POSnap 1;

      }
    else{
    $nodes01=`spaceLocator -p 0 0 0 -n ($theNode+"_SnapLoc_f"+$frame)`;
    select -r $nodes;
    select -add $nodes01;
    POSnap 1;
    }

    select -r $nodes01[0];
    string $grptest[]=`pickWalk -d up`;
    if($grptest[0]!="snapLocsGrp")
    {
    if(`objExists "snapLocsGrp"`)
    {parent $nodes01[0] snapLocsGrp;}
    else {group -n "snapLocsGrp" $nodes01[0];}
    }

    if($mode==1)
    {select -r $nodes[0];}
    if($mode==2){select -r $nodes01[0]  $nodes[0];}
    return $nodes01[0];

    }
    //int $locNum = size(`ls -transforms "SnapLoc_f*"`);
    //print "n";
    //print ("There are now "+$locNum +" snapLocators in your scenes :)");
    }


    global proc invertSelectSnapLocItems ()
    {
    string $itemsSelected []=`textScrollList -q -selectItem myTSL`;
    string $allItems []=`textScrollList -q -allItems myTSL`;
    for ($eachAllItems in $allItems)
    {textScrollList -e -selectItem $eachAllItems myTSL;}
    for ($eachItemtoDeselect in $itemsSelected)
    {textScrollList -e -deselectItem $eachItemtoDeselect myTSL;}
    selectSnapLocItem;
    }


    global proc selectSameObjSnapLocItem ()
    {
    string $itemsSelected []=`textScrollList -q -selectItem myTSL`;
    select -cl;
    for ($theItem in $itemsSelected)
    {
    string $buffer[];
    //string $theItem="pCube3_SnapLoc_f2";
    $numTokens = `tokenize $theItem "_" $buffer`;
    // string $newToken =($buffer[0]+"_"+$buffer[1]+"_");
    //int $startNum = size($newToken)+1;
    int $endNum = size ($buffer[($numTokens-1)]);
    $endNum=size($theItem)-$endNum;
    string $objName =`substring $theItem 1 $endNum`;
    string $objSets[] = `ls -transforms ($objName+"f*")`;
    select -add $objSets;
    for ($eachObj in $objSets)
    {textScrollList -e -selectItem $eachObj myTSL;}
    }
    }

    global proc selectSnapLocItem ()
    {
    string $itemsSelected []=`textScrollList -q -selectItem myTSL`;
    select -cl;
    for ($theItem in $itemsSelected)
    {select -add $theItem;}
    }


    global proc hideSnapLocItem (int $mode)
    {

    string $itemsSelected []=`textScrollList -q -selectItem myTSL`;
    if($mode==2)
    { hide `ls "*SnapLoc_f*"`;
    selectSnapLocItem;
    return;
    }
    if($mode==3)
    { showHidden `ls "*SnapLoc_f*"`;
    selectSnapLocItem;
    return;
    }
    for ($theItem in $itemsSelected)
    {
    if($mode==0)
    {hide $theItem;selectSnapLocItem;}
    if($mode==1)
    {showHidden $theItem;selectSnapLocItem;}

    }
    }


    global proc appendSnapLocTsl()
    {
    string $formerSelected []=`ls -sl -l`;
    string $thelocs []=`ls "*SnapLoc_f*"`;
    if (`size $thelocs `==0)
    {
    confirmDialog -title `MG_DualLan "footStepSnap.warnSelect.title"`
    -message `MG_DualLan "snapLoc.appendNoMarker.war"`
    -button `MG_DualLan "footStepSnap.warnSelect.ok"`;
    deleteUI snapLocListUI;
    }
    else
    {
    select -r "*SnapLoc_f*";
    string $snapLocs[] =`ls -sl`;
    string $snapTrans[];
    for ($eachName in $snapLocs)
    {
    if (`objectType $eachName`=="transform" )
    {
    $snapTrans [`size $snapTrans`]=$eachName;
    }
    }
    textScrollList -e  -removeAll myTSL ;
    for ($eachLoc in $snapTrans)
    {textScrollList -e -append $eachLoc myTSL;}
    }
    select -r $formerSelected ;
    }

    global proc delecteSelectedSnapLocTsl ()
    {
    string $forDelete[]=`textScrollList -q -selectItem myTSL `;
    for ($eachItem in $forDelete)
    {
    delete $eachItem;
    textScrollList -e -removeItem $eachItem myTSL;
    }
    }

    global proc goToSelectedSnapLocFrame ()
    {
    string $selectedItem[]=`textScrollList -q -selectItem myTSL `;
    select $selectedItem[0];
    if (`size $selectedItem`!=0)
    {
    string $buffer[];
      $numTokens = `tokenize $selectedItem[0] "_" $buffer`;
    string $frameIndi= $buffer[(size($buffer)-1)];
    int $size = `size $frameIndi`;
    string $timeString=`substring $frameIndi 2 $size`;
    int $timeCode=$timeString;
    currentTime $timeCode ;
    }
    }


    global proc deleteAllSnaploc ()
    {
    if(`objExists "*SnapLoc_f*"`)
    {
    string $exlocs[]=`ls -transforms "*SnapLoc_f*"`;
    int $size=size($exlocs);
    int $leftSize=0;
    for($each in $exlocs)
    {
    string $list[] = `listConnections -s 0 $each`;
    if(size($list)==0)
    {delete $each;}
    else{$leftSize=$leftSize+1;}
    }
    print `MG_DualLanFormat_2 "snapLoc.sweepMarker.rep" ($size-$leftSize) $leftSize`;
    //print (($size-$leftSize)+" snapLocators swept, "+$leftSize+" snapLocators skiped because of their/its output connections :P");
    }
    if(`window -exists snapLocListUI`){deleteUI snapLocListUI;}
    if(`objExists "*_RelativeLoc"`) {$exRelocs =`ls -transforms "*_RelativeLoc"`;delete $exRelocs; }
    if(`objExists "*:*_RelativeLoc"`) {$exRelocs =`ls -transforms "*:*_RelativeLoc"`;delete $exRelocs; }
    if(`objExists "*:*:*_RelativeLoc"`) {$exRelocs =`ls -transforms "*:*:*_RelativeLoc"`;delete $exRelocs; }
    if(`objExists "snapLocsGrp"`)
    {
    string $locs []=`listRelatives "snapLocsGrp"`;
    if (size($locs)==0)
    {delete "snapLocsGrp"; }
    }
    }

    global proc createMultipleSnapLocPrompt()
      {
      // Get the dialog's formLayout.
      //
      string $form = `setParent -q`;

      // layoutDialog's are not resizable, so hard code a size here,
      // to make sure all UI elements are visible.
      //
      formLayout -e -width 300 $form;
      string $annoText=`MG_DualLan "snapLoc.multiMarker.message"`;
      string $btn1Text=`MG_DualLan "snapLoc.multiMarker.No.btn"`;
      string $btn1Text1=`MG_DualLan "snapLoc.multiMarker.Yes.btn"`;

      string $t = `text -l $annoText`;
      
      string $b1 = `button -l $btn1Text -c "layoutDialog -dismiss "Cancel""`;
      string $b2 = `button -l $btn1Text1 -c "layoutDialog -dismiss "Next""`;


      formLayout -edit
      -attachForm $t "top" 2
      -attachForm $t "left" 5
      -attachNone $t "bottom"
      -attachForm $t "right" 5
      
      -attachControl $b1 "top" 5 $t
      -attachForm $b1 "left" 5
      -attachNone $b1 "bottom"
      -attachPosition $b1 "right" 0 48
      
      -attachControl $b2 "top" 5 $t
      -attachControl $b2 "left" 3 $b1
      -attachNone $b2 "bottom"
      -attachForm        $b2 "right" 5
      

      $form;
      }

    global proc arr_snap(string $master,string $slave)
    {
    string $s[]=`ls -sl -l`;
    if ($master=="" || $slave=="")
    {
    $master = $s[0];
    $slave = $s[1];
    }

    string $command = "parentConstraint -n pConstrainForSnap ";

    int $lockX  = `getAttr -lock ($slave+".translateX")`;
    int $lockY  = `getAttr -lock ($slave+".translateY")`;
    int $lockZ  = `getAttr -lock ($slave+".translateZ")`;
    int $lockrX  = `getAttr -lock ($slave+".rotateX")`;
    int $lockrY  = `getAttr -lock ($slave+".rotateY")`;
    int $lockrZ  = `getAttr -lock ($slave+".rotateZ")`;

    if ($lockX==1)
    {
    $command=($command+" -skipTranslate x ");
    }
    if ($lockY==1)
    {
    $command=($command+" -skipTranslate y ");
    }

    if ($lockZ==1)
    {
    $command=($command+" -skipTranslate z ");
    }

    if ($lockrX==1)
    {
    $command=($command+" -skipRotate x ");
    }

    if ($lockrY==1)
    {
    $command=($command+" -skipRotate y ");
    }
      
    if($lockrZ==1)
    {
    $command=($command+" -skipRotate z ");
    }

    $command=($command+" "+$master+" "+$slave   );

    int $needReON = tempToggleOffConstraintBackup();   
    if(`objExists pConstrainForSnap`)delete pConstrainForSnap;
    //catch(`eval ("delete pConstrainForSnap")`);
    //refresh;
    catch(`eval($command)`);
    setAttr "pConstrainForSnap.interpType" 2;
    //refresh;
    catch(`eval ("delete pConstrainForSnap")`);
    if($needReON)tempToggleOnConstraintBackup;
    //refresh;

    }


    global proc keyedSnap(string $master,string $slave)
    {
    string $s[] = `ls -sl -l`;
    if ($master=="" || $slave=="")
    {
    $master = $s[0];
    $slave = $s[1];
    }

    float $xt[] = `getAttr ($master+".translate")`;
    float $xr[] = `getAttr ($master+".rotate")`;

    int $lockX  = `getAttr -lock ($slave+".translateX")`;
    int $lockY  = `getAttr -lock ($slave+".translateY")`;
    int $lockZ  = `getAttr -lock ($slave+".translateZ")`;
    int $lockrX  = `getAttr -lock ($slave+".rotateX")`;
    int $lockrY  = `getAttr -lock ($slave+".rotateY")`;
    int $lockrZ  = `getAttr -lock ($slave+".rotateZ")`;

    if ($lockX==0)
    {
    setAttr ($slave+".translateX") $xt[0];
    }
    if ($lockY==0)
    {
    setAttr ($slave+".translateY") $xt[1];
    }

    if ($lockZ==0)
    {
    setAttr ($slave+".translateZ") $xt[2];
    }

    if ($lockrX==0)
    {
    setAttr ($slave+".rotateX") $xr[0];
    }

    if ($lockrY==0)
    {
    setAttr ($slave+".rotateY") $xr[1];
    }
      
    if($lockrZ==0)
    {
    setAttr ($slave+".rotateZ") $xr[2];
    }
    }

    //==========================point snap==================================
    global proc pointsnap(string $master,string $slave)
    {
    string $s[]=`ls -sl -l`;
    if ($master=="" || $slave=="")
    {
    $master = $s[0];
    $slave = $s[1];
    }
    string $command = "pointConstraint -n pConstrainForSnap ";

    int $lockX  = `getAttr -lock ($slave+".translateX")`;
    int $lockY  = `getAttr -lock ($slave+".translateY")`;
    int $lockZ  = `getAttr -lock ($slave+".translateZ")`;


    if ($lockX==1)
    {
    $command=($command+" -skip x ");
    }
    if ($lockY==1)
    {
    $command=($command+" -skip y ");
    }

    if ($lockZ==1)
    {
    $command=($command+" -skip z ");
    }



    $command=($command+" "+$master+" "+$slave   );
    int $needReON = tempToggleOffConstraintBackup();  
    catch(`eval($command)`);
    catch(`eval ("delete pConstrainForSnap")`);
    //refresh;
    if($needReON)tempToggleOnConstraintBackup;

    }


    global proc pointkeyedSnap(string $master,string $slave)
    {
    string $s[] = `ls -sl -l`;
    if ($master=="" || $slave=="")
    {
    $master = $s[0];
    $slave = $s[1];
    }

    float $xt[] = `getAttr ($master+".translate")`;

    int $lockX  = `getAttr -lock ($slave+".translateX")`;
    int $lockY  = `getAttr -lock ($slave+".translateY")`;
    int $lockZ  = `getAttr -lock ($slave+".translateZ")`;


    if ($lockX==0)
    {
    setAttr ($slave+".translateX") $xt[0];
    }
    if ($lockY==0)
    {
    setAttr ($slave+".translateY") $xt[1];
    }

    if ($lockZ==0)
    {
    setAttr ($slave+".translateZ") $xt[2];
    }


    }
    //==========================orient snap==================================

    global proc orientsnap(string $master,string $slave)
    {
    string $s[]=`ls -sl -l`;
    if ($master=="" || $slave=="")
    {
    $master = $s[0];
    $slave = $s[1];
    }
    string $command = "orientConstraint -n pConstrainForSnap ";

    int $lockX  = `getAttr -lock ($slave+".rotateX")`;
    int $lockY  = `getAttr -lock ($slave+".rotateY")`;
    int $lockZ  = `getAttr -lock ($slave+".rotateZ")`;


    if ($lockX==1)
    {
    $command=($command+" -skip x ");
    }
    if ($lockY==1)
    {
    $command=($command+" -skip y ");
    }

    if ($lockZ==1)
    {
    $command=($command+" -skip z ");
    }



    $command=($command+" "+$master+" "+$slave   );
    int $needReON = tempToggleOffConstraintBackup();  
    catch(`eval($command)`);
    setAttr "pConstrainForSnap.interpType" 2;
    catch(`eval ("delete pConstrainForSnap")`);
    //refresh;
    if($needReON)tempToggleOnConstraintBackup;
    }


    global proc orientkeyedSnap(string $master,string $slave)
    {
    string $s[] = `ls -sl -l`;
    if ($master=="" || $slave=="")
    {
    $master = $s[0];
    $slave = $s[1];
    }

    float $xt[] = `getAttr ($master+".rotate")`;

    int $lockX  = `getAttr -lock ($slave+".rotateX")`;
    int $lockY  = `getAttr -lock ($slave+".rotateY")`;
    int $lockZ  = `getAttr -lock ($slave+".rotateZ")`;


    if ($lockX==0)
    {
    setAttr ($slave+".rotateX") $xt[0];
    }
    if ($lockY==0)
    {zz
    setAttr ($slave+".rotateY") $xt[1];
    }

    if ($lockZ==0)
    {
    setAttr ($slave+".rotateZ") $xt[2];
    }

    }

  • 2018-08-13 19:33:57

    你如果是要做无缝的话,xform没有用吧?
    如果是IK match到 FK 就是获取肘关节跟腕关节的坐标,然后IK目标点对齐到手腕关节坐标,极向量对齐到肘关节坐标,这样就对齐到了。

  • 2016-08-12 22:24:47

    路过帮顶。问题太高深。坐等高手回答

1900

 

回答数采纳率提问数
0 0% 2

一个提问,一份期待;一条回答,一份回应。知识问与答,连接你和我!

-- 来自问答管理员 cg问答

扫描二维码进入手机版


客服
返回顶部