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

Source Code for Module nukescripts.ViewerProcess

 1  import nuke 
 2  import ocionuke 
 3  import os 
 4   
 5   
6 -def _setOCIOConfig(configPath):
7 ''' 8 Set the OCIO Config to use the specified config path, unless 9 the OCIO environment variable is defined, in which case that will 10 override configPath. Otherwise if configPath is None then the nuke 11 default config is used. If configPath doesn't exist an IOError is raised. 12 ''' 13 rootNode = nuke.root() 14 ocioConfigKnob = rootNode.knob("OCIO_config") 15 16 # When the OCIO env var is set the OCIO knobs are disabled 17 canChangeConfig = ocioConfigKnob.enabled() 18 if canChangeConfig: 19 # The root node handles checking whether the OCIO envvar needs to be used 20 # or not. This check is performed whenever the OCIO knobs are changed, so 21 # isn't needed here. 22 useDefaultNukeConfig = configPath == "" 23 if useDefaultNukeConfig: 24 ocioConfigKnob.setValue("nuke-default") 25 else: 26 if os.path.exists(configPath): 27 ocioConfigKnob.setValue("custom") 28 customOCIOConfigPathKnob = rootNode.knob("customOCIOConfigPath") 29 customOCIOConfigPathKnob.setText(configPath) 30 else: 31 raise IOError("Config '%s' doesn't exist" % configPath)
32 33 34 # Maintaining this function for backwards compatability
35 -def getDefaultOCIOConfig(ocioConfigName = ""):
36 _setOCIOConfig(ocioConfigName)
37 38
39 -def register_default_viewer_processes():
40 41 # The ViewerProcess_None gizmo is a pass-through -- it has no effect on the image. 42 nuke.ViewerProcess.register("None", nuke.createNode, ("ViewerProcess_None", )) 43 # The ViewerProcess_1DLUT gizmo just contains a ViewerLUT node, which 44 # can apply a 1D LUT defined in the project LUTs. ViewerLUT features both 45 # software (CPU) and GPU implementations. 46 47 nuke.ViewerProcess.register("sRGB", nuke.createNode, ( "ViewerProcess_1DLUT", "current sRGB" )) 48 nuke.ViewerProcess.register("rec709", nuke.createNode, ( "ViewerProcess_1DLUT", "current rec709" )) 49 nuke.ViewerProcess.register("rec1886", nuke.createNode, ( "ViewerProcess_1DLUT", "current Gamma2.4" ))
50 51
52 -def unregister_viewers(ocioConfigPath):
53 ocioConfig = ocionuke.config.loadConfig(ocioConfigPath) 54 55 # unregister all OCIO LUTS 56 # For every display, loop over every view 57 DISPLAY_UI_FORMAT = "%(view)s (%(display)s)" 58 for display in ocioConfig.getDisplays(): 59 for view in ocioConfig.getViews(display): 60 # Unregister the node 61 name = DISPLAY_UI_FORMAT % {'view': view, "display": display} 62 nuke.ViewerProcess.unregister(name)
63 64
65 -def _register_viewer_processes(defaultLUTS, ocioConfigName):
66 if defaultLUTS is True: 67 # register the default viewer processes 68 register_default_viewer_processes() 69 else: 70 # register OCIO viewer processes 71 ocionuke.viewer.register_viewers(ocioConfigName)
72 73
74 -def register_viewers(defaultLUTS = True, ocioConfigName = ""):
75 76 ocioConfigName = os.path.normpath(ocioConfigName).replace("\\", "/") 77 78 # make sure we register the config before we begin 79 _setOCIOConfig(ocioConfigName)
80