/* This file downloaded from Highend3d.com '' '' Highend3d.com File Information: '' '' Script Name: ks_finalGatherCamera '' Author: '' Last Updated: Feb 19, 2008 '' Update/Change this file at: '' http://Highend3d.com/maya/downloads/mel_scripts/rendering/mental_ray/4976.html '' '' Please do not alter any information above this line '' it is generated dynamically by Highend3d.com and will '' be changed automatically on any updates. */ // //ks_finalGatherCamera.mel by Katrin Schmid 2007 //Retime animated camera to speed up mental ray fg map pre-rendering. // // Features: // When using FinalGather in animation (especiallly on a render farm) // it's common to pre-render a Fg map only (or low antialiased images first) // and FG Freeze when rendering the camera flight. // There is a description here http://forums.cgsociety.org/showthread.php?t=356092. // This workflow reduces for flickering in the final rendering as render time FG points cause flicker. // This script retimes a copied camera to speed up the pre-rendering and // lets you set some prescale on the camera so you get // additional fg points at the edges of the camera. // Works with keyframes only. Bake other aniamtion types before using script. // // Usage: // Select render camera to copy from Option menu. // Set your settings, hit copy button. // Use this retimed camera for fg map rendering only. // // Install: Put ks_finalGatherCamera.mel in you script directory. // Start the GUI by typing "ks_finalGatherCamera" in the script editor. // if (`pluginInfo -q -loaded Mayatomr`== 0) { loadPlugin -quiet Mayatomr; } global proc ks_finalGatherCamera() { global string $gl_frCam; if (`window -query -exists ks_fgCamera`) deleteUI ks_fgCamera; // Strings declarations string $title = " ks_finalGatherCamera"; string $sh = "showHelp -absolute \"http://www.lo-motion.de/scripts.html\""; //UI-Window window -wh 450 420 -menuBar true -title $title -s 1 ks_fgCamera; // Help menue menu -label "Help" -helpMenu true; menuItem -label "About" -c $sh; // Layout string $form = `formLayout`; string $child1 = `columnLayout -adjustableColumn true`; frameLayout -label "Select animated camera to copy:" -li 7 -borderStyle "out" -marginHeight 7 -marginWidth 10 -labelAlign "bottom"; rowLayout -numberOfColumns 2 -columnWidth2 300 250 -columnAlign1 "left" ; // column 1 columnLayout -rowSpacing 6 -columnWidth 290 col2; //-columnAttach "both" 5 $gl_frCam = `optionMenuGrp -adj 0 -cw 1 4 -enable 1 -w 170 -cat 1 "left" 0 -cc "updateGUI" me_nameSpc`; floatSliderGrp -cal 1 left -label "Camera prescale (zoom):" -field true -minValue 0.1 -maxValue 1 -value 1 -cw 1 130 -dc "" -cc "" fs_PreScale; floatSliderGrp -cal 1 left -label "New animation length (%):" -field true -minValue 1 -maxValue 100 -step .001 -value 100 -cw 1 130 -dc "previewSlider()" -cc "previewSlider()" fs_CompressKeys; text -align "left" -w 200 -label "New camera animation length (in frames):"; textField -editable 0 -w 120 tx_camLen; text -align "left" -w 220 -label "Minimum camera animation length (in frames):"; textField -editable 0 -w 120 tx_minCamLen; text -align "left" -w 150 -label "New start frame:"; textField -tx 0 -editable 1 -w 50 tx_startFrame; checkBox -w 240 -value 1 -label "Set all other cameras non renderable" -align "left" ch_nonRend; checkBox -w 240 -value 1 -label "Set render frame range to new camera length" -align "left" ch_frRange; checkBox -w 240 -value 1 -label "Enable Finalgather" -align "left" ch_enFg; checkBox -w 240 -value 1 -label "Set Finalgather rebuild to OFF" -align "left" ch_FgOff; text -align "left" -w 150 -label "Finalgather map name:"; textField -tx "" -editable 1 -w 250 tx_fgMap; button -bgc .5 .7 .7 -align "left" -enable 1 -w 250 -l "Make new fg camera" -c "fgCam()" bu_selNmspc; separator -w 260; intSliderGrp -cal 1 left -label "Finalgather presample density:" -field true -minValue 1 -maxValue 20 -value 1 -cw 1 150 -dc "" -cc "updateFGSettings(0)" fs_PreDensity; setParent ..; columnLayout -rowSpacing 3 col3; setParent ..; setParent ..; setParent ..; // setParent ..; showWindow ks_fgCamera; updateGUI(); } //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////// Cameras not renderable global proc pa_setAllCamsNotRenderable() { global int $gl_debug; if ($gl_debug) { print ("\n +++++function: pa_setAllCamsNotRenderable()"); } string $allCams[] = `ls -l -type camera`; string $curCam; for( $i=0; $i < size($allCams); $i++) { string $curCam[] = `listRelatives -f -ap $allCams[$i]`; setAttr ($curCam[0] +".renderable") 0; } } ///////////////////////////////////////////////////////// global proc fgCam() { global int $gl_debug; if ($gl_debug) { print ("\n +++++function: fgCam()"); } global string $gl_frCam; string $pmTime; if (`checkBox -q -value ch_nonRend`) { pa_setAllCamsNotRenderable(); } float $transKeysCount[]; float $shapeKeysCount[]; float $transKeysMax=0; float $shapeKeysMax=0; string $fgCam[]; string $fgCamShape[]; float $firstKey, $lastKey=0; float $preScaleFactor=`floatSliderGrp -q -value fs_PreScale`; float $keyFactor=(`floatSliderGrp -q -value fs_CompressKeys`/100); string $origCam =`optionMenuGrp -q -v $gl_frCam`; if (`objExists $origCam`) { $fgCam =`duplicate -rr -n ("fg_" + $origCam+"#") -un $origCam`; $fgCamShape =`listRelatives -s $fgCam[0]`; setAttr ($fgCamShape[0] + ".displayResolution") 1; menuItem -p ($gl_frCam + "|OptionMenu") -l $fgCam; float $currPrescale= `getAttr ($fgCamShape[0] + ".preScale")`; setAttr ($fgCamShape[0] + ".preScale")($currPrescale* $preScaleFactor); setAttr ($fgCamShape[0] + ".renderable") 1; select -cl; // string $selected1[] = `ls -type animCurveTL -type animCurveTA -type animCurveTT -type animCurveTU`; // string $selected[] = `select -add $fgCam[0]`; //findKeyframe -timeSlider -which last; $firstKey =`findKeyframe -which first $fgCam[0]`; //-timeSlider $lastKey =`findKeyframe -which last $fgCam[0]`; } float $keyLengthOld =$lastKey - $firstKey; textField -e -tx ($keyLengthOld*$keyFactor) tx_camLen; string $transKeys[]=`listConnections $fgCam[0]`; string $shapeKeys[]=`listConnections $fgCamShape[0]`; for ($i = 0; $i < size($shapeKeys); $i++) { if(`isAnimCurve $shapeKeys[$i]`) { int $count=`size($shapeKeysCount)`; $shapeKeysCount[$count] = `keyframe -q -keyframeCount $shapeKeys[$i]`; $shapeKeysMax=`max $shapeKeysMax $shapeKeysCount[$count]`; } } for ($p = 0; $p < size($transKeys); $p++) { int $count1=`size($transKeysCount)`; $transKeysCount[$count1] = `keyframe -q -keyframeCount $transKeys[$p]`; $transKeysMax=`max $transKeysMax $transKeysCount[$count1]`; } float $allMax=`max $transKeysMax $shapeKeysMax`; float $startFrame=`textField -q -tx tx_startFrame`; selectKey -clear $fgCam[0]; int $selKeys=`selectKey $fgCam[0]`; float $endFrame=0; if ($selKeys > 0) { $endFrame= $startFrame + ($keyLengthOld*$keyFactor); scaleKey -newStartTime $startFrame -newEndTime $endFrame -attribute $fgCam[0]; /* print ("$firstKey# " + $firstKey +"\n"); print (" $lastKey# " + $lastKey +"\n"); print ("$keyLengthOld# " + $keyLengthOld +"\n"); print ("$startFrame# " + $startFrame +"\n"); print ("$keyFactor# " + $keyFactor +"\n"); print ("$endFrame# " + $endFrame +"\n"); print ("`ceil($endFrame)`# " + `ceil($endFrame)` +"\n"); */ } else { confirmDialog -title "Warning" -message "Selected camera has no keyframe animation." -button "Ok"; delete $fgCam[0]; } if (`checkBox -q -value ch_frRange`) { setAttr "defaultRenderGlobals.startFrame" `floor($startFrame)`; setAttr "defaultRenderGlobals.endFrame" `ceil($endFrame)`; } int $val2= `checkBox -q -value ch_enFg`; if ($val2) { updateFGSettings(2); } int $val3= `checkBox -q -value ch_FgOff`; if ($val3) { updateFGSettings(1); } } ///////////////////////////////////////////////////////// global proc updateGUI() { global int $gl_debug; if ($gl_debug) { print ("\n +++++function: updateGUI()"); } global string $gl_frCam; string $cams[] = `ls -l -type camera`; string $menItems[] = `optionMenuGrp -q -itemListLong $gl_frCam`; string $origCam; if (`size($menItems)`>0) { $origCam =`optionMenuGrp -q -v $gl_frCam`; } else { string $transformC[]=`listRelatives -p $cams[0]`; $origCam =$transformC[0]; } string $origCamShape[]; if (`objExists $origCam`) { $origCamShape =`listRelatives -s $origCam`; for ($t = 0; $t < size($menItems); $t++) { deleteUI $menItems[$t]; } for ($p = 0; $p < size($cams); $p++) { $camName= `listRelatives -p $cams[$p]`; menuItem -p ($gl_frCam + "|OptionMenu") -l $camName; } } else { confirmDialog -title "Missing object" -message "Camera not found in scene." -button "OK"; } float $preScaleFactor=`floatSliderGrp -q -value fs_PreScale`; float $keyFactor=`floatSliderGrp -q -value fs_CompressKeys`/100.0; //// float $transKeysCount[]; float $shapeKeysCount[]; float $transKeysMax=0; float $shapeKeysMax=0; string $shapeKeys[]; string $transKeys[]=`listConnections $origCam`; if (`objExists $origCamShape[0]`) { $shapeKeys=`listConnections $origCamShape[0]`; } for ($i = 0; $i < size($shapeKeys); $i++) { if(`isAnimCurve $shapeKeys[$i]`) { int $count=`size($shapeKeysCount)`; $shapeKeysCount[$count] = `keyframe -q -keyframeCount $shapeKeys[$i]`; $shapeKeysMax=`max $shapeKeysMax $shapeKeysCount[$count]`; } } for ($p = 0; $p < size($transKeys); $p++) { if(`isAnimCurve $transKeys[$p]`) { int $count1=`size($transKeysCount)`; $transKeysCount[$count1] = `keyframe -q -keyframeCount $transKeys[$p]`; $transKeysMax=`max $transKeysMax $transKeysCount[$count1]`; } } float $firstKey =`findKeyframe -timeSlider -which first $origCam`; float $lastKey =`findKeyframe -which last $origCam`; float $keyLengthOld=$lastKey- $firstKey; float $allMax=`max $transKeysMax $shapeKeysMax`; textField -e -tx $allMax tx_minCamLen; if ($keyLengthOld!=0) { floatSliderGrp -e -minValue ($allMax/$keyLengthOld* 100.0) fs_CompressKeys; } if (`objExists $origCam`) { optionMenuGrp -e -v $origCam $gl_frCam; } textField -e -tx ($keyLengthOld*$keyFactor) tx_camLen; previewSlider(); } ///////////////////////////////////////////////////////// global proc previewSlider() { global int $gl_debug; if ($gl_debug) { print ("\n +++++function: previewSlider()"); } global string $gl_frCam; float $preScaleFactor=`floatSliderGrp -q -value fs_PreScale`; float $keyFactor=`floatSliderGrp -q -value fs_CompressKeys`/100.0; string $origCam =`optionMenuGrp -q -v $gl_frCam`; float $firstKey =`findKeyframe -which first $origCam`;//-timeSlider float $lastKey =`findKeyframe -which last $origCam`; float $keyLengthOld=$lastKey - $firstKey; textField -e -tx ($keyLengthOld*$keyFactor) tx_camLen; //print ("$keyLengthOld " +$keyLengthOld +"\n"); //print ("$keyFactor: " + $keyFactor +"\n"); } ///////////////////////////////////////////////////////// global proc updateFGSettings(int $which) { setAttr "miDefaultOptions.finalGather" 1; setAttr -type "string" miDefaultOptions.finalGatherFilename `textField -q -tx tx_fgMap`; switch($which) { case 0: int $val= `intSliderGrp -q -value fs_PreDensity`; setAttr "miDefaultOptions.finalGatherPresampleDensity" $val; break; case 1: int $val3= `checkBox -q -value ch_FgOff`; setAttr "miDefaultOptions.finalGatherRebuild" 0; break; case 2: int $val2= `checkBox -q -value ch_enFg`; setAttr "miDefaultOptions.finalGather" $val2; break; } }