Scripts to print out the animation information

来源:互联网 发布:手机屏幕录像软件ios 编辑:程序博客网 时间:2024/05/16 11:03
   1: //PrintAnim Script
   2: proc printAnim(int $detailed)
   3: {
   4:     print "/nAnimation...";
   5:     
   6:     string $animNodes[];
   7:     float $keytimes[];
   8:     //get the list of objects selected
   9:     string $sel[]=`ls -selection`;
  10:     //for each selected object
  11:     for($node in $sel)
  12:     {
  13:         print ("/nNode: "+$node);
  14:         //get all the animation curves associated with a given node
  15:         $animNodes=`keyframe -query -name $node`;
  16:         //for each animation curve
  17:         for($ac in $animNodes)
  18:         {
  19:             print("/nAnimCurve: "+$ac);
  20:             //get all the key times for current animation curve
  21:             $keytimes=`keyframe -query -timeChange $ac`;
  22:             print("/n"+size($keytimes)+" keys: ");
  23:             //for each key in the animation curve
  24:             for($keyt in $keytimes)
  25:             {
  26:                 
  27:                 $keyv=`keyframe -time $keyt -query -valueChange $ac`;
  28:                 if($detailed)
  29:                 {
  30:                     // the type of the key
  31:                     float $isBd[]=`keyframe -time $keyt -query -breakdown $ac`;
  32:                     print("/n"+($isBd[0]?"Breakdown":"Normal")+" Key:");
  33:                 }
  34:                 
  35:                 // the key time and key value
  36:                 print("["+$keyt+", "+$keyv[0]+"]");
  37:                 
  38:                 if($detailed)
  39:                 {
  40:                     // Tangent information of the current key
  41:                     print("/nTangent: ");
  42:                     $keyinT=`keyTangent -time $keyt -query -inTangentType $ac`;
  43:                     $keyoutT=`keyTangent -time $keyt -query -outTangentType $ac`;
  44:                     $keyinA=`keyTangent -time $keyt -query -inAngle $ac`;
  45:                     $keyoutA=`keyTangent -time $keyt -query -outAngle $ac`;
  46:                     print("("+$keyinT[0]+" angle="+$keyinA[0]+", "+$keyoutT[0]+" angle="+$keyoutA[0]+")");
  47:                 }
  48:             }
  49:         }
  50:     }
  51: }
  52:  
  53:  
  54: // Print Tangent Positions Script
  55: proc printTangentPositions(string $animCurve, int $absolute)
  56: {
  57:     print("/nTangent Positions...");
  58:     
  59:     float $ktimes[], $kvalues[];
  60:     // absolute positions
  61:     if($absolute)
  62:     {
  63:         $ktimes=`keyframe -query -timeChange $animCurve`;
  64:         $kvalues=`keyframe -query -valueChange $animCurve`;
  65:     }
  66:     
  67:     float $xcomps[], $ycomps[], $weights[];
  68:     int $i, $j;
  69:     // two tangents: in tangent and out tangent
  70:     for($i=0;$i<2;++$i)
  71:     {
  72:         // x and y vector components, weight
  73:         string $xreq, $yreq, $wreq;
  74:         if($i==0)
  75:         {
  76:             $xreq="-ix";
  77:             $yreq="-iy";
  78:             $wreq="-inWeight";
  79:         }else
  80:         {
  81:             $xreq="-ox";
  82:             $yreq="-oy";
  83:             $wreq="-outWeight";
  84:         }
  85:         
  86:         $xcomps=`keyTangent -query $xreq $animCurve`;
  87:         $ycomps=`keyTangent -query $yreq $animCurve`;
  88:         $weights=`keyTangent -query $wreq $animCurve`;
  89:         
  90:         print("/n");
  91:         for($j=0;$j<size($xcomps);++$j)
  92:         {
  93:             // x,y construct the unit vector of the tangent, represent direction
  94:             // weight is the length,
  95:             $xcomps[$j]*=$weights[$j];
  96:             $ycomps[$j]*=$weights[$j];
  97:             
  98:             // if absolute, move the vector to its own frame
  99:             if($absolute)
 100:             {
 101:                 $xcomps[$j]+=$ktimes[$j];
 102:                 $ycomps[$j]+=$kvalues[$j];
 103:             }
 104:             
 105:             print("["+$xcomps[$j]+", "+$ycomps[$j]+"]");
 106:         }
 107:     }
 108: }
 109:  
 110: proc testProc()
 111: {
 112:     string $animCurves[]=`keyframe -query -name ball.translateX`;
 113:     printTangentPositions($animCurves[0], true);
 114: }
 115:  
 116: testProc();

The printAnim() function prints out the animation information of each frame and each animation node.

The printTangentPositions() function prints out the in tangent and out tangent of each frame.

Commands:

1. ls

2. keyframe

3. keyTangent