// David Chen // http://cgfx.moved.in /** * creates the UI window */ global proc sd_drawUI () { //If such a window already exists, destory it. if ( (`window -exists sd_window`) == true ) deleteUI sd_window; //Create the window. window -title "ACME Slice 'n Dicer" -rtf true sd_window; columnLayout -adj true -rs 15 -co "both" 5; button -l "Render Settings" -c "unifiedRenderGlobalsWindow;"; separator -height 5 -style "in"; text -align "left" -label "Slicing Settings:" -fn boldLabelFont; rowColumnLayout -numberOfColumns 2 -columnOffset 1 "right" 10; text -label "Slice Width (px)" -align "right"; intField -minValue 100 -step 1 -v 1000 sd_width; text -label "Slice Height (px)" -align "right"; intField -minValue 100 -step 1 -v 1000 sd_height; setParent..; separator -height 5 -style "in"; button -l "Do Batch Render" -w 125 -h 40 -c "file -save;sd_execUI"; //End of the column. setParent..; //Show it. showWindow sd_window; } /* * Execute the slicing command based on UI input. */ global proc sd_execUI() { int $width = `intField -q -v sd_width`; int $height = `intField -q -v sd_height`; sd_doSlice($width, $height); } /* * Construct the Render command and execute it. */ global proc sd_doRender( string $scene, string $outname, int $left, int $right, int $bottom, int $top ) { string $cmd = "Render -im "+$outname+" -reg "+$left+" "+$right+" "+$bottom+" "+$top+" "+"\""+$scene+"\""; print ("#EXECUTING COMMAND RENDERER\n"); print ("#$ "+$cmd+"\n"); // debugging line // print (`system("ping -n 5 127.0.0.1")`); print( `system($cmd)` ); } /* * Calculate the number of slices needed, and use the command-line renderer * to render them. */ global proc sd_doSlice( int $x, int $y ) { string $scene_name = `file -q -sceneName`; string $render_fileprefix; string $render_fileprefix = `getAttr defaultRenderGlobals.imageFilePrefix`; if ( $render_fileprefix == "" ) { $render_fileprefix = `file -q -sceneName -shortName`; $render_fileprefix = `substring $render_fileprefix 1 (size($render_fileprefix)-3)`; } int $slice_x = $x; int $slice_y = $y; int $render_x = `getAttr defaultResolution.w`; int $render_y = `getAttr defaultResolution.h`; print ($render_x+" :: "+$render_y+"\n"); int $x_num = $render_x / $slice_x; if ( $render_x % $slice_x > 0 ) $x_num += 1; int $y_num = $render_y / $slice_y; if ( $render_y % $slice_y > 0 ) $y_num += 1; print ("#number of slices: "+$x_num+" x "+$y_num+"\n" ); int $count = 0; int $total = $x_num*$y_num; string $status_text = "Rendering "+$count+" of "+$total+" slices"; progressWindow -title "Rendering Slices" -progress 0 -status $status_text -isInterruptable true; $break_flag = false; for ( $j = 0, $v = $render_y; $j < $y_num; $j++, $v -= $slice_y ) { if ( $break_flag ) break; for ( $i = 0, $u = 0; $i < $x_num; $i++, $u += $slice_x ) { // Check if the dialog has been cancelled if ( `progressWindow -query -isCancelled` ) { $break_flag = true; break; } // Check if end condition has been reached if ( `progressWindow -query -progress` >= 100 ) break; int $left = $u; int $right = $u+$slice_x; if ( $right > $render_x ) $right = $render_x; int $top = $v; int $bottom = $v-$slice_y; if ( $bottom < 0 ) $bottom = 0; print ("#slice dimension: "+$left+","+$top+ " : "+$right+","+$bottom+"\n"); $count++; $status_text = "Rendering "+$count+" of "+$total+" slices"; progressWindow -edit -status $status_text; sd_doRender( $scene_name, ($render_fileprefix+"_r"+$j+"c"+$i), $left, $right, $bottom, $top ); float $amount = (float)$count/$total*100; progressWindow -edit -progress $amount; } } progressWindow -endProgress; } if ( `menu -exists slicerMenu` ) deleteUI -m slicerMenu; menu -label "Slice 'n Dice" -tearOff true -p MayaWindow slicerMenu; menuItem -label "Slicer 'n Dicer" -c "sd_drawUI";