forked from d-00001101/mayaLiquify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mayaLiquify_2.2022.mel
3137 lines (1559 loc) · 69.5 KB
/
mayaLiquify_2.2022.mel
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 2007 Daniel Arzabe
//
//For suggestions: [email protected]
//
//proc string[] daGetValidCameras() //returns cameraShapes that have their project image set
//
//proc daCreateLiquifyPlane(string $ui_CameraShape)
//
//proc string[] daLiquifySurface() - returns the name of the surface shader as well as the file node attached to it
//
//proc string[] daListCamConnections(string $currentCamShape)
//returns: //[0] - camImagePlane [1] - liquifyPlane
//[2] - liquifyPlaneShape [3] - shadingEngine
//[4] - surfaceShader [5] - projectionNode
//[6] - fileNode [7] - targetObject
//proc string replaceSourceImage(string $currentCamShape) //this proc returns the new source image and places the value
//in the appropriate camShape attr
//proc daResetResolutionDisplay( string $textControlName, string $cameraShape)//
//
//proc daSetGlobalTargetObject()
//
//proc daLoadTargetObject(string $cameraShape)
//
//proc daVisibilityToggle(string $symbolButtonName, string $cameraShape)
//
//proc string daConfirmMessage(string $title, string $message)
//
//proc string[] daWhichCam()
//
//proc daLookThroughCamera(string $currentCamera)
//
//proc int daWireframeOnShaded()
//
//proc refreshLiquifyUI()
//
//proc string[] daMaterialsAttrEditor(string $cameraShape, string $attr, int $io)
// 3rd argument 0 = returnValues only
// 1 = graphMaterials
//returns the shading engine name and the surface shader name
//proc daTearOffHypershade()
//
//proc int daDoesFileExist(string $fileName, string $folder)
////return - bool - determines whether or not a file exists in the images folder
//global proc daResetCameraImagePlane()
//
//proc string daSaveRenderedImage(string $fileName)////returns the path name of image saved. Saves image in images folder
//
//proc daRenderCurrentCamera(string $currentCamShape)
//
//proc string daLiquifySourceImage(string $cameraShape, string $textFieldName)
//
//proc daClearLiquifyPlane(string $cameraShape)
//
//proc daSetLiquifyPlaneTransparency(string $currentCamShape, string $transparencySlider)
global float $daMayaLiquifyScrollValue;
global string $daTargetObject;
proc string[] daGetValidCameras()
{
int $numOfProjCams = 0;
string $tempCameraShapes[] = `ls -type camera`;
string $cameraShapes[];
string $currentCamShape;
int $i = 0;
for($currentCamShape in $tempCameraShapes)
{
if (`attributeExists "projectImage" $currentCamShape`)
{
int $io = `getAttr ($currentCamShape + ".projectImage")`;
print( $currentCamShape + " " + $io + " " + $i + "\n");
if($io)
{
$cameraShapes[$i] = $currentCamShape;
$i++;
}
}
}
return $cameraShapes;
}
//this proc simply updates the Maya UI sp that some internal UI procs are initialized
proc daPrepScene()
{
unifiedRenderGlobalsWindow;
setAttr "defaultResolution.pixelAspect" 1;
}
proc daPrepCamera(string $cameraShape)
{
//unifiedRenderGlobalsWindow;
setAttr "defaultResolution.pixelAspect" 1;
string $whichCam[];
$whichCam = daWhichCam();
setAttr ($whichCam[1] + ".locatorScale") 0.1;
string $imagePlanes[] = `listConnections -type imagePlane $whichCam[1]`;
if (size($imagePlanes) == 0)
{
daConfirmMessage("Error", "Camera does not have an imagePlane.", 1 );
error ("Camera does not have an imagePlane.");
}
select -r $imagePlanes[0];
ShowAttributeEditorOrChannelBox;
ShowAttributeEditorOrChannelBox;
setAttr ($imagePlanes[0] + ".displayOnlyIfCurrent") on;
AEupdateNode($imagePlanes[0], "");
int $coverageX = `getAttr ($imagePlanes[0] + ".coverageX")`;
int $coverageY = `getAttr ($imagePlanes[0] + ".coverageY")`;
//sets the res on the render globals
setAttr defaultResolution.width $coverageX;
setAttr defaultResolution.height $coverageY;
updateMayaSoftwarePixelAspectRatio;
setAttr "defaultResolution.pixelAspect" 1;
//fit to resolution gate
//setAttr ($imagePlanes[0] + ".fit") 1;//fit - best
setAttr ($imagePlanes[0] + ".fit") 4;//to size
AEinvokeFitRezGate ($imagePlanes[0] + ".sizeX") ($imagePlanes[0] + ".sizeY");
AEupdateNode($imagePlanes[0], "");
camera -e -displayFilmGate off -displayResolution on -overscan 1.3 $whichCam[0];
daResetCameraImagePlane();
}
proc daCreateLiquifyPlane(string $ui_CameraShape)
{
print("_______________INSIDE daCreateLiquifyPlane PROC______________\n");
global string $daTargetObject;
print("global target object = " + $daTargetObject + "\n");
if ($daTargetObject == "")
{
daSetGlobalTargetObject();
print("inside daCreateLiquifyPlane proc - $daTargetObject = " + $daTargetObject + "\n");
}
string $whichCam[];
$whichCam = daWhichCam();
print ("camera = " + $whichCam[0] + "\n");
string $imagePlanes[] = `listConnections -type imagePlane $whichCam[1]`;
print ("imagePlane = " + $imagePlanes[0] + "\n");
daPrepCamera($whichCam[1]);
AEinvokeFitRezGate ($imagePlanes[0] + ".sizeX") ($imagePlanes[0] + ".sizeY");
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//the fileTextureName in imagePlane node
string $imageName = `getAttr ($imagePlanes[0] + ".imageName")`;
print ("$imageName = " + $imageName + "\n");
//will contain the name of the liquifyplane
string $liquifyPlane[];
int $resetTransformations = 1;
float $tx = 0; float $ty = 0; float $tz = 0;
float $rx = 0; float $ry = 0; float $rz = 0;
float $sx = 1; float $sy = 1; float $sz = 1;
//if this block of code runs it means that the user is
//creating a second plane which will delete the previous. It will also delete the previous texture reference plane
//it starts by checking if the cameraShape has been intitialized
//with the custom attributes.
if(`attributeExists "projectImage" $whichCam[1]`)
{
print ("projectImage attr exists\n");
//print ($whichCam[0] + "\n");
string $temp = "";
$temp = `getAttr ($whichCam[1] + ".liquifyPlane")`;
print("The liquifyPlane name: " + $temp + "\n");
if( `objExists $temp` )
{
print("The previous liquifyPlane exists: " + $temp + "\n");
string $result = daConfirmMessage("Warning", "Would you like to replace the current liquify plane?", 1 );
if($result == "OK")
{
string $world[] = `listRelatives -p $temp`;
if (`size($world)`)
{
parent -w $temp;
}
//get the old transformation values from previous liquify plane
$tx = `getAttr ($temp + ".translateX")`;
$ty = `getAttr ($temp + ".translateY")`;
$tz = `getAttr ($temp + ".translateZ")`;
$rx = `getAttr ($temp + ".rotateX")`;
$ry = `getAttr ($temp + ".rotateY")`;
$rz = `getAttr ($temp + ".rotateZ")`;
$sx = `getAttr ($temp + ".scaleX")`;
$sy = `getAttr ($temp + ".scaleY")`;
$sz = `getAttr ($temp + ".scaleZ")`;
$resetTransformations = 0;
delete $temp;
if( `objExists ($whichCam[0] + "_Liquify_Plane_reference")` )
{
delete ($whichCam[0] + "_Liquify_Plane_reference");
}
}
else if ($result == "Cancel")
{
error ("Operation cancelled.");
}
}
$liquifyPlane = `nurbsPlane -ch on -o on -po 0 -ax 0 0 1 -u 6 -v 6 -n ($whichCam[0] + "_Liquify_Plane")`;
addAttr -ln "projectionMapped" -at bool -min 0 -max 1 $liquifyPlane;
setAttr -e -channelBox true ($liquifyPlane[0] + ".projectionMapped");
addAttr -ln "worldRotPivot" -at double3 $liquifyPlane;
addAttr -ln "worldRotPivotX" -at double -p worldRotPivot $liquifyPlane;
addAttr -ln "worldRotPivotY" -at double -p worldRotPivot $liquifyPlane;
addAttr -ln "worldRotPivotZ" -at double -p worldRotPivot $liquifyPlane;
print("worldRotatePivot custom attr created\n");
//get the plane's shape in order to set its display to wireframe
string $planeShape[] = `listRelatives -s $liquifyPlane`;
setAttr ($planeShape[0] + ".overrideEnabled") 1;
setAttr ($planeShape[0] + ".overrideShading") 0;
setAttr ($liquifyPlane[0] + ".translateX") $tx;
setAttr ($liquifyPlane[0] + ".translateY") $ty;
setAttr ($liquifyPlane[0] + ".translateZ") $tz;
setAttr ($liquifyPlane[0] + ".rotateX") $rx;
setAttr ($liquifyPlane[0] + ".rotateY") $ry;
setAttr ($liquifyPlane[0] + ".rotateZ") $rz;
setAttr ($liquifyPlane[0] + ".scaleX") $sx;
setAttr ($liquifyPlane[0] + ".scaleY") $sy;
setAttr ($liquifyPlane[0] + ".scaleZ") $sz;
setAttr ($whichCam[1] + ".liquifyPlane") -type "string" $liquifyPlane[0];
setAttr ($whichCam[1] + ".projectImage") true;
setAttr -type "string" ($whichCam[1] + ".targetObject") $daTargetObject;
}
else
{
$liquifyPlane = `nurbsPlane -ch on -o on -po 0 -ax 0 0 1 -u 6 -v 6 -n ($whichCam[0] + "_Liquify_Plane")`;
addAttr -ln "projectionMapped" -at bool -min 0 -max 1 $liquifyPlane;
setAttr -e -channelBox true ($liquifyPlane[0] + ".projectionMapped");
addAttr -ln "worldRotPivot" -at double3 $liquifyPlane;
addAttr -ln "worldRotPivotX" -at double -p worldRotPivot $liquifyPlane;
addAttr -ln "worldRotPivotY" -at double -p worldRotPivot $liquifyPlane;
addAttr -ln "worldRotPivotZ" -at double -p worldRotPivot $liquifyPlane;
print("worldRotatePivot custom attr created\n");
//get the plane's shape in order to set its display to wireframe
string $planeShape[] = `listRelatives -s $liquifyPlane`;
setAttr ($planeShape[0] + ".overrideEnabled") 1;
setAttr ($planeShape[0] + ".overrideShading") 0;
addAttr -ln "projectImage" -at bool -dv true $whichCam[1];
setAttr -e-channelBox true ( $whichCam[1] + ".projectImage");
addAttr -ln "liquifyPlane" -dt "string" $whichCam[1];
setAttr -e -keyable false ( $whichCam[1] + ".liquifyPlane");
setAttr ( $whichCam[1] + ".liquifyPlane") -type "string" $liquifyPlane[0];
addAttr -ln "sourceImage" -sn "si" -dt "string" $whichCam[1];
setAttr -e-channelBox true ( $whichCam[1] + ".sourceImage");
//set the imageName attr to the image name attr in imagePlane
setAttr ( $whichCam[1] + ".sourceImage") -type "string" $imageName;
//now connect the value back from the cameraShape to the imagePlane
//if the new source image is loaded via the liquifyUI, the value will be applied to the cameraShape
//and so update in the imagePlane
connectAttr -f ( $whichCam[1] + ".sourceImage") ($imagePlanes[0] + ".imageName");
addAttr -ln "liquifiedImage" -sn "li" -dt "string" $whichCam[1];
setAttr -e-keyable false ( $whichCam[1] + ".liquifiedImage");
//setAttr -type "string" ( $whichCam[1] + ".liquifiedImage") ( $whichCam[0] + "_liquified");
print("This is the liquifiedImage value = "); print (`getAttr ($whichCam[1] + ".liquifiedImage")`);
//addAttr -ln "bakedLiquifiedImage" -sn "bli" -dt "string" $whichCam[1];
//setAttr -e-keyable false ( $whichCam[1] + ".bakedLiquifiedImage");
//setAttr -type "string" ( $whichCam[1] + ".liquifiedImage") ( $whichCam[0] + "_liquified");
addAttr -ln "bakedMaskImage" -sn "bmi" -dt "string" $whichCam[1];
setAttr -e-keyable false ( $whichCam[1] + ".bakedMaskImage");
//setAttr -type "string" ( $whichCam[1] + ".liquifiedImage") ( $whichCam[0] + "_liquified");
addAttr -ln "projectionCameraShape" -dt "string" $whichCam[1];
setAttr -e-keyable false ( $whichCam[1] + ".projectionCameraShape");
setAttr ($whichCam[1] + ".projectionCameraShape") -type "string" $whichCam[1];
setAttr -lock true ($whichCam[1] + ".projectionCameraShape");
addAttr -ln "projectionImagePlane" -dt "string" $whichCam[1];
setAttr -e-keyable false ( $whichCam[1] + ".projectionImagePlane");
setAttr ($whichCam[1] + ".projectionImagePlane") -type "string" $imagePlanes[0];
setAttr -lock true ($whichCam[1] + ".projectionImagePlane");
addAttr -ln "includeLiquified" -at bool $whichCam[1];
setAttr -e-channelBox true ( $whichCam[1] + ".includeLiquified");
setAttr ( $whichCam[1] + ".includeLiquified") true;
addAttr -ln "targetObject" -dt "string" $whichCam[1];
setAttr -e-keyable true ($whichCam[1] + ".targetObject");
if($daTargetObject != "")
{
setAttr -type "string" ($whichCam[1] + ".targetObject") $daTargetObject;
}
addAttr -longName imageSizeX -min 16 -attributeType long $whichCam[1];
addAttr -longName imageSizeY -min 16 -attributeType long $whichCam[1];
connectAttr -f ($imagePlanes[0] + ".coverageX") ($whichCam[1] + ".imageSizeX");
connectAttr -f ($imagePlanes[0] + ".coverageY") ($whichCam[1] + ".imageSizeY");
addAttr -longName panelColor -attributeType double3 $whichCam[1];
addAttr -longName colorR -attributeType double -parent panelColor $whichCam[1];
addAttr -longName colorG -attributeType double -parent panelColor $whichCam[1];
addAttr -longName colorB -attributeType double -parent panelColor $whichCam[1];
vector $randVec;
$randVec = << rand(.4, .8), rand(.2, .8), rand(.3, .8) >>;
setAttr ($whichCam[1] + ".panelColor") ($randVec.x) ($randVec.y) ($randVec.z);
addAttr -ln "liqProjSS" -dt "string" $whichCam[1];
setAttr -e-keyable false ( $whichCam[1] + ".liqProjSS");
addAttr -ln "bakedLiquifiedSS" -dt "string" $whichCam[1];
setAttr -e-keyable false ( $whichCam[1] + ".bakedLiquifiedSS");
addAttr -ln "bakedLiquifiedSource" -dt "string" $whichCam[1];
setAttr -e-keyable false ($whichCam[1] + ".bakedLiquifiedSource");
addAttr -ln "maskProjSS" -dt "string" $whichCam[1];
setAttr -e-keyable false ( $whichCam[1] + ".maskProjSS");
addAttr -ln "bakedMaskProjSS" -dt "string" $whichCam[1];
setAttr -e-keyable false ( $whichCam[1] + ".bakedMaskProjSS");
addAttr -ln "fresnel" -dt "string" $whichCam[1];
setAttr -e-keyable false ( $whichCam[1] + ".fresnel");
}
//parent plane under camera to
//orient the plane towards the camera
//print ($liquifyPlane[0] + "\n");
parent $liquifyPlane[0] $whichCam[0];
if ($resetTransformations)
{
setAttr ($liquifyPlane[0] + ".translateX") 0;
setAttr ($liquifyPlane[0] + ".translateY") 0;
setAttr ($liquifyPlane[0] + ".rotateX") 0;
setAttr ($liquifyPlane[0] + ".rotateY") 0;
setAttr ($liquifyPlane[0] + ".rotateZ") 0;
vector $bBoxSize = `getAttr ($daTargetObject + ".boundingBox.boundingBoxSize")`;
print ("BBox size = " + $bBoxSize + " \n");
float $ZXPlane = ( sqrt(($bBoxSize.x * $bBoxSize.x) + ($bBoxSize.y * $bBoxSize.y) ) ) ;
print ("ZXPlane = " + $ZXPlane + "\n");
float $tz = `getAttr ($liquifyPlane[0] + ".translateZ")`;
print ("Plane tz = " + $tz + "\n");
$ZXPlane = $tz + $ZXPlane;
print ("tz + ZXPlane = " + $ZXPlane + "\n");
setAttr ($liquifyPlane[0] + ".translateZ") $ZXPlane;
//this is the identity rotation pivot. we get these values before the user
//futz with the plane. If the imagePlane is rotated we have to rotate
// the liquified plane after it is texture referenced so that the projection
//registers with the imagePlane. To do this, the liquifyPlane has to rotate in Z camera space
//with the imagePlanes center as the fulcrum. By capturing this world pivot value
//we can apply it to the liquifyPlane after it is has been futzed and texture referenced and then
//we rotate by the same amount as the imagePlane
vector $worldRotPivot = `xform -q -ws -rp $liquifyPlane[0]`;
setAttr ($liquifyPlane[0] + ".worldRotPivot") ($worldRotPivot.x) ($worldRotPivot.y) ($worldRotPivot.z);
}
refreshLiquifyUI();
select -r $liquifyPlane[0];
setDisplaySmoothness 1;
print("\n_____________________OUT PROC______________________\n");
}
//creates the surface shader and returns the name of the surface
//shader as well as the file node attached to it
proc string[] daLiquifySurface()
{
//refreshLiquifyUI();
print("_______________________________________\nInside daLiquifySurface Proc\n");
string $whichCam[];
$whichCam = daWhichCam();
daPrepCamera($whichCam[1]);
//determine the plane to liquify by getting its name from cameraShape info attrs
string $liquifyPlane = `getAttr ($whichCam[1] + ".liquifyPlane")`;
string $liquifyPlaneShape[] = `ls -dag -shapes -ap $liquifyPlane`;//planeShape
//lock camera attrs when we create a plane
setAttr -lock true ($whichCam[0] + ".tx");
setAttr -lock true ($whichCam[0] + ".ty");
setAttr -lock true ($whichCam[0] + ".tz");
setAttr -lock true ($whichCam[0] + ".rx");
setAttr -lock true ($whichCam[0] + ".ry");
setAttr -lock true ($whichCam[0] + ".rz");
setAttr -lock true ($whichCam[0] + ".sx");
setAttr -lock true ($whichCam[0] + ".sy");
setAttr -lock true ($whichCam[0] + ".sz");
//set its display to shaded and best quality
setAttr ($liquifyPlaneShape[0] + ".overrideShading") 1;
setAttr ($liquifyPlaneShape[0] + ".overrideEnabled") 0;
setDisplaySmoothness 3;
//create the Surface shader and apply it to plane with image with projection
//add custom string attribute with cameraShape name
//connect the cameraShape's message attr to the surfaceShader's linkedCamera attr
string $surfaceShader = `shadingNode -asShader surfaceShader -n ($whichCam[0] + "_liquifySurfaceShader")`;
addAttr -ln "linkedCamera" -dt "string" $surfaceShader;
setAttr -e-keyable false ( $surfaceShader + ".linkedCamera");
setAttr -type "string" ( $surfaceShader + ".linkedCamera") $whichCam[0];
connectAttr -f ($whichCam[0] + ".message") ( $surfaceShader + ".linkedCamera");
setAttr ($surfaceShader + ".outTransparency") -type double3 0.18 0.18 0.18 ;
string $surfaceShaderSG = `sets -renderable true -noSurfaceShader true -empty -name ($surfaceShader + "SG")`;
connectAttr -f ($surfaceShader + ".outColor") ($surfaceShaderSG + ".surfaceShader");
//create the file, projection, place2dTexture and place3dtexture nodes and connect them
//to the color attr of surface shader
string $projNode = `shadingNode -asTexture projection -n ($whichCam[0] + "_liquifyProjectionNode")`;
string $fileNode = `shadingNode -asTexture file -n ($whichCam[0] + "_liquifyFile")`;
connectAttr -f ($whichCam[1] + ".sourceImage") ($fileNode + ".fileTextureName");
//string $tempSourceImageName = `getAttr ($whichCam[1] + ".sourceImage")`;
//setAttr -type "string" ($fileNode + ".fileTextureName") $tempSourceImageName;
string $place3dNode = `shadingNode -asUtility place3dTexture -n ($whichCam[0] + "_place3dTexture")`;
connectAttr ($place3dNode + ".wim[0]") ($projNode + ".pm");
connectAttr ($fileNode + ".outColor") ($projNode + ".image");
string $place2dNode = `shadingNode -asUtility place2dTexture -n ($whichCam[0] + "_place2dTexture")`;
connectAttr -f ($place2dNode + ".coverage") ($fileNode + ".coverage");
connectAttr -f ($place2dNode + ".translateFrame") ($fileNode + ".translateFrame");
connectAttr -f ($place2dNode + ".rotateFrame") ($fileNode + ".rotateFrame");
connectAttr -f ($place2dNode + ".mirrorU") ($fileNode + ".mirrorU");
connectAttr -f ($place2dNode + ".mirrorV") ($fileNode + ".mirrorV");
connectAttr -f ($place2dNode + ".stagger") ($fileNode + ".stagger");
connectAttr -f ($place2dNode + ".wrapU") ($fileNode + ".wrapU");
connectAttr -f ($place2dNode + ".wrapV") ($fileNode + ".wrapV");
connectAttr -f ($place2dNode + ".repeatUV") ($fileNode + ".repeatUV");
connectAttr -f ($place2dNode + ".offset") ($fileNode + ".offset");
connectAttr -f ($place2dNode + ".rotateUV") ($fileNode + ".rotateUV");
connectAttr -f ($place2dNode + ".noiseUV") ($fileNode + ".noiseUV");
connectAttr -f ($place2dNode + ".vertexUvOne") ($fileNode + ".vertexUvOne");
connectAttr -f ($place2dNode + ".vertexUvTwo") ($fileNode + ".vertexUvTwo");
connectAttr -f ($place2dNode + ".vertexUvThree") ($fileNode + ".vertexUvThree");
connectAttr -f ($place2dNode + ".vertexCameraOne") ($fileNode + ".vertexCameraOne");
connectAttr ($place2dNode + ".outUV") ($fileNode + ".uv");
connectAttr ($place2dNode + ".outUvFilterSize") ($fileNode + ".uvFilterSize");
connectAttr -force ($projNode + ".outColor") ($surfaceShader + ".outColor");
//set projection attrs
setAttr ($projNode + ".projType") 8;
connectAttr -f ($whichCam[1] + ".message") ($projNode + ".linkedCamera");//cameraShape to projection node
setAttr ($projNode + ".fitType") 2; //Match Camera resolution Gate - this is the same as the cameras imagePlane fitType
//setAttr ($projNode + ".fitType") 1; //Match Camera Film Gate - this is different than the cameras imagePlane fitType
setAttr ($projNode + ".fitFill") 2; //vertical
//set the file node's filter type to mipmap
setAttr ($fileNode + ".filterType") 1;
//apply shader to plane
sets -edit -forceElement $surfaceShaderSG $liquifyPlaneShape[0];
//make the texture reference
select -r $liquifyPlane;
makeReferenceObject;
//connectAttr -f ($liquifyPlane + ".translate") ($liquifyPlane + "_reference.translate");
setAttr ($liquifyPlane + "_reference.visibility") 0;
select -cl ;
string $imagePlanes[] = `listConnections -t "imagePlane" $whichCam[1]`;
float $imagePlaneRot[];
//we get these values on of the possibility that the user
//changed the offset and rotate values of the image plane
//if so, the projection will not match the position and rotation of the image plane
$imagePlaneRot = `getAttr ($imagePlanes[0] + ".rotate")`;
$imagePlaneOffsetX = `getAttr ($imagePlanes[0] + ".offsetX")`;
$imagePlaneOffsetY = `getAttr ($imagePlanes[0] + ".offsetY")`;
//we can match the rotation but not the offset of the imagePlane values
if( $imagePlaneRot[0] != 0 || $imagePlaneRot[1] != 0 || $imagePlaneRot[2] != 0 )
{
print("imagePlane rot != 0 \n");
print("imagePlane rotation = " + $imagePlaneRot[0] + ", " + $imagePlaneRot[1] + ", " + $imagePlaneRot[2] + "\n");
$imagePlaneRot[0] *= -1;
$imagePlaneRot[1] *= -1;
$imagePlaneRot[2] *= -1;
print("imagePlane rotation NEGATED: " + $imagePlaneRot[0] + ", " + $imagePlaneRot[1] + ", " + $imagePlaneRot[2] + "\n");
//get the plane's original worldRotatePivot value stored at creation time in custom attr
vector $WRP = `getAttr ($liquifyPlane + ".worldRotPivot")`;
print("WRP = " + $WRP + "\n");
//set the original rotate pivot before we re-rotate the plane so that
//the projection matches the rotation o the imageplane
xform -ws -p true -rp ($WRP.x) ($WRP.y) ($WRP.z) $liquifyPlane;
print("New WRP set\n");
rotate -r -os 0 0 $imagePlaneRot $liquifyPlane;
}
if( ($imagePlaneOffsetX != 0) || ($imagePlaneOffsetY != 0) )
{
string $confirm = daConfirmMessage("Warning", "Camera imagePlane has non-zero offset values.\nThe liquify plane will not register perfectly.", 1 );
if($confirm == "Cancel")
{
error("Operation cancelled.");
}
}
//////////////////////////////////
parent -w $liquifyPlane;//unparent plane from camera
//determine if the liquify plane has already been projection mapped.
//If it hasn'e been mapped, set its projectionMapped attr to true and continue
if( `getAttr ($liquifyPlane + ".projectionMapped")`)
{
daConfirmMessage("Error", "Plane is already connected to surface shader.", 1 );
error("Plane is already connected to surface shader.");
}
else
{
setAttr ($liquifyPlane + ".projectionMapped") true;
}
//lock the plane attrs in order to prevent further movement
setAttr -lock true ($liquifyPlane + ".tx");
setAttr -lock true ($liquifyPlane + ".ty");
setAttr -lock true ($liquifyPlane + ".tz");
setAttr -lock true ($liquifyPlane + ".rx");
setAttr -lock true ($liquifyPlane + ".ry");
setAttr -lock true ($liquifyPlane + ".rz");
setAttr -lock true ($liquifyPlane + ".sx");
setAttr -lock true ($liquifyPlane + ".sy");
setAttr -lock true ($liquifyPlane + ".sz");
string $returnValues[];
$returnValues[0] = $surfaceShader;
$returnValues[1] = $fileNode;
setAttr ($projNode + ".fitType") 2;
refreshLiquifyUI();
return $returnValues;
}
//[0] - camImagePlane [1] - liquifyPlane
//[2] - liquifyPlaneShape [3] - shadingEngine
//[4] - surfaceShader [5] - projectionNode
//[6] - fileNode [7] - targetObject
proc string[] daListCamConnections(string $currentCamShape)
{
string $returnValues[];
string $camImagePlane[] = `listConnections -type imagePlane $currentCamShape`;
//print ("ImagePlane = " + $camImagePlane[0] + "\n");
$returnValues[0] = $camImagePlane[0];
string $liquifyPlane = `getAttr ($currentCamShape + ".liquifyPlane")`;
//print ("LiquifyPlane = " + $liquifyPlane + "\n");
$returnValues[1] = $liquifyPlane;
string $liquifyPlaneShape[] = `listRelatives -s $liquifyPlane`;
//print ("LiquifyPlaneShape = " + $liquifyPlaneShape[0] + "\n");
$returnValues[2] = $liquifyPlaneShape[0];
string $shadingEngine[] = `listConnections -type shadingEngine $liquifyPlaneShape[0]`;
//print ("ShadingEngine = " + $shadingEngine[0] + "\n");
$returnValues[3] = $shadingEngine[0];
string $surfaceShader[] = `listConnections -type surfaceShader $shadingEngine[0]`;
//print ("SurfaceShader = " + $surfaceShader[0] + "\n");
$returnValues[4] = $surfaceShader[0];
string $projectionNode[] = `listConnections -type projection $surfaceShader[0]`;
//print ("ProjectionNode = " + $projectionNode[0] + "\n");
$returnValues[5] = $projectionNode[0];
string $fileNode[6] = `listConnections -type file $projectionNode[0]`;
//print ("fileNode = " + $fileNode[0] + "\n");
$returnValues[6] = $fileNode[0];
string $targetObject = `getAttr ($currentCamShape + ".targetObject")`;
$returnValues[7] = $targetObject;
return $returnValues;
}
//this proc returns the new source image and places the value
//in the appropriate camShape attr
proc string daReplaceSourceImage(string $currentCamShape, string $attribute)
{
string $newSourceImage = `fileDialog -m 0`;
if($newSourceImage == "")
{
daConfirmMessage("error", "No file selected", 1 );
error "No File Selected";
}
else
{
//print ($newSourceImage + "\n");
setAttr -type "string" ($currentCamShape + "." + $attribute) $newSourceImage;
return $newSourceImage;
}
refreshLiquifyUI();
}
proc daResetResolutionDisplay( string $textControlName, string $cameraShape)//("resolutions_text_" + $currentCamShape)