-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathLines_Callbacks.py
More file actions
128 lines (92 loc) · 3.92 KB
/
Lines_Callbacks.py
File metadata and controls
128 lines (92 loc) · 3.92 KB
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
from __future__ import division
import nuke
def delete_pt():
max_pts = int(nuke.thisNode().knob('Max PTS').value()) - 1
if max_pts < 2:
nuke.message('Minimum 2 points')
return
pt_num = int(nuke.thisKnob().name()[6:])
node = nuke.thisNode()
for pt in range(pt_num, max_pts):
knob_name = 'pt' + str(pt)
next_knob = 'pt' + str(pt + 1)
node[knob_name].fromScript(node[next_knob].toScript())
node.knob('pt' + str(max_pts)).clearAnimated()
node.knob('pt' + str(max_pts)).setValue([0, 0])
for name in ('pt', 'delete', 'insert'):
node.knobs()[name + str(max_pts)].setVisible(False)
node.knob('Max PTS').setValue(max_pts)
def insert_pt():
max_pts = int(nuke.thisNode().knob('Max PTS').value())
MAX_POINTS = int(nuke.thisNode().knob('Max Limit').value())
if max_pts >= MAX_POINTS:
nuke.message('Maximum %i points' % (MAX_POINTS))
return
pt_num = int(nuke.thisKnob().name()[6:])
node = nuke.thisNode()
# Shuffle values upwards
for pt in range(max_pts, pt_num, -1):
knob_name = 'pt' + str(pt)
prev_knob = 'pt' + str(pt - 1)
node[knob_name].fromScript(node[prev_knob].toScript())
# Set new position to midpoint of adjacent points
if pt_num > 1:
ptA = node.knob('pt' + str(pt_num - 1)).value()
else:
ptA = node.knob('Start').value()
ptB = node.knob('pt' + str(pt_num + 1)).value()
midpoint = [sum(x) / 2 for x in zip(ptA, ptB)]
node.knob('pt' + str(pt_num)).clearAnimated()
node.knob('pt' + str(pt_num)).setValue(midpoint)
# Reveal next row
for name in ('pt', 'delete', 'insert'):
node.knobs()[name + str(max_pts)].setVisible(True)
node.knob('Max PTS').setValue(max_pts + 1)
def add_pt():
max_pts = int(nuke.thisNode().knob('Max PTS').value())
MAX_POINTS = int(nuke.thisNode().knob('Max Limit').value())
if max_pts >= MAX_POINTS:
nuke.message('Maximum %i points' % (MAX_POINTS))
return
node = nuke.thisNode()
for name in ('pt', 'delete', 'insert'):
node.knobs()[name + str(max_pts)].setVisible(True)
node.knob('Max PTS').setValue(max_pts + 1)
def initialiseNode(node, max_num=4):
node.knob(node.name()).setLabel('Appearance')
knob_names = [x for x in list(node.knobs().keys()) if x.startswith('pt')]
knob_names.sort(key=lambda x: int(x[2:]))
# Add new Tab for points
start_knob = node.knobs()['Start']
node.removeKnob(start_knob)
node.addKnob(nuke.Tab_Knob('Points'))
text = "Insert adds a point between its adjacent and previous point\nDelete removes the adjacent point\nAdd adds a point at the end"
node.addKnob(nuke.Text_Knob('info', '', text))
node.addKnob(nuke.Text_Knob('', ''))
node.addKnob(start_knob)
# Remove and store all pt knobs
knobs = []
for name in knob_names:
knob = node.knobs()[name]
knobs.append(knob)
node.removeKnob(knob)
# Add each back along with their delete and insert buttons
for knob in knobs:
num = knob.name()[2:]
delete = nuke.PyScript_Knob('delete' + num, 'Delete', "Lines_Callbacks.delete_pt()")
insert = nuke.PyScript_Knob('insert' + num, 'Insert', "Lines_Callbacks.insert_pt()")
# Hide knobs greater than the max value
if int(num) >= max_num:
knob.setVisible(False)
delete.setVisible(False)
insert.setVisible(False)
node.addKnob(knob)
node.addKnob(delete)
node.addKnob(insert)
# Add the Add knob
add_knob = nuke.PyScript_Knob('add_pt', 'Add', "Lines_Callbacks.add_pt()")
add_knob.setFlag(nuke.STARTLINE)
node.addKnob(add_knob)
node.knob('Max PTS').setValue(max_num)
node.knobs()['Max PTS'].setVisible(False)
node.knobs()['Max Limit'].setVisible(False)