global proc string meWriteProxy( int $aniMats) { // this writes out a mi scene fragment for the current selection per-frame, // then creates a proxy friendly version of these mi's via includes. // it was written in production, so will probably need a bit of fiddling to make it usable elsewhere, // mainly just paths I'd say. // // $aniMats 0 will make a single mi per-frame // $aniMats 1 will make a seperate mi for materials, for ease of editing. not much need for this now, // by prefixing the material assignment name with '::' it'll look in your maya scene for shaders // instead. // // to use: // 1. group everything you want to proxy, give the group a useful name. // 2. create a polycube called 'bBox' and scale it over the group you want to proxy, hide if you like // 3. set render globals frame range, turn on motion blur if you need it. // 4. select the group, run 'meWriteProxy 0' // // more details at http://www.mayawiki.com // check globals are set correctly: // moblur setAttr miDefaultOptions.motionBlur 2; // frame range //setAttr "defaultRenderGlobals.startFrame" 1; //setAttr "defaultRenderGlobals.endFrame" 100; // hierachy option // get selected node name (assume its top of tree) string $sel[] = `ls -sl`; if (size($sel) != 1) return "select one top-level group only. don't include 'bBox' in this selection (or group)"; if (size(`ls bBox`) == 0) return "no bounding box found! make a cube named 'bBox', scale it to fit over your objects. ta!"; float $bboxvalues[] = `exactWorldBoundingBox bBox`; string $bbox; for ($v in $bboxvalues) { $bbox += $v+" "; } string $selShapes[] = `listRelatives -f -ad -type "mesh" -type "particle" -type "fluidShape" $sel`; string $SG[]; for ($each in $selShapes) { string $SGnodes[] = `listSets -type 1 -object $each`; if (size($SGnodes)!=0) appendStringArray( $SG,$SGnodes ,1); } print ("size of SG: "+(size($SG))); if (size($SG) == 0) return "couldn't find shaders. are display layers turned off? shaders assigned?"; // set path string $baseSrc = "/path/to/raw/miFrameDump"; string $pathSrc = $baseSrc+$sel[0]+"/"; int $result = `sysFile -makeDir $pathSrc`; if ($result == 0) return "could not create source output folder, aborting"; string $pathFile = $pathSrc+$sel[0]+".mi"; string $geoFile = $pathSrc+"geo"+$sel[0]+".mi"; string $matFile = $pathSrc+"mat"+$sel[0]+".mi"; // print ("output path: "+$pathFile+"\n"); if ($aniMats == 0) { // select the SG's, write out materials. do for start frame only int $startFrame = `getAttr "defaultRenderGlobals.startFrame"`; int $endFrame = `getAttr "defaultRenderGlobals.endFrame"`; setAttr "defaultRenderGlobals.endFrame" $startFrame; setAttr "mentalrayGlobals.exportExactHierarchy" 0; dgdirty -a; select -clear; select -ne $SG; // Mayatomr has loads of options, here's what we're using (note its different for materials vs geo): // // -fe = fragment export, allow us to seperate materials from geo // -fcd = fragment child dag, ie everything beneath selected node // -fem = fragment materials, translate attached materials in current selection // -fis = fragment incoming shaders, additionally translate shading nodes linked to nodes in current sel. driving textures vs shaders. // -fma = fragment material assignments, i guess the material["thisSG"] bit // -e = echo, export file by 'pretending' to do a render // Mayatomr -mi -perframe 2 -padframe 4 -exportFilter 2089719 -active -binary -fe -fem -fis -xp "3313333333" -file $matFile; //Mayatomr -mi -exportFilter 2089719 -active -binary -fe -fem -fis -xp "3313333333" -file $matFile; Mayatomr -mi -e -exportFilter 2089719 -active -binary -fe -fem -fis -xp "3313333333" -file $matFile; setAttr "defaultRenderGlobals.endFrame" $endFrame; } // restore the selection, write out geo setAttr "mentalrayGlobals.exportExactHierarchy" 1; dgdirty -a; select -clear; select $sel; if ($aniMats == 1) { Mayatomr -mi -perframe 2 -padframe 4 -exportFilter 721600 -active -binary -fe -fem -fis -fma -fcd -xp "3313333333" -file $geoFile; } else { Mayatomr -mi -perframe 2 -padframe 4 -exportFilter 721600 -active -binary -fe -fma -fcd -xp "3313333333" -file $geoFile; } setAttr "mentalrayGlobals.exportExactHierarchy" 1; // CREATE INCLUDE BASED MI'S int $startFrame = `getAttr defaultRenderGlobals.startFrame`; int $endFrame = `getAttr defaultRenderGlobals.endFrame`; int $i; // loop over frame range string $baseProxy = "/path/to/proxies"; string $pathProxy = $baseProxy+"/"+$sel[0]; int $result = `sysFile -makeDir $pathProxy`; if ($result == 0 ) { return "could not create output directory, aborting."; } for ($i = $startFrame; $i <= $endFrame; $i++) { // create .mi file with include, bounding box string $file = ($sel[0]+".mi"); string $padfile = ($sel[0]+"."+pad($i,4)+".mi"); string $miPath = $pathProxy+"/"+$padfile; string $miInclude = $padfile; string $data[]; //$data[0] = "# assembly root bbox: -82 -2 -86 88 222 86"; // $data[0] = "# assembly root bbox: -51 -19 -638 132 709 -429"; $data[0] = "# assembly root bbox: "+$bbox; if ($aniMats == 0 ) { $data[1] = "$include \""+$pathSrc+"mat"+$file+"\""; } else { $data[1] = "# animated material..."; } $data[2] = "$include \""+$pathSrc+"geo"+$miInclude+"\""; $data[3] = "instgroup \""+$sel[0]+"Grp\""; $data[4] = "\""+$sel[0]+"\""; $data[5] = "\"instancerGrpInst\""; $data[6] = "end instgroup"; $data[7] = "root \""+$sel[0]+"Grp\""; int $fid = `fopen $miPath "w"`; for ($j = 0; $j < size($data); $j++) { fprint $fid ($data[$j]+"\n"); } fclose $fid; } setAttr "mentalrayGlobals.exportExactHierarchy" 0; return ("sequence: "+$pathProxy); }