best viewed in syntax highlighting text editor such as Textpad

global proc camplc()

{

string $executeWindow =`window -t "cameraPlacement" -rtf 1 cameraplacementWindow`;

string $uvFilePath;

columnLayout;

      text -label " ";

      text -label "select camera base geometry, set ctrls";

      text -label "and then press button to set cameras onto the geometry";

      text -label " ";

      text -label "enter path and file for uv's to be written to";

      textField -tx "C:/INNOVATIONS_PROJECT/multiViewResearch/uvPos.txt" -w 300 uvFileNameField;

      button -label "find file" -c ("string $tempUVfile = `fileDialog`;textField -e -tx $tempUVfile uvFileNameField;");

      text -label " ";

      text -label "set the base camera focal length";

      floatField -min 22 -max 140 -v 40 -s 2.5 -ann "focal length" -ec "floatField -e -v `floatField -q -v focalLengthField` focalLengthField" focalLengthField;

      text -label " ";

      button -label "go!" -align "center" -c ("camPlacement");

paneLayout;

showWindow $executeWindow;

}

 

 

 

proc camPlacement()

{

 

int $uvFileId;

string $uvFilePath;

$uvFilePath = `textField -q -tx uvFileNameField`;

 

int $i,$j;

int $totalCAMS;

float $uvPOScurrent[];

float $uvPOSother[];

float $distanceToOther,$closestDistance;

float $vertCOL[];

float $focalLength = `floatField -q -v focalLengthField`;

 

int $points[]= `polyEvaluate -v`;//get the number of points in the current object

$totalCAMS=$points[0];//assign number of points to interger

float $camSIZE = 0.2;

 

//------- set up file for writing some info about each cam --------

 

    $uvFileId = `fopen $uvFilePath "w"`;

    fprint $uvFileId ( $totalCAMS + "\n");

 

//get name of current selection, hopefully the camera shape

string $selected_Cur[] =`ls -sl`;

rename $selected_Cur[0] camGRID;//name it to be grid for reference later

 

 

for ($i=0;$i<$totalCAMS;$i++) // for the specifided number of cameras (ie number of vertices in obj)

      {

     

            select -r camGRID.vtx[$i] ;

            PolySelectConvert 4;  //change selection to be current uv   uv numbering is not neccessarily == to vtx numbering, so we select vtx and convert to uv

            $uvPOScurrent = `polyEditUV -q`; //query the current uv posisition     

            $closestDistance = 10000000; //reset closest distance to be very large

                  for($j=0;$j<$totalCAMS;$j++)

                  {

                        if($j!=$i)

                        {

                        select -r camGRID.vtx[$j];

                        PolySelectConvert 4;

                        $uvPOSother = `polyEditUV -q`;

                        $distanceToOther = ( pow(( $uvPOSother[0] - $uvPOScurrent[0] ),2) + pow(( $uvPOSother[1] - $uvPOScurrent[1] ),2) );//as we do not need the actual distances, no sqrt-ing for speed

                        }

                        if($distanceToOther < $closestDistance)

                        {

                        $closestDistance = $distanceToOther; //check if current uv is closer than any other

                        }

                  }

     

            select -r camGRID.vtx[$i] ;

            $closestDistance = $closestDistance * 30 + 0.1;//scale and range the colorValues

      polyColorPerVertex -nun -rgb $closestDistance $closestDistance $closestDistance;  //set vertex's color to be closest distance

     

     

     

     

      //make a camera

      camera -centerOfInterest 5  -lensSqueezeRatio 1 -horizontalFilmAperture 1.4173 -horizontalFilmOffset 0 -verticalFilmAperture 0.9449 -verticalFilmOffset 0 -filmFit Vertical -overscan 1.2562 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.1 -farClipPlane 1000 -orthographic 0 -orthographicWidth 30; objectMoveCommand; cameraMakeNode 1 "";

      string $selected_c[] = `ls -sl`;

      rename $selected_c[0] ("cam" + $i);//name the cameras , they will be in sequence cam0 .. camN

      //shrinkemdown

      setAttr ("cam" + $i + ".scaleX") ($camSIZE * $closestDistance);

      setAttr ("cam" + $i + ".scaleY") ($camSIZE * $closestDistance);

      setAttr ("cam" + $i + ".scaleZ") ($camSIZE * $closestDistance);

 

 

     

      //aim the camera along the normal vector

      normalConstraint -weight 1 -aimVector 0 0 -1 -upVector 0 1 0 -worldUpType "vector" -worldUpVector 0 1 0 camGRID ("cam" + $i);

     

      //move camera to point on grid

      string $expressionCommand = ("float $f1[] = `xform -q -ws -t camGRID.vtx[" + $i + "]`; \n setAttr cam" + $i + ".translateX $f1[0]; \n setAttr cam" + $i + ".translateY $f1[1];\n setAttr cam" + $i + ".translateZ $f1[2];\n");

      expression -n ("camExpr" + $i) -s $expressionCommand; //this is an expression so that the grid can be deformed

     

      //query the vertex color and print it into a file (to be used to scale rendered tiles in shake composite)

      select -r camGRID.vtx[$i] ;

      $vertCOL = ` polyColorPerVertex -q -r`;

      setAttr ("camShape" + $i + ".focalLength") ( ( 50 * (1-$vertCOL[0]) ) + $focalLength ); //set the associated cameras focal length to vary depending on vertex color

      fprint $uvFileId ( $vertCOL[0] + "\n");

     

      //query the texture space posistions for current vert & print them into file which will be read by render script

      PolySelectConvert 4;  //change selection to be current uv

      $uvPOS = `polyEditUV -q`; //query the current uv posisition

      fprint $uvFileId ( $uvPOS[0] + "\n");

      fprint $uvFileId ( $uvPOS[1] + "\n");

      }

 

 

      fclose $uvFileId;

 

 

      deleteUI cameraplacementWindow;

 

}