-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplineWire.jsx
271 lines (221 loc) · 9.67 KB
/
SplineWire.jsx
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//This script creates a chain of "CC Simple Wire Removal" Effects along a Created MaskPath
//You can define the Thickness for a Spline
//Everytime you change the position of your spline, you have to recreate the effect
{
function SplineWire(thisObj)
{
//Globals
//todo better inits
var scriptName = "Chained Wire Removal Tool";
var EffectName = "CC Simple Wire Removal";
activeComp =0;
mask = 0;
maskPath = 0;
numOfKeys = -1;
compFrameRate = -1;
wireThickness = -1;
myMasks = -1;
numOfMasks = -1;
var masksContainer = new Array();
//======================================================
//==================== UI CALL BACKS ===================
//======================================================
function onFontStringChanged()
{
fontSizePX = parseInt(pt2px(this.text));
}
function onFindStringChanged()
{
myFindString = this.text;
}
// Called when the Replacement Text string is edited
function onReplaceStringChanged()
{
myReplaceString = this.text;
}
//======================================================
//================ MAIN ENTRY FUNCTION =================
//======================================================
function onCreate()
{
compFrameRate = activeComp.frameRate;
activeComp = app.project.activeItem;
myMasks = activeComp.layer(1).Masks;
numOfMasks = myMasks.numProperties;
getAllMasks();
addWireRemovalEffect();
setEffectValues();
}
function getAllMasks(){
for(i = 1; i <= numOfMasks; i++){
tempMask = activeComp.layer(1).mask(i);
masksContainer.push(tempMask);
}
}
function addWireRemovalEffect(){
removeAllWireEffects();
for(k = 0; k <= numOfMasks-1; k++){
for (j = 0 ; j < masksContainer[k].maskPath.value.vertices.length-1; j++){
var wireEffect = activeComp.layer(1).property("Effects").addProperty("CC Simple Wire Removal");
var maskGroupID = "m" + k;
wireEffect.name = maskGroupID + " CC Simple Wire Removal " + j;
}
}
//Create a Slider for the thickness
//var slider = activeComp.layer(1).property("Effects").addProperty("Slider Control");
//slider.property(1).setValue(12);
}
function onUpdateThickness(id, thickness){
if(!isValid(masksContainer[id].maskPath.value))
return;
myEffects = activeComp.layer(1).Effects;
for (j = 0; j < masksContainer[id].maskPath.value.vertices.length-1; j++){
compareString = "m" + id + " " + EffectName + " " + j;
activeComp.layer(1).property("Effects").property(compareString).property("Thickness").setValue(thickness);
}
}
function removeAllWireEffects(){
try{
myEffects = activeComp.layer(1).Effects;
for(id= 1; id <= numOfMasks; id++){
compareString = "m" + id + " " + EffectName;
for (j = myEffects.numProperties; j > 0; j--){
if(myEffects.property(j).name.substring(0, 25).localeCompare(compareString) == 0){
myEffects.property(j).remove();
}
}
}
}catch(err){
}
}
function setEffectValues(){
myEffects = activeComp.layer(1).Effects;
for(k = 0; k <= numOfMasks-1; k++){
//Iterate through the Frame Keys
for(j = 1; j <= masksContainer[k].maskPath.numKeys; j++){
actualKeyTime = masksContainer[k].maskPath.keyTime(j);
var pathKeyValue = getValueAtTime(actualKeyTime, k);
iterator = masksContainer[k].maskPath.value.vertices.length-1;
for(i = 0; i < iterator; i++){
propname = "m" + (k) + " CC Simple Wire Removal " + i;
var pointA = [pathKeyValue.vertices[i][0], pathKeyValue.vertices[i][1]];
var pointB = [pathKeyValue.vertices[i+1][0], pathKeyValue.vertices[i+1][1]];
activeComp.layer(1).property("Effects").property(propname).property("Point A").addKey(actualKeyTime);
activeComp.layer(1).property("Effects").property(propname).property("Point A").setValueAtTime(actualKeyTime, pointA);
activeComp.layer(1).property("Effects").property(propname).property("Point B").addKey(actualKeyTime);
activeComp.layer(1).property("Effects").property(propname).property("Point B").setValueAtTime(actualKeyTime, pointB);
activeComp.layer(1).property("Effects").property(propname).property("Thickness").setValue(10);
}
}
}
}
function getValueAtTime(timeOfKey, k){
return masksContainer[k].maskPath.valueAtTime(timeOfKey, true);
}
//================================================================
//========================= GUI CREATION =========================
//================================================================
if (parseFloat(app.version) < 8)
{
alert("This script requires After Effects CS3 or later.", scriptName);
return;
}
else
{
// Create and show a floating palette
var my_palette = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName, undefined, {resizeable:true});
if (my_palette != null)
{
var res =
"group { \
orientation:'column', alignment:['fill','fill'], alignChildren:['left','top'], spacing:5, margins:[0,0,0,0], \
findRow: Group { \
alignment:['fill','top'], \
selectTxtButton: Button { text:'Video Layer', alignment:['fill','left'] }, \
}, \
title: Group{ \
alignment: ['left', 'top'],\
fontString: StaticText { text:'Thickness of Wire:', alignment:['left','center'] }, \
}, \
m1: Group { \
alignment:['fill','top'],\
fontString: StaticText { text:'1 :', alignment:['left','left'] }, \
mask1: EditText { text:'2', characters:3, alignment:['right','center'] }, \
},\
m2: Group { \
alignment:['fill','top'],\
fontString: StaticText { text:'2 :', alignment:['left','left'] }, \
mask2: EditText { text:'2', characters:3, alignment:['right','center'] }, \
},\
m3: Group { \
alignment:['fill','top'],\
fontString: StaticText { text:'3 :', alignment:['left','left'] }, \
mask3: EditText { text:'2', characters:3, alignment:['right','center'] }, \
},\
m4: Group { \
alignment:['fill','top'],\
fontString: StaticText { text:'4 :', alignment:['left','left'] }, \
mask4: EditText { text:'2', characters:3, alignment:['right','center'] }, \
},\
m5: Group { \
alignment:['fill','top'],\
fontString: StaticText { text:'5 :', alignment:['left','left'] }, \
mask5: EditText { text:'2', characters:3, alignment:['right','center'] }, \
},\
replaceRow: Group { \
alignment:['fill','top'], \
}, \
cmds: Group { \
alignment:['fill','top'], \
createButton: Button { text:'Create', alignment:['fill','center'] }, \
helpButton: Button { text:'?', alignment:['right','center'], preferredSize:[25,20] }, \
}, \
}";
my_palette.margins = [10,10,10,10];
my_palette.grp = my_palette.add(res);
// Workaround to ensure the editext text color is black, even at darker UI brightness levels
var winGfx = my_palette.graphics;
var darkColorBrush = winGfx.newPen(winGfx.BrushType.SOLID_COLOR, [0,0,0], 1);
//my_palette.grp.findRow.findEditText.graphics.foregroundColor = darkColorBrush;
//my_palette.grp.replaceRow.replaceEditText.graphics.foregroundColor = darkColorBrush;
//my_palette.grp.findRow.findStr.preferredSize.width = my_palette.grp.replaceRow.replaceStr.preferredSize.width;
//my_palette.grp.findRow.findEditText.onChange = my_palette.grp.findRow.findEditText.onChanging = onFindStringChanged;
//my_palette.grp.findRow.mask1.onChange = my_palette.grp.findRow.mask1.onChanging = onFontStringChanged;
//my_palette.grp.findRow.mask2.onChange = my_palette.grp.findRow.mask2.onChanging = onFontStringChanged;
//my_palette.grp.findRow.mask3.onChange = my_palette.grp.findRow.mask3.onChanging = onFontStringChanged;
//my_palette.grp.findRow.mask4.onChange = my_palette.grp.findRow.mask4.onChanging = onFontStringChanged;
//my_palette.grp.m1.mask5.onChange = my_palette.grp.m1.mask5.onChanging = onFontStringChanged;
//my_palette.grp.replaceRow.replaceEditText.onChange = my_palette.grp.replaceRow.replaceEditText.onChanging = onReplaceStringChanged;
//my_palette.grp.findRow.selectTxtButton.onClick =onSelectFont;
my_palette.grp.cmds.createButton.onClick = onCreate;
//wireThickness = my_palette.grp.cmds.fontString.value;
//alert(wireThickness);
my_palette.grp.m1.mask1.onChange = function(){ onUpdateThickness(0, this.text)};
my_palette.grp.m2.mask2.onChange = function(){ onUpdateThickness(1, this.text)};
my_palette.grp.m3.mask3.onChange = function(){ onUpdateThickness(2, this.text)};
my_palette.grp.m4.mask4.onChange = function(){ onUpdateThickness(3, this.text)};
my_palette.grp.m5.mask5.onChange = function(){ onUpdateThickness(4, this.text)};
//my_palette.grp.findRow.mask2.onChange = function(){ onUpdateThickness(2, this.text)};
//my_palette.grp.findRow.mask3.onChange = function(){ onUpdateThickness(3, this.text)};
//my_palette.grp.findRow.mask4.onChange = function(){ onUpdateThickness(4, this.text)};
// my_palette.grp.m1.mask5.onChange = function(){ onUpdateThickness(5, this.text)};
//alert(my_palette.grp.findRow.mask1);
//alert(my_palette.grp.findRow.fontString.value);
//my_palette.grp.cmds.replaceButton.onClick = onReplaceAll;
//my_palette.grp.cmds.helpButton.onClick = onShowHelp;
my_palette.onResizing = my_palette.onResize = function () {this.layout.resize();}
if (my_palette instanceof Window) {
my_palette.center();
my_palette.show();
} else {
my_palette.layout.layout(true);
my_palette.layout.resize();
}
}
else {
alert("Could not open the user interface.", scriptName);
}
}
}
}
SplineWire();