VRay Utils for Maya 2011


/ Published in: Python
Save to your folder(s)

Currently supports exporting to VRScene only. This will change over time.


Copy this code and paste it in your HTML
  1. from pymel.core import *
  2. import os
  3. def infoPrint(info):
  4. print ('\n[INFO]: %s\n') % (info)
  5. def errorPrint(error):
  6. print ('\n' + '='*20 + ' ERROR ' + '='*20 + '\n[ERROR] : ' + error + '\n' + '='*20 + ' ERROR ' + '='*20 + '\n')
  7.  
  8.  
  9. def exportVRScene (cam, range, layer=''):
  10. '''Export a VRScene file based on settings:\n
  11. camera - the render camera\n
  12. range - the frame range (formatted like '5-100')\n
  13. layer - the render layer (optional, and uses the default if none specified)\n
  14. '''
  15.  
  16. renderLayer = ''
  17. renderCam = ''
  18.  
  19. infoPrint('Exporting VRScene with frame range %s' % range)
  20. startFrame = float(range.split('-')[0])
  21. endFrame = float(range.split('-')[1])
  22. if layer != '':
  23. if layer in ls (type='renderLayer'):
  24. renderLayer = layer
  25.  
  26. for curCam in ls (type='camera'):
  27. if curCam == cam:
  28. renderCam = curCam
  29.  
  30. if renderCam == '' :
  31. errorPrint ('camera %s not in scene' % (cam))
  32. sys.exit(1)
  33. else :
  34. if getAttr (cam + '.renderable') == 1:
  35. infoPrint('Using camera %s' % (cam))
  36. else:
  37. errorPrint('%s is not renderable!' % (cam))
  38. sys.exit(1)
  39. if layer != '' :
  40. if renderLayer == '' :
  41. errorPrint('render layer %s not in scene' % (layer))
  42. sys.exit(1)
  43. else :
  44. infoPrint('Using layer %s' % (layer))
  45. editRenderLayerGlobals( currentRenderLayer=layer )
  46.  
  47. # set up the vray shite here
  48.  
  49. setAttr('defaultRenderGlobals.animation', 1)
  50. setAttr('defaultRenderGlobals.startFrame', startFrame)
  51. setAttr('defaultRenderGlobals.endFrame', endFrame)
  52. setAttr('defaultRenderGlobals.byFrameStep', 1)
  53. setAttr('vraySettings.animBatchOnly', 0)
  54. setAttr('vraySettings.fileNamePadding', 4)
  55. setAttr('vraySettings.runToAnimationStart', 0)
  56. setAttr('vraySettings.runToCurrentTime', 0)
  57. setAttr('vraySettings.vrscene_render_on', 0)
  58. setAttr('vraySettings.vrscene_on', 1)
  59. setAttr('vraySettings.misc_separateFiles', 0)
  60. setAttr('vraySettings.misc_eachFrameInFile', 0)
  61. setAttr('vraySettings.misc_meshAsHex', 1)
  62. setAttr('vraySettings.misc_compressedVrscene', 1)
  63. setAttr('vraySettings.sys_low_thread_priority', 1)
  64. setAttr('vraySettings.imgOpt_exr_compression', 3)
  65. setAttr('vraySettings.imgOpt_exr_bitsPerChannel', 16)
  66. setAttr('vraySettings.imgOpt_exr_attributes', 'testing=foo')
  67.  
  68. tmpdir = os.environ['TEMP'].replace('\\','/')
  69. vrScene = tmpdir + '/export.vrscene'
  70. for curfile in os.listdir(tmpdir):
  71. if curfile[-7:] == 'vrscene':
  72. os.unlink (tmpdir + '/' + curfile)
  73. infoPrint('Removed existing vrscene : %s' % curfile)
  74. setAttr ('vraySettings.vrscene_filename', vrScene)
  75. # check to see if the renderlayer is blank. if it is we don't export the layer.
  76. # simple eh?
  77. if layer != '':
  78. renderLayer = '-layer %s' % (renderLayer)
  79. else:
  80. renderLayer = ''
  81. vrendCommand = 'vrend -w 20 -h 20 -camera %s %s' % (renderCam, renderLayer)
  82. mel.eval (vrendCommand)
  83. if layer != '' :
  84. renderLayer = '_%s' % (layer)
  85. else :
  86. renderLayer = '_masterLayer'
  87.  
  88. #if renderLayer == 'defaultRenderLayer': renderLayer = 'masterLayer'
  89. retVal = '%s/export%s.vrscene' % (tmpdir, renderLayer)
  90. infoPrint('Exported : %s' % (retVal))
  91. return retVal

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.