def outputMPlayFormatOptions(wrangler, cam, now): plist = cam.wrangle(wrangler, _iplay_specific, now) rendermode = plist['rendermode'].Value[0] framemode = plist['framemode'].Value[0] trange = plist['trange'].Value[0] curframe = hou.timeToFrame(now) if trange: frange = cam.wrangleInt(wrangler, 'f', now, [curframe, curframe]) if len(frange) < 2: frange = [curframe, curframe] else: frange = [curframe, curframe] # There are 4 combinations of rendermode and framemode # rendermode/framemode | append | match # ---------------------+------------+----------- # new | new-append | new-frame # current | append | replace # However, we only perform "new" render mode if we the render # frame is at the beginning of the frame range if abs(curframe - frange[0]) < 0.01: rendermode = 'current' if rendermode == 'new': if framemode == 'append': rendermode = 'new-append' else: rendermode = 'new-frame' else: if framemode == 'append': rendermode = 'append' else: rendermode = 'replace' cmd_declare('plane', 'string', 'IPlay.rendermode', [rendermode]) frange = '%d %d' % (int(frange[0]), int(frange[1])) cmd_declare('plane', 'string', 'IPlay.framerange', [frange]) cmd_declare('plane', 'float', 'IPlay.currentframe', [curframe]) rendersource = soho.getDefaultedString('lv_rendersource', [soho.getOutputDriver().getName()]) cmd_declare('plane', 'string', 'IPlay.rendersource', rendersource)
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)
def isPreviewMode(): mode = soho.getDefaultedString('state:previewmode', ['default'])[0] return mode != 'default'
'adaptive_tile_renderer/noise_threshold': soho.getDefaultedFloat('aps_variance', ['0.1'])[0], 'uniform_pixel_renderer/samples': soho.getDefaultedInt('aps_minsamples', ['16'])[0], 'uniform_pixel_renderer/force_antialiasing': soho.getDefaultedInt('aps_uniformforceantialiasing', ['true'])[0], 'uniform_pixel_renderer/decorrelate_pixels': soho.getDefaultedInt('aps_uniformdecorrelatepixels', ['true'])[0], # TODO: # 'samplelock' : soho.getDefaultedInt( 'aps_samplelock', ['0'] )[0], # 'randomseed' : soho.getDefaultedInt( 'aps_randomseed', ['0'] )[0], } Rendering = { 'lighting_engine': soho.getDefaultedString('aps_lightingengine', [''])[0], 'spectrum_mode': 'rgb' if not soho.getDefaultedInt('aps_spectrummode', [''])[0] else 'spectral', 'rendering_threads': soho.getDefaultedInt('aps_threads', ['0'])[0], } PathTracing = { 'pt/enable_ibl': 'true' if soho.getDefaultedInt('aps_imagebasedlighting', [True])[0] else 'false', 'pt/enable_dl': 'true' if soho.getDefaultedInt('aps_directlighing', [True])[0] else 'false', 'pt/enable_caustics':
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()) 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()
soho.objectList('objlist:dirtyfog')) LSDhooks.call('post_iprUpdate', parmlist, objparms, now, camera) else: LSDgeo.reset() # Output LSD header 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) #
# # This document is under CC-3.0 Attribution-Share Alike 3.0 # http://creativecommons.org/licenses/by-sa/3.0/ # Attribution: There is no requirement to attribute the author. # Create a simple SOHO scene and traverse the objects import soho, sys # 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] # However, for our purposes, we don't actually need a camera, so... camera = None # Evaluate an intrinsic parameter (see HDK_SOHO_API::evaluate()) # The 'state:time' parameter evaluates the time from the ROP. evaltime = soho.getDefaultedFloat('state:time', [0.0])[0] # Initialize SOHO with the camera. if not soho.initialize(evaltime, camera): soho.error('Unable to initialize rendering module with camera: %s' % repr(camera)) # Now, add objects to our scene # addObjects(time, geometry, light, fog, use_display_flags) soho.addObjects(evaltime, "*", "*", "*", True) # Before we can evaluate the scene from SOHO, we need to lock the object lists. soho.lockObjects(evaltime)