/ Published in: Python
Currently supports exporting to VRScene only. This will change over time.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
from pymel.core import * import os def infoPrint(info): print ('\n[INFO]: %s\n') % (info) def errorPrint(error): print ('\n' + '='*20 + ' ERROR ' + '='*20 + '\n[ERROR] : ' + error + '\n' + '='*20 + ' ERROR ' + '='*20 + '\n') def exportVRScene (cam, range, layer=''): '''Export a VRScene file based on settings:\n camera - the render camera\n range - the frame range (formatted like '5-100')\n layer - the render layer (optional, and uses the default if none specified)\n ''' renderLayer = '' renderCam = '' infoPrint('Exporting VRScene with frame range %s' % range) startFrame = float(range.split('-')[0]) endFrame = float(range.split('-')[1]) if layer != '': if layer in ls (type='renderLayer'): renderLayer = layer for curCam in ls (type='camera'): if curCam == cam: renderCam = curCam if renderCam == '' : errorPrint ('camera %s not in scene' % (cam)) sys.exit(1) else : if getAttr (cam + '.renderable') == 1: infoPrint('Using camera %s' % (cam)) else: errorPrint('%s is not renderable!' % (cam)) sys.exit(1) if layer != '' : if renderLayer == '' : errorPrint('render layer %s not in scene' % (layer)) sys.exit(1) else : infoPrint('Using layer %s' % (layer)) editRenderLayerGlobals( currentRenderLayer=layer ) # set up the vray shite here setAttr('defaultRenderGlobals.animation', 1) setAttr('defaultRenderGlobals.startFrame', startFrame) setAttr('defaultRenderGlobals.endFrame', endFrame) setAttr('defaultRenderGlobals.byFrameStep', 1) setAttr('vraySettings.animBatchOnly', 0) setAttr('vraySettings.fileNamePadding', 4) setAttr('vraySettings.runToAnimationStart', 0) setAttr('vraySettings.runToCurrentTime', 0) setAttr('vraySettings.vrscene_render_on', 0) setAttr('vraySettings.vrscene_on', 1) setAttr('vraySettings.misc_separateFiles', 0) setAttr('vraySettings.misc_eachFrameInFile', 0) setAttr('vraySettings.misc_meshAsHex', 1) setAttr('vraySettings.misc_compressedVrscene', 1) setAttr('vraySettings.sys_low_thread_priority', 1) setAttr('vraySettings.imgOpt_exr_compression', 3) setAttr('vraySettings.imgOpt_exr_bitsPerChannel', 16) setAttr('vraySettings.imgOpt_exr_attributes', 'testing=foo') tmpdir = os.environ['TEMP'].replace('\\','/') vrScene = tmpdir + '/export.vrscene' for curfile in os.listdir(tmpdir): if curfile[-7:] == 'vrscene': os.unlink (tmpdir + '/' + curfile) infoPrint('Removed existing vrscene : %s' % curfile) setAttr ('vraySettings.vrscene_filename', vrScene) # check to see if the renderlayer is blank. if it is we don't export the layer. # simple eh? if layer != '': renderLayer = '-layer %s' % (renderLayer) else: renderLayer = '' vrendCommand = 'vrend -w 20 -h 20 -camera %s %s' % (renderCam, renderLayer) mel.eval (vrendCommand) if layer != '' : renderLayer = '_%s' % (layer) else : renderLayer = '_masterLayer' #if renderLayer == 'defaultRenderLayer': renderLayer = 'masterLayer' retVal = '%s/export%s.vrscene' % (tmpdir, renderLayer) infoPrint('Exported : %s' % (retVal)) return retVal