def main(): import sys import hou import soho import sohoglue import SOHOcommon import sys import ctypes if hasattr(sys, 'setdlopenflags'): sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL) import _vfh_ipr from soho import SohoParm LogLevel = type('Enum', (), { 'Msg': 0, 'Info': 1, 'Progress': 2, 'Warning': 3, 'Error': 4, 'Debug': 5 }) def logMessage(level, fmt, *args): _vfh_ipr.logMessage(level, fmt % args) def printDebug(fmt, *args): logMessage(LogLevel.Debug, fmt, *args) def dumpObjects(listName): printDebug("Checking \"%s\"" % listName) for obj in soho.objectList(listName): printDebug(" %s", obj.getName()) def exportObjects(listName): for obj in soho.objectList(listName): _vfh_ipr.exportOpNode(opNode=obj.getName()) def deleteObjects(listName): for obj in soho.objectList(listName): _vfh_ipr.deleteOpNode(opNode=obj.getName()) def getViewParams(camera, sohoCam, t): camParms = { 'space:world': SohoParm('space:world', 'real', [], False), 'focal': SohoParm('focal', 'real', [0.050], False), 'aperture': SohoParm('aperture', 'real', [0.0414214], False), 'orthowidth': SohoParm('orthowidth', 'real', [2], False), 'near': SohoParm('near', 'real', [0.001], False), 'far': SohoParm('far', 'real', [1000], False), 'res': SohoParm('res', 'int', [640, 480], False), 'projection': SohoParm('projection', 'string', ["perspective"], False), 'cropl': SohoParm('cropl', 'real', [-1], False), 'cropr': SohoParm('cropr', 'real', [-1], False), 'cropb': SohoParm('cropb', 'real', [-1], False), 'cropt': SohoParm('cropt', 'real', [-1], False), 'camera': SohoParm('camera', 'string', ['/obj/cam1'], False) } camParmsEval = sohoCam.evaluate(camParms, t) if not camParmsEval: return {} viewParams = {} for key in camParmsEval: viewParams[key] = camParmsEval[key].Value[0] viewParams['transform'] = camParmsEval['space:world'].Value viewParams['ortho'] = 1 if camParmsEval['projection'].Value[0] in { 'ortho' } else 0 viewParams['res'] = camParmsEval['res'].Value cropX = viewParams['res'][0] * viewParams['cropl'] cropY = viewParams['res'][1] * (1.0 - viewParams['cropt']) cropW = viewParams['res'][0] * (viewParams['cropr'] - viewParams['cropl']) cropH = viewParams['res'][1] * (viewParams['cropt'] - viewParams['cropb']) printDebug(" Res: %s" % viewParams['res']) printDebug(" Crop: %i-%i %i x %i " % (cropX, cropY, cropW, cropH)) return viewParams def exportView(rop, camera, sohoCam, t): printDebug("exportView()") _vfh_ipr.exportView(viewParams=getViewParams(camera, sohoCam, t)) mode = soho.getDefaultedString('state:previewmode', ['default'])[0] # Evaluate an intrinsic parameter (see HDK_SOHO_API::evaluate()) # The 'state:time' parameter evaluates the time from the ROP. now = soho.getDefaultedFloat('state:time', [0.0])[0] # Evaluate the 'camera' parameter as a string. # If the 'camera' parameter doesn't exist, use ['/obj/cam1']. # SOHO always returns lists of values. camera = soho.getDefaultedString('camera', ['/obj/cam1'])[0] # MPlay / Render View port. port = soho.getDefaultedInt("vm_image_mplay_socketport", [0])[0] # ROP node. ropPath = soho.getOutputDriver().getName() ropNode = hou.node(ropPath) printDebug("Initialize SOHO...") # Initialize SOHO with the camera. # XXX: This doesn't work for me, but it should according to the documentation... # soho.initialize(now, camera) if not sohoglue.initialize(now, camera, None): soho.error("Unable to initialize rendering module with given camera") # Now, add objects to our scene soho.addObjects(now, "*", "*", "*", True) # Before we can evaluate the scene from SOHO, we need to lock the object lists. soho.lockObjects(now) for sohoCam in soho.objectList('objlist:camera'): break else: soho.error("Unable to find viewing camera for render") sohoOverride = soho.getDefaultedString('soho_overridefile', ['Unknown'])[0] printDebug("Processing Mode: \"%s\"" % mode) if mode in {"generate"}: # generate: Generation phase of IPR rendering # In generate mode, SOHO will keep the pipe (soho_pipecmd) # command open between invocations of the soho_program. # objlist:all # objlist:camera # objlist:light # objlist:instance # objlist:fog # objlist:space # objlist:mat # printDebug("IPR Port: %s" % port) printDebug("Driver: %s" % ropPath) printDebug("Camera: %s" % camera) printDebug("Now: %.3f" % now) _vfh_ipr.init(rop=ropPath, port=port, now=now, viewParams=getViewParams(camera, sohoCam, now)) elif mode in {"update"}: # update: Send updated changes from previous generation # # In this rendering mode, the special object list parameters: # objlist:dirtyinstance # objlist:dirtylight # objlist:dirtyspace # objlist:dirtyfog # will contain the list of all objects modified since the last render # (whether a generate or update). # # As well, the parameters: # objlist:deletedinstance # objlist:deletedlight # objlist:deletedspace # objlist:deletedfog # will list all objects which have been deleted from the scene. # if not _vfh_ipr.isRopValid(): _vfh_ipr.init(rop=ropPath, port=port, now=now, viewParams=getViewParams(camera, sohoCam, now)) else: if _vfh_ipr.setTime(now): # Have to handle "time" event manually here. exportObjects("objlist:dirtyinstance") exportObjects("objlist:dirtylight") # Update view. exportView(ropPath, camera, sohoCam, now)
_vfh_ipr.deleteOpNode(opNode=obj.getName()) mode = soho.getDefaultedString('state:previewmode', ['default'])[0] # Evaluate an intrinsic parameter (see HDK_SOHO_API::evaluate()) # The 'state:time' parameter evaluates the time from the ROP. now = soho.getDefaultedFloat('state:time', [0.0])[0] # Evaluate the 'camera' parameter as a string. # If the 'camera' parameter doesn't exist, use ['/obj/cam1']. # SOHO always returns lists of values. camera = soho.getDefaultedString('camera', ['/obj/cam1'])[0] # MPlay / Render View port. port = soho.getDefaultedInt("vm_image_mplay_socketport", [0])[0] # ROP node. ropPath = soho.getOutputDriver().getName() ropNode = hou.node(ropPath) # Use callbacks or SOHO render_rt_update_mode = hou.evalParm("render_rt_update_mode") printDebug("Initialize SOHO...") # Initialize SOHO with the camera. # XXX: This doesn't work for me, but it should according to the documentation... # soho.initialize(now, camera) if not sohoglue.initialize(now, camera, None): soho.error("Unable to initialize rendering module with given camera")
reload(APSframe) reload(APSmisc) reload(haps) reload(APSobj) reload(APSsettings) motion_blur_params = APSmisc.initializeMotionBlur(cam, now) FPS = soho.getDefaultedFloat('state:fps', [24])[0] FPSinv = 1.0 / FPS aps = APSobj.Appleseed() scene = aps.scene Sampling = { 'passes': soho.getDefaultedInt('aps_passes', [''])[0], 'pixel_renderer': 'uniform' if not soho.getDefaultedInt('aps_adaptivesampling', [''])[0] else '', 'adaptive_tile_renderer/min_samples': soho.getDefaultedInt('aps_minsamples', ['16'])[0], 'adaptive_tile_renderer/max_samples': soho.getDefaultedInt( 'aps_maxsamples', ['265'], )[0], 'adaptive_tile_renderer/batch_size': soho.getDefaultedInt('aps_batchsize', ['16'])[0], 'adaptive_tile_renderer/noise_threshold': soho.getDefaultedFloat('aps_variance', ['0.1'])[0], 'uniform_pixel_renderer/samples':
LSDmisc.header(now, propdefs) if mode == 'generate': # Notify mantra that it's rendering for IPR print 'cmd_iprmode generate' for i in range(0, numpathmap): map = soho.getDefaultedString('lv_pathmap%d' % (i + 1), []) if map and len(map) == 2: cmd_pathmap(map[0], map[1]) if not LSDhooks.call('pre_otl', parmlist, objparms, now, camera): # # Output OTLs loaded by Houdini otls = soho.getDefaultedString('state:otllist', []) if soho.getDefaultedInt('lv_otlfullpath', [0])[0]: for i in range(len(otls)): otls[i] = hou.expandString(otls[i]) if len(otls): cmd_comment("OTLs loaded into the .hip file") cmd_loadotl(otls) # # Output OTL preferences set in Houdini otprefs = soho.getDefaultedString('state:otprefer', []) if soho.getDefaultedInt('lv_otlfullpath', [0])[0]: for i in range(1, len(otprefs), 2): otprefs[i] = hou.expandString(otprefs[i]) if len(otprefs): cmd_comment("OTL preferences from the .hip file") cmd_otprefer(otprefs)