This repository was archived by the owner on Aug 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmod_ViewerShortcuts.py
196 lines (153 loc) · 8.8 KB
/
mod_ViewerShortcuts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'''
Based on QuckCreate by MADS HAGBARTH DAMSBO
'''
#------------------------------------------------------------------------------
#-Module Import
#------------------------------------------------------------------------------
import platform
import os
from Qt import QtWidgets, QtGui, QtCore
import nuke, nukescripts
#------------------------------------------------------------------------------
#-Header
#------------------------------------------------------------------------------
__VERSION__ = '1.0'
__OS__ = platform.system()
__AUTHOR__ = "Tianlun Jiang"
__WEBSITE__ = "jiangovfx.com"
__COPYRIGHT__ = "copyright (c) %s - %s" % (__AUTHOR__, __WEBSITE__)
__TITLE__ = "ViewerShortcuts v%s" % __VERSION__
def _version_():
ver='''
version 1.0
- List of convient viewer short cuts
- Minor edit to fit kupipeline
'''
return ver
# ------------------------------------------------------------------------------
# Main Functions
# ------------------------------------------------------------------------------
#Base Gridwarp Struct.
#Dear Foundry... could setValue() support?
gridWarpBaseStruct = '''
1 5 5 4 1 0
{default }
{
{ {2 _x0 _y0} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x1 _y0} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x2 _y0} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x3 _y0} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x4 _y0} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x0 _y1} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x1 _y1} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x2 _y1} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x3 _y1} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x4 _y1} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x0 _y2} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x1 _y2} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x2 _y2} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x3 _y2} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x4 _y2} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x0 _y3} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x1 _y3} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x2 _y3} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x3 _y3} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x4 _y3} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x0 _y4} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x1 _y4} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x2 _y4} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x3 _y4} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
{ {2 _x4 _y4} { {2 0 _ty0} {2 0 -_ty0} {2 _tx0 0} {2 -_tx0 0} } }
}
'''
def CreateOnSelection(_kind):
#If the viewer is connected to a node we will use input 0 for ref. Else we just use the viewer itself.
if nuke.activeViewer().node().input(0):
myNode = nuke.activeViewer().node().input(0)
if not nuke.selectedNodes(): #Trying to be smart by assuming that you don't want to add a node to nothing.
myNode.setSelected(1)
else:
myNode = nuke.activeViewer().node()
bboxinfo = nuke.activeViewer().node()['colour_sample_bbox'].value() #Get the position info from the colour sample bbox
aspect = float(myNode.width()*myNode.pixelAspect())/float(myNode.height()) #Calcualte the aspect (thanks Tom van Dop for notifying and Jelmen Palsterman for the correction!)
cornerA = [(bboxinfo[0]*0.5+0.5)*myNode.width(),(((bboxinfo[1]*0.5)+(0.5/aspect))*aspect)*myNode.height()] #Get the button left corner
cornerB = [(bboxinfo[2]*0.5+0.5)*myNode.width(),(((bboxinfo[3]*0.5)+(0.5/aspect))*aspect)*myNode.height()] #Get the top right corner
area_WH = [cornerB[0]-cornerA[0],cornerB[1]-cornerA[1]] #Get the width and height of the bbox
area_Mid = [cornerA[0]+(area_WH[0]/2),cornerA[1]+(area_WH[1]/2)] #Get the center of the bbox
if _kind == 'Crop': #-----Crop Node-----
newNode = nuke.Node("Crop")
newNode['box'].setValue([cornerA[0],cornerA[1],cornerB[0],cornerB[1]])
elif _kind == 'ROI': #-----ROI-----
nuke.activeViewer().node()["roi"].setValue(bboxinfo)
elif _kind == 'Transform': #-----Tranform Node-----
newNode = nuke.Node("Transform")
newNode['center'].setValue([area_Mid[0],area_Mid[1]])
elif _kind == 'GridWarp': #-----GridWarp Node-----
newNode = nuke.Node("GridWarp3")
gridwarpLayout = gridWarpBaseStruct
for x in range(0,5): #Remap placeholder values to x and y coordinates split up to 5 subdevisions
gridwarpLayout=gridwarpLayout.replace("_x%s"%x,"%.0f" % (cornerA[0]+((area_WH[0]/4)*x)))
gridwarpLayout=gridwarpLayout.replace("_y%s"%x,"%.0f" % (cornerA[1]+((area_WH[1]/4)*x)))
gridwarpLayout=gridwarpLayout.replace("_tx0","%.3f" % (area_WH[0]/12)) #Remap tangent's
gridwarpLayout=gridwarpLayout.replace("_ty0","%.3f" % (area_WH[1]/12)) #Remap tangent's
newNode['source_grid_col'].fromScript(gridwarpLayout) #Set Source Grid
newNode['destination_grid_col'].fromScript(gridwarpLayout) #Set Destination Grid
if _kind == 'Text':
newNode = nuke.Node("Text2")
newNode['box'].setValue([cornerA[0],cornerA[1],cornerB[0],cornerB[1]])
elif _kind == 'Radial':
newNode = nuke.Node("Radial")
newNode['area'].setValue([cornerA[0],cornerA[1],cornerB[0],cornerB[1]])
elif _kind == 'Keylight':
newNode = nuke.Node("OFXuk.co.thefoundry.keylight.keylight_v201")
ColorR = myNode.sample(1,area_Mid[0],area_Mid[1],area_WH[0],area_WH[1])
ColorG = myNode.sample(2,area_Mid[0],area_Mid[1],area_WH[0],area_WH[1])
ColorB = myNode.sample(3,area_Mid[0],area_Mid[1],area_WH[0],area_WH[1])
newNode['screenColour'].setValue([ColorR,ColorG,ColorB])
elif _kind == 'Tracker':
#If we allready have a tracker selexted then append tracks to exsisting tracker node.
if myNode.Class()=="Tracker4":
newNode = myNode
nuke.show(newNode)
else: #Creat a new tracker node
newNode = nuke.Node("Tracker4")
numColumns = 31
colTrackX = 2
colTrackY = 3
colRelTrack = 12
trackIdx = int(newNode["tracks"].toScript().split(" ")[3])
newNode['add_track'].execute()
newNode.knob("tracks").setValue(area_Mid[0],numColumns*trackIdx + colTrackX)
newNode.knob("tracks").setValue(area_Mid[1],numColumns*trackIdx + colTrackY)
newNode.knob("tracks").setValue(-area_WH[0]/2,numColumns*trackIdx + colRelTrack)
newNode.knob("tracks").setValue(-area_WH[1]/2,numColumns*trackIdx + colRelTrack+1)
newNode.knob("tracks").setValue(area_WH[0]/2,numColumns*trackIdx + colRelTrack+2)
newNode.knob("tracks").setValue(area_WH[1]/2,numColumns*trackIdx + colRelTrack+3)
elif _kind == 'CornerpinFrom':
newNode = nuke.Node("CornerPin2D")
newNode['from1'].setValue([cornerA[0],cornerA[1]])
newNode['from2'].setValue([cornerB[0],cornerA[1]])
newNode['from3'].setValue([cornerB[0],cornerB[1]])
newNode['from4'].setValue([cornerA[0],cornerB[1]])
elif _kind == 'CornerpinTo':
newNode = nuke.Node("CornerPin2D")
newNode['to1'].setValue([cornerA[0],cornerA[1]])
newNode['to2'].setValue([cornerB[0],cornerA[1]])
newNode['to3'].setValue([cornerB[0],cornerB[1]])
newNode['to4'].setValue([cornerA[0],cornerB[1]])
elif _kind == 'CornerpinFromTo':
newNode = nuke.Node("CornerPin2D")
newNode['to1'].setValue([cornerA[0],cornerA[1]])
newNode['to2'].setValue([cornerB[0],cornerA[1]])
newNode['to3'].setValue([cornerB[0],cornerB[1]])
newNode['to4'].setValue([cornerA[0],cornerB[1]])
newNode['from1'].setValue([cornerA[0],cornerA[1]])
newNode['from2'].setValue([cornerB[0],cornerA[1]])
newNode['from3'].setValue([cornerB[0],cornerB[1]])
newNode['from4'].setValue([cornerA[0],cornerB[1]])
elif _kind == 'Constant':
newNode = nuke.Node("Constant", inpanel=False)
ColorR = myNode.sample(1,area_Mid[0],area_Mid[1],area_WH[0],area_WH[1])
ColorG = myNode.sample(2,area_Mid[0],area_Mid[1],area_WH[0],area_WH[1])
ColorB = myNode.sample(3,area_Mid[0],area_Mid[1],area_WH[0],area_WH[1])
newNode['color'].setValue([ColorR,ColorG,ColorB,1])