// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // provided at the time of installation or download, or which otherwise accompanies source "showEditor.mel"; global string $gIlrCurrentSelection[]; global int $gIlrAutoUpdateAttrEdFlag = 0; global int $gIlrRenderRegionFlag = 0; global proc ilrTakeMayaRenderOptions() { int $erl = `getAttr defaultRenderGlobals.renderLayerEnable`; setAttr TurtleRenderOptions.renderLayers $erl; } global proc ilrShowBatchRender() { global int $gIlrIsSystemNT; global int $gIlrIsSystemLinux; global int $gIlrIsSystemMac; string $filename = (ilrGetTempDir() + "batch.tmp"); $fileId = `fopen ($filename) "r"`; if (!$fileId) { error("No batch render exists!"); } string $s = `fread $fileId $s`; fclose $fileId; if ($gIlrIsSystemNT == 1) { system("start cmd /c fcheck.exe \"" + $s + "\""); } else if ($gIlrIsSystemLinux) { $cmd1 = "fcheck " + $s + " >/dev/null 2>&1"; string $cmd = `substitute "\n" $cmd1 ""`; ilrDebugPrint($cmd); system($cmd); } else if ($gIlrIsSystemMac) { string $f = "\"" + $s + "\""; string $cmd = "open -a " + `getenv MAYA_LOCATION` + "/Fcheck.app " + $f; $cmd = `substitute "\n" $cmd ""`; $cmd = `substitute "/Maya.app/Contents" $cmd ""`; system($cmd); } else { error("Unsupported architecture, cannot show batch render!"); } } proc ilrFixMultiTextureShader() { string $allTexures[]; $allTexures = `ls -tex`; int $s = size($allTexures); int $i = 0; for ($i=0; $i< $s; $i++) { if (attributeExists("shaderFlag", $allTexures[$i])) { setAttr ($allTexures[$i]+".shaderFlag") 0; } } }; proc ilrResetMultiTextureShader() { string $allTexures[]; $allTexures = `ls -tex`; int $s = size($allTexures); int $i = 0; for ($i=0; $i< $s; $i++) { if (attributeExists("shaderFlag", $allTexures[$i])) { setAttr ($allTexures[$i]+".shaderFlag") -1; } } }; proc ilrRemoveHDRILights() { string $list[]; string $lightList[]; string $lightObj; $list = `ls -l`; for ($item in $list) { $lightObj = `match "HDRIlight[0-9]+$" $item`; if (size($lightObj)) { delete $lightObj; } } } global proc ilrInitRender(string $camera) { // Make sure the rendering options node exist ilrDefaultNodes(); // Take all neccessary Maya options ilrTakeMayaRenderOptions(); ilrFixMultiTextureShader(); } global proc ilrExitRender() { ilrRemoveHDRILights(); } // // Setup the renderer to render only the specified layers and passes. // Empty strings means to ignore this option. // global proc ilrSetRenderLayersAndPasses(string $layers, string $passes) { int $i; int $j; int $state; string $allLayers[] = `listConnections renderLayerManager.renderLayerId`; // Handle the layers first if ($layers != "") { if ($layers == "off" || $layers == "false" || $layers == "0") { // // Set the default layer to renderable, and all others to // non-renderable. // The subdirectory "defaultRenderLayer" will automatically // be created if any render layers (other than the default) exist. // for( $i=0 ; $i= 4) { // Abort render if region outside range of image // if ( $r[2] >= $width || $r[3] >= $height ) { // Adjust region for next attempt to succeed // Select region at bottom left of image. // string $panel = `ilrGetRenderWindowPanel`; renderWindowEditor -edit -marquee 0.5 0.0 0.0 0.5 $panel; error("Region out of range!"); return; } $cmd += " -region " + $r[0] + " " + $r[1] + " " + $r[2] + " " + $r[3]; } } print($cmd + "\n"); // Set the camera to be used next time // string $panel = `ilrGetRenderWindowPanel`; renderWindowEditor -edit -currentCamera $camera $panel; string $axis = `upAxis -q -axis`; int $axisUp = strcmp("z", $axis); setAttr TurtleRenderOptions.yAxis $axisUp; // Display render view window // ilrRenderWindow; // Execute the render command // string $items[] = `selectedNodes`; if ( catch(eval($cmd)) ) { ilrProgressEnd(); select -replace $items; error("Unexpected error during rendering!"); } select -replace $items; } // Render region procedure for plug-in render // We use Maya's render region procedure, but make sure // Turtle gets the -doRegion flag // global proc ilrRenderRegionCallback(string $editor) { global int $gIlrRenderRegionFlag; $gIlrRenderRegionFlag = 1; eval("mayaRenderRegion " + $editor); $gIlrRenderRegionFlag = 0; } // // Render procedure for batch rendering // global proc ilrRenderBatchCallback(string $options) { ilrDefaultNodes(); // determine scene name string $sceneName = `file -q -ns`; // interactive batch appends pid to scene name, remove to get original string $temp = $sceneName; if (`match "__[0-9]+$" $temp` != "") { $temp = `match ".+[^0-9]+" $temp`; $temp = substring($temp, 1, size($temp)-2); } if (size($temp) > 0) { $sceneName = $temp; } $options += " -sceneName " + $sceneName; string $cmd = "ilrBatchRenderCmd" + $options; print("\n\n" + $cmd + "\n\n"); eval $cmd; } // Procedure handling interactive rendering for all render types. // Starts the right render procedure depending on the selected // render type. // global proc ilrRender(int $width, int $height, int $doShadow, int $doGlow, string $camera, string $options) { ilrDefaultNodes(); string $cmd = ""; int $renderType = `getAttr TurtleRenderOptions.renderer`; switch ($renderType) { case 0: // Render $cmd = "ilrRenderCallback"; break; case 1: // Baking $cmd = "ilrBakeCallback"; break; } if (size($cmd) == 0) { error("Current render type doesn't support interactive rendering!"); return; } $cmd += "(" + $width + ", " + $height + ", " + $doShadow + ", " + $doGlow + ", \"" + $camera + "\", \"" + $options + "\")"; print("Interactive render command : " + $cmd + "\n"); eval $cmd; } // Procedure handling region rendering for all render types. // Starts the right render procedure depending on the selected // render type. // global proc ilrRegionRender(string $editor) { ilrDefaultNodes(); string $cmd = ""; int $renderType = `getAttr TurtleRenderOptions.renderer`; switch ($renderType) { case 0: // Render $cmd = "ilrRenderRegionCallback"; break; case 1: // Baking $cmd = "ilrBakeRegionCallback"; break; } if (size($cmd) == 0) { error("Current render type doesn't support region rendering!"); return; } $cmd += "(\"" + $editor + "\")"; print("Region render command : " + $cmd + "\n"); eval $cmd; } // Procedure handling batch rendering for all render types. // Starts the right render procedure depending on the selected // render type. // global proc ilrBatchRender(string $options) { ilrDefaultNodes(); string $cmd = ""; int $renderType = `getAttr TurtleRenderOptions.renderer`; switch ($renderType) { case 0: // Render $cmd = "ilrRenderBatchCallback"; break; case 1: // Baking $cmd = "ilrBakeBatchCallback"; break; } if (size($cmd) == 0) { error("Current render type doesn't support batch rendering!"); return; } $cmd += "(\"" + $options + "\")"; print("Batch render command : " + $cmd + "\n"); eval $cmd; }