/* NAME: dbCreateStoryboards.mel VERSION: 1.0 CATEGORY: Utilities FUNCTION: This is a script to aid in the creation of image planes. It takes an image or a sequence of images, creates a plane with the correct aspect ratio of the images and organizes them in rows and columns. It's useful for creating a single image plane for modeling reference, or to create a series of planes of "storyboards" to allow for editing and camera movement of a storyboard animatic within Maya. USAGE: 1. Copy the dbCreateStoryboards.mel into your Maya Scripts directory (Usually found in "My Documents\maya\\scripts\"). 2. In the Maya Script Editor, type in "source dbCreateStoryboards.mel;" 3. To create 1 image plane, use dbCreateStoryboard(). For multiple organized image planes, use dbCreateStoryboards() AUTHOR: David Bokser E-MAIL: me@davidbokser.com WEBSITE: www.davidbokser.com */ ///////////////// // Creates a UI to make // storyboard planes from // a set of images global proc dbCreateStoryboards() { if(`window -q -ex storyboardWin`) deleteUI -window storyboardWin; window -height 115 -title "Storyboard Creator" -width 190 storyboardWin; columnLayout -columnWidth 182 -height 96 -width 182; rowLayout -columnWidth3 50 100 30 -height 23 -numberOfColumns 3 -width 180; text -height 17 -label "Filename" -width 50; textField -height 23 -width 100 filenameField; button -height 20 -label "Set" -width 30 -c ("fileBrowserDialog -m 0 -fc \"csSetFile\" -ft \"image\" -an \"Add File\" -om \"Import\";"); setParent ..; rowLayout -columnWidth2 30 100 -height 23 -numberOfColumns 2 -width 130; text -height 17 -label "Start" -width 30; intField -height 23 -value 1 -width 100 startField; setParent ..; rowLayout -columnWidth2 30 100 -height 23 -numberOfColumns 2 -width 130; text -height 17 -label "End" -width 30; intField -height 23 -width 100 endField; setParent ..; button -height 18 -label "Create" -width 182 -c "dbMakeBoards"; showWindow storyboardWin; } global proc dbCreateStoryboard() { if(`window -q -ex storyboardWin`) deleteUI -window storyboardWin; window -height 115 -title "Storyboard Creator" -width 190 storyboardWin; columnLayout -columnWidth 182 -height 96 -width 182; rowLayout -columnWidth3 50 100 30 -height 23 -numberOfColumns 3 -width 180; text -height 17 -label "Filename" -width 50; textField -height 23 -width 100 filenameField; button -height 20 -label "Set" -width 30 -c ("fileBrowserDialog -m 0 -fc \"csSetFile\" -ft \"image\" -an \"Add File\" -om \"Import\";"); setParent ..; button -height 18 -label "Create" -width 182 -c "dbMakeBoard"; showWindow storyboardWin; } ////////////////////// // Sets the textField to // the input filename global proc csSetFile(string $filename, string $fileType) { textField -e -tx $filename filenameField; } ////////////////////// // Gets the properties // from the UI window // and runs the storyboard // creation procedure. global proc dbMakeBoards() { string $filename = `textField -q -tx filenameField`; string $filepath[] = `dbBreakApartPath($filename)`; int $start = `intField -q -v startField`; int $end = `intField -q -v endField`; if(`objExists "Storyboards"`) delete "Storyboards"; string $group = `group -empty`; $group = `rename $group "Storyboards"`; if($start > $end) error "Start number is larger than the end number. Don't be an idiot.\n"; dbCreateMultiBoards($filepath[0], $filepath[1], $filepath[2], $start, $end); dbStoryboardSort; dbCreateBoardCam; } global proc dbMakeBoard() { string $filename = `textField -q -tx filenameField`; if(`objExists "Storyboards"`) delete "Storyboards"; string $group = `group -empty`; $group = `rename $group "Storyboards"`; dbCreateStoryPlane($filename); } //////////////////////// // Creates a storyboard camera global proc dbCreateBoardCam() { string $camera[] = `camera`; setAttr ($camera[0] + ".rx") -90; $camera[0] = `rename $camera[0] "Storyboard_Cam"`; float $boardSize[] = `getBoardSize`; setAttr ($camera[0] + ".ty") $boardSize[0]; } ////////////////////////// // Returns the height and width // of the first storyboard // in the storyboards node global proc float[] getBoardSize() { string $storyboards[] = `listRelatives -children "Storyboards"`; float $boardSize[2]; $boardSize[0] = `getAttr ($storyboards[0] + ".sx")`; $boardSize[1] = `getAttr ($storyboards[0] + ".sz")`; return $boardSize; } /////////////////////////// // Sorts the storyboards global proc dbStoryboardSort() { string $storyboards[] = `listRelatives -children "Storyboards"`; int $numBoards = `size($storyboards)`; int $i = 0; int $p = 0; int $s = 0; float $divide; float $boardSize[2]; for($i = 0; $i <= ($numBoards / 5); $i++) { for($p = 0; $p < 5; $p++) { $boardSize[0] = `getAttr ($storyboards[$s] + ".sx")`; $boardSize[1] = `getAttr ($storyboards[$s] + ".sz")`; if($boardSize[0]<$boardSize[1]) { $divide = ($boardSize[1] / 12); setAttr ($storyboards[$s] + ".ry") -90; setAttr ($storyboards[$s] + ".tx") (($boardSize[1] * $p) + ($divide * $p)); setAttr ($storyboards[$s] + ".tz") (($boardSize[0] * $i) + ($divide * $i)); } else { $divide = ($boardSize[0] / 12); setAttr ($storyboards[$s] + ".tx") (($boardSize[0] * $p) + ($divide * $p)); setAttr ($storyboards[$s] + ".tz") (($boardSize[1] * $i) + ($divide * $i)); } $s++; } } } ////////////// // Break apart a file path // into directory [0], filename [1] // and extension [2] global proc string[] dbBreakApartPath(string $path) { string $broken[] = {}; $broken[0] = `match "^.*[/\\]" $path`; $broken[1] = `match "[^/\\]*$" $path`; $broken[1] = `substitute "....$" $broken[1] ""`; source "libString.mel"; $broken[1] = `objGetPrefix($broken[1])`; $broken[1] = $broken[1] + "_"; $broken[2] = `match "....$" $path`; return $broken; } //////////////// // Create multiple boards global proc dbCreateMultiBoards(string $dir, string $filename, string $ext, int $start, int $end) { int $i; for($i = $start; $i <= $end; $i++) { dbCreateStoryPlane($dir + $filename + $i + $ext); } } ///////////////// // create a polyPlane // with a texture global proc dbCreateStoryPlane(string $texture) { source AEfileTemplate.mel; source buildShaderMenus.mel; string $plane[] = `polyPlane -w 1 -h 1 -sx 10 -sy 10 -ax 0 1 0 -tx 1 -ch 1`; string $lambert = `shadingNode -asShader lambert`; string $fileShader = `shadingNode -asTexture file`; connectAttr -force ($fileShader + ".outColor") ($lambert + ".color"); string $textureName = `match "[^/\\]*$" $texture`; $textureName = `substitute "....$" $textureName ""`; AEassignTextureCB ($fileShader + ".fileTextureName") $texture "image"; assignSG $lambert $plane[0]; float $size[2] = `getAttr ($fileShader + ".outSize")`; setAttr ($plane[0] + ".sx") ($size[0] / 100); setAttr ($plane[0] + ".sz") ($size[1] / 100); rename $plane[0] $textureName; $plane[0] = $textureName; rename $lambert ($textureName + "_lambert"); $lambert = ($textureName + "_lambert"); } //////////////////// // Create a window that // controls the transparency // of a given storyboard. // // a storyboard must be selected // before running. global proc dbCreateTransparencyWin() { string $selected[] = `ls -sl`; if (`size($selected)` != 1) warning "More than one object selected, using the first\n"; string $shader = ($selected[0] + "_lambert"); if(`window -q -ex transparencyWin`) deleteUI -window transparencyWin; window -height 140 -title "Transparency" -width 300 transparencyWin; columnLayout; textField -editable 0 -w 290 -text $shader; attrFieldSliderGrp -min 0.0 -max 1.0 -cw 1 70 -cw 2 35 -cw 3 130 -label "Red" -at ($shader + ".transparencyR"); attrFieldSliderGrp -min 0.0 -max 1.0 -cw 1 70 -cw 2 35 -cw 3 130 -label "Green" -at ($shader + ".transparencyG"); attrFieldSliderGrp -min 0.0 -max 1.0 -cw 1 70 -cw 2 35 -cw 3 130 -label "Blue" -at ($shader + ".transparencyB"); rowLayout -columnWidth3 96 96 96 -numberOfColumns 3 -width 290; button -label "refresh" -w 96 -c "dbCreateTransparencyWin"; button -label "key" -w 96 -c ("setKeyframe \"" + $shader + ".transparencyR\"; setKeyframe \"" + $shader + ".transparencyG\"; setKeyframe \"" + $shader + ".transparencyB\";"); button -label "select shader" -w 96 -c ("select " + $shader); showWindow transparencyWin; window -e -w 300 -h 140 transparencyWin; }