Package nukescripts :: Module fnFlipbookRenderer
[hide private]
[frames] | no frames]

Source Code for Module nukescripts.fnFlipbookRenderer

  1  import nuke 
  2  import string 
  3  from os import unlink as unlink 
  4  from foundry.frameserver.nuke.bases import RenderQueueObserverMixin 
  5  from foundry.ui import executeInMainThread 
  6   
  7  incompleteRenderStr = """Render did not complete, do you want to show the completed range? 
  8  Frame range contains %s frames but only %s finished.""" 
  9   
 10   
11 -class SimpleFlipbook():
12 #todo: extract the flipbookdialog options and the flipbooktorun options into 13 #another class so that we dont need it's details
14 - def __init__(self, flipbookDialog, flipbookToRun):
15 self._flipbookDialog = flipbookDialog 16 self._flipbookToRun = flipbookToRun
17
18 - def getFlipbookOptions(self):
19 #common method 20 frameRange = nuke.FrameRanges(self._flipbookDialog._frameRange.value().split(',')) 21 views = self._flipbookDialog._selectedViews() 22 return (frameRange, views)
23 24
25 - def getOptions(self):
26 #common method 27 options = self._flipbookDialog._getOptions( self._nodeToFlipbook ) 28 extraOptions = self._flipbookToRun.getExtraOptions( self._flipbookDialog, self._nodeToFlipbook ) 29 options.update( extraOptions ) 30 return options
31 32
33 - def doFlipbook(self):
34 self.initializeFlipbookNode() 35 self.runFlipbook()
36 37
38 - def initializeFlipbookNode(self):
39 self._nodeToFlipbook = self._flipbookDialog._node
40 41
42 - def runFlipbook(self):
43 #this method is used for firing up the flipbook viewer given a node 44 if self._nodeToFlipbook: 45 frameRange, views = self.getFlipbookOptions() 46 self._flipbookToRun.runFromNode(self._nodeToFlipbook, 47 frameRange, 48 views, 49 self.getOptions() )
50 51
52 -class SynchronousRenderedFlipbook(SimpleFlipbook):
53
54 - def __init__(self, flipbookDialog, flipbookToRun):
55 SimpleFlipbook.__init__(self, flipbookDialog, flipbookToRun)
56
57 - def doFlipbook(self):
60 61
62 - def initializeFlipbookNode(self):
63 self._nodeToFlipbook, self._writeNode = self._flipbookDialog._createIntermediateNode()
64 65
66 - def renderFlipbookNode(self):
67 try: 68 frameRange, views = self.getFlipbookOptions() 69 nuke.executeMultiple((self._writeNode,), 70 frameRange, 71 views, 72 self._flipbookDialog._continueOnError.value()) 73 except RuntimeError, msg: 74 import traceback 75 print traceback.format_exc() 76 if msg.args[0][0:9] == "Cancelled": 77 splitMsg = string.split(msg.args[0]) 78 msg = incompleteRenderStr% (splitMsg[3], splitMsg[1]) 79 if nuke.ask(msg) == False: 80 nuke.delete(self._nodeToFlipbook) 81 self._nodeToFlipbook = None 82 else: 83 nuke.delete(self._nodeToFlipbook) 84 self._nodeToFlipbook = None 85 nuke.message("Flipbook render failed:\n%s" % (msg.args[0],)) 86 self.runFlipbook()
87 88 89
90 -class BackgroundRenderedFlipbook(SynchronousRenderedFlipbook):
91
92 - def __init__(self, flipbookDialog, flipbookToRun):
93 SynchronousRenderedFlipbook.__init__(self, flipbookDialog, flipbookToRun)
94
95 - def renderFlipbookNode(self):
96 # Override of renderFlipbookNode from SynchronousRenderedFlipbook 97 # this will trigger the render on a bg process that will launch the flipbook 98 # on finished. 99 try: 100 frameRange, views = self.getFlipbookOptions() 101 self._flipbookDialog._showDeprecatedWarningMessage() 102 nuke.executeBackgroundNuke(nuke.EXE_PATH, 103 [self._writeNode], 104 frameRange, 105 views, 106 self._flipbookDialog._getBackgroundLimits(), 107 self._flipbookDialog._continueOnError.value(), 108 self._flipbookDialog._flipbookEnum.value(), 109 self.getOptions() ) 110 except RuntimeError, msg: 111 import traceback 112 print traceback.format_exc() 113 nuke.delete(self._nodeToFlipbook) 114 self._nodeToFlipbook = None 115 nuke.message("Flipbook render failed:\n%s" % (msg.args[0],))
116
117 -class FrameserverRenderedFlipbook(SynchronousRenderedFlipbook):
118 - def __init__(self, flipbookDialog, flipbookToRun):
119 SynchronousRenderedFlipbook.__init__(self, flipbookDialog, flipbookToRun)
120 121
122 - def renderFlipbookNode(self, ):
123 name, wasSaved = self._flipbookDialog.saveFileToRender("tmp_flipbook",True) 124 try: 125 nodeName = self._writeNode.fullName() 126 frameRange, views = self.getFlipbookOptions() 127 flipbookRenderPath= nuke.filename(self._nodeToFlipbook) 128 options = self.getOptions() 129 import hiero.ui.nuke_bridge.FnNsFrameServer as FrameServer 130 task = FlipbookFrameServerTask(name, 131 frameRange, 132 nodeName, 133 flipbookRenderPath, 134 options, 135 views, 136 self._flipbookToRun ) 137 FrameServer.renderFrames( 138 name, 139 frameRange, 140 nodeName, 141 views) 142 finally: 143 if wasSaved: 144 unlink(name)
145
146 -class FlipbookFrameServerTask(RenderQueueObserverMixin):
147
148 - def __init__(self, scriptPath, frameRange, nodeName, flipbookpath, options, views,flipbookToRun):
149 #flipbook options 150 self._flipbookToRun = flipbookToRun 151 self._flipbookpath = flipbookpath 152 self._frameRange = frameRange 153 self._options = options 154 self._views = views 155 #needed to control the observer process 156 self._scriptPath = scriptPath 157 self._nodeName = nodeName 158 self._totalFrames = frameRange.maxFrame() - frameRange.minFrame() + 1 159 self._successfulFrames = 0 160 self._completedFrames = 0 161 import hiero.ui.nuke_bridge.FnNsFrameServer as FrameServer 162 FrameServer.addBackgroundRenderObserver(self)
163
164 - def showFlipbookWindow(self):
165 try: 166 if self._totalFrames != self._successfulFrames: 167 msg = incompleteRenderStr% (self._totalFrames, self._successfulFrames) 168 if nuke.ask(msg) == False: 169 return 170 self._flipbookToRun.runFromPath(self._flipbookpath, 171 self._frameRange, 172 self._views, 173 self._options) 174 except Exception, e: 175 nuke.tprint(e) 176 finally: 177 import hiero.ui.nuke_bridge.FnNsFrameServer as FrameServer 178 FrameServer.removeBackgroundRenderObserver(self)
179
180 - def renderFinished(self):
182
183 - def onFrameRendered(self, scriptPath, frame, nodeName):
184 """ Callback when a frame is rendered. If it's for the script being 185 rendered, increment the count. """ 186 if scriptPath == self._scriptPath and nodeName == self._nodeName: 187 self._completedFrames = self._completedFrames + 1 188 self._successfulFrames = self._successfulFrames + 1 189 if self._completedFrames == self._totalFrames: 190 self.renderFinished()
191 192
193 - def onFrameRenderError(self, scriptPath, frame, nodeName, errorMsg):
194 """ Callback when there is an error rendering a frame. Set the error state 195 and cancel. """ 196 if scriptPath == self._scriptPath and nodeName == self._nodeName: 197 self._completedFrames = self._completedFrames + 1 198 if self._completedFrames == self._totalFrames: 199 self.renderFinished()
200
201 - def onFrameRenderCancelled(self, scriptPath, frame, nodeName):
202 if scriptPath == self._scriptPath and nodeName == self._nodeName: 203 self._completedFrames = self._completedFrames + 1 204 if self._completedFrames == self._totalFrames: 205 self.renderFinished()
206 207
208 -def getFlipbookRenderer(flipbookDialog, flipbookToRun):
209 if not flipbookDialog._requireIntermediateNode(flipbookDialog._node): 210 return SimpleFlipbook( flipbookDialog, flipbookToRun ) 211 else: 212 #require intermediateNode 213 if flipbookDialog.isBackgrounded(): 214 return BackgroundRenderedFlipbook( flipbookDialog, flipbookToRun ) 215 elif flipbookDialog._frameserverRender.value(): 216 return FrameserverRenderedFlipbook( flipbookDialog, flipbookToRun ) 217 else: 218 return SynchronousRenderedFlipbook( flipbookDialog, flipbookToRun ) 219 raise RuntimeError("No suitable Flipbook Rendered could be found")
220