-
Notifications
You must be signed in to change notification settings - Fork 14
/
spReticleLoc.cpp
3055 lines (2571 loc) · 107 KB
/
spReticleLoc.cpp
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
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2009, Sony Pictures Imageworks
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution. Neither the name of Sony Pictures Imageworks nor the
// names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////
/*
* @file spReticleLoc.cpp
* This plug-in creates a custom locator to display a customizable reticle.
* The reticle has the ability to display any number of aspect ratios as
* well as pan-and-scan, projection masks, filmback data, etc. The look of
* the reticle is customizable in regards to color and transparency for
* masks, lines and text.There is also an option to specify whether the
* reticle should respect the show/hide locator display options. Finally,
* the reticle can be filtered to only display on cameras which contain
* an attribute (see defines.h) set to true or are connected to the reticle.
*/
#include "defines.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <maya/MPxLocatorNode.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MColor.h>
#include <maya/M3dView.h>
#include <maya/MFnPlugin.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnEnumAttribute.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MIOStream.h>
#include <maya/MDagPath.h>
#include <maya/MFnCamera.h>
#include <maya/MVector.h>
#include <maya/MMatrix.h>
#include <maya/MFnMatrixData.h>
#include <maya/MFnStringData.h>
#include <maya/MTime.h>
#include <maya/MGlobal.h>
#include <maya/MFileIO.h>
#include <maya/MFileObject.h>
#include <maya/MFnMessageAttribute.h>
#if (MAYA_API_VERSION>=201200)
// Viewport 2.0 includes
#include <maya/MDrawRegistry.h>
#include <maya/MPxDrawOverride.h>
#include <maya/MUserData.h>
#include <maya/MDrawContext.h>
#include <maya/MGlobal.h>
#include <maya/MSelectionList.h>
#endif
#include "spReticleLoc.h"
#define McheckStatus(stat,msg) \
if (!stat) { \
stat.perror(msg); \
return stat; \
}
#define McheckVoid(stat,msg) \
if (!stat) { \
stat.perror(msg); \
return; \
}
MTypeId spReticleLoc::id( 0x00000502 );
#if (MAYA_API_VERSION>=201200)
MString spReticleLoc::drawDbClassification("drawdb/geometry/spReticleLoc");
MString spReticleLoc::drawRegistrantId("spReticleLoc");
#endif
MObject spReticleLoc::DrawingEnabled;
MObject spReticleLoc::EnableTextDrawing;
MObject spReticleLoc::FilmbackAperture;
MObject spReticleLoc::HorizontalFilmAperture;
MObject spReticleLoc::VerticalFilmAperture;
MObject spReticleLoc::RelativeFilmback;
MObject spReticleLoc::SoundTrackWidth;
MObject spReticleLoc::DisplayFilmGate;
MObject spReticleLoc::ProjectionGate;
MObject spReticleLoc::HorizontalProjectionGate;
MObject spReticleLoc::VerticalProjectionGate;
MObject spReticleLoc::DisplayProjectionGate;
MObject spReticleLoc::SafeAction;
MObject spReticleLoc::HorizontalSafeAction;
MObject spReticleLoc::VerticalSafeAction;
MObject spReticleLoc::DisplaySafeAction;
MObject spReticleLoc::SafeTitle;
MObject spReticleLoc::HorizontalSafeTitle;
MObject spReticleLoc::VerticalSafeTitle;
MObject spReticleLoc::DisplaySafeTitle;
MObject spReticleLoc::AspectRatios;
MObject spReticleLoc::AspectRatio;
MObject spReticleLoc::DisplayMode;
MObject spReticleLoc::AspectMaskColor;
MObject spReticleLoc::AspectMaskTrans;
MObject spReticleLoc::AspectLineColor;
MObject spReticleLoc::AspectLineTrans;
MObject spReticleLoc::AspectDisplaySafeAction;
MObject spReticleLoc::AspectDisplaySafeTitle;
MObject spReticleLoc::PanScanAttr;
MObject spReticleLoc::PanScanAspectRatio;
MObject spReticleLoc::PanScanDisplayMode;
MObject spReticleLoc::PanScanDisplaySafeTitle;
MObject spReticleLoc::PanScanDisplaySafeAction;
MObject spReticleLoc::PanScanRatio;
MObject spReticleLoc::PanScanOffset;
MObject spReticleLoc::PanScanMaskColor;
MObject spReticleLoc::PanScanMaskTrans;
MObject spReticleLoc::PanScanLineColor;
MObject spReticleLoc::PanScanLineTrans;
MObject spReticleLoc::FilmGateMaskColor;
MObject spReticleLoc::FilmGateMaskTrans;
MObject spReticleLoc::FilmGateLineColor;
MObject spReticleLoc::FilmGateLineTrans;
MObject spReticleLoc::ProjGateMaskColor;
MObject spReticleLoc::ProjGateMaskTrans;
MObject spReticleLoc::ProjGateLineColor;
MObject spReticleLoc::ProjGateLineTrans;
MObject spReticleLoc::HideLocator;
// Deprecating this attribute in favor of CameraFilterMode, using an alias temporarily
//MObject spReticleLoc::UseSpReticle;
MObject spReticleLoc::CameraFilterMode;
MObject spReticleLoc::Cameras;
MObject spReticleLoc::DisplayLineH;
MObject spReticleLoc::DisplayLineV;
MObject spReticleLoc::DisplayThirdsH;
MObject spReticleLoc::DisplayThirdsV;
MObject spReticleLoc::DisplayCrosshair;
MObject spReticleLoc::DisplayFieldGuide;
MObject spReticleLoc::MiscTextColor;
MObject spReticleLoc::MiscTextTrans;
MObject spReticleLoc::LineColor;
MObject spReticleLoc::LineTrans;
MObject spReticleLoc::Time;
MObject spReticleLoc::DriveCameraAperture;
MObject spReticleLoc::MaximumDistance;
MObject spReticleLoc::UseOverscan;
MObject spReticleLoc::Pad;
MObject spReticleLoc::UsePad;
MObject spReticleLoc::PadAmount;
MObject spReticleLoc::PadAmountX;
MObject spReticleLoc::PadAmountY;
MObject spReticleLoc::PadDisplayMode;
MObject spReticleLoc::PadMaskColor;
MObject spReticleLoc::PadMaskTrans;
MObject spReticleLoc::PadLineColor;
MObject spReticleLoc::PadLineTrans;
MObject spReticleLoc::Text;
MObject spReticleLoc::TextType;
MObject spReticleLoc::TextStr;
MObject spReticleLoc::TextAlign;
MObject spReticleLoc::TextVAlign;
MObject spReticleLoc::TextPos;
MObject spReticleLoc::TextPosX;
MObject spReticleLoc::TextPosY;
MObject spReticleLoc::TextPosRel;
MObject spReticleLoc::TextLevel;
MObject spReticleLoc::TextARLevel;
MObject spReticleLoc::TextColor;
MObject spReticleLoc::TextTrans;
MObject spReticleLoc::TextEnabled;
MObject spReticleLoc::TextBold;
MObject spReticleLoc::TextSize;
MObject spReticleLoc::TextScale;
MObject spReticleLoc::Tag;
spReticleLoc::spReticleLoc() {}
spReticleLoc::~spReticleLoc() {}
// Make a huge bounding box
//
/*
MBoundingBox spReticleLoc::boundingBox() const
{
return MBoundingBox(MPoint(-1000000,-1000000,-1000000),
MPoint(1000000,1000000,1000000));
}
*/
// This method will retrieve the individual r,g,b and alpha values from
// various plugs and store them in an MColor object.
//
MStatus spReticleLoc::getColor(MObject colorObj, MObject transObj, MColor & color)
{
MPlug p,c;
MStatus stat;
p = MPlug( thisNode, colorObj );
// Get red
c = p.child(0, &stat);
McheckStatus (stat, ("spReticleLoc::getColor getting red plug from "+p.name() ) );
McheckStatus ( c.getValue ( color.r ), ("spReticleLoc::getColor getting red from "+p.name() ) );
// Get green
c = p.child(1,&stat);
McheckStatus (stat, ("spReticleLoc::getColor getting green plug from "+p.name() ) );
McheckStatus ( c.getValue ( color.g ), ("spReticleLoc::getColor getting green from "+p.name() ) );
// Get blue
c = p.child(2, &stat);
McheckStatus (stat, ("spReticleLoc::getColor getting blue plug from "+p.name() ) );
McheckStatus ( c.getValue ( color.b ), ("spReticleLoc::getColor getting blue from "+p.name() ) );
p = MPlug( thisNode, transObj );
McheckStatus ( p.getValue ( color.a ), ("spReticleLoc::getColor gettings transparency from "+p.name() ) );
return MS::kSuccess;
}
//This method returns the specified matrix.
//
MMatrix spReticleLoc::getMatrix(MString matrixStr)
{
MStatus stat;
MMatrix matrix;
// Extract the matrix attribute that is inherited from 'dagNode'
MFnDependencyNode fnThisNode( thisNode );
MObject matrixAttribute = fnThisNode.attribute( matrixStr, &stat );
if (!stat)
{
stat.perror("spReticleLoc::getMatrix getting attribute : "+matrixStr);
return matrix.identity;
}
MPlug matrixPlug( thisNode, matrixAttribute);
if (matrixPlug.isNull())
{
stat.perror("spReticleLoc::getting plug for attribute : "+matrixStr);
return matrix.identity;
}
// If matrix is an array so we must specify which element the plug refers to
if (matrixPlug.isArray())
{
matrixPlug = matrixPlug.elementByLogicalIndex (0, &stat);
if (!stat)
{
stat.perror("spReticleLoc::getMatrix setting logical index to 0 for "+matrixStr);
return matrix.identity;
}
}
// Get the value of the matrix attribute
MObject matObject;
stat = matrixPlug.getValue(matObject);
if (!stat)
{
stat.perror("spReticleLoc::getMatrix getting value for "+matrixStr);
return matrix.identity;
}
MFnMatrixData matrixData(matObject, &stat);
if (!stat)
{
stat.perror("spReticleLoc::getMatrix getting MfnMatrixData");
return matrix.identity;
}
matrix = matrixData.matrix( &stat );
if (!stat)
{
stat.perror("spReticleLoc::getMatrix getting matrix");
return matrix.identity;
}
return matrix;
}
// This method outputs to cerr the attributes of an Aspect_Ratio
// class instance.
//
void spReticleLoc::printAspectRatio(Aspect_Ratio & ar)
{
cerr << "-------------------------------------------------" << endl;
cerr << "aspect ratio : " << ar.aspectRatio << endl;
cerr << "displayMode : " << ar.displayMode << endl;
cerr << "maskColor : " << ar.aspectGeom.maskColor << endl;
cerr << "lineColor : " << ar.aspectGeom.lineColor << endl;
}
// This method outputs to cerr the attributes of an PanScan class instance.
//
void spReticleLoc::printPanScan(PanScan & ps)
{
printAspectRatio( ps );
cerr << "panScanRatio : " << ps.panScanRatio << endl;
cerr << "panScanOffset : " << ps.panScanOffset << endl;
cerr << "displaySafeTitle : " << ps.displaySafeTitle << endl;
cerr << "displaySafeAction : " << ps.displaySafeAction << endl;
}
// This method outputs to cerr the attributes of an TextData class instance.
//
void spReticleLoc::printText(TextData & td)
{
cerr << "-------------------------------------------------" << endl;
cerr << "text type : " << td.textType << endl;
cerr << "text string : " << td.textStr << endl;
cerr << "text align : " << td.textAlign << endl;
cerr << "text pos : " << td.textPosX << ", " << td.textPosY << endl;
cerr << "text pos rel : " << td.textPosRel << endl;
cerr << "text level : " << td.textLevel << endl;
cerr << "text ar level : " << td.textARLevel << endl;
}
// This method outputs to cerr the attributes of an Geom class instance.
//
void spReticleLoc::printGeom(Geom & g)
{
cerr << "-------------------------------------------------" << endl;
cerr << "x : " << g.x << endl;
cerr << "y : " << g.y << endl;
cerr << "x1 : " << g.x1 << endl;
cerr << "x2 : " << g.x2 << endl;
cerr << "y1 : " << g.y1 << endl;
cerr << "y2 : " << g.y2 << endl;
cerr << "mc : " << g.maskColor << endl;
cerr << "lc : " << g.lineColor << endl;
cerr << "iv : " << g.isValid << endl;
}
// This method outputs to cerr the various options that have been specified.
//
void spReticleLoc::printOptions()
{
cerr << "-------------------------------------------------" << endl;
cerr << "cameraFilterMode : " << options.cameraFilterMode << endl;
cerr << "displayLineH : " << options.displayLineH << endl;
cerr << "displayLineV : " << options.displayLineV << endl;
cerr << "displayThirdsH : " << options.displayThirdsH << endl;
cerr << "displayThirdsV : " << options.displayThirdsV << endl;
cerr << "displayCrosshair : " << options.displayCrosshair << endl;
cerr << "displayFieldGuide : " << options.displayFieldGuide << endl;
cerr << "driveCameraAperture : " << options.driveCameraAperture << endl;
cerr << "maximumDistance : " << options.maximumDistance << endl;
cerr << "useOverscan : " << options.useOverscan << endl;
}
// This method gets the pad data.
//
MStatus spReticleLoc::getPadData()
{
MPlug p;
MStatus stat;
// Get the pad attribute;
p = MPlug ( thisNode, UsePad );
McheckStatus ( p.getValue ( pad.usePad ), "spReticleLoc::getPadData pad");
// Get the padAmountX attribute;
p = MPlug ( thisNode, PadAmountX );
McheckStatus ( p.getValue ( pad.padAmountX ), "spReticleLoc::getPadData padAmountX");
// Get the padAmountY attribute;
p = MPlug ( thisNode, PadAmountY );
McheckStatus ( p.getValue ( pad.padAmountY ), "spReticleLoc::getPadData padAmountX");
// Set whether the filmback is padded
pad.isPadded = (pad.padAmountX > EPSILON || pad.padAmountY > EPSILON );
if (pad.usePad && pad.isPadded)
{
// Get the pad display mode
p = MPlug ( thisNode, PadDisplayMode );
McheckStatus ( p.getValue ( pad.displayMode ), "spReticleLoc::getPadData padDisplayMode");
// Get the pad mask color
stat = getColor( PadMaskColor, PadMaskTrans, pad.padGeom.maskColor );
McheckStatus ( stat, "spReticleLoc::getPadData get padMaskColor");
// Get the pad line color
stat = getColor( PadLineColor, PadLineTrans, pad.padGeom.lineColor );
McheckStatus ( stat, "spReticleLoc::getPadData get padLineColor");
}
else
{
pad.padAmountX = 0;
pad.padAmountY = 0;
}
return MS::kSuccess;
}
// This method retrieves all of the data related to the filmback from
// various plugs.
//
MStatus spReticleLoc::getFilmbackData()
{
MPlug p;
MStatus stat;
//Get horizontal film aperture
p = MPlug( thisNode, HorizontalFilmAperture );
McheckStatus ( p.getValue ( filmback.horizontalFilmAperture ), "spReticleLoc::getFilmbackData get horizontalFilmAperture");
//Get vertical film aperture
p = MPlug( thisNode, VerticalFilmAperture );
McheckStatus ( p.getValue ( filmback.verticalFilmAperture ), "spReticleLoc::getFilmbackData get verticalFilmAperture");
//Get whether the film aperture is relative or absolute
p = MPlug( thisNode, RelativeFilmback );
McheckStatus ( p.getValue ( filmback.relativeFilmback ), "spReticleLoc::getFilmbackData get relativeFilmback");
//Get sound track width
p = MPlug( thisNode, SoundTrackWidth );
McheckStatus ( p.getValue ( filmback.soundTrackWidth ), "spReticleLoc::getFilmbackData get soundTrackWidth");
//Get whether to display the film gate
p = MPlug( thisNode, DisplayFilmGate );
McheckStatus ( p.getValue ( filmback.displayFilmGate ), "spReticleLoc::getFilmbackData get displayFilmGate");
//Get the filmback mask color
stat = getColor( FilmGateMaskColor, FilmGateMaskTrans, filmback.filmbackGeom.maskColor );
McheckStatus ( stat, "spReticleLoc::getFilmbackData get filmGateMaskColor");
//Get the filmback line color
stat = getColor( FilmGateLineColor, FilmGateLineTrans, filmback.filmbackGeom.lineColor );
McheckStatus ( stat, "spReticleLoc::getFilmbackData get filmGateLineColor");
return MS::kSuccess;
}
// This method retrieves all of the data related to the projection mask from
// various plugs and then calls calcProjGeom to calculate the various
// projection geometry instances.
//
MStatus spReticleLoc::getProjectionData()
{
MPlug p;
MStatus stat;
//Get whether to display the projection gate
p = MPlug( thisNode, DisplayProjectionGate );
McheckStatus ( p.getValue ( filmback.displayProjGate ), "spReticleLoc::getProjectionData get displayProjectionGate");
if ( filmback.displayProjGate )
{
//Get horizontal projection gate
p = MPlug( thisNode, HorizontalProjectionGate );
McheckStatus ( p.getValue ( filmback.horizontalProjectionGate ), "spReticleLoc::getProjectionData get horizontalProjectionGate");
//Get vertical projection gate
p = MPlug( thisNode, VerticalProjectionGate );
McheckStatus ( p.getValue ( filmback.verticalProjectionGate ), "spReticleLoc::getProjectionData get verticalProjectionGate");
//Get the projection gate mask color
stat = getColor( ProjGateMaskColor, ProjGateMaskTrans, filmback.projGeom.maskColor );
McheckStatus ( stat, "spReticleLoc::getProjectionData get projGateMaskColor");
//Get the projection gate line color
stat = getColor( ProjGateLineColor, ProjGateLineTrans, filmback.projGeom.lineColor );
McheckStatus ( stat, "spReticleLoc::getProjectionData get projGateLineColor");
}
return MS::kSuccess;
}
// This method returns the data related to the filmback's safe action area.
//
MStatus spReticleLoc::getSafeActionData()
{
MPlug p;
//Get whether to display safe action
p = MPlug( thisNode, DisplaySafeAction );
McheckStatus ( p.getValue ( filmback.displaySafeAction ), "spReticleLoc::getSafeActionData get displaySafeAction");
//Get horizontal safe action
p = MPlug( thisNode, HorizontalSafeAction );
McheckStatus ( p.getValue ( filmback.horizontalSafeAction ), "spReticleLoc::getSafeActionData get horizontalSafeAction");
//Get vertical safe action
p = MPlug( thisNode, VerticalSafeAction );
McheckStatus ( p.getValue ( filmback.verticalSafeAction ), "spReticleLoc::getSafeActionData get verticalSafeAction");
//Set the safe action line color to the filmback line color
filmback.safeActionGeom.lineColor = filmback.filmbackGeom.lineColor;
return MS::kSuccess;
}
// This method returns the data relating to the filmback's safe title area.
//
MStatus spReticleLoc::getSafeTitleData()
{
MPlug p;
//Get whether to display safe title
p = MPlug( thisNode, DisplaySafeTitle );
McheckStatus ( p.getValue ( filmback.displaySafeTitle ), "spReticleLoc::getSafeTitleData get displaySafeTitle");
//Get horizontal safe title
p = MPlug( thisNode, HorizontalSafeTitle );
McheckStatus ( p.getValue ( filmback.horizontalSafeTitle ), "spReticleLoc::getSafeTitleData get horizontalSafeTitle");
//Get vertical safe title
p = MPlug( thisNode, VerticalSafeTitle );
McheckStatus ( p.getValue ( filmback.verticalSafeTitle ), "spReticleLoc::getSafeTitleData get verticalSafeTitle");
//Set the safe title line color to the filmback line color
filmback.safeTitleGeom.lineColor = filmback.filmbackGeom.lineColor;
return MS::kSuccess;
}
// This method gets the data for a specified aspect ratio. The aspectratios
// attribute is effectively a complex compound attribute where each index
// is the data for a specific aspect ratio.
//
MStatus spReticleLoc::getAspectRatioChildren(MPlug arPlug, Aspect_Ratio & ar)
{
MStatus stat;
MPlug p, c;
p = arPlug.child( 0 , &stat );
McheckStatus( p.getValue( ar.aspectRatio ), "spReticleLoc::getAspectRatioChildren - aspectRatio" );
p = arPlug.child( 1 , &stat );
McheckStatus( p.getValue( ar.displayMode ), "spReticleLoc::getAspectRatioChildren - displayMode" );
if (ar.displayMode != 0)
{
p = arPlug.child( 2 , &stat );
c = p.child( 0, &stat );
McheckStatus( c.getValue( ar.aspectGeom.maskColor.r ), "spReticleLoc::getAspectRatioChildren - aspectMaskColorR" );
c = p.child( 1, &stat );
McheckStatus( c.getValue( ar.aspectGeom.maskColor.g ), "spReticleLoc::getAspectRatioChildren - aspectMaskColorG" );
c = p.child( 2, &stat );
McheckStatus( c.getValue( ar.aspectGeom.maskColor.b ), "spReticleLoc::getAspectRatioChildren - aspectMaskColorB" );
p = arPlug.child( 3 , &stat );
McheckStatus( p.getValue( ar.aspectGeom.maskColor.a ), "spReticleLoc::getAspectRatioChildren - aspectMaskTrans" );
p = arPlug.child( 4 , &stat );
c = p.child( 0, &stat );
McheckStatus( c.getValue( ar.aspectGeom.lineColor.r ), "spReticleLoc::getAspectRatioChildren - aspectLineColorR" );
c = p.child( 1, &stat );
McheckStatus( c.getValue( ar.aspectGeom.lineColor.g ), "spReticleLoc::getAspectRatioChildren - aspectLineColorG" );
c = p.child( 2, &stat );
McheckStatus( c.getValue( ar.aspectGeom.lineColor.b ), "spReticleLoc::getAspectRatioChildren - aspectLineColorB" );
p = arPlug.child( 5 , &stat );
McheckStatus( p.getValue( ar.aspectGeom.lineColor.a ), "spReticleLoc::getAspectRatioChildren - aspectLineTrans" );
p = arPlug.child( 6 , &stat );
McheckStatus( p.getValue( ar.displaySafeAction ), "spReticleLoc::getAspectRatioChildren - displaySafeAction" );
p = arPlug.child( 7 , &stat );
McheckStatus( p.getValue( ar.displaySafeTitle ), "spReticleLoc::getAspectRatioChildren - displaySafeTitle" );
}
return MS::kSuccess;
}
bool spReticleLoc::aspectRatioSortPredicate(const Aspect_Ratio & lhs,
const Aspect_Ratio & rhs)
{
return lhs.aspectRatio <= rhs.aspectRatio;
}
// This retrieves the data for all of the various aspect ratios.
//
MStatus spReticleLoc::getAspectRatioData()
{
// Get the aspectRatios data
MPlug arsPlug = MPlug( thisNode, AspectRatios );
int numPlugs = arsPlug.numElements();
MStatus stat;
// Clear the aspect ratio vector
ars.clear();
for (int i = 0; i < numPlugs; i++)
{
MPlug p = arsPlug.elementByPhysicalIndex( i, &stat );
McheckStatus( stat, "spReticleLoc::getAspectRatioData - cannot get index" );
Aspect_Ratio ar;
stat = getAspectRatioChildren( p, ar );
McheckStatus( stat, "spReticleLoc::getAspectRatioData - cannot get children" );
//printAspectRatio( ar );
ars.push_back( ar );
}
numAspectRatios = (int)ars.size();
// Sort aspect ratios
std::sort(ars.begin(),ars.end(),aspectRatioSortPredicate);
return MS::kSuccess;
}
bool spReticleLoc::needToUpdateAspectRatios()
{
MPlug arsPlug = MPlug( thisNode, AspectRatios );
return (ars.size() != arsPlug.numElements() );
}
// This method gets the data for a PanScan class instance.
//
MStatus spReticleLoc::getPanScanData ( PanScan & ps )
{
MPlug psPlug( thisNode, PanScanAttr );
MStatus stat = getAspectRatioChildren( psPlug, ps );
McheckStatus( stat, "spReticleLoc::getPanScanData - cannot get children" );
if (ps.displayMode != 0)
{
MPlug p;
p = psPlug.child( 8 , &stat );
McheckStatus( p.getValue( ps.panScanRatio ), "spReticleLoc::getPanScanData - panScanRatio" );
p = psPlug.child( 9 , &stat );
McheckStatus( p.getValue( ps.panScanOffset ), "spReticleLoc::getPanScanData - panScanOffset" );
}
//printPanScan( ps );
return MS::kSuccess;
}
// This method gets the data for a specified text entry. The text attribute
// is a complex compound attribute where each index is the data for a specific
// text element.
//
MStatus spReticleLoc::getTextChildren(MPlug tPlug, TextData & td)
{
MStatus stat;
MPlug p, c;
p = tPlug.child( 0 , &stat );
McheckStatus( p.getValue( td.textType ), "spReticleLoc::getTextChildren - textType" );
p = tPlug.child( 1 , &stat );
McheckStatus( p.getValue( td.textStr ), "spReticleLoc::getTextChildren - textStr" );
p = tPlug.child( 2 , &stat );
McheckStatus( p.getValue( td.textAlign ), "spReticleLoc::getTextChildren - textAlign" );
p = tPlug.child( 3 , &stat );
c = p.child( 0, &stat );
McheckStatus( c.getValue( td.textPosX ), "spReticleLoc::getTextChildren - textPosX" );
c = p.child( 1, &stat );
McheckStatus( c.getValue( td.textPosY ), "spReticleLoc::getTextChildren - textPosY" );
p = tPlug.child( 4 , &stat );
McheckStatus( p.getValue( td.textPosRel ), "spReticleLoc::getTextChildren - textPosRel" );
p = tPlug.child( 5 , &stat );
McheckStatus( p.getValue( td.textLevel ), "spReticleLoc::getTextChildren - textLevel" );
p = tPlug.child( 6 , &stat );
McheckStatus( p.getValue( td.textARLevel ), "spReticleLoc::getTextChildren - textARLevel" );
p = tPlug.child( 7 , &stat );
c = p.child( 0, &stat );
McheckStatus( c.getValue( td.textColor.r ), "spReticleLoc::getTextChildren - textColorR" );
c = p.child( 1, &stat );
McheckStatus( c.getValue( td.textColor.g ), "spReticleLoc::getTextChildren - textColorG" );
c = p.child( 2, &stat );
McheckStatus( c.getValue( td.textColor.b ), "spReticleLoc::getTextChildren - textColorB" );
p = tPlug.child( 8 , &stat );
McheckStatus( p.getValue( td.textColor.a ), "spReticleLoc::getTextChildren - textTrans" );
p = tPlug.child( 9, &stat );
McheckStatus( p.getValue( td.textEnabled ), "spReticleLoc::getTextChildren - textEnabled" );
p = tPlug.child( 10 , &stat );
McheckStatus( p.getValue( td.textBold ), "spReticleLoc::getTextChildren - textBold" );
p = tPlug.child( 11 , &stat );
McheckStatus( p.getValue( td.textSize ), "spReticleLoc::getTextChildren - textSize" );
p = tPlug.child( 12 , &stat );
McheckStatus( p.getValue( td.textScale ), "spReticleLoc::getTextChildren - textScale" );
p = tPlug.child( 13 , &stat );
McheckStatus( p.getValue( td.textVAlign ), "spReticleLoc::getTextChildren - textVAlign" );
return MS::kSuccess;
}
MStatus spReticleLoc::getTextData()
{
// Clear the text vector
text.clear();
MStatus stat;
MPlug p,tp,cp;
p = MPlug( thisNode, Text );
int numPlugs = p.numElements();
// Clamp the number of text items at 100 for now.
numPlugs = (numPlugs > 100) ? 100: numPlugs;
for (int i = 0; i < numPlugs && i < numPlugs; i++ )
{
TextData td;
tp = p.elementByPhysicalIndex( i, &stat );
McheckStatus( stat, "spReticleLoc::getTextData - cannot get index" );
stat = getTextChildren( tp, td );
McheckStatus( stat, "spReticleLoc::getTextData - cannot get children" );
//printText( td );
text.push_back( td );
}
return MS::kSuccess;
}
// This method retrieves all of the options settings.
//
MStatus spReticleLoc::getOptions()
{
MPlug p;
MStatus stat;
// Check to see if drawing is enabled
p = MPlug ( thisNode, DrawingEnabled );
McheckStatus ( p.getValue ( options.drawingEnabled ), "spReticleLoc::getOptions drawingEnabled" );
if (options.drawingEnabled)
{
// Check to see if the text should be rendered;
p = MPlug ( thisNode, EnableTextDrawing );
McheckStatus ( p.getValue( options.enableTextDrawing), "spReticleLoc::getOptions enableTextDrawing" );
// Get the camera filter mode
p = MPlug ( thisNode, CameraFilterMode );
McheckStatus ( p.getValue ( options.cameraFilterMode ), "spReticleLoc::getOptions cameraFilterMode");
// Display horizontal line option;
p = MPlug ( thisNode, DisplayLineH );
McheckStatus ( p.getValue ( options.displayLineH ), "spReticleLoc::getOptions displayLineH");
// Display vertical line option;
p = MPlug ( thisNode, DisplayLineV );
McheckStatus ( p.getValue ( options.displayLineV ), "spReticleLoc::getOptions displayLineV");
// Display horizontal thirds option;
p = MPlug ( thisNode, DisplayThirdsH );
McheckStatus ( p.getValue ( options.displayThirdsH ), "spReticleLoc::getOptions displayThirdsH");
// Display vertical thirds option;
p = MPlug ( thisNode, DisplayThirdsV );
McheckStatus ( p.getValue ( options.displayThirdsV ), "spReticleLoc::getOptions displayThirdsV");
// Display crosshair option;
p = MPlug ( thisNode, DisplayCrosshair );
McheckStatus ( p.getValue ( options.displayCrosshair ), "spReticleLoc::getOptions displayCrosshair");
// Display crosshair option;
p = MPlug ( thisNode, DisplayFieldGuide );
McheckStatus ( p.getValue ( options.displayFieldGuide ), "spReticleLoc::getOptions displayFieldGuide");
// Text Color;
stat = getColor (MiscTextColor, MiscTextTrans, options.textColor );
McheckStatus ( stat, "spReticleLoc::getOptions textColor");
// Line Color;
stat = getColor ( LineColor, LineTrans, options.lineColor );
McheckStatus ( stat, "spReticleLoc::getOptions lineColor");
// Get whether to drive a camera or not;
p = MPlug ( thisNode, DriveCameraAperture );
McheckStatus ( p.getValue ( options.driveCameraAperture ), "spReticleLoc::getOptions driveCameraAperture");
// Get the maximum distance attribute;
p = MPlug ( thisNode, MaximumDistance );
McheckStatus ( p.getValue ( options.maximumDistance ), "spReticleLoc::getOptions maximumDistance");
// Get whether to respect overscan or not;
p = MPlug ( thisNode, UseOverscan );
McheckStatus ( p.getValue ( options.useOverscan ), "spReticleLoc::getOptions useOverscan");
}
// Print the options to cerr
//printOptions();
return MS::kSuccess;
}
// This method calculates the geometry of the current window. This data is
// stored in a instance of the Geom class.
//
void spReticleLoc::calcPortGeom()
{
portGeom.x1 = 0;
portGeom.x2 = portWidth;
portGeom.y1 = 0;
portGeom.y2 = portHeight;
portGeom.x = portWidth / 2;
portGeom.y = portHeight / 2;
portGeom.isValid = true;
}
// This method calculates the geometry for the filmback. There are multiple
// Geom instances that are used for displaying all of the filmback options.
// This method takes the filmback data and calculates the appropriate settings
// for the filmback Geom instances.
//
void spReticleLoc::calcFilmbackGeom()
{
filmback = oFilmback;
// See if we are using the camera's filmback data
bool useCameraFilmback = filmback.horizontalFilmAperture < 0;
// If the horizontalFilmAperture equals -1, then use the cameras settings
if (useCameraFilmback)
{
filmback.horizontalFilmAperture = camera.horizontalFilmAperture();
filmback.verticalFilmAperture = camera.verticalFilmAperture();
}
// If drive camera aperture is on, then set camera values
else if (options.driveCameraAperture)
{
if (fabs(camera.horizontalFilmAperture() - filmback.horizontalFilmAperture) > EPSILON)
McheckVoid( camera.setHorizontalFilmAperture(filmback.horizontalFilmAperture), "spReticleLoc::calcFilmbackGeom - setting "+camera.name()+".horizontalFilmAperture");
if (fabs(camera.verticalFilmAperture() - filmback.verticalFilmAperture) > EPSILON)
McheckVoid( camera.setVerticalFilmAperture(filmback.verticalFilmAperture), "spReticleLoc::calcFilmbackGeom - setting "+camera.name()+".verticalFilmAperture");
}
// Calculate the aspect ratio of the cameras filmback
double cameraAspectRatio = camera.horizontalFilmAperture() / camera.verticalFilmAperture();
// Calculate the aspect ratio of the viewport and determine if it has a horizontal or vertical orientation
double portAspectRatio = portWidth/portHeight;
bool portHoriz = portAspectRatio > cameraAspectRatio;
MFnCamera::FilmFit filmFit = camera.filmFit();
if (filmFit == MFnCamera::kFillFilmFit)
{
if (portHoriz)
filmFit = MFnCamera::kHorizontalFilmFit;
else
filmFit = MFnCamera::kVerticalFilmFit;
}
else if (filmFit == MFnCamera::kOverscanFilmFit)
{
if (portHoriz)
filmFit = MFnCamera::kVerticalFilmFit;
else
filmFit = MFnCamera::kHorizontalFilmFit;
}
double panX = 0.0;
double panY = 0.0;
double zoom = 1.0;
#if MAYA_API_VERSION >= 201100
if (camera.panZoomEnabled() && !camera.renderPanZoom())
{
zoom = camera.zoom();
panX = camera.horizontalPan();
panY = camera.verticalPan();
}
#endif
double pixelScale = 1.0;
// Calculate the pixel scale value to use when drawing the filmback
switch ( filmFit )
{
case MFnCamera::kInvalid :
case MFnCamera::kHorizontalFilmFit :
{
pixelScale = portWidth / overscan / camera.horizontalFilmAperture() / zoom;
portGeom.x -= (panX * pixelScale);
portGeom.y -= (panY * pixelScale);
break;
}
case MFnCamera::kVerticalFilmFit :
{
pixelScale = portHeight / overscan / camera.verticalFilmAperture() / zoom;
portGeom.x -= (panX * pixelScale);
portGeom.y -= (panY * pixelScale);
break;
}
default:
{
MGlobal::displayError( name() + " invalid camera film fit (" + filmFit + ")");
break;
}
}
// If the reticle is in relativeFilmback mode, then scale the reticle filmback to fit the camera filmback
if (filmback.relativeFilmback)
{
double aspectRatio = filmback.horizontalFilmAperture / filmback.verticalFilmAperture;
if (aspectRatio > cameraAspectRatio)
pixelScale *= camera.horizontalFilmAperture() / filmback.horizontalFilmAperture;
else
pixelScale *= camera.verticalFilmAperture() / filmback.verticalFilmAperture;
}
// Account for lens squeeze for the filmback
double pixelScaleX = pixelScale * camera.lensSqueezeRatio();
// Calculate the filmback width and height
filmback.filmbackGeom.x = filmback.horizontalFilmAperture * pixelScaleX;
filmback.filmbackGeom.y = filmback.verticalFilmAperture * pixelScale;
// Calculate the actual filmback geometry corner values
filmback.filmbackGeom.x1 = portGeom.x - (filmback.filmbackGeom.x / 2);
filmback.filmbackGeom.x2 = portGeom.x + (filmback.filmbackGeom.x / 2);
filmback.filmbackGeom.y1 = portGeom.y - (filmback.filmbackGeom.y / 2);
filmback.filmbackGeom.y2 = portGeom.y + (filmback.filmbackGeom.y / 2);
filmback.filmbackGeom.isValid = true;
// Set the image area to match the filmback
filmback.imageGeom = filmback.filmbackGeom;
filmback.horizontalImageAperture = filmback.horizontalFilmAperture;
filmback.verticalImageAperture = filmback.verticalFilmAperture;
// Calculate the pad area width and height
if (pad.usePad && pad.isPadded)
{
pad.padGeom.x = (filmback.horizontalFilmAperture - pad.padAmountX) * pixelScaleX;
pad.padGeom.y = (filmback.verticalFilmAperture - pad.padAmountY) * pixelScale;
// Calculate rest of the pad area
pad.padGeom.x1 = portGeom.x - (pad.padGeom.x / 2);
pad.padGeom.x2 = portGeom.x + (pad.padGeom.x / 2);
pad.padGeom.y1 = portGeom.y - (pad.padGeom.y / 2);
pad.padGeom.y2 = portGeom.y + (pad.padGeom.y / 2);
pad.padGeom.isValid = true;
//Update the image area
filmback.horizontalImageAperture -= pad.padAmountX;
filmback.verticalImageAperture -= pad.padAmountY;
}
// Adjust for sound track if necessary