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

Source Code for Module nukescripts.flipbooking

  1  # Copyright (c) 2010 The Foundry Visionmongers Ltd.  All Rights Reserved. 
  2  ############################################################################### 
  3   
  4  import nuke 
  5   
  6   
7 -class FlipbookApplication(object):
8 """An interface, for so far as Python supports it. To add support for a 9 flipbook this needs to be subclassed and the 3 methods implemented. The 10 default implementation just raises an exception so any sub implementer 11 will soon find out whether his implementation works."""
12 - def __init__(self):
13 return
14
15 - def name(self):
16 """ Return the name of the flipbook. 17 @return: String""" 18 raise NotImplementedError
19
20 - def path(self):
21 """Return the executable path required to run a flipbook. 22 @return: String""" 23 raise NotImplementedError
24
25 - def cacheDir(self):
26 """Return the preferred directory for rendering. 27 @return: String""" 28 raise NotImplementedError
29
30 - def runFromNode(self, nodeToFlipbook, frameRanges, views, options):
31 """Execute the flipbook on a node. 32 This method will use the node's filename to call run() 33 @param node: The node to run the flipbook 34 @param frameRanges: A FrameRanges object representing the range that should be flipbooked. Note that in 6.2v1-2 this was a FrameRange object. 35 @param views: A list of strings comprising of the views to flipbook. Willnot be more than the maximum supported by the flipbook. 36 @param options: A dictionary of options to use. This may contain the keys pixelAspect, roi, dimensions, audio and lut. These contain a float, a dict with bounding box dimensions, a dict with width and height, a path to audio file and a string indicating the LUT conversion to apply. 37 @return: None""" 38 39 filename = nuke.filename(nodeToFlipbook) 40 if filename is None or filename == "": 41 raise RuntimeError("Cannot run a flipbook on '%s', expected to find a filename and there was none." % (nodeToFlipbook.fullName(),)) 42 self.run( filename, frameRanges, views, options)
43 44
45 - def run(self, path, frameRanges, views, options):
46 """Execute the flipbook on a path. 47 @param path: The path to run the flipbook on. This will be similar to /path/to/foo%03d.exr 48 @param frameRanges: A FrameRanges object representing the range that should be flipbooked. Note that in 6.2v1-2 this was a FrameRange object. 49 @param views: A list of strings comprising of the views to flipbook. Willnot be more than the maximum supported by the flipbook. 50 @param options: A dictionary of options to use. This may contain the keys pixelAspect, roi, dimensions, audio and lut. These contain a float, a dict with bounding box dimensions, a dict with width and height, a path to audio file and a string indicating the LUT conversion to apply. 51 @return: None""" 52 raise NotImplementedError
53
54 - def capabilities(self):
55 """Return the capabilities of the flipbook application in a dict. Currently used are: 56 canPreLaunch: bool, whether the flipbook can display a frames that are still being rendered by Nuke. 57 maximumViews: int, the number of views supported by this flipbook, should be 1 or higher. 58 fileTypes: list, the extensions of the file types supported by this format. Must all be lowercase, e.g ["exr", "jpg", ...]. 59 A wildcard ["*"] can also be used to indicate support for any file type Nuke supports 60 "roi: bool, whether the flipbook supports region-of-interest 61 @return: dict with the capabilities above.""" 62 raise NotImplementedError
63
64 - def dialogKnobs(self, dialog):
65 """This is called when the user has selected this flipbook application, and will be interested in any knobs that you might have to show for custom settings. 66 @param dialog: The FlipbookDialog that has requested the knobs to be added to it, e.g. dialog.addKnob(...) 67 @return: None""" 68 raise NotImplementedError
69
70 - def dialogKnobChanged(self, dialog, knob):
71 """Called whenever this flipbook is selected and one of the knobs added in dialogKnobs was changed. 72 @param dialog: The FlipbookDialog that contains the knob 73 @param knob: The knob added in dialogKnobs that was modified. 74 @return: None""" 75 raise NotImplementedError
76
77 - def getExtraOptions(self, flipbookDialog, nodeToFlipbook):
78 """Called whenever this flipbook is selected to retrieve extra options from the node selected to flipbook 79 and the flipbook dialog. 80 @param flipbookDialog: the flipbook dialog 81 @param nodeToFlipbook: node selected to flipbook 82 @return: a dictionary with the extra options """ 83 return dict()
84
85 -class FlipbookFactory(object):
86 - def __init__(self):
87 self._flipbookApplications = {}
88
89 - def isRegistered(self, flipbook):
90 """ Return whether a flipbook app with that name has already been registered. 91 @param flipbook: FlipBookApplication object that's tested for. 92 @return: bool""" 93 return self._flipbookApplications.has_key(flipbook.name())
94
95 - def register(self, flipbookApplication):
96 """Register a flipbook app. It will fail if the flipbook app name isn't unique. 97 @param flipbook: FlipBookApplication object to register 98 @return: None""" 99 if not self.isRegistered(flipbookApplication): 100 nuke.registerFlipbook(flipbookApplication.name()) 101 self._flipbookApplications[flipbookApplication.name()] = flipbookApplication 102 else: 103 raise RuntimeError("Already registered a flipbook application with this name")
104
105 - def getNames(self):
106 """Returns a list of the names of all available flipbook apps. 107 @return: list""" 108 return sorted(self._flipbookApplications.keys())
109
110 - def getApplication(self, name):
111 """Returns the flipbook app implementation with the given name, raises an exception if none could be found. 112 @param name: The name of a flipbook that was registered. 113 @return: FlipBookApplication""" 114 if self._flipbookApplications.has_key(name): 115 return self._flipbookApplications[name] 116 else: 117 raise RuntimeError("Requested flipbook not registered")
118
119 -class FlipbookLUTPathRegistry(object):
120 """A registery of all LUT files against LUTs for each specific flipbook."""
121 - def __init__(self):
122 self._luts = {}
123
124 - def registerLUTPathForFlipbook(self, flipbook, lut, path):
125 """Register the given LUT file. 126 @param flipbook: The unique name of the flipbook 127 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709' 128 @param path: Location of the flipbook specific file.""" 129 if not self._luts.has_key(flipbook): 130 self._luts[flipbook] = {} 131 self._luts[flipbook][lut] = path
132
133 - def getLUTPathForFlipbook(self, flipbook, lut):
134 """Return the path for the given flipbook and lut. May return an empty string if none registered. 135 @param flipbook: The unique name of the flipbook 136 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709'""" 137 return self._luts.get(flipbook, {}).get(lut, "")
138 139 # Global registry of flipbooks. 140 gFlipbookFactory = FlipbookFactory() 141 # Global registry of user specified LUTs 142 gFlipbookLUTPathRegistry = FlipbookLUTPathRegistry() 143 144 # Convenience functions that make access to the globals a few key strokes less.
145 -def register(flipbookApplication):
146 """Register a flipbook. Convenience function that simple calls register() on the FlipbookFactory.""" 147 gFlipbookFactory.register(flipbookApplication)
148
149 -def registerLUTPath(flipbookApplication, lut, path):
150 """Register a LUT for a specific flipbook. The path should refer to a file that contains the LUT for the given flipbook identified by the name in flipbookApplication. It is up to the flipbook subimplementation to actually use this file and the format may vary. 151 @param flipbook: The unique name of the flipbook 152 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709' 153 @param path: Location of the flipbook specific file.""" 154 gFlipbookLUTPathRegistry.registerLUTPathForFlipbook(flipbookApplication, lut, path)
155
156 -def getLUTPath(flipbookAppliction, lut):
157 """Returns a path to a LUT file for the given flipbook. The contents of the file will be different for each flipbook application. Please see the relevant documentation for the specific flipbook applications. 158 @param flipbook: The unique name of the flipbook 159 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709'""" 160 return gFlipbookLUTPathRegistry.getLUTPathForFlipbook(flipbookAppliction, lut)
161