forked from dokluch/gridder-aftereffects
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGridder.jsx
1411 lines (1147 loc) · 146 KB
/
Gridder.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//The Gridder
//v1.0 - Initial release
//v1.1 - Expressions, CC fix
//v1.2 - Grid Overlay feature, more robust expressions, code cleanup
//v1.5 - New grid modes - 3D and Circular
// Duplicator mode
// Fixed bug with wrong icons folder
//by Nik Ska, 2013
//vk.com/ae_exp
//CC-BY 3.0
this.version = 1.5;
this.name = "Gridder";
this.texts = {
gridStepText: "Set grid step:",
setSp: "Set spacing:",
square: "Square grid",
nullControlName: "GRIDDER_Control",
nullControlName3D: "GRIDDER_Control_3D",
nullControlNameCirc: "GRIDDER_Control_Circ",
gridOverlayName: "GRIDDER_Grid_Overlay",
colorControlName: "Grid Color",
gridThicknessName: "Grid thickness",
circModeHeader: "Set circle parameters",
rotateAll: "Rotate circle",
spiralText: "Spiral",
tips: {
col: "Columns only grid mode",
row: "Rows only grid mode",
plane: "Select 3d plane",
xSpacing: "X axis spacing",
ySpacing: "Y axis spacing",
zSpacing: "Z axis spacing",
angle: "Angle",
radius: "Radius",
spiral: "Spiral offset",
spiralReverse: "Reverse spiral path",
duplicator: "Toggle Duplicator mode",
grid: "Create grid overlay layer",
rect: "Rectangle mode",
threeD: "3D mode",
circ: "Circular mode",
sqGrid: "Square grid",
gridOverlay: "Create grid overlay layer",
rotateAll: "Rotate all circle",
}
};
this.selLength = 0;
this.selLayers = [];
function make2DGrid(thisObj){
//main function to arrage elements into 2D grid
var activeComp = app.project.activeItem;
if(activeComp){
var selLayers;
// if(activeComp.selectedLayers.length!=thisObj.selLength){
// //upon new selection
// thisObj.selLayers = activeComp.selectedLayers.sort(function(a,b){
// return (a.index - b.index)
// });
// thisObj.selLength = thisObj.selLayers.length;
// }
// selLayers = thisObj.selLayers;
var selLayers = activeComp.selectedLayers;
if(thisObj.duplicator == true){
//work in Duplicator mode
var sel = activeComp.selectedLayers;
if(sel && sel.length == 1){
selLayers = createDuplicates(sel[0], thisObj.numCols*thisObj.numRows);
}
}
//select more than one layer
if(selLayers.length>1){
//set reference position
var firstPos = selLayers[0].transform.position.value;
for(var i = 0; i<selLayers.length; i++){
selLayers[i].threeDLayer = false;
selLayers[i].transform.rotation.setValue(0);
if(thisObj.onlyRows == false){
if(thisObj.onlyCols == false){
//rectangular grid
trueIndex = i%(thisObj.numRows*thisObj.numCols);
}
else{
//only columns
trueIndex = i;
}
var thisCol = trueIndex % thisObj.numCols;
var thisRow = Math.floor(trueIndex/thisObj.numCols);
if(!selLayers[i].transform.position.isTimeVarying){
selLayers[i].transform.position.setValue(firstPos+[thisCol*dist[0], thisRow*dist[1]]);
}
else{
selLayers[i].transform.position.setValueAtTime(activeComp.time,firstPos+[thisCol*dist[0], thisRow*dist[1]]);
}
}
else{
//only rows
trueIndex = i;
var thisCol = trueIndex % thisObj.numRows;
var thisRow = Math.floor(trueIndex/thisObj.numRows);
if(!selLayers[i].transform.position.isTimeVarying){
selLayers[i].transform.position.setValue(firstPos+[thisRow*dist[0], thisCol*dist[1]]);
}
else{
selLayers[i].transform.position.setValueAtTime(activeComp.time,firstPos+[thisRow*dist[0], thisCol*dist[1]]);
}
}
}
if(thisObj.gridOverlay){
updateGridOverlay(thisObj);
}
}
}
}
function make3DGrid(thisObj){
var activeComp = app.project.activeItem;
if(activeComp){
var selLayers;
if(activeComp.selectedLayers.length!=thisObj.selLength){
//upon new selection
thisObj.selLayers = activeComp.selectedLayers.sort(function(a,b){
return (a.index - b.index)
});
thisObj.selLength = thisObj.selLayers.length;
}
selLayers = thisObj.selLayers;
if(thisObj.duplicator == true){
//work in Duplicator mode
var sel = activeComp.selectedLayers;
if(sel && sel.length == 1){
selLayers = createDuplicates(sel[0], thisObj.numCols*thisObj.numRows);
}
}
//select more than one layer
if(selLayers.length>1){
//set reference position
var firstPos = selLayers[0].transform.position.value;
var isCam = 0;
for(var i = 0; i<selLayers.length; i++){
if((selLayers[i] instanceof CameraLayer) == false){
selLayers[i].threeDLayer = true;
selLayers[i].transform.zRotation.setValue(0);
trueIndex = i-isCam;
var thisZ = Math.floor(trueIndex/(thisObj.numRows*thisObj.numCols));
trueIndex = trueIndex%(thisObj.numRows*thisObj.numCols);
var thisX = trueIndex % thisObj.numCols;
var thisY = Math.floor(trueIndex/thisObj.numCols);
if(thisObj.planeSelect == 0) var pV = [thisX*dist3d[0], thisY*dist3d[1], thisZ*dist3d[2]]; //XY
else if(thisObj.planeSelect == 1) var pV = [thisZ*dist3d[0], thisY*dist3d[1], thisX*dist3d[2]]; //XZ
else if(thisObj.planeSelect == 2) var pV = [thisX*dist3d[0], thisZ*dist3d[1], thisY*dist3d[2]];//YZ
if(!selLayers[i].transform.position.isTimeVarying){
selLayers[i].transform.position.setValue(firstPos+pV);
}
else{
selLayers[i].transform.position.setValueAtTime(activeComp.time,firstPos+pV);
}
}
else isCam++;
}
}
}
}
function makeCircGrid(thisObj){
var activeComp = app.project.activeItem;
if(activeComp){
var selLayers;
if(activeComp.selectedLayers.length!=thisObj.selLength){
//upon new selection
thisObj.selLayers = activeComp.selectedLayers.sort(function(a,b){
return (a.index - b.index)
});
thisObj.selLength = thisObj.selLayers.length;
}
selLayers = thisObj.selLayers;
//select more than one layer
if(selLayers.length>1){
//set reference position
var firstPos = [activeComp.width/2, activeComp.height/2];
for(var i = 0; i < selLayers.length; i++){
selLayers[i].threeDLayer = false;
var r = thisObj.radius + i*thisObj.spiral;
var a = i*thisObj.angle+thisObj.rotateAll;
// $.writeln(thisObj.spiralReverse)
if(thisObj.spiralReverse == true) a*=-1;
if(!selLayers[i].transform.position.isTimeVarying){
selLayers[i].transform.position.setValue(firstPos+[r*Math.cos(a), r*Math.sin(a)]);
}
else{
selLayers[i].transform.position.setValueAtTime(activeComp.time, firstPos+[r*Math.cos(a), r*Math.sin(a)]);
}
}
}
}
}
function buildGUI(thisObj){
getPrefs(thisObj);
// thisObj.gridMode = "RECT";
//creating icons in appdata folder
thisObj.iconsFiles = new Array();
var fldr = new Folder(Folder.userData.fullName + '/Gridder/')
fldr.create();
for(i = 0; i <= 13; i++) {
thisObj.iconsFiles[i] = new File(fldr.fullName+'/gridderIconFile_'+ i + ".png");
thisObj.iconsFiles[i].encoding = "BINARY";
thisObj.iconsFiles[i].open("w");
thisObj.iconsFiles[i].write(thisObj.iconsBinaries[i]);
thisObj.iconsFiles[i].close();
}
thisObj.w = (thisObj instanceof Panel) ? thisObj : new Window("palette", thisObj.scriptTitle, undefined, {resizeable:true});
var w = thisObj.w;
thisObj.w.preferredSize = "width: 250, height: 450";
thisObj.w.maximumSize = "width:250, height: 450";
thisObj.w.alignChildren = ["left", "top"]
thisObj.w.margins = [10,10,10,0];
thisObj.w.setBG([.25,.25,.25])
var mainGroup = thisObj.w.add("group{orientation:'stack',alignment:['left','top']}");
//==================================
//Rectangle mode
//==================================
var twoDmodeGroup = mainGroup.add("group{orientation:'column',alignment:['left','top'],alignChildren:['left','top']}");
twoDmodeGroup.add("staticText", undefined, thisObj.texts.gridStepText).setFG([1,1,1]);
var lineOne = twoDmodeGroup.add("group{orientation:'row'}");
var colsBttn = lineOne.add("group{margins: 4, alignment: ['left', 'center']}").setIcon(thisObj.iconsFiles[0]).setTip(thisObj.texts.tips.col);
var colsSlider = lineOne.add("slider", undefined, thisObj.numCols, 1, 15);
colsSlider.size = 'width: 150, height: 10';
var colsEdit = lineOne.add("editText{alignment: ['right', 'center'], size: [25,20], justify: 'center'}");
colsEdit.text = colsSlider.value;
var lineTwo = twoDmodeGroup.add("group{orientation:'row',alignment:['fill','top']}");
var rowsBttn = lineTwo.add("group { margins: 4, alignment: ['left', 'center']}").setIcon(thisObj.iconsFiles[1]).setTip(thisObj.texts.tips.row);
var rowsSlider = lineTwo.add("slider", undefined, thisObj.numRows, 1, 15);
rowsSlider.size = 'width: 150, height: 10';
var rowsEdit = lineTwo.add("editText{alignment: ['right', 'center'], size: [25,20], justify: 'center'}");
rowsEdit.text = rowsSlider.value;
twoDmodeGroup.add("statictext{alignment: ['left','top'], text: '"+thisObj.texts.setSp+"'}").setFG([1,1,1]);
var lineFour = twoDmodeGroup.add("group{orientation:'row', alignment: ['fill','top']}").setIcon(thisObj.iconsFiles[3]).setTip(thisObj.texts.tips.xSpacing);
var xSlider = lineFour.add ("slider", undefined, thisObj.xSpacing, 0, 1000);
xSlider.size = 'width: 150, height: 10';
var xEdit = lineFour.add("editText{alignment: ['right', 'center'], size: [30,20], justify: 'center'}", undefined, 50);
xEdit.text = Math.floor(xSlider.value);
var lineFive = twoDmodeGroup.add("group{orientation:'row',alignment:['fill','top']}").setIcon(thisObj.iconsFiles[4]).setTip(thisObj.texts.tips.ySpacing);
var ySlider = lineFive.add ("slider", undefined, thisObj.ySpacing, 0, 1000);
ySlider.size = 'width: 150, height: 10';
var yEdit = lineFive.add ("editText{alignment: ['right', 'center'], size: [30,20], justify: 'center'}");
yEdit.text = Math.floor(ySlider.value);
var lineThree = twoDmodeGroup.add("group{orientation:'row'}");
var sqGridChckbx = lineThree.add("checkbox", undefined, thisObj.texts.square).setTip(thisObj.texts.tips.sqGrid).setFG([1,1,1]);
sqGridChckbx.preferredSize = [85,20]
sqGridChckbx.value = parseInt(thisObj.sqGrid);
//==================================
//3D Mode
//==================================
var threeDmodeGroup = mainGroup.add("group{orientation:'column',alignment:['left','top'],alignChildren:['left','top']}");
threeDmodeGroup.visible = false;
threeDmodeGroup.add("staticText", undefined, thisObj.texts.gridStepText).setFG([1,1,1]);
var lineOne3d = threeDmodeGroup.add("group{orientation:'row',alignment:['left','top']}");
var colsBttn3d = lineOne3d.add("group{margins: 4, alignment: ['left', 'center']}").setIcon(thisObj.iconsFiles[0]).setTip(thisObj.texts.tips.col);
var colsSlider3d = lineOne3d.add("slider", undefined, thisObj.numCols, 1, 15);
colsSlider3d.size = 'width: 100, height: 10';
var colsEdit3d = lineOne3d.add("editText{alignment: ['right', 'center'], size: [25,20], justify: 'center'}");
colsEdit3d.text = colsSlider3d.value;
var planeSelect = lineOne3d.add("dropdownlist", undefined, ["XY", "XZ", "YZ"]).setTip(thisObj.texts.tips.plane);
planeSelect.selection = thisObj.planeSelect;
var line3D = threeDmodeGroup.add("group{orientation:'row',alignment:['fill','top']}");
var rowsBttn3d = line3D.add("group { margins: 4, alignment: ['left', 'center']}").setIcon(thisObj.iconsFiles[1]).setTip(thisObj.texts.tips.row);
var rowsSlider3d = line3D.add("slider", undefined, thisObj.numRows, 1, 15);
rowsSlider3d.size = 'width: 100, height: 10';
var rowsEdit3d = line3D.add("editText{alignment: ['left', 'center'], size: [25,20], justify: 'center'}");
rowsEdit3d.text = rowsSlider3d.value;
threeDmodeGroup.add("statictext{alignment: ['left','top'], text: '"+thisObj.texts.setSp+"'}").setFG([1,1,1]);
var lineFour3d = threeDmodeGroup.add("group{orientation:'row', alignment: ['fill','top']}").setTip(thisObj.texts.tips.xSpacing);
lineFour3d.add("group{margins: 4, alignment: ['left', 'center']}").add("statictext", undefined, "X")
var xSlider3d = lineFour3d.add ("slider", undefined, thisObj.xSpacing, 0, 1000);
xSlider3d.size = 'width: 40, height: 10';
var xEdit3d = lineFour3d.add("editText{alignment: ['left', 'center'], size: [30,20], justify: 'center'}", undefined, 50);
xEdit3d.text = Math.floor(xSlider3d.value);
lineFour3d.add("group{margins: 4, alignment: ['left', 'center']}").add("statictext", undefined, "Y")
var ySlider3d = lineFour3d.add ("slider", undefined, thisObj.ySpacing, 0, 1000);
ySlider3d.size = 'width: 40, height: 10';
var yEdit3d = lineFour3d.add ("editText{alignment: ['left', 'center'], size: [30,20], justify: 'center'}");
yEdit3d.text = Math.floor(ySlider3d.value);
var lineFive3d = threeDmodeGroup.add("group{orientation:'row',alignment:['fill','top']}")
lineFive3d.add("group{margins: 4, alignment: ['left', 'center']}").add("statictext", undefined, "Z").setTip(thisObj.texts.tips.zSpacing);
var zSlider = lineFive3d.add ("slider", undefined, thisObj.ySpacing, 0, 1000);
zSlider.size = 'width: 40, height: 10';
var zEdit = lineFive3d.add ("editText{alignment: ['left', 'center'], size: [30,20], justify: 'center'}");
zEdit.text = Math.floor(zSlider.value);
var lineThree3d = threeDmodeGroup.add("group{orientation:'row',alignment:['left','top']}");
var sqGridChckbx3d = lineThree3d.add("checkbox", undefined, thisObj.texts.square).setTip(thisObj.texts.tips.sqGrid).setFG([1,1,1]);
sqGridChckbx3d.preferredSize = [85,20]
sqGridChckbx3d.value = parseInt(thisObj.sqGrid);
//==================================
//Circular mode
//==================================
var circModeGroup = mainGroup.add("group{orientation:'column',alignment:['left','top'],alignChildren:['left','top']}").setFG([1,1,1]);
circModeGroup.visible = false;
circModeGroup.add("staticText", undefined, thisObj.texts.circModeHeader).setFG([1,1,1]);
var lineOneCirc = circModeGroup.add("group{orientation:'row'}");
var radiusBttn = lineOneCirc.add("group{margins: 4, alignment: ['left', 'center'], alignChildren:['left', 'top']}").setIcon(thisObj.iconsFiles[13]).setTip(thisObj.texts.tips.radius);
var radiusSlider = lineOneCirc.add("slider", undefined, thisObj.radius, 0, 1000);
radiusSlider.size = 'width: 150, height: 10';
var radiusEdit = lineOneCirc.add("editText{size: [25,20], justify: 'center'}");
radiusEdit.text = radiusSlider.value;
var lineTwoCirc = circModeGroup.add("group{orientation:'row',alignment:['fill','top'], alignChildren:['left', 'top']}");
var angleButton = lineTwoCirc.add("group { margins: 4}").setIcon(thisObj.iconsFiles[10]).setTip(thisObj.texts.tips.angle);
var angleSlider = lineTwoCirc.add("slider", undefined, thisObj.angle, -359, 359);
angleSlider.size = 'width: 150, height: 10';
var angleEdit = lineTwoCirc.add("editText{size: [25,20], justify: 'center'}");
angleEdit.text = angleSlider.value;
circModeGroup.add("staticText", undefined, thisObj.texts.rotateAll).setFG([1,1,1]);
var lineThreeCirc = circModeGroup.add("group{orientation:'row',alignment:['fill','top'], alignChildren:['left', 'top']}");
var rotateBttn = lineThreeCirc.add("group{margins: 4, alignment: ['left', 'center'], alignChildren:['left', 'top']}").setIcon(thisObj.iconsFiles[10]).setTip(thisObj.texts.tips.rotateAll);
var rotateSlider = lineThreeCirc.add("slider", undefined, thisObj.rotateAll, -359, 359);
rotateSlider.size = 'width: 150, height: 10';
var rotateEdit = lineThreeCirc.add("editText{size: [25,20], justify: 'center'}");
rotateEdit.text = rotateSlider.value;
circModeGroup.add("staticText", undefined, thisObj.texts.spiralText).setFG([1,1,1]);
var lineFourCirc = circModeGroup.add("group{orientation:'row',alignment:['fill','top'], alignChildren:['left', 'top']}");
var spiralBttn = lineFourCirc.add("group{margins: 4, alignment: ['left', 'center'], alignChildren:['left', 'top']}").setIcon(thisObj.iconsFiles[11]).setTip(thisObj.texts.tips.spiral);
spiralBttn.setState(false);
var spiralSlider = lineFourCirc.add("slider", undefined, thisObj.spiral, 0, 50);
spiralSlider.size = 'width: 127, height: 10';
var spiralEdit = lineFourCirc.add("editText{size: [25,20], justify: 'center'}");
spiralEdit.text = spiralSlider.value;
var spiralReverse = lineFourCirc.add("checkbox", undefined, "").setTip(thisObj.texts.tips.spiralReverse);
spiralReverse.value = false;
thisObj.spiralReverse = false;
//==================================
//Expression panel
//==================================
var exprPanel = thisObj.w.add("panel{text: 'Expressions', justify: 'center', alignment:['fill','top'], properties:{borderStyle: 'black'}}").setFG([1,1,1]);
exprPanel.margins = [10,20,10,10];
var lineSix = exprPanel.add("group{orientation:'row', alignChildren:['left', 'top']}");
var createExpr = lineSix.add("button", undefined, "Create");
var bakeExpr = lineSix.add("button", undefined, "Bake");
//==================================
//Modes panel
//==================================
var lineSeven = thisObj.w.add("group{orientation:'row', alignChildren:['left', 'top']}");
var modesPanel = lineSeven.add("panel{text: 'Grid Mode', justify: 'center', alignment:['fill','top'], properties:{borderStyle: 'black'}}").setFG([1,1,1]);
modesPanel.margins = [10,15,10,10];
var modesGroup = modesPanel.add("group{orientation:'row', alignChildren:['left', 'top']}");
var rectModeBttn = modesGroup.add("group { margins: 4, alignment: ['left', 'center']}").setIcon(thisObj.iconsFiles[5]).setTip(thisObj.texts.tips.rect);
if(thisObj.gridMode == "RECT") rectModeBttn.setState(true);
var threeDModeBttn = modesGroup.add("group { margins: 4, alignment: ['left', 'center']}").setIcon(thisObj.iconsFiles[6]).setTip(thisObj.texts.tips.threeD);
if(thisObj.gridMode == "3D") threeDModeBttn.setState(true);
var circModeBttn = modesGroup.add("group { margins: 4, alignment: ['left', 'center']}").setIcon(thisObj.iconsFiles[7]).setTip(thisObj.texts.tips.circ);
if(thisObj.gridMode == "CIRC") circModeBttn.setState(true);
//==================================
//Options panel
//==================================
var optionPanel = lineSeven.add("panel{text: 'Utils', justify: 'center', alignment:['fill','top'], properties:{borderStyle: 'black'}}").setFG([1,1,1]);
optionPanel.margins = [10,15,10,10];
var optionGroup = optionPanel.add("group{orientation:'row', alignChildren:['left', 'top']}");
var duplicatorBttn = optionGroup.add("group { margins: 4, alignment: ['left', 'center']}").setIcon(thisObj.iconsFiles[8]).setTip(thisObj.texts.tips.duplicator);
duplicatorBttn.setState(thisObj.duplicator);
var gridOverlayBttn = optionGroup.add("group { margins: 4, alignment: ['left', 'center']}").setIcon(thisObj.iconsFiles[9]).setTip(thisObj.texts.tips.gridOverlay);
gridOverlayBttn.setState(false);
//==================================
//Defining callbacks for buttons
//==================================
gridOverlayBttn.addEventListener("mousedown", function(k){
if(k.button == 0){
gridOverlayBttn.setState(true);
}
});
gridOverlayBttn.addEventListener("mouseup", function(k){
if(k.button == 0){
gridOverlayBttn.setState(false);
createGridOverlay(thisObj);
updateGridOverlay(thisObj);
}
});
duplicatorBttn.addEventListener("click", function(k){
//clicking images
if(k.button == 0){
thisObj.duplicator =! thisObj.duplicator;
duplicatorBttn.setState(thisObj.duplicator);
}
});
spiralReverse.onClick = function (){
thisObj.spiralReverse =! thisObj.spiralReverse;
doGrid();
}
createExpr.onClick = function(){
updateSliders();
updateSpacingStates();
createExpressions(thisObj);
}
bakeExpr.onClick = function(){
bakeExpressions(thisObj);
}
sqGridChckbx.onClick = function(){
yEdit.text = xEdit.text;
updateSliders();
doGrid();
}
sqGridChckbx3d.onClick = function(){
yEdit3d.text = xEdit3d.text;
zEdit.text = xEdit3d.text;
updateSliders();
doGrid();
}
colsBttn.addEventListener("click", function(k){
//clicking images
if(k.button == 0){
thisObj.onlyCols =!thisObj.onlyCols; //change clicked state
setRowCol(colsBttn); //update radiobutton states
doGrid();
}
});
rowsBttn.addEventListener("click", function(k){
//clicking images
if(k.button == 0){
thisObj.onlyRows =!thisObj.onlyRows; //change clicked state
setRowCol(rowsBttn); //update radiobutton states
doGrid();
}
});
rectModeBttn.addEventListener("click", function(k){
//setting 2D grid mode
if(k.button == 0){
thisObj.gridMode = "RECT"
updateModes();
doGrid();
}
});
threeDModeBttn.addEventListener("click", function(k){
//setting 3D grid mode
if(k.button == 0){
thisObj.gridMode = "3D"
updateModes();
doGrid();
}
});
circModeBttn.addEventListener("click", function(k){
//setting circular grid mode
if(k.button == 0){
thisObj.gridMode = "CIRC"
updateModes();
doGrid();
}
});
function updateModes(){
if(thisObj.gridMode == "RECT"){
rectModeBttn.setState(true);
threeDModeBttn.setState(false);
circModeBttn.setState(false);
twoDmodeGroup.visible = true;
threeDmodeGroup.visible = false;
circModeGroup.visible = false;
optionPanel.enabled = true;
duplicatorBttn.enabled = true;
gridOverlayBttn.enabled = true;
}
else if(thisObj.gridMode == "3D"){
twoDmodeGroup.visible = false;
threeDmodeGroup.visible = true;
circModeGroup.visible = false;
rectModeBttn.setState(false);
threeDModeBttn.setState(true);
circModeBttn.setState(false);
optionPanel.enabled = false;
duplicatorBttn.enabled = false;
gridOverlayBttn.enabled = false;
}
else{
twoDmodeGroup.visible = false;
threeDmodeGroup.visible = false;
circModeGroup.visible = true;
rectModeBttn.setState(false);
threeDModeBttn.setState(false);
circModeBttn.setState(true);
optionPanel.enabled = false;
duplicatorBttn.enabled = false;
gridOverlayBttn.enabled = false;
}
}
planeSelect.onChange = function(){
thisObj.planeSelect = planeSelect.selection.index;
doGrid();
}
function setRowCol(caller){
//Main function for custom radiobuttons work.
if(thisObj.onlyCols == true && thisObj.onlyRows == true){
if(caller == rowsBttn){
thisObj.onlyCols = false;
thisObj.onlyRows = true;
}
else if(caller == colsBttn){
thisObj.onlyCols = true;
thisObj.onlyRows = false;
}
else{
thisObj.onlyCols = false;
thisObj.onlyRows = false;
}
}
//set enabled/disabled state
rowsEdit.enabled =!thisObj.onlyCols;
rowsSlider.enabled =!thisObj.onlyCols;
colsEdit.enabled =!thisObj.onlyRows;
colsSlider.enabled =!thisObj.onlyRows;
colsBttn.setState(thisObj.onlyCols);
rowsBttn.setState(thisObj.onlyRows);
}
//set radiobuttons' states
setRowCol();
//==================================
//Callbacks for sliders and fields
//==================================
var editFields = [colsEdit, colsEdit3d, rowsEdit, rowsEdit3d, radiusEdit, angleEdit, spiralEdit, rotateEdit, xEdit, xEdit3d, yEdit, yEdit3d, zEdit];
var sliders = [colsSlider, colsSlider3d, rowsSlider, rowsSlider3d, radiusSlider, angleSlider, spiralSlider, rotateSlider, xSlider, xSlider3d, ySlider, ySlider3d, zSlider];
for(var i = 0; i < editFields.length; i++){
editFields[i].onChange = function(){updateFields()};
editFields[i].onEnterKey = function(){updateFields()};
sliders[i].boundField = editFields[i];
if(i<8){
//set first 8 sliders
sliders[i].onChanging = function(){
this.boundField.text = parseInt(this.value);
doGrid();
}
}
}
xSlider.onChanging = function () {
this.boundField.text = parseInt(this.value);
if(sqGridChckbx.value == 1){
ySlider.value = xSlider.value;
yEdit.text = parseInt(ySlider.value);
}
doGrid();
}
ySlider.onChanging = function () {
this.boundField.text = parseInt(this.value);
if(sqGridChckbx.value == 1){
xSlider.value = ySlider.value;
xEdit.text = parseInt(ySlider.value);
}
doGrid();
}
xSlider3d.onChanging = function () {
this.boundField.text = parseInt(this.value);
if(sqGridChckbx3d.value == 1){
ySlider3d.value = this.value;
ySlider3d.boundField.text = parseInt(ySlider3d.value);
zSlider.value = this.value;
zSlider.boundField.text = parseInt(zSlider.value);
}
doGrid();
}
ySlider3d.onChanging = function () {
this.boundField.text = parseInt(this.value);
if(sqGridChckbx3d.value == 1){
xSlider3d.value = this.value;
xSlider3d.boundField.text = parseInt(this.value);
zSlider.value = this.value;
zSlider.boundField.text = parseInt(zSlider.value);
}
doGrid();
}
zSlider.onChanging = function () {
this.boundField.text = parseInt(this.value);
if(sqGridChckbx3d.value == 1){
xSlider3d.value = this.value;
xSlider3d.boundField.text = parseInt(this.value);
ySlider3d.value = this.value;
ySlider3d.boundField.text = parseInt(ySlider3d.value);
}
doGrid();
}
//==================================
//Service update functions
//==================================
function updateFields(){
//function to update text fields
updateSliders();
doGrid();
}
function updateSliders(){
for (var i = 0; i < editFields.length; i++) {
if(isNaN(Number(editFields[i].text))) sliders[i].value = 1;
else sliders[i].value = parseInt(editFields[i].text);
};
}
function updateSpacingStates(){
//function to update variables according to sliders/editTexts
if(thisObj.gridMode=="RECT"){
if(sqGridChckbx.value == 1){
thisObj.ySpacing = xSlider.value;
thisObj.xSpacing = xSlider.value;
dist = xSlider.value*[1,1];
}
else{
thisObj.xSpacing = xSlider.value;
thisObj.ySpacing = ySlider.value;
dist = [xSlider.value, ySlider.value]
}
thisObj.sqGrid = sqGridChckbx.value;
thisObj.numRows = Number(rowsEdit.text);
thisObj.numCols = Number(colsEdit.text);
}
else if(thisObj.gridMode == "3D"){
if(sqGridChckbx3d.value == 1){
thisObj.xSpacing = xSlider3d.value;
thisObj.ySpacing = xSlider3d.value;
thisObj.zSpacing = xSlider3d.value;
dist3d = thisObj.xSpacing*[1,1,1];
}
else{
thisObj.xSpacing = xSlider3d.value;
thisObj.ySpacing = ySlider3d.value;
thisObj.zSpacing = zSlider.value;
dist3d = [thisObj.xSpacing,thisObj.ySpacing,thisObj.zSpacing];
}
thisObj.sqGrid = sqGridChckbx3d.value;
thisObj.numRows = Number(rowsEdit3d.text);
thisObj.numCols = Number(colsEdit3d.text);
}
else if(thisObj.gridMode == "CIRC"){
thisObj.radius = Number(radiusEdit.text);
thisObj.angle = Number(angleEdit.text)*Math.PI/180;
thisObj.spiral = Number(spiralEdit.text);
thisObj.rotateAll = Number(rotateEdit.text)*Math.PI/180;
}
}
function doGrid(){
updateSpacingStates();
setPrefs(thisObj);
if(thisObj.gridMode == "RECT") make2DGrid(thisObj);
else if(thisObj.gridMode == "3D") make3DGrid(thisObj);
else if(thisObj.gridMode == "CIRC") makeCircGrid(thisObj);
}
updateModes();
if (thisObj.w instanceof Window){
thisObj.w.center();
thisObj.w.show();
}
else thisObj.w.layout.layout(true);
}
//==================================
//Create expressions
//==================================
function createExpressions(thisObj){
var activeComp = app.project.activeItem;
if(activeComp){
app.beginUndoGroup("Creating expressions");
var selLayers = activeComp.selectedLayers;
if(selLayers.length>1){
// sort layers ascending so index 1 is on top
selLayers.sort(function(a,b){
return (a.index - b.index);
});
//======================
//Rectangle mode
//======================
if(thisObj.gridMode == "RECT"){
var nullExists = false
for(var i = 1; i<=activeComp.layers.length;i++){
if(activeComp.layers[i].name == thisObj.texts.nullControlName){
var nullControl = activeComp.layers[i];
nullExists = true;
}
}
if(nullExists == false){
thisObj.nullControl = activeComp.layers.addNull(activeComp.duration)
thisObj.nullControl.label = 11;
thisObj.nullControl.moveBefore(selLayers[0]);
thisObj.nullControl.name = thisObj.texts.nullControlName;
var stepXControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
stepXControl.name = "Colums";
var stepYControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
stepYControl.name = "Rows";
var onlyColsControl = thisObj.nullControl("Effects").addProperty("ADBE Checkbox Control");
onlyColsControl.name = "Only Columns";
var onlyRowsControl = thisObj.nullControl("Effects").addProperty("ADBE Checkbox Control");
onlyRowsControl.name = "Only Rows";
var spacingXControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
spacingXControl.name = "Spacing X";
var spacingYControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
spacingYControl.name = "Spacing Y";
var sqGridControl = thisObj.nullControl("Effects").addProperty("ADBE Checkbox Control");
sqGridControl.name = "Square Grid";
var colorControl = thisObj.nullControl("Effects").addProperty("ADBE Color Control");
colorControl.name = thisObj.texts.colorControlName;
colorControl(1).setValue([0,1,1]);
var gridThicknessControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
gridThicknessControl.name = thisObj.texts.gridThicknessName;
gridThicknessControl(1).setValue(1);
//set expresions
thisObj.nullControl.effect(1).slider.expression = "if(value==0) value = 1 else value"
thisObj.nullControl.effect(2).slider.expression = "if(value==0) value = 1 else value"
thisObj.nullControl.effect(3).checkbox.expression = "if(effect(4)(1) == true) false else value"
thisObj.nullControl.effect(4).checkbox.expression = "if(effect(3)(1) == true) false else value"
thisObj.nullControl.effect(6).slider.expression = "if(effect(7)(1) == true) effect(5)(1) else value";
}
//set slider values
thisObj.nullControl.effect(1).slider.setValue(thisObj.numCols);
thisObj.nullControl.effect(2).slider.setValue(thisObj.numRows);
thisObj.nullControl.effect(3).checkbox.setValue(thisObj.onlyCols)
thisObj.nullControl.effect(4).checkbox.setValue(thisObj.onlyRows)
thisObj.nullControl.effect(5).slider.setValue(thisObj.xSpacing);
thisObj.nullControl.effect(6).slider.setValue(thisObj.ySpacing);
thisObj.nullControl.effect(7).checkbox.setValue(thisObj.sqGrid);
thisObj.nullControl.transform.position.setValue([selLayers[0].transform.position.value[0],selLayers[0].transform.position.value[1]]);
for(var i = 0; i<selLayers.length; i++){
//set expressions for selected layers
selLayers[i].transform.position.expression = thisObj.expressions.pos2D;
selLayers[i].transform.rotation.expression = thisObj.expressions.rot2D;
}
}
//======================
//3D mode
//======================
else if(thisObj.gridMode == "3D"){
var nullExists = false
for(var i = 1; i<=activeComp.layers.length;i++){
if(activeComp.layers[i].name == thisObj.texts.nullControlName3D){
var nullControl = activeComp.layers[i];
nullExists = true;
}
}
if(nullExists == false){
thisObj.nullControl = activeComp.layers.addNull(activeComp.duration)
thisObj.nullControl.label = 13;
thisObj.nullControl.threeDLayer = true;
thisObj.nullControl.moveBefore(selLayers[0]);
thisObj.nullControl.name = thisObj.texts.nullControlName3D;
var stepXControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
stepXControl.name = "Colums";
var stepYControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
stepYControl.name = "Rows";
var XYChckbx = thisObj.nullControl("Effects").addProperty("ADBE Checkbox Control");
XYChckbx.name = "XY";
var XZChckbx = thisObj.nullControl("Effects").addProperty("ADBE Checkbox Control");
XZChckbx.name = "XZ";
var YZChckbx = thisObj.nullControl("Effects").addProperty("ADBE Checkbox Control");
YZChckbx.name = "YZ";
var spacingXControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
spacingXControl.name = "Spacing X";
var spacingYControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
spacingYControl.name = "Spacing Y";
var spacingZControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
spacingZControl.name = "Spacing Z";
var sqGridControl = thisObj.nullControl("Effects").addProperty("ADBE Checkbox Control");
sqGridControl.name = "Square Grid";
//set expresions
thisObj.nullControl.effect(1).slider.expression = "if(value==0) value = 1 else value";
thisObj.nullControl.effect(2).slider.expression = "if(value==0) value = 1 else value";
thisObj.nullControl.effect(3).checkbox.expression = "if(effect(4)(1) == true) false else value";
thisObj.nullControl.effect(4).checkbox.expression = "if(effect(3)(1) == true) false else value";
thisObj.nullControl.effect(5).checkbox.expression = "if(effect(3)(1) == true) false else value";
thisObj.nullControl.effect(7).slider.expression = "if(effect(9)(1) == true) effect(6)(1) else value";
thisObj.nullControl.effect(8).slider.expression = "if(effect(9)(1) == true) effect(6)(1) else value";
}
//set slider values
thisObj.nullControl.effect(1).slider.setValue(thisObj.numCols);
thisObj.nullControl.effect(2).slider.setValue(thisObj.numRows);
for(var i = 0; i <= 2; i++){
if(thisObj.planeSelect == i){
thisObj.nullControl.effect(3+i).checkbox.setValue(true);
}
else thisObj.nullControl.effect(3+i).checkbox.setValue(false);
}
thisObj.nullControl.effect(6).slider.setValue(thisObj.xSpacing);
thisObj.nullControl.effect(7).slider.setValue(thisObj.ySpacing);
thisObj.nullControl.effect(8).slider.setValue(thisObj.zSpacing);
thisObj.nullControl.effect(9).checkbox.setValue(thisObj.sqGrid);
thisObj.nullControl.transform.position.setValue([selLayers[0].transform.position.value[0],selLayers[0].transform.position.value[1]]);
for(var i = 0; i<selLayers.length; i++){
//set expressions for selected layers
selLayers[i].position.expression = thisObj.expressions.pos3D;
selLayers[i].orientation.expression = thisObj.expressions.rot3D;
}
}
//======================
//Circular mode
//======================
else if(thisObj.gridMode == "CIRC"){
var nullExists = false
for(var i = 1; i<=activeComp.layers.length;i++){
if(activeComp.layers[i].name == thisObj.texts.nullControlNameCirc){
var nullControl = activeComp.layers[i];
nullExists = true;
}
}
if(nullExists == false){
thisObj.nullControl = activeComp.layers.addNull(activeComp.duration)
thisObj.nullControl.label = 12;
thisObj.nullControl.moveBefore(selLayers[0]);
thisObj.nullControl.name = thisObj.texts.nullControlNameCirc;
var radiusControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
radiusControl.name = "Radius";
var angleControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
angleControl.name = "Angle";
var spiralControl = thisObj.nullControl("Effects").addProperty("ADBE Slider Control");
spiralControl.name = "Spiral";
var spiralChckBx = thisObj.nullControl("Effects").addProperty("ADBE Checkbox Control");
spiralChckBx.name = "Reverse Spiral";
}
//set slider values
thisObj.nullControl.effect(1).slider.setValue(thisObj.radius);