forked from throb/vfxpipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Added multiread and auto comp
- Loading branch information
unknown
authored and
unknown
committed
Jun 26, 2014
1 parent
1cce255
commit 18546c6
Showing
5 changed files
with
194 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
################################################################ | ||
# | ||
# Breakout multichannels based on a specific set of parameters | ||
# | ||
# | ||
|
||
import nuke | ||
import nukescripts | ||
import fxpipe | ||
import fxpipenukescripts | ||
|
||
class autoComperPanel(nukescripts.PythonPanel): | ||
def __init__(self, node): | ||
channels = node.channels() | ||
layers = list( set([c.split('.')[0] for c in channels]) ) | ||
layers.sort() | ||
layers.insert(0,'None') | ||
nukescripts.PythonPanel.__init__(self, 'Auto Comper') | ||
self.myNode = node | ||
self.diff = nuke.Enumeration_Knob('diffuse', 'Diffuse (lighting)', layers) | ||
self.gi = nuke.Enumeration_Knob('gi', 'GI', layers) | ||
self.spec = nuke.Enumeration_Knob('specular', 'specular', layers) | ||
self.refl = nuke.Enumeration_Knob('reflect', 'reflect', layers) | ||
self.refr = nuke.Enumeration_Knob('refract', 'refract', layers) | ||
self.sss = nuke.Enumeration_Knob('sss', 'SSS', layers) | ||
self.selfIllum = nuke.Enumeration_Knob('selfIllum', 'Self Illumination', layers) | ||
self.depth = nuke.Channel_Knob('zdepth', 'Z Depth') | ||
self.depthNormal = nuke.Boolean_Knob('normalizeDepth','Normalize Depth?') | ||
|
||
for k in (self.diff, self.gi, self.spec, self.refl, self.refr, self.sss, self.selfIllum, self.depth, self.depthNormal): | ||
self.addKnob(k) | ||
if 'lighting' in layers: | ||
self.diff.setValue('lighting') | ||
if 'gi' in layers: | ||
self.gi.setValue('gi') | ||
if 'specular' in layers: | ||
self.spec.setValue('specular') | ||
if 'reflect' in layers: | ||
self.refl.setValue('reflect') | ||
if 'refract' in layers: | ||
self.refr.setValue('refract') | ||
if 'SSS' in layers: | ||
self.sss.setValue('SSS') | ||
if 'selfIllum' in layers: | ||
self.selfIllum.setValue('selfIllum') | ||
if 'depth.Z' in layers: | ||
self.depth.setValue('depth.z') | ||
|
||
def shuffleLayer( node, layer ): | ||
shuffleNode = nuke.nodes.Shuffle( label=layer, inputs=[node] ) | ||
shuffleNode['in'].setValue( layer ) | ||
shuffleNode['postage_stamp'].setValue( False ) | ||
if layer == 'None': | ||
shuffleNode['disable'].setValue(True) | ||
gradeNode = nuke.nodes.Grade( inputs=[shuffleNode] ) | ||
allNodes.append(shuffleNode) | ||
allNodes.append(gradeNode) | ||
return nuke.nodes.Dot( inputs=[ gradeNode ] ) | ||
|
||
def mergeLayers (nodeB, nodeA): | ||
mergeNode = nuke.nodes.Merge2( operation='plus', inputs=[ nodeB, nodeA ], output='rgb' ) | ||
allNodes.append(mergeNode) | ||
if mergeNode.input(1).input(0).input(0)['label'].value() == 'None': | ||
mergeNode['disable'].setValue(True) | ||
return mergeNode | ||
|
||
def autoComper(node): | ||
|
||
p = autoComperPanel(node) | ||
|
||
if p.showModalDialog(): | ||
nuke.Undo().name('auto comp') | ||
nuke.Undo().begin() | ||
global allNodes | ||
allNodes = [] | ||
dotParent = nuke.nodes.Dot(inputs=[node], ypos = node['ypos'].value(), xpos = node['xpos'].value()+200 ) | ||
unPremultNode = nuke.nodes.Unpremult(inputs=[dotParent],channels='all') | ||
allNodes.append(unPremultNode) | ||
diffNode = shuffleLayer( unPremultNode, p.diff.value() ) | ||
giNode = shuffleLayer( unPremultNode, p.gi.value() ) | ||
specNode = shuffleLayer( unPremultNode, p.spec.value() ) | ||
reflectNode = shuffleLayer( unPremultNode, p.refl.value() ) | ||
refractNode = shuffleLayer( unPremultNode, p.refr.value() ) | ||
sssNode = shuffleLayer( unPremultNode, p.sss.value() ) | ||
selfIllumNode = shuffleLayer( unPremultNode, p.selfIllum.value() ) | ||
depthNode = shuffleLayer( dotParent, p.depth.value() ) | ||
|
||
|
||
|
||
mergeNode = mergeLayers(diffNode, giNode) | ||
mergeNode = mergeLayers(mergeNode, specNode) | ||
mergeNode = mergeLayers(mergeNode, reflectNode) | ||
mergeNode = mergeLayers(mergeNode, refractNode) | ||
mergeNode = mergeLayers(mergeNode, sssNode) | ||
mergeNode = mergeLayers(mergeNode, selfIllumNode) | ||
|
||
copyNode = nuke.nodes.Copy(from0='rgba.alpha',to0='rgba.alpha',inputs=[mergeNode,node]) | ||
|
||
black, white = fxpipenukescripts.getMinMax( node, p.depth.value() ) | ||
normNode = nuke.nodes.Grade( channels=p.depth.value(), blackpoint=black, whitepoint=white, white_clamp=True, label='normalize depth', inputs=[copyNode] ) | ||
invNode = nuke.nodes.Invert( channels=p.depth.value(), disable=True, inputs=[normNode]) | ||
|
||
allNodes.append(nuke.nodes.Premult(channels='rgba',inputs=[invNode])) | ||
for n in allNodes: | ||
n.setSelected(True) | ||
node.setSelected(False) | ||
backdrop = nukescripts.autoBackdrop() | ||
backdrop['label'].setValue('Auto Comp') | ||
nuke.Undo.end() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
########################################################## | ||
# | ||
# Autoplace and create shuffles on mutliple read nodes | ||
# | ||
# throb | ||
|
||
def autoShuffleReads(nodes): | ||
import re | ||
import nuke | ||
|
||
nuke.Undo().name('organize and split') | ||
nuke.Undo().begin() | ||
readList = [] | ||
yPosAvg = 0 | ||
xPosAvg = 0 | ||
count = 0 | ||
try: | ||
nodes # does a exist in the current namespace | ||
except NameError: | ||
nodes = nuke.selectedNodes() | ||
for curNode in nodes: | ||
if curNode.Class() == 'Read': | ||
readList.append({'file':nuke.filename(curNode),'node':curNode}) | ||
yPosAvg = yPosAvg + curNode['ypos'].value() | ||
xPosAvg = xPosAvg + curNode['xpos'].value() | ||
count += 1 | ||
|
||
readListSorted = sorted(readList,key=lambda k: k['file']) | ||
xPosAvg = int(xPosAvg/count) | ||
yPosAvg = int(yPosAvg/count) | ||
|
||
count = 0 | ||
for readNode in readListSorted: | ||
readNode['node']['xpos'].setValue(xPosAvg - 110*count) | ||
readNode['node']['ypos'].setValue(yPosAvg) | ||
readNode['node']['selected'].setValue(True) | ||
count += 1 | ||
|
||
for n in nuke.selectedNodes(): | ||
n.autoplace() | ||
|
||
prevNode = nuke.nodes.Dot() | ||
originalDot = prevNode | ||
for curNode in nuke.selectedNodes(): | ||
if curNode.Class() == 'Read': | ||
filename = nuke.filename(curNode) | ||
passName = filename.split('.')[1] | ||
if re.match(r'^[A-Za-z0-9_]+$', passName): | ||
newLayer = nuke.Layer( passName, [passName+'.red', passName+'.green', passName+'.blue'] ) | ||
shuffle = nuke.nodes.Shuffle(label = passName, inputs=[curNode]) | ||
shuffle['out'].setValue( passName ) | ||
dotNode = nuke.nodes.Dot( inputs=[ shuffle ] ) | ||
copyNode = nuke.nodes.Copy(inputs=[prevNode, dotNode], channels=passName, selected=True) | ||
prevNode = copyNode | ||
else: | ||
masterNode = curNode | ||
originalDot.setInput(0,masterNode) | ||
nukescripts.autoBackdrop() | ||
nuke.Undo().end() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import nuke | ||
|
||
def getMinMax( srcNode, channel='depth.Z' ): | ||
''' | ||
Return the min and max values of a given node's image as a tuple | ||
args: | ||
srcNode - node to analyse | ||
channels - channels to analyse. This can either be a channel or layer name | ||
''' | ||
MinColor = nuke.nodes.MinColor( channels=channel, target=0, inputs=[srcNode] ) | ||
Inv = nuke.nodes.Invert( channels=channel, inputs=[srcNode]) | ||
MaxColor = nuke.nodes.MinColor( channels=channel, target=0, inputs=[Inv] ) | ||
|
||
curFrame = nuke.frame() | ||
nuke.execute( MinColor, curFrame, curFrame ) | ||
minV = -MinColor['pixeldelta'].value() | ||
|
||
nuke.execute( MaxColor, curFrame, curFrame ) | ||
maxV = MaxColor['pixeldelta'].value() + 1 | ||
|
||
for n in ( MinColor, MaxColor, Inv ): | ||
nuke.delete( n ) | ||
return minV, maxV |