i haven't tried JooJa's method, but here is a simple script i wrote to automatically manage and bake ambient occlusion.
CODE
{
$curSel=ls -sl
;
if (!pluginInfo -q -l Mayatomr
);
{
loadPlugin -qt Mayatomr;
}
if (!objExists mentalrayGlobals
)
{
createNode "mentalrayGlobals" -n "mentalrayGlobals";
}
// Create a bake set with the appropriate settings
if ( objExists OcclusionSet
== 0 )
{
$bakeSetAO=createBakeSet OcclusionSet vertexBakeSet
;
setAttr OcclusionSet.colorMode 3;
setAttr OcclusionSet.occlusionRays 256;
setAttr OcclusionSet.occlusionFalloff 500;
setAttr OcclusionSet.normalDirection 1;
setAttr OcclusionSet.orthogonalReflection 1;
setAttr OcclusionSet.bakeColor 1;
setAttr OcclusionSet.bakeAlpha 0;
setAttr -type "string" OcclusionSet.colorSetName "COLOR1";
}
// Mental Ray expects an initial Vertex and Texture Bake Set or else it complains, so create them.
if ( objExists initialTextureBakeSet
== 0 )
{
createBakeSet initialTextureBakeSet textureBakeSet;
}
if ( objExists initialVertexBakeSet
== 0 )
{
createBakeSet initialVertexBakeSet vertexBakeSet;
}
// Assign the shape nodes to the bake set created earlier.
for ( $eachObj in $curSel )
{
string $shape[]=listRelatives -s $eachObj
;
sets -forceElement OcclusionSet $shape[0];
}
// Do the baking on the selected Objects.
select -r $curSel;
catchQuiet ( convertLightmapSetup -camera persp -sh -vm -showcpv
);
}