Advertisement
Guest User

Untitled

a guest
May 19th, 2017
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.22 KB | None | 0 0
  1. /**
  2.  
  3.     @file       xyMatchCameraFilmGate.mel
  4.  
  5.     @version    0.1
  6.     @date       2007-01-21
  7.     @author     Imre Tuske
  8.     <br>        mail: imre.tuske@gmail.com
  9.  
  10.     \brief      Modify camera film gate to match the resolution gate.
  11.  
  12. \section qcmd       Quick commands:
  13.  
  14.             - <a href="mel:xyMatchCameraFilmGate({})">Match Film Gate of selected camera(s)</a> -- Select camera(s)
  15.             - <a href="mel:xyMatchCameraFilmGate(`ls -type camera`)">Match Film Gate of all cameras</a>
  16.  
  17.  
  18. \section desc       Description:
  19.  
  20.             Maya cameras have many attributes that allow sophistical view setups, but it is also
  21.             a tedium for the regular user to make sure they are set up properly.
  22. <br><br>
  23.             The camera Film Gate describes the width/height of the camera view plane. In an ideal
  24.             default case, the camera Film Gate should have the same proportions as the output
  25.             resolution (the actual rendered frame).
  26. <br><br>
  27.             This script modifies the camera film gate to have the same proportions as the output
  28.             resolution. This modification doesn't modify the current camera view (if it is, it's
  29.             a script bug :)).
  30. <br><br>
  31.  
  32.             Why Is It Important To Match The Film Gate:
  33. <br><br>
  34.             The 'FilmFit' camera attribute determines how would Maya fit the camera view (Film Gate)
  35.             to the output frame (Resolution Gate). However it also affects how the view is shown
  36.             in the viewports. (Fill, Horizontal, Vertical, Overscan).
  37.  
  38.             Artists often change this attribute to have a better view in the viewport display,
  39.             and this can result in problems such as mismatched renders. If the Film Gate and
  40.             Resolution Gate is properly matched, such trouble can be avoided.
  41.  
  42.  
  43.  
  44. <br><br>
  45. <small>
  46. \section hist       History:
  47.  
  48. \par            2001-10-27 [0.1]
  49.             First version.
  50. <br><br>
  51. \section todoo      Todo:
  52.  
  53.             - none
  54. </small>
  55.  
  56. */
  57.  
  58.  
  59. proc match_film_gate( string $c )
  60. {
  61.     string      $os[]={ "Fill", "Horizontal", "Vertical", "Overscan" };
  62.     string      $dr="defaultResolution";
  63.  
  64.     if (size(`ls -type camera $c`) && !getAttr($c+".orthographic"))
  65.     {
  66.         float   $iw=getAttr($dr+".width"), $ih=getAttr($dr+".height");      // current resolution and aspect
  67.         float   $r=getAttr($dr+".deviceAspectRatio");
  68.  
  69.         $r=($ih/$iw)*$r;    // convert to pixel aspect ratio
  70.         $iw*=$r;        // and apply ratio to resolution
  71.  
  72.         float   $iR=$ih/$iw;                            // image ratio (aspect-corrected)
  73.  
  74.  
  75.         float   $aw=getAttr($c+".hfa"), $ah=getAttr($c+".vfa");         // current film gate
  76.         int $m=getAttr($c+".filmFit");
  77.  
  78.         float   $aR=$ah/$aw;
  79.  
  80.         // determine actual film fit of camera
  81.         // (1=horizontal, 2=vertical)
  82.  
  83.         if ($m==0) $m=( $aR<$iR ? 2 : 1 );
  84.         else if ($m==3) $m=( $aR<$iR ? 1 : 2 );
  85.  
  86.         print("- "+$c+": current fit type "+$os[$m]+"; changing aperture from "+$aw+"/"+$ah);
  87.  
  88.         switch($m)                              // calculate new aperture
  89.         {
  90.             case 1: // horizontal: modify vertical aperture
  91.             $ah=$aw*$iR;
  92.             break;
  93.  
  94.             case 2: // vertical: modify horizontal aperture
  95.             $aw=$ah/$iR;
  96.             break;
  97.         }
  98.  
  99.         print(" to "+$aw+"/"+$ah+"\n");
  100.  
  101.         // set new overscan value
  102.  
  103.         catch(`setAttr ($c+".hfa") $aw`);
  104.         catch(`setAttr ($c+".vfa") $ah`);
  105.     }
  106. }
  107.  
  108.  
  109. global proc xyMatchCameraFilmGate( string $sel[] )
  110. {
  111.     string $sl[]=`ls $sel`, $s;
  112.     if (!size($sl)) $sl=`ls -sl`;
  113.  
  114.     $sl=`ls -dag -lf -ni -type camera $sl`;
  115.  
  116.     for($s in $sl)
  117.         match_film_gate($s);
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement