Esempio n. 1
0
def coreCycle(knob, node, mode):
	'''main cycling operation
	@knob='ch': channels for nodes with channels knob
	@knob='op': operation for merge node
	@mode='regular': often used channels/operations in merge node
	@mode='all': all channels/operations in last selected node
	@node: input node, obj
	'''
	if knob=='ch':
		ls_ch = []
		if mode == 'regular':
			ls_ch = ['rgb', 'rgba', 'alpha','all']
		elif mode == 'all':
			# unconnected nodes will return empty list
			ls_ch = nuke.layers(node) if nuke.layers(node) else ['rgb', 'rgba', 'alpha','all']

		if node.Class() == 'Shuffle':
			try:
				ls_ch.remove('all')
			except: pass
			setKnob(node,'in',ls_ch)
		else:
			setKnob(node,'channels', ls_ch)
	elif knob=='op':
		ls_op = []
		if mode == 'regular':
			ls_op = ['plus', 'minus', 'mask', 'stencil', 'over', 'under', 'max', 'min', 'hypot']
		elif mode == 'all':
			ls_op = node['operation'].values()
		setKnob(node, 'operation', ls_op)
Esempio n. 2
0
 def test_add_layer(self):
     from edit import add_layer
     self.assertNotIn('test', nuke.layers())
     add_layer('test')
     self.assertIn('test', nuke.layers())
     for i in ('test.red', 'test.green', 'test.blue', 'test.alpha'):
         self.assertIn(i, nuke.channels())
Esempio n. 3
0
    def test_copy_layer(self):
        from edit import copy_layer
        rgba = nuke.nodes.Constant()
        depth = nuke.nodes.Constant(channels='depth')

        # Base case.
        result = copy_layer(depth, rgba)
        self.assertIsInstance(result, nuke.Node)
        self.assertEqual(result.Class(), 'Merge2')
        self.assertEqual(nuke.layers(result),
                         [b'rgb', b'rgba', b'alpha', b'depth'])

        # Self copy (shuffle).
        result = copy_layer(depth, depth, 'depth', 'rgba')
        self.assertIsInstance(result, nuke.Node)
        self.assertEqual(result.Class(), 'Shuffle')
        self.assertEqual(nuke.layers(result),
                         [b'rgb', b'rgba', b'alpha', b'depth'])

        # Skip no effect.
        result = copy_layer(rgba, rgba)
        self.assertIs(result, rgba)

        # Take rgba if no such layer in input1.
        result = copy_layer(rgba, rgba, 'depth')
        self.assertEqual(nuke.layers(result),
                         [b'rgb', b'rgba', b'alpha', b'depth'])

        # Raise ValueError if no such layer and no rgba in input1.
        self.assertRaises(ValueError, copy_layer, rgba, depth, 'rgba')
Esempio n. 4
0
	def setLayers(self,node_expr,node_sel):
		'''get layers from root
		return: ls_layers (list of str)
		'''
		self.mu_layers.clear()
		self.ls_layers = nuke.layers() if node_sel == None else nuke.layers(node_sel)
		self.mu_layers.addItems(self.ls_layers)

		return self.ls_layers # ['rgba', 'Id06']
Esempio n. 5
0
	def set_layer_box(self,node_expr,node_sel):
		'''get layers from root or selected node
		return: ls_layers (list of str)
		'''
		if node_sel:
			self.ls_layers = nuke.layers(node_sel)
		elif node_expr.dependencies() != []:
			self.ls_layers = nuke.layers(node_expr)
		else:
			self.ls_layers = nuke.layers()

		self.layer_box.clear()
		self.layer_box.addItems(self.ls_layers)

		return self.ls_layers # ['rgba', 'Id06']
Esempio n. 6
0
    def confirm(self):
        if self.checkFakeEnter() == False:
            self.answerList = [self.in1.lineEdit.text(), self.out1.lineEdit.text(), self.in2.lineEdit.text(), self.out2.lineEdit.text()]
            self.createList = []
            for x in self.answerList:
                if not x in nuke.layers() and not x in self.extras:
                    self.createList.append(x)
            if not self.createList == []:
                self.hide()
                if nuke.ask('''<font left>The following layers don't exist. Do you want to create them?

<i>%s</i>''' %'''
'''.join(self.createList)):
                    for l in self.createList:
                        nuke.Layer(l, ['%s.red' %l, '%s.green' %l, '%s.blue' %l, '%s.alpha' %l])
                self.show()
            if self.node == None or not self.modifyNodeCheckBox.isChecked():
                with self.context:
                    if self.typeCheckbox.isChecked():
                        node = nuke.createNode('ShuffleCopy')
                    else:
                        node = nuke.createNode('Shuffle')
            else:
                node = self.node
            node['in'].setValue(self.answerList[0])
            node['out'].setValue(self.answerList[1])
            node['in2'].setValue(self.answerList[2])
            node['out2'].setValue(self.answerList[3])
            self.close()
Esempio n. 7
0
def cycleChannels(mode='rgba'):
	'''cycle through channels nodes
	@mode='rgba': 'rgb', 'rgba', 'alpha'
	@mode='all': all channels in last selected node
	'''

	if not nuke.selectedNodes():
		nuke.message('Select some nodes, Sil vous plait')
	else:
		ls_ch = []

		if mode == 'rgba':
			ls_ch = ['rgb', 'rgba', 'alpha','all']
		elif mode == 'all':
			ls_ch = nuke.layers(nuke.selectedNode())

		print "\n====="

		for n in nuke.selectedNodes():
			try:
				ch = n['channels']
				ch_cur = ch.value()
				ch_new = None
				if ch_cur in ls_ch:
					ch_count = ls_ch.index(ch_cur)
					ch_new_idx = 0 if ch_count==len(ls_ch)-1 else ch_count+1
					ch_new = ls_ch[int(ch_new_idx)]
				else:
					ch_new = ls_ch[0]

				ch.setValue(ch_new)
				print "%s set to %s" % (n.name(), ch_new)
			except:
				print "knob 'channels' not in %s" % n.name()
Esempio n. 8
0
    def _prepare_channels(cls, input_node):
        n = input_node
        if CONFIG['masks']:
            if 'SSS.alpha' in input_node.channels():
                n = nuke.nodes.Keyer(inputs=[n],
                                     input='SSS',
                                     output='SSS.alpha',
                                     operation='luminance key',
                                     range='0 0.01 1 1')
            if 'Emission.alpha' in input_node.channels():
                n = nuke.nodes.Keyer(inputs=[n],
                                     input='Emission',
                                     output='Emission.alpha',
                                     operation='luminance key',
                                     range='0 0.2 1 1')
        if 'MotionVectors' in nuke.layers(input_node):
            n = nuke.nodes.MotionFix(inputs=[n],
                                     channel='MotionVectors',
                                     output='motion')
        if 'depth.Z' not in input_node.channels():
            _constant = nuke.nodes.Constant(
                channels='depth',
                color=1,
                label=b'**用渲染出的depth层替换这个**\n或者手动指定数值')
            n = nuke.nodes.Merge2(inputs=[n, _constant],
                                  also_merge='all',
                                  label='add_depth')
        n = nuke.nodes.Reformat(inputs=[n], resize='fit')

        n = nuke.nodes.DepthFix(inputs=[n])
        return n
Esempio n. 9
0
    def __init__(self, groupNode=None):
        super(ShuffleMgrWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("Manage Shuffle Masks")

        allLayers = nuke.layers()

        self.charComboBox.addItems(allLayers)
        self.cmptComboBox.addItems(allLayers)

        self.addCharBtn.clicked.connect(lambda x: self.addMask(True))
        self.addCmpBtn.clicked.connect(lambda x: self.addMask(False))
        self.delBtn.clicked.connect(self.deleteMask)

        self.__maskList = []
        self.__group = groupNode

        self.__group.begin()
        inputNodes = [x for x in nuke.allNodes() if x.Class() == "Input"]
        self.__input = inputNodes[0]
        # delete the temp shuffle node
        nuke.delete(nuke.toNode("Temp"))
        self.__group.end()

        self.updateUI()
Esempio n. 10
0
def _update_encyptomatte_setup_layers(gizmo):
    setup_layers = gizmo.knob('setupLayers').value()
    num_layers = gizmo.knob('cryptoLayers').value()
    input_layers = gizmo.knob('inputCryptoLayers').value()
    crypto_layer = gizmo.knob('cryptoLayer').value()

    if not setup_layers:
        gizmo.knob('manifestKey').setValue("")
        for ch_add, ch_remove in zip(GIZMO_ADD_CHANNEL_KNOBS, GIZMO_REMOVE_CHANNEL_KNOBS):
            gizmo.knob(ch_add).setValue("none")
            gizmo.knob(ch_remove).setValue("none")
        return

    all_layers = nuke.layers()

    num_ch = len(GIZMO_ADD_CHANNEL_KNOBS)
    for i, ch_add, ch_remove in zip(
            range(num_ch), GIZMO_ADD_CHANNEL_KNOBS, GIZMO_REMOVE_CHANNEL_KNOBS):
        this_layer = "{0}{1:02d}".format(crypto_layer, i)
        # Add
        if i < num_layers:
            if not this_layer in all_layers:
                channels = ["%s.%s" % (this_layer, c) for c in ['red', 'green', 'blue', 'alpha']]
                nuke.Layer(this_layer, channels)

            gizmo.knob(ch_add).setValue(this_layer)
            gizmo.knob(ch_remove).setValue("none")
        else:
            gizmo.knob(ch_add).setValue("none")
            if i <= input_layers:
                gizmo.knob(ch_remove).setValue(this_layer)
            else:
                gizmo.knob(ch_remove).setValue("none")
Esempio n. 11
0
	def set_preset(self):
		'''Called when preset button is pressed'''
		thisBtn=self.sender().text()
		thisPreset=PRESET_BTN[thisBtn]
		thisNode=self.node

		if thisBtn=='Raw Lighting':
			p=nuke.Panel('Select the albeto pass')
			p.addEnumerationPulldown('aov', ' '.join(nuke.layers()))
			if p.show():
				albeto=p.value('aov')
				for k in thisPreset:
					self.set_knobValue(k, '<albeto>', albeto)
		elif thisBtn == 'AOV Mask':
			p=AOVMaskBox()
			_mask = p.run(self.ls_layers)
			if _mask:
				self.node['expr3'].setValue('%s.%s' % (_mask[0], _mask[1]))
				self.node['tile_color'].setValue(COL[_mask[1]])
				self.node['label'].setValue('matte::[value expr3]')
		else:
			for k in thisPreset:
				self.set_knobValue(k)

		# self.node['label'].setValue(thisBtn)
		self.close()
def _update_encyptomatte_setup_layers(gizmo):
    setup_layers = gizmo.knob('setupLayers').value()
    num_layers = gizmo.knob('cryptoLayers').value()
    input_layers = gizmo.knob('inputCryptoLayers').value()
    crypto_layer = gizmo.knob('cryptoLayer').value()

    if not setup_layers:
        gizmo.knob('manifestKey').setValue("")
        for ch_add, ch_remove in zip(GIZMO_ADD_CHANNEL_KNOBS, GIZMO_REMOVE_CHANNEL_KNOBS):
            gizmo.knob(ch_add).setValue("none")
            gizmo.knob(ch_remove).setValue("none")
        return

    all_layers = nuke.layers()

    num_ch = len(GIZMO_ADD_CHANNEL_KNOBS)
    for i, ch_add, ch_remove in zip(
            range(num_ch), GIZMO_ADD_CHANNEL_KNOBS, GIZMO_REMOVE_CHANNEL_KNOBS):
        this_layer = "{0}{1:02d}".format(crypto_layer, i)
        # Add
        if i < num_layers:
            if not this_layer in all_layers:
                channels = ["%s.%s" % (this_layer, c) for c in ['red', 'green', 'blue', 'alpha']]
                nuke.Layer(this_layer, channels)

            gizmo.knob(ch_add).setValue(this_layer)
            gizmo.knob(ch_remove).setValue("none")
        else:
            gizmo.knob(ch_add).setValue("none")
            if i <= input_layers:
                gizmo.knob(ch_remove).setValue(this_layer)
            else:
                gizmo.knob(ch_remove).setValue("none")
Esempio n. 13
0
	def setPreset(self):
		'''Called when preset button is pressed'''
		thisBtn=self.sender().text()
		thisPreset=PRESET_BTN[thisBtn]
		thisNode=self.node

		def setKnobValue(kvPaire, *strSub):
			'''set knob value
			@kvPaire: (<knob>, <value>)
			@*strSub: string to replace if any, (replaceThis, withThis)
			'''
			pKnob, pValue = kvPaire
			if len(strSub)>0 and len(strSub)==2:
				pValue=re.sub(strSub[0], strSub[1], pValue)
			else:
				pValue

			self.node[pKnob].setValue(pValue)

		if thisBtn=='Raw Lighting':
			p=nuke.Panel('Select the albeto pass')
			p.addEnumerationPulldown('aov', ' '.join(nuke.layers()))
			if p.show():
				albeto=p.value('aov')
				for k in thisPreset:
					setKnobValue(k, '<albeto>', albeto)
		else:
			for k in thisPreset:
				setKnobValue(k)

		self.node['label'].setValue(thisBtn)
		self.close()
Esempio n. 14
0
def check_for_layers():
    '''
		Creates layers from the the Light Passes List and other custom layers
	'''
    layers = []
    for i in nuke.layers():
        layers.append(i)
    print(layers)

    layerExists = False

    for lp in lightPasses:
        lpass = "******".format(lp.upper())

        for layer in layers:
            if lpass == layer:
                layerExists = True
                print(str(str(layer) + ' layer already exists.'))

        if layerExists == False:
            create_lp_layer(lp)
            print(str("Creating " + str(lpass) + ' layer.'))

    for layer in layers:
        if layer == 'DIP':
            layerExists == True
            print('DIP layer already exists.')

    if layerExists == False:
        create_rgba_layer('DIP')
        print("Creating DIP layer.")
Esempio n. 15
0
def nk_comp_multipass_exr():
	"""
	Comp multipass EXR
	"""
	mergeLUT = dict(DIFFNS="plus", SPECNS="plus", INDIRR="plus", REFL="plus", SHD="difference")
	bases = ["DIFFNS"]
	read = nuke.selectedNode()
	if read.Class()=="Read":
		remove = nuke.nodes.Remove(channels="alpha")
		remove.setInput(0,read)
		known_passes = [name for name in nuke.layers(read) if name.split("_")[0] in mergeLUT.keys()]
		# Shuffle each pass into RGB:
		shuffles = [nuke.nodes.Shuffle(out='rgb', label="[knob in]") for _pass in known_passes]
		[shuffle['in'].setValue(name) for (shuffle,name) in zip(shuffles,known_passes)]
		[shuffle.setInput(0,remove) for shuffle in shuffles]
		base_nodes, layers = [], []
		[base_nodes.append(shuffle) if name.split("_")[0] in bases else layers.append((name,shuffle))
		 for (shuffle,name) in zip(shuffles,known_passes)]
		last_merge = None
		for base in base_nodes:
			last_merge = base
			for (name, output) in layers:
				operation = mergeLUT[name.split("_")[0]]
				merge = nuke.nodes.Merge(output='rgb', operation=operation)
				merge.setInput(0,output)
				merge.setInput(1,last_merge)
				last_merge = merge
		copy = nuke.nodes.Copy(from0="alpha", to0="alpha")
		copy.setInput(1,read)
		copy.setInput(0,last_merge)
Esempio n. 16
0
    def __init__(self, node):
        super(Calculate_data, self).__init__()
        self.node = node
        self.show()

        self.channel_ = self.channels_name
        self.selectlayer = self.channels_name.split('.')[0]

        if self.selectlayer in nuke.layers(self.node):
            self.layer_bool = True
        else:
            self.layer_bool = False

        self.Min_value = ''
        self.Min_value_frame = ''

        self.Max_value = ''
        self.Max_value_frame = ''

        self.e1 = '%s==0?inf:%s' % (self.channel_, self.channel_)
        self.e2 = '%s>nan||%s<%s?%s:0' % (self.channel_, self.channel_,
                                          self.depth_clamp_value,
                                          self.channel_)

        self.Expression2 = ''
Esempio n. 17
0
def copy_layer(input0, input1=None, layer='rgba', output=None):
    """Copy whole layer from a node to another.

    Args:
        input0 (nuke.Node): Source node
        input1 (nuke.Node, optional): Defaults to None.
            If given, use source layer from this node.
        layer (str, optional): Defaults to 'rgba'.
            Source layer name.
        output (str, optional): Defaults to None.
            Output layer name. If not given, use same with source layer.

    Returns:
        nuke.Node: Final output node.
    """

    output = output or layer
    input1 = input1 or input0

    # Skip case that has no effect.
    if (input0 is input1 and layer == output and layer in nuke.layers(input0)):
        return input0

    # Choice input channel name.
    try:
        input1_layers = nuke.layers(input1)
        input_channel = [
            i for i in (layer, output, 'rgba') if i in input1_layers
        ][0]
    except IndexError:
        raise ValueError('Can not find avaliable layer in input1',
                         input1_layers)

    add_layer(output)
    # Use shuffle if input0 is input1 else use merge.
    if input0 is input1:
        _d = {"in": input_channel}
        ret = nuke.nodes.Shuffle(inputs=[input1], out=output, **_d)
    else:
        ret = nuke.nodes.Merge2(tile_color=0x9e3c63ff,
                                inputs=[input0, input1],
                                operation='copy',
                                Achannels=input_channel,
                                Bchannels='none',
                                output=output,
                                label=layer)
    return ret
Esempio n. 18
0
	def setLayers(self,node_expr,node_sel):
		'''get layers from root
		return: ls_layers (list of str)
		'''
		self.mu_layers.clear()
		self.ls_layers if node_sel == None else self.ls_layers.extend(nuke.layers(node_sel))
		self.mu_layers.addItems(self.ls_layers)

		return self.ls_layers
def Shuffle(n, forwards):

    try:

        # get knob
        k = n.knob('in')

        # get current layer (str)
        currL = k.value()

        # get all existing layers
        listL = nuke.layers()

        # get index of current layer
        i = 0
        for eachL in listL:
            if eachL == currL:
                break
            i += 1

        # get new layer
        if forwards:
            if len(listL) == i + 1:
                newL = listL[0]
            else:
                newL = listL[i + 1]
        else:
            if i == 0:
                newL = listL[len(listL) - 1]
            else:
                newL = listL[i - 1]

        # set new layer
        k.setValue(newL)

        # get label knob
        label = n.knob('label')

        # get new label text
        labelText = '[value in]'

        # get current label text
        currLabel = label.getValue()

        # check if the label is already present
        if not labelText in currLabel:

            # add new line and original value before new label text, if a label already exists
            if currLabel is not '':
                label.setValue(currLabel + '\n' + labelText)
            else:
                label.setValue(labelText)

    except:
        pass
Esempio n. 20
0
def AOVContactSheet():

	node_sel = nuke.selectedNode()

	if node_sel:

		# Collecting Data
		aovs_all = [l for l in nuke.layers(node_sel)]
		mu_sel = ['multi', 'diffMulti', 'specMulti', 'Shading', 'spec', 'diff', 'Data', 'id', 'all']
		ls_shading = ['diffDir', 'diffInd', 'specDir', 'specInd', 'emission', 'emission', 'subsurface']
		ls_data = ['depth', 'norm', 'postion', 'refPosition', 'uv']

		# Select AOVs
		p = nuke.Panel('SelLayerContact')
		p.addEnumerationPulldown('AOV Group', ' '.join(aovs_all))

		if p.show():
			aovs_group = p.value('AOV Group')
		else:
			print "Operation Cancelled"
			break

		# Find Matching AOVs
		aovs_sel = []

		for l in aovs_all:
			if aovs_group in l: # diff, spec, multiLights, id
				aovs_sel.append(l)
			elif aovs_group == 'Shading' and l in ls_shading:
				aovs_sel.append(l)
			elif aovs_group == 'Data' and l in ls_data:
				aovs_sel.append(l)
			elif aovs_group == 'all':
				aovs_sel = aovs_all

		# Filter aovs_sel
		## for Remove node, with operation set to 'remove'
		aovs_remove = ls_remove(aovs_all, aovs_sel)

		# Find how many remove nodes needed
		num_remove = int(math.ceil(len(aovs_remove)/4.0))

		# Removing unwanted layers
		g_aov = nuke.node.Group(name='AOVContactSheet')

		k_tab = nuke.Tab_Knob('tb_user', 'AOVContactSheet')
		k_mu = nuke.Enumeration_Knob('mu_aovs', "AOV Groups", ' '.join(mu_sel))
		k_apply = nuke.PyScript_Knob('bt_apply', "Apply", 'mod_AOVContactSheet.applyAOVGroup(nuke.thisNode().toNode('input'), )')

		k_apply.clearFlag(nuke.STARTLINE)

		g_aov.addKnob(k_tab)
		g_aov.addKnob(k_mu)
		g_aov.addKnob(k_apply)
Esempio n. 21
0
    def reinitialise(self):
        #reset all the panels to default state when reopened
        self.node = None
        self.layerCopyValue = 'none'
        self.copyFrom0Value = 'none'
        self.copyTo0Value = 'none'
        self.copyFrom1Value = 'none'
        self.copyTo1Value = 'none'
        self.copyFrom2Value = 'none'
        self.copyTo2Value = 'none'
        self.copyFrom3Value = 'none'
        self.copyTo3Value = 'none'

        try:
            with self.context:
                if not len(nuke.selectedNodes()) > 1:
                    if nuke.selectedNode().Class() == 'Copy':
                        self.node = nuke.selectedNode()
                        self.layerCopyValue = self.node.knobs(
                        )['channels'].value()
                        self.copyFrom0Value = self.node.knobs()['from0'].value(
                        )
                        self.copyTo0Value = self.node.knobs()['to0'].value()
                        self.copyFrom1Value = self.node.knobs()['from1'].value(
                        )
                        self.copyTo1Value = self.node.knobs()['to1'].value()
                        self.copyFrom2Value = self.node.knobs()['from2'].value(
                        )
                        self.copyTo2Value = self.node.knobs()['to2'].value()
                        self.copyFrom3Value = self.node.knobs()['from3'].value(
                        )
                        self.copyTo3Value = self.node.knobs()['to3'].value()
        except:
            pass
        self.layerCopy.lineEdit.setText(self.layerCopyValue)
        self.layerCopy.lineEdit.updateList(nuke.layers() + ['none', 'all'])
        extras = ['none', 'red', 'green', 'blue', 'alpha']
        self.channelCopy0.update(self.copyFrom0Value, self.copyTo0Value,
                                 nuke.channels() + extras)
        self.channelCopy1.update(self.copyFrom1Value, self.copyTo1Value,
                                 nuke.channels() + extras)
        self.channelCopy2.update(self.copyFrom2Value, self.copyTo2Value,
                                 nuke.channels() + extras)
        self.channelCopy3.update(self.copyFrom3Value, self.copyTo3Value,
                                 nuke.channels() + extras)

        self.layerCopy.lineEdit.setFocus()
        self.layerCopy.lineEdit.selectAll()

        self.modifyNodeCheckBox.setChecked(True)
        self.modifyNodeCheckBox.setVisible(True)
        self.updateSubtitle()
Esempio n. 22
0
def shuffle_in_layer_index(selected):
    """
    Find node's layers and index of 'in 1' layer's index.
    :param selected: Shuffle node
    :type selected: Node
    :return: List of node's layers and current 'in 1' layer's index.
    :rtype: tuple
    """
    layers = nuke.layers(selected)
    layers.insert(0, "none")
    shuffle_in = selected["in"].value()
    in_index = layers.index(shuffle_in)
    return layers, in_index
Esempio n. 23
0
def shuffleLayers():
	""" expand channels
	"""

	selectedNode = nuke.selectedNode()

	re_rgba = re.compile(r"^rgba$")
	re_rgb = re.compile(r"^rgb$")
	re_alpha = re.compile(r"^alpha$")

	layerList = [i for i in nuke.layers(selectedNode) if (not re_rgba.match(i)) and (not re_rgb.match(i)) and (not re_alpha.match(i))]
	if not layerList:
		return
	print layerList

	dot1 = nuke.createNode('Dot', inpanel = False)
	dot1.setInput(0, selectedNode)
	dot1['ypos'].setValue(dot1.ypos() + 100)

	# first shuffle
	firstLayer = layerList[0]
	shuffle = nuke.createNode('Shuffle', inpanel = False)
	shuffle['label'].setValue('<b>[value in]')
	shuffle['in'].setValue(firstLayer)
	shuffle['in2'].setValue('alpha')
	shuffle['alpha'].setValue('rea2')

	shuffle.setInput(0, dot1)
	shuffle['selected'].setValue(False)
	shuffle['ypos'].setValue(shuffle.ypos() + 100)

	if len(layerList) == 1:
		return

	# dot1['selected'].setValue(Ture)
	dotList = []
	shuffleList = []

	m = 0
	n = 0

	for i in layerList[1:]:
		m += 1
		n += 200
	    dotn = nuke.createNode('Dot', inpanel = False)
	    dotList.append(dotn)
	    dotn['xpos'].setValue(dot1.xpos() + n)
	    dotn['ypos'].setValue(dot1.ypos())
	    if m == 1:
	    	dotn.setInput(0, dot1)
Esempio n. 24
0
def main():
    target_node = nuke.selectedNode()
    if target_node.Class() != "Read": pass
    # get target node's position value
    pos_x, pos_y = target_node.xpos(), target_node.ypos()
    # get target node's channels and layers
    channels = target_node.channels()
    nukeLayers = nuke.layers()
    nukeLayers.remove("rgb")
    nukeLayers.remove("rgba")
    nukeLayers.remove("alpha")

    layerNames = []
    for i in channels:
        t = i.split(".")
        t.pop(1)
        layerNames.extend(t)

    passes = []
    for layer in nukeLayers:
        if layer in layerNames:
            passes.append(layer)

    main_dot = nuke.Node("Dot")

    main_dot_y = main_dot.ypos()
    if main_dot_y != pos_y + 150:
        main_dot.setYpos(int(pos_y + 150))

    main_dot.setInput(0, target_node)
    main_dot_y = main_dot["ypos"].getValue()
    main_dot_x = main_dot["xpos"].getValue()
    multi = 0
    for layer in passes:
        pos_offset = 150 * multi

        dot_node = nuke.Node("Dot")
        dot_node['name'].setValue("%s_dot" % layer)
        dot_node.setInput(0, main_dot)
        dot_node.setXYpos(int(main_dot_x + pos_offset), int(main_dot_y))
        dot_node_y = dot_node.ypos()
        multi = multi + 1

        shuffle_node = nuke.Node("Shuffle")
        shuffle_node['name'].setValue(layer)
        shuffle_node.setInput(0, dot_node)
        shuffle_node["in"].setValue(layer)
        shuffle_node.setYpos(dot_node_y + 150)
    nuke.message("Done!")
    return
Esempio n. 25
0
    def reinitialise(self):
        #reset all the panels to default state when reopened
        self.node = None
        self.in1Value = 'rgba'
        self.out1Value = 'rgba'
        self.in2Value = 'none'
        self.out2Value = 'none'
        try:
            with self.context:
                if not len(nuke.selectedNodes()) > 1:
                    if nuke.selectedNode().Class() == 'Shuffle':
                        self.typeCheckbox.setChecked(False)
                        self.node = nuke.selectedNode()
                    if nuke.selectedNode().Class() == 'ShuffleCopy':
                        self.typeCheckbox.setChecked(True)
                        self.node = nuke.selectedNode()
                    self.in1Value = self.node.knobs()['in'].value()
                    self.out1Value = self.node.knobs()['out'].value()
                    self.in2Value = self.node.knobs()['in2'].value()
                    self.out2Value = self.node.knobs()['out2'].value()
        except:
            pass
        self.in1.lineEdit.setText(self.in1Value)
        self.in1.lineEdit.updateList(nuke.layers() + self.extras)
        self.out1.lineEdit.setText(self.out1Value)
        self.out1.lineEdit.updateList(nuke.layers() + self.extras)
        self.in2.lineEdit.setText(self.in2Value)
        self.in2.lineEdit.updateList(nuke.layers() + self.extras)
        self.out2.lineEdit.setText(self.out2Value)
        self.out2.lineEdit.updateList(nuke.layers() + self.extras)

        self.in1.lineEdit.setFocus()
        self.in1.lineEdit.selectAll()

        self.modifyNodeCheckBox.setChecked(True)
        self.modifyNodeCheckBox.setVisible(True)
        self.updateSubtitle()
Esempio n. 26
0
def add_layer(layername):
    """Add layer to nuke from @layername.

    Returns:
        nuke.Layer or None: Added layer.
    """

    if layername in nuke.layers():
        return

    channels = [
        '{}.{}'.format(layername, channel)
        for channel in ('red', 'green', 'blue', 'alpha')
    ]
    return nuke.Layer(layername, channels)
Esempio n. 27
0
def Shuffle_Short(shuffle_num=None):
    node = nuke.selectedNode()
    if not node or node.Class() != 'Shuffle':
        nuke.message('The node type is not "Shuffle".')
        return False
    if node.Class() == "Shuffle":
        channel_list = [i for i in nuke.layers(node)]
        channel_name = node.knob('in').value()
        if channel_name in channel_list:
            num = (channel_list.index(channel_name) +
                   shuffle_num) % len(channel_list)
            print(channel_list[num])
            node.knob('in').setValue(channel_list[num])
        else:
            node.knob('in').setValue('rgba')
Esempio n. 28
0
def split_layers(node):
    """Create Shuffle node for each layers in node @n.  """

    ret = []

    for layer in nuke.layers(node):
        if layer in ['rgb', 'rgba', 'alpha']:
            continue
        kwargs = {'in': layer, 'label': layer}
        try:
            kwargs['postage_stamp'] = node['postage_stamp'].value()
        except NameError:
            pass
        n = nuke.nodes.Shuffle(inputs=[node], **kwargs)
        ret.append(n)
    return ret
Esempio n. 29
0
 def _merge_screen(cls, input_node):
     _nodes = Comp.get_nodes_by_tags('FOG')
     n = input_node
     for _read_node in _nodes:
         input1 = nuke.nodes.Reformat(inputs=[_read_node], resize='fit')
         if 'VolumeLighting' in nuke.layers(input1):
             input1 = nuke.nodes.Shuffle(inputs=[input1],
                                         **{'in': 'VolumeLighting'})
         n = nuke.nodes.Merge2(
             inputs=[n, input1],
             output='rgb',
             operation='screen',
             maskChannelInput='rgba.alpha',
             label=_read_node[ReadNode.tag_knob_name].value(),
         )
     return n
Esempio n. 30
0
def shuffle(width=4096, height=4096):
    """
    For either selected read nodes in the compositing script, shuffle out all channels contained and create a write node for each channel.

    :param width: Contact sheet width
    :type width: int
    :param height: Contact sheet height
    :type height: int
    """
    exr_data = {
        'channels': 'rgb',
        'file_type': 'exr',
        'datatype': '16 bit half',
        'compression': 'Zip (1 scanline)',
        'reading': True
    }
    import nuke
    for read in nuke.selectedNodes():
        if read.Class() != 'Read':
            continue
        shuffle_nodes = []
        for layer in nuke.layers(read):
            shuffle = nuke.nodes.Shuffle(name='shuffle_{0}'.format(layer),
                                         inputs=[read])
            shuffle['in'].setValue(layer)
            shuffle['alpha'].setValue('black')
            shuffle_nodes.append(shuffle)
            write = nuke.nodes.Write(name='write_{0}'.format(layer),
                                     inputs=[shuffle])
            write['file'].setValue('{0}.{1}.exr'.format(
                read['file'].value().replace('.exr', ''), layer))
            write['file_type'].setValue(exr_data['file_type'])
            for attr, value in exr_data.iteritems():
                write[attr].setValue(value)
        contact = nuke.nodes.ContactSheet(inputs=shuffle_nodes)
        contact['width'].setValue(width)
        contact['height'].setValue(height)
        sqrt = math.ceil(math.sqrt(len(shuffle_nodes)))
        contact['rows'].setValue(sqrt)
        contact['columns'].setValue(sqrt)
        contact_write = nuke.nodes.Write(
            name='write_{0}_contact_sheet'.format(layer), inputs=[contact])
        contact_write['file'].setValue('{0}.ContactSheet.exr'.format(
            read['file'].value().replace('.exr', '')))
        for attr, value in exr_data.iteritems():
            contact_write[attr].setValue(value)
Esempio n. 31
0
def _update_encyptomatte_setup_layers(gizmo):
    setup_layers = gizmo.knob('setupLayers').value()
    num_layers = gizmo.knob('cryptoLayers').value()
    input_layers = gizmo.knob('inputCryptoLayers').value()
    crypto_layer = gizmo.knob('cryptoLayer').value()

    if not setup_layers:
        for i in range(len(GIZMO_ADD_CHANNEL_KNOBS)):
            gizmo.knob(GIZMO_ADD_CHANNEL_KNOBS[i]).setValue("none")
            gizmo.knob(GIZMO_REMOVE_CHANNEL_KNOBS[i]).setValue("none")
        #gizmo.knob('manifestKey').setValue("")
        return

    all_layers = nuke.layers()

    for i in range(len(GIZMO_ADD_CHANNEL_KNOBS)):

        if i > 0:
            this_layer = "{0}{1:02d}".format(crypto_layer, i - 1)
        else:
            this_layer = crypto_layer

        # Add
        if i <= num_layers:
            if not this_layer in all_layers:
                if i == 0:
                    nuke.Layer(this_layer, [
                        this_layer + '.' + c for c in ['red', 'green', 'blue']
                    ])
                else:
                    nuke.Layer(this_layer, [
                        this_layer + '.' + c
                        for c in ['red', 'green', 'blue', 'alpha']
                    ])

            gizmo.knob(GIZMO_ADD_CHANNEL_KNOBS[i]).setValue(this_layer)
            gizmo.knob(GIZMO_REMOVE_CHANNEL_KNOBS[i]).setValue("none")
        else:
            gizmo.knob(GIZMO_ADD_CHANNEL_KNOBS[i]).setValue("none")
            if i <= input_layers:
                gizmo.knob(GIZMO_REMOVE_CHANNEL_KNOBS[i]).setValue(this_layer)
            else:
                gizmo.knob(GIZMO_REMOVE_CHANNEL_KNOBS[i]).setValue("none")
Esempio n. 32
0
def split(filename, output_dir, file_format=None):
    """Render splited files.  """

    path = PurePath(re.sub(r' [\d -]*$', '', filename))
    output_dir = Path(output_dir)

    # Create read node.
    read_node = nuke.nodes.Read()
    read_node['file'].fromUserText(filename)
    if file_format:
        assert isinstance(file_format, (str, unicode))
        suffix = '.{}'.format(file_format.strip('.'))
    else:
        suffix = path.suffix or '.mov'

    # Get layers for render.
    layers = nuke.layers(read_node)
    assert isinstance(layers, list)
    layers_overlap = {'rgba': ('rgb', 'alpha')}
    for k, v in layers_overlap.items():
        if k in layers:
            for i in v:
                try:
                    layers.remove(i)
                except ValueError:
                    pass

    # Create write nodes.
    for layer in layers:
        _kwargs = {'in': layer}  # Avoid use of python keyword 'in'.
        n = nuke.nodes.Shuffle(inputs=[read_node], label=layer, **_kwargs)
        n = nuke.nodes.Write(
            inputs=[n],
            file=((output_dir /
                   '{}.{}{}'.format(path.stem, layer, suffix)).as_posix()),
            channels='rgba')

    # Render.
    output_dir.mkdir(parents=True, exist_ok=True)
    nuke.render(nuke.Root(),
                start=read_node.firstFrame(),
                end=read_node.lastFrame())
Esempio n. 33
0
def quickChannel():
	node = nuke.selectedNode()
	ch_node = nuke.layers(node)
	ch = ['all']
	ch.extend(ch_node)

	if 'channels' in node.knobs().keys():

		p = nuke.Panel(node.name() + ".Channels")
		p.addEnumerationPulldown('Channel', ' '.join(ch))
		p.show()

		ch_sel = p.value('Channel')

		if ch_sel:
			node['channels'].setValue(ch_sel)

		print "n", node.name(), " --> ", ch_sel

	else:
		nuke.message("No Channel to Change")
Esempio n. 34
0
	def listChannel(self):
		self.edit(1)
		L = nuke.layers()
		p = nuke.Panel( 'all Channels' )
		p.addEnumerationPulldown( 'mySelection', ' '.join( L ) )
		if not p.show():
			return
		else:
			layer = p.value('mySelection')
		#for Loop in AllNodes
		if layer:
			for i in nuke.allNodes():
				name = i.name()
				channels = i.channels()
				allLayers = list( set([c.split('.')[0] for c in channels]) )
				if layer in allLayers:
					self.dicModif[name] = self.goodColor
				else:
					self.dicModif[name] = self.darkColor
		#Store Data
		self.edit(0)
Esempio n. 35
0
def _update_encyptomatte_setup_layers(gizmo):
    setup_layers = gizmo.knob('setupLayers').value()
    num_layers = gizmo.knob('cryptoLayers').value()
    input_layers = gizmo.knob('inputCryptoLayers').value()
    crypto_layer = gizmo.knob('cryptoLayer').value()

    if not setup_layers:
        for i in range(len(GIZMO_ADD_CHANNEL_KNOBS)):
            gizmo.knob(GIZMO_ADD_CHANNEL_KNOBS[i]).setValue("none")
            gizmo.knob(GIZMO_REMOVE_CHANNEL_KNOBS[i]).setValue("none")
        #gizmo.knob('manifestKey').setValue("")
        return


    all_layers = nuke.layers()

    for i in range(len(GIZMO_ADD_CHANNEL_KNOBS)):

        if i > 0:
            this_layer = "{0}{1:02d}".format(crypto_layer, i - 1)
        else:
            this_layer = crypto_layer

        # Add
        if i <= num_layers:
            if not this_layer in all_layers:
                if i == 0:
                    nuke.Layer(this_layer, [this_layer + '.' + c for c in ['red', 'green', 'blue']])
                else:
                    nuke.Layer(this_layer, [this_layer + '.' + c for c in ['red', 'green', 'blue', 'alpha']])

            gizmo.knob(GIZMO_ADD_CHANNEL_KNOBS[i]).setValue(this_layer)
            gizmo.knob(GIZMO_REMOVE_CHANNEL_KNOBS[i]).setValue("none")
        else:
            gizmo.knob(GIZMO_ADD_CHANNEL_KNOBS[i]).setValue("none")
            if i <= input_layers:
                gizmo.knob(GIZMO_REMOVE_CHANNEL_KNOBS[i]).setValue(this_layer)
            else:
                gizmo.knob(GIZMO_REMOVE_CHANNEL_KNOBS[i]).setValue("none")
Esempio n. 36
0
def preCompForArnold():
    # set a ordered list of input layer
    layerlist = ['indirect_diffuse', 'direct_diffuse', 'indirect_specular', 'direct_specular', 'reflection',
                 'refraction',
                 'AO', 'depth', 'MV', 'alpha']
    gradelayers = ['indirect_diffuse', 'direct_diffuse', 'indirect_specular', 'direct_specular', 'reflection',
                   'refraction',
                   'AO']
    # Get The Layers Of Selected Read Node

    orderedmerge = []

    Read = nuke.selectedNode()
    layers = nuke.layers(Read)

    for i in layerlist:
        for n in layers:
            if i == n:
                orderedmerge.append(i)

    for o in orderedmerge:
        for l in layers:
            if l == o:
                layers.remove(l)

    layers.remove('rgba')
    layers.remove('rgb')
    orderedshow = layers

    ################Create Shuffle########################################

    x = Read['xpos'].getValue()
    y = Read['ypos'].getValue()

    shufflegroup = []
    gradegroup = []
    dotYgroup = []
    mergegroup = []
    for k in orderedmerge:
        shuffle = nuke.nodes.Shuffle(name=k, postage_stamp=1, note_font_size=25)
        shuffle.setInput(0, Read)
        shuffle.knob('in').setValue(k)
        num = int(orderedmerge.index(k))
        shuffle.setXYpos(int(x + 150 * num), int(y + 250))
        shuffleX = shuffle['xpos'].getValue()
        shuffleY = shuffle['ypos'].getValue()
        shufflegroup.append(shuffle)

        ###Create Grade###
        if num < 7:
            gradenode = nuke.nodes.Grade(name=k, note_font_size=15)
            gradenode.setInput(0, shuffle)
            gradegroup.append(gradenode)
        else:
            pass

        ###Create Dot#####

        if num >= 1 and num < 7:
            dot = nuke.nodes.Dot(name=k, label=k, note_font_size=25)
            dot.setInput(0, gradenode)
            dot.setXYpos(int(shuffleX + 34), int(shuffleY + 180 * num))
            dotX = dot['xpos'].getValue()
            dotY = dot['ypos'].getValue()
            dotYgroup.append(dotY)

        elif num > 6:
            dot = nuke.nodes.Dot(name=k, label=k, note_font_size=25)
            dot.setInput(0, shuffle)
            dot.setXYpos(int(shuffleX + 34), int(shuffleY + 180 * num))
            dotX = dot['xpos'].getValue()
            dotY = dot['ypos'].getValue()
            dotYgroup.append(dotY)

        ###Create Merge####

        if num < 1:
            pass
        elif num > 0 and num < 2:
            merge = nuke.nodes.Merge(name=k, operation='plus', mix=1, inputs=[gradegroup[0], dot], note_font_size=15)
            merge.setXYpos(int(x), int(dotY - 6))
            mergegroup.append(merge)
        elif num > 1 and num < 6:
            merge = nuke.nodes.Merge(name=k, operation='plus', mix=1, inputs=[mergegroup[num - 2], dot],
                                     note_font_size=15)
            mergegroup.append(merge)
            merge.setXYpos(int(x), int(dotY - 6))
        elif num > 5 and num < 7:
            merge = nuke.nodes.Merge(name=k, operation='multiply', mix=0.15, inputs=[mergegroup[num - 2], dot],
                                     note_font_size=15)
            mergegroup.append(merge)
            merge.setXYpos(int(x), int(dotY - 6))
        elif num > 6 and num < 8:
            copy = nuke.nodes.Copy(name=k, from0='rgba.red', to0='depth.Z', inputs=[mergegroup[num - 2], dot],
                                   note_font_size=15)
            mergegroup.append(copy)
            copy.setXYpos(int(x), int(dotY - 14))
        elif num > 7 and num < 9:
            copy = nuke.nodes.Copy(name=k, from0='rgba.red', to0='MV.red', from1='rgba.green', to1='MV.green',
                                   inputs=[mergegroup[num - 2], dot], note_font_size=15)
            mergegroup.append(copy)
            copy.setXYpos(int(x), int(dotY - 26))
        elif num > 8 and num < 10:
            copy = nuke.nodes.Copy(name=k, from0='rgba.red', to0='rgba.alpha', inputs=[mergegroup[num - 2], dot],
                                   note_font_size=15)
            mergegroup.append(copy)
            copy.setXYpos(int(x), int(dotY - 14))
            ###Create show Layers####

    for element in orderedshow:
        num += 1
        shuffle = nuke.nodes.Shuffle(name=element, postage_stamp=1, note_font_size=25)
        shuffle.setInput(0, Read)
        shuffle.knob('in').setValue(element)
        shuffle.setXYpos(int(x + 150 * num), int(y + 250))

    nuke.connectViewer(0, mergegroup[-1])