Skip to content

Instantly share code, notes, and snippets.

@hiko9lock
Created August 16, 2013 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiko9lock/6249942 to your computer and use it in GitHub Desktop.
Save hiko9lock/6249942 to your computer and use it in GitHub Desktop.
Maya MEL script that transfer camera attribute to locator for unity.
// file hq_convertCameraAttribute
// CameraDataConvert for unity.
// author Masahiko.Ishii <esuna.dev@gmail.com>
// date 2013/8/16
global proc hq_convertCameraAttribute()
{
string $sels[]= `ls -sl`;
string $node[]= `listRelatives -shapes $sels[0]`;
print $node;
if( `nodeType $node[0]`!= "camera") {
return;
}
string $loc[]= `spaceLocator -n "cameraLocator1"`;
connectAttr -f ($sels[0]+".tx") ($loc[0]+".tx");
connectAttr -f ($sels[0]+".ty") ($loc[0]+".ty");
connectAttr -f ($sels[0]+".tz") ($loc[0]+".tz");
connectAttr -f ($sels[0]+".rx") ($loc[0]+".rx");
connectAttr -f ($sels[0]+".ry") ($loc[0]+".ry");
connectAttr -f ($sels[0]+".rz") ($loc[0]+".rz");
connectAttr -f ($sels[0]+".nearClipPlane") ($loc[0]+".sx");
connectAttr -f ($sels[0]+".farClipPlane") ($loc[0]+".sy");
string $ex= "float $flen= `getAttr (\""+ $node[0]+ ".focalLength\")`;\n";
$ex+= "float $vFilApe= `getAttr (\""+ $node[0]+ ".verticalFilmAperture\")`;\n";
$ex+= "float $FoV= 2.0* atan((0.5*$vFilApe) / ($flen* 0.03937))* 57.29578;\n";
$ex+= "setAttr (\""+$loc[0]+".sz\") $FoV;";
expression -s $ex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment