# Sean Dooley # 13 April 2012 # http://www.smdooley.com # http://smdooley.com/Extras/Python/FGScripts/fgSimple.html # - This script is run to set up the building of the FG map to expidite render times. # - The default values for this definition set Maya to create a FG map from the start frame # to the last frame going at incriments of the incr value set in the call of the script. # - You do not need to set the render type to render FG only, my script makes all the necessary # changes for you and resets the render method back at the completion of the script. # ---------------------------------------------------------------------------------------- # Suggested to change the incr value for your own needs, 10 is just a starting place recomendation. # This script has commented out some default suggested values for FG sample quality # *** as a suggested place to start. [ lines45-48 ] # ---------------------------------------------------------------------------------------- from pymel.core import * import maya.cmds import os def fgBake(first=playbackOptions(query=True, min=True), last=playbackOptions(query=True, max=True), incr=10, cam='camera1'): maya.cmds.setAttr('mentalrayGlobals.renderMode', 3) # sets Render Mode to "FG Only" maya.cmds.setAttr('miDefaultOptions.finalGatherRebuild', 0) # sets Rebuild to "Off" -- adds to existing map # check for existing fgmap name existing = maya.cmds.getAttr('miDefaultOptions.finalGatherFilename') if existing != '': mapName = existing.rstrip('.fgmap') else: # if not using a fgmap, get scene name and use that as the default fgmap name scenePath = maya.mel.eval('file -q -sn') temp = os.path.basename(scenePath) sceneName, ext = temp.split('.') mapName = sceneName maya.mel.eval('setAttr -type "string" miDefaultOptions.finalGatherFilename "%s.fgmap"' % mapName ) print("Using FG Map: %s.fgmap" % mapName) i = first while i < (last + 1): currentTime(i) print("Adding to existing FGMap - Frame: %s" % (i) ) # maya.cmds.setAttr('miDefaultOptions.finalGatherRays', 150) # maya.cmds.setAttr('miDefaultOptions.finalGatherPresampleDensity', 15) # maya.cmds.setAttr('miDefaultOptions.finalGatherPoints', 100) maya.cmds.Mayatomr(preview=True, camera=cam) i += incr # loop to make sure that the last frame is being used for the map if i != last: currentTime(last) print("Adding to existing FGMap - Frame: %s" % (last) ) maya.cmds.Mayatomr(preview=True, camera=cam) print("Returning render settings to Normal render mode and to Freeze the FG Map rebuild.") maya.cmds.setAttr('mentalrayGlobals.renderMode', 0) # sets Render Mode to "Normal" maya.cmds.setAttr('miDefaultOptions.finalGatherRebuild', 2) # sets Rebuild to "Freeze"