-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnkPoseStack.mel
5335 lines (4720 loc) · 269 KB
/
nkPoseStack.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
/*! © 2023 imaoki | MIT License | https://github.com/imaoki */
// /////////////////////////////////////////////////////////////////////////////
// ボイラープレート
// /////////////////////////////////////////////////////////////////////////////
/*1.0.0:Python*/proc string escapeStringForPython(string $input) {string $escapedText;int $size = `size $input`;for ($i = 1; $i <= $size; $i++) {string $c = `substring $input $i $i`;switch ($c) {case "\\": $escapedText += "\\\\"; break;case "'": $escapedText += "\\'"; break;case "\n": $escapedText += "\\n"; break;case "\r": $escapedText += "\\r"; break;default: $escapedText += $c; break;}}return $escapedText;}proc string convertStringForPythonString(string $input) {return ("'" + escapeStringForPython($input) + "'");}proc string convertStringArrayForPythonList(string $input[]) {string $literal = "[";for ($i = 0; $i < `size $input`; $i++) {if ($i > 0) {$literal += ", ";}$literal += convertStringForPythonString($input[$i]);}$literal += "]";return $literal;}proc string convertStringArrayForPythonTuple(string $input[]) {string $literal = "(";for ($i = 0; $i < `size $input`; $i++) {if ($i > 0) {$literal += ", ";}$literal += convertStringForPythonString($input[$i]);}$literal += ")";return $literal;}
// -----------------------------------------------------------------------------
/*1.1.3:Array*/global int $nkArrayIsInitialized;proc nkArrayInitializeParameters(int $force) {global int $nkArrayIsInitialized;if ($force || !$nkArrayIsInitialized) {python("import re");python("nkArrayCharSortOrder = '_-,;:!?.\\'\"()[]{}@*/\\&#%`^+<=>|~$0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'");python("nkArrayCharTable = str.maketrans(nkArrayCharSortOrder, ''.join(sorted(nkArrayCharSortOrder)))");python("nkArrayPunctuationPattern = r'[_\\-,;:!?\\.\\'\"()\\[\\]{}@*/\\\\&#%`^+<=>|~$]'");python("nkArrayPunctuationDegitPattern = r'([_\\-,;:!?\\.\\'\"()\\[\\]{}@*/\\\\&#%`^+<=>|~$]|[0-9]+)'");$nkArrayIsInitialized = true;}}proc int minFloatArrayCount(float $a[], float $b[]) {int $numA = `size $a`;int $numB = `size $b`;return `min $numA $numB`;}proc int minIntArrayCount(int $a[], int $b[]) {int $numA = `size $a`;int $numB = `size $b`;return `min $numA $numB`;}proc int minStringArrayCount(string $a[], string $b[]) {int $numA = `size $a`;int $numB = `size $b`;return `min $numA $numB`;}proc string[] nsort(string $input[]) {string $result[] = `python("sorted(" + convertStringArrayForPythonList($input) + ", key=lambda item: [" + "(" + "0 if re.fullmatch(nkArrayPunctuationPattern, part) else " + "1 if part.isdigit() else " + "2, " + "int(part) if part.isdigit() else part.translate(nkArrayCharTable)" + ")" + " for part in re.split(nkArrayPunctuationDegitPattern, item)" + "]" + ")")`;if (`size $result` == 1 && !`size $result[0]`) clear $result;return $result;}
/*1.2.0:Assertion*/proc string assertTrue(int $a) {return ($a == true) ? "" : ("Assert: expected 1, got " + $a);}proc string assertFalse(int $a) {return ($a == false) ? "" : ("Assert: expected 0, got " + $a);}proc string assertFloatEqual(float $e, float $a, float $t) {return (`abs ($e - $a)` <= $t) ? "" : ("Assert: expected " + $e + ", got " + $a);}proc string assertFloatNotEqual(float $e, float $a, float $t) {return (`abs ($e - $a)` > $t) ? "" : ("Assert: expected " + $e + ", got " + $a);}proc string assertIntEqual(int $e, int $a) {return ($a == $e) ? "" : ("Assert: expected " + $e + ", got " + $a);}proc string assertIntNotEqual(int $e, int $a) {return ($a != $e) ? "" : ("Assert: expected " + $e + ", got " + $a);}proc string assertStringEqual(string $e, string $a) {return ($a == $e) ? "" : ("Assert: expected " + $e + ", got " + $a);}proc string assertStringNotEqual(string $e, string $a) {return ($a != $e) ? "" : ("Assert: expected " + $e + ", got " + $a);}proc string assertStringMatch(string $e, string $a) {return (!`size $e` || `match $e $a` != "") ? "" : ("Assert: expected " + $e + ", got " + $a);}proc string assertStringMismatch(string $e, string $a) {return (!`size $e` || `match $e $a` == "") ? "" : ("Assert: expected " + $e + ", got " + $a);}proc string assertFloatArrayEqual(float $es[], float $as[], float $t) {int $numAs = `size $as`;int $isEqual = $numAs == `size $es`;if ($isEqual) {for ($i = 0; $i < $numAs; $i++) {$isEqual = `abs ($es[$i] - $as[$i])` <= $t;if (!$isEqual) break;}}return ($isEqual) ? "" : ("Assert: expected {" + floatArrayToString($es, ", ") + "}, got {" + floatArrayToString($as, ", ") + "}");}proc string assertIntArrayEqual(int $es[], int $as[]) {int $numAs = `size $as`;int $isEqual = $numAs == `size $es`;if ($isEqual) {for ($i = 0; $i < $numAs; $i++) {$isEqual = $as[$i] == $es[$i];if (!$isEqual) break;}}return ($isEqual) ? "" : ("Assert: expected {" + intArrayToString($es, ", ") + "}, got {" + intArrayToString($as, ", ") + "}");}proc string assertStringArrayEqual(string $es[], string $as[]) {int $numAs = `size $as`;int $isEqual = $numAs == `size $es`;if ($isEqual) {for ($i = 0; $i < $numAs; $i++) {$isEqual = $as[$i] == $es[$i];if (!$isEqual) break;}}return ($isEqual) ? "" : ("Assert: expected {" + stringArrayToString($es, ", ") + "}, got {" + stringArrayToString($as, ", ") + "}");}proc testNewScene() {file -f -new;}proc testOpenScene(string $filename) {file -f -op "v=0;" -iv -typ "mayaAscii" -pmt false -o $filename;}
/*1.6.0:File*/proc int isValidFilename(string $input) {return (`match "[:\?\"\*/\\<>\|\n\r\t]" $input` == "");}proc string escapeInvalidFileNameChars(string $input, string $replacement) {python("import re");string $result = `python("re.sub(r" + convertStringForPythonString("[:\?\"\*/\\<>\|\n\r\t]") + ", " + convertStringForPythonString($replacement) + ", " + convertStringForPythonString($input) + ")")`;return $result;}proc string getSourceFilename(string $procName) {string $filename;string $thisIs = `whatIs $procName`;string $pattern1 = "^Mel procedure found in: *";string $pattern2 = "^Script found in: *";if (`match $pattern1 $thisIs` != "") {$filename = `substitute $pattern1 $thisIs ""`;}else if (`match $pattern2 $thisIs` != "") {$filename = `substitute $pattern2 $thisIs ""`;}return $filename;}proc string getSourceDirname(string $procName) {return dirname(getSourceFilename($procName));}proc int existsDirname(string $dirname) {return `filetest -d $dirname`;}proc int existsFilename(string $filename) {return `filetest -f $filename`;}proc string[] getDirnames(string $dirname) {string $subDirnames[];string $filenames[] = `getFileList -fld $dirname`;for ($i = 0; $i < `size $filenames`; $i++) {string $subDirname = $dirname + "/" + $filenames[$i];if (existsDirname($subDirname)) {$subDirnames[`size $subDirnames`] = $subDirname;}}$subDirnames = `sortCaseInsensitive $subDirnames`;return $subDirnames;}proc string[] getFilenames(string $dirname, string $filenamePattern) {string $filenames[] = `getFileList -fs $filenamePattern -fld $dirname`;for ($i = 0; $i < `size $filenames`; $i++) {$filenames[$i] = $dirname + "/" + $filenames[$i];}$filenames = `sortCaseInsensitive $filenames`;return $filenames;}proc string getOpenFilename(string $caption, string $fileFilter) {string $filename;string $filenames[] = `fileDialog2 -cap $caption -ds 2 -ff $fileFilter -fm 1`;if (`size $filenames`) $filename = $filenames[0];return $filename;}proc string getSaveFilename(string $caption, string $fileFilter) {string $filename;string $filenames[] = `fileDialog2 -cap $caption -ds 2 -ff $fileFilter -fm 0`;if (`size $filenames`) $filename = $filenames[0];return $filename;}proc string[] readAllLines(string $filename, string $encoding) {if (!`size $encoding`) $encoding = "utf-8";string $lines[];if (!existsFilename($filename)) return $lines;python("with open('" + $filename + "', 'r', encoding='" + $encoding + "') as f:" + " lines = tuple(s.rstrip('\\r\\n') for s in f.readlines())");$lines = `python("lines")`;return $lines;}proc string readAllText(string $filename, string $encoding) {if (!`size $encoding`) $encoding = "utf-8";string $text;if (!existsFilename($filename)) return $text;python("with open('" + $filename + "', 'r', encoding='" + $encoding + "') as f: text = f.read()");$text = `python("text")`;return $text;}proc int writeAllText(string $filename, string $encoding, string $input) {string $dirname = dirname($filename);if (!existsDirname($dirname)) return false;if (!`size $encoding`) $encoding = "utf-8";python("with open(" + convertStringForPythonString($filename) + ", 'w', encoding=" + convertStringForPythonString($encoding) + ") as f:" + " num = f.write(" + convertStringForPythonString($input) + ")");return (existsFilename($filename));}proc int writeAllLines(string $filename, string $encoding, string $lines[]) {string $text = stringArrayToString($lines, "\n");if (`size $lines`) $text += "\n";return (writeAllText($filename, $encoding, $text));}proc int makeDirs(string $dirname) {if (existsDirname($dirname)) return true;if (existsFilename($dirname)) return false;python("import os");python("os.makedirs('" + $dirname + "')");return (existsDirname($dirname));}proc int moveDir(string $sourceDirname, string $destDirname) {if (!existsDirname($sourceDirname)) return false;if (existsDirname($destDirname) || existsFilename($destDirname)) return false;python("import os");python("os.rename('" + $sourceDirname + "', '" + $destDirname +"')");return (!existsDirname($sourceDirname) && existsDirname($destDirname));}proc int moveFile(string $sourceFilename, string $destFilename) {if (!existsFilename($sourceFilename)) return false;if (existsDirname($destFilename) || existsFilename($destFilename)) return false;python("import os");python("os.rename('" + $sourceFilename + "', '" + $destFilename +"')");return (!existsFilename($sourceFilename) && existsFilename($destFilename));}proc int deleteDir(string $dirname) {if (!existsDirname($dirname)) return false;python("import os");python("if len(os.listdir('" + $dirname + "')) == 0:" + " os.rmdir('" + $dirname + "')");return (!existsDirname($dirname));}proc int deleteFile(string $filename) {if (!existsFilename($filename)) return false;python("import os");python("os.remove('" + $filename + "')");return (!existsFilename($filename));}
/*1.20.3:Node*/proc int nodesExists(string $nodes[]) {int $numNodes = `size $nodes`;if (!$numNodes) return false;int $count;for ($n in $nodes) {if (`objExists $n`) $count += 1;}return ($count == $numNodes);}proc int isSelected(string $n) {if (!`objExists $n`) return false;string $nodes[] = `ls -l -sl $n`;return (`size $nodes` > 0);}proc string[] getShapeNodes(string $n, string $type) {if (!`objExists $n`) return {};if (`size $type`) {return `listRelatives -f -s -typ $type $n`;}else {return `listRelatives -f -s $n`;}}proc int isType(string $n, string $types[], int $isExact) {if (!`objExists $n`) return false;if (!`size $types`) return true;if ($isExact) {if (stringArrayContains(`nodeType $n`, $types)) return true;}else {string $subtypes[] = `nodeType -i $n`;for ($subtype in $subtypes) {if (stringArrayContains($subtype, $types)) return true;}}return false;}proc int hasType(string $n, string $types[], int $isExact) {if (isType($n, $types, $isExact)) return true;string $shapeNodes[] = getShapeNodes($n, "");for ($shapeNode in $shapeNodes) {if (isType($shapeNode, $types, $isExact)) return true;}return false;}proc int isTypeContains(string $nodes[], string $types[], int $isExact) {if (!`size $nodes`) return false;if (!`size $types`) return true;for ($n in $nodes) {if (isType($n, $types, $isExact)) return true;}return false;}proc int isNodeReferenced(string $n) {return (`objExists $n` && `referenceQuery -inr $n`);}proc int isConstraintNode(string $n) {return isType($n, {"constraint"}, false);}proc int isDagNode(string $n) {return isType($n, {"dagNode"}, false);}proc int isTransformNode(string $n) {return isType($n, {"transform"}, true);}proc int isJointNode(string $n) {return isType($n, {"joint"}, true);}proc int isShapeNode(string $n) {return isType($n, {"shape"}, false);}proc int isLocatorNode(string $n) {return isType($n, {"locator"}, true);}proc int hasLocatorNode(string $n) {return hasType($n, {"locator"}, true);}proc int isNurbsSurfaceNode(string $n) {return isType($n, {"nurbsSurface"}, true);}proc int hasNurbsSurfaceNode(string $n) {return hasType($n, {"nurbsSurface"}, true);}proc int isNurbsCurveNode(string $n) {return isType($n, {"nurbsCurve"}, true);}proc int hasNurbsCurveNode(string $n) {return hasType($n, {"nurbsCurve"}, true);}proc int isBezierCurveNode(string $n) {return isType($n, {"bezierCurve"}, true);}proc int hasBezierCurveNode(string $n) {return hasType($n, {"bezierCurve"}, true);}proc int isMeshNode(string $n) {return isType($n, {"mesh"}, true);}proc int hasMeshNode(string $n) {return hasType($n, {"mesh"}, true);}proc int isLightNode(string $n) {return isType($n, {"light"}, false);}proc int hasLightNode(string $n) {return hasType($n, {"light"}, false);}proc int isCameraNode(string $n) {return isType($n, {"camera"}, false);}proc int hasCameraNode(string $n) {return hasType($n, {"camera"}, false);}proc int isUUID(string $input) {string $hex = "[A-F0-9]";string $digit4 = $hex + $hex + $hex + $hex;string $digit8 = $digit4 + $digit4;string $digit12 = $digit8 + $digit4;return (isValidString($input,$digit8 + "-" + $digit4 + "-" + $digit4 + "-" + $digit4 + "-" + $digit12));}proc string toShortName(string $path) {string $shortName;if (!`size $path`) return $shortName;string $buffer1[];int $numBuffer1 = `tokenize $path "|" $buffer1`;if ($numBuffer1 > 0) {string $buffer2[];int $numBuffer2 = `tokenize $buffer1[$numBuffer1 - 1] ":" $buffer2`;if ($numBuffer2 > 0) {$shortName = $buffer2[$numBuffer2 - 1];}}return $shortName;}proc string toUUID(string $n) {string $uuid;if (!`objExists $n`) return $uuid;string $uuids[] = `ls -uid $n`;if (`size $uuids` == 1) $uuid = $uuids[0];return $uuid;}proc string uuidToLongName(string $uuid) {string $longName;if (!isUUID($uuid)) return $longName;string $nodes[] = `ls -l $uuid`;int $numNodes = `size $nodes`;if ($numNodes == 1) {$longName = $nodes[0];}else if ($numNodes > 1) {string $editableNodes[];for ($node in $nodes) {if (isNodeReferenced($node)) continue;$editableNodes[`size $editableNodes`] = $node;}if (`size $editableNodes` == 1) {$longName = $editableNodes[0];}}return $longName;}proc string setNodeName(string $n, string $newName, int $inheritNamespace) {if (!`objExists $n` || !`size $newName` || isNodeReferenced($n)) return $n;string $namespace;if ($inheritNamespace) {string $names[] = `ls -sns $n`;if (`size $names` == 2 && $names[1] != ":") {$namespace += $names[1];}}$newName = `substitute "^:+" $newName ""`;if (`gmatch $newName "*:*"`) {string $newNamespace;$newNamespace = `substitute ":[^:]+$" $newName ""`;if (`size $newNamespace`) {$namespace += ((`size $namespace`) ? ":" : "") + $newNamespace;}if (!`namespace -ex $namespace`) {namespace -add $namespace;}$newName = `match "[^:]+$" $newName`;}if (`size $namespace`) {$newName = ":" + $namespace + ":" + $newName;}string $nodeId = toUUID($n);$n = uuidToLongName($nodeId);rename $n $newName;$n = uuidToLongName($nodeId);return $n;}proc string getParentNode(string $n) {if (!`objExists $n`) return "";string $parents[] = `listRelatives -f -p $n`;if (!`size $parents`) return "";return $parents[0];}proc string[] setParentNode(string $nodes[], string $parentNode) {int $toWorld = `size $parentNode` == 0;int $parentIsDagNode = isDagNode($parentNode);if (!$toWorld && !$parentIsDagNode) return $nodes;string $nodeIds[];string $dagNodes[];for ($n in $nodes) {$nodeIds[`size $nodeIds`] = toUUID($n);if (isDagNode($n) && !isNodeReferenced($n)) {$dagNodes[`size $dagNodes`] = $n;}}int $numDagNodes = `size $dagNodes`;if (!$numDagNodes) return $nodes;string $selectedNodes[] = `ls -l -sl`;string $selectedNodeIds[];for ($n in $selectedNodes) {$selectedNodeIds[`size $selectedNodeIds`] = toUUID($n);}if ($numDagNodes) {if ($toWorld) {parent -w $dagNodes;}else if ($parentIsDagNode) {parent -a $dagNodes $parentNode;}}string $newNodes[];for ($id in $nodeIds) {$newNodes[`size $newNodes`] = uuidToLongName($id);}string $newSelectedNodes[];for ($id in $selectedNodeIds) {$newSelectedNodes[`size $newSelectedNodes`] = uuidToLongName($id);}select -r $newSelectedNodes;return $newNodes;}proc string getRootNode(string $n) {string $rootNode;if (!`objExists $n`) return $rootNode;$rootNode = $n;string $parentNode = getParentNode($rootNode);while (`objExists $parentNode`) {$rootNode = $parentNode;$parentNode = getParentNode($rootNode);}return $rootNode;}proc string[] collectRootNodes(string $nodes[]) {string $rootNodes[];if (!`size $nodes`) return $rootNodes;for ($n in $nodes) {string $rootNode = getRootNode($n);if (`objExists $rootNode`) {$rootNodes[`size $rootNodes`] = $rootNode;}}$rootNodes = stringArrayRemoveDuplicates($rootNodes);return $rootNodes;}proc string[] collectChildNodes(string $n) {string $childNodes[];if (!`objExists $n`) return $childNodes;$childNodes = `listRelatives -f -c $n`;return $childNodes;}proc string[] collectDescendantNodes(string $n,string $parentNode,string $types[],int $isExact,string $script) {string $descendantNodes[];if (!`objExists $n`) return $descendantNodes;$n = longNameOf($n);$parentNode = longNameOf($parentNode);string $sourceNode = $n;string $nextNode = $sourceNode;if (`exists $script` && isType($sourceNode, $types, $isExact)) {string $arg1 = "\"" + toUUID($sourceNode) + "\"";string $arg2 = "\"" + toUUID($parentNode) + "\"";string $result[] = `eval $script $arg1 $arg2`;if (`size $result` == 2 && (!`size $result[0]` || isUUID($result[0])) && (!`size $result[1]` || isUUID($result[1]))) {$sourceNode = uuidToLongName($result[0]);$nextNode = uuidToLongName($result[1]);}}if (`objExists $sourceNode`) {$descendantNodes[`size $descendantNodes`] = $sourceNode;}string $childNodes[] = collectChildNodes($nextNode);for ($c in $childNodes) {$descendantNodes = stringArrayCatenate($descendantNodes,collectDescendantNodes($c, $sourceNode, $types, $isExact, $script));}if (`size $types`) {for ($i = `size $descendantNodes` - 1; $i >= 0; $i--) {if (!isType($descendantNodes[$i], $types, $isExact)) {stringArrayRemoveAtIndex($i, $descendantNodes);}}}return $descendantNodes;}proc string[] collectHierarchyNodes(string $nodes[],string $parentNode,string $types[],int $isExact,string $script) {string $hierarchyNodes[];if (!`size $nodes`) return $hierarchyNodes;string $rootNodes[] = collectRootNodes($nodes);for ($n in $rootNodes) {$hierarchyNodes = stringArrayCatenate($hierarchyNodes,collectDescendantNodes($n, $parentNode, $types, $isExact, $script));}$hierarchyNodes = stringArrayRemoveDuplicates($hierarchyNodes);return $hierarchyNodes;}proc string[] gatherNodes(string $types[],int $isExact,int $selectedOnly,string $pattern) {if (!`size $pattern`) $pattern = "::*";string $nodes[];if (`size $types`) {for ($type in $types) {if ($selectedOnly) {if ($isExact) {$nodes = stringArrayCatenate($nodes, `ls -l -sl -et $type $pattern`);}else {$nodes = stringArrayCatenate($nodes, `ls -l -sl -typ $type $pattern`);}}else {if ($isExact) {$nodes = stringArrayCatenate($nodes, `ls -l -et $type $pattern`);}else {$nodes = stringArrayCatenate($nodes, `ls -l -typ $type $pattern`);}}}}else {if ($selectedOnly) {$nodes = `ls -l -sl $pattern`;}else {$nodes = `ls -l $pattern`;}}$nodes = stringArrayRemoveDuplicates($nodes);return $nodes;}proc string nodesAsCSV(string $types[],int $isExact,int $selectedOnly,string $pattern,int $singleNodeOnly) {string $nodes[] = gatherNodes($types, $isExact, $selectedOnly, $pattern);if (`size $nodes` > 1 && $singleNodeOnly) clear $nodes;return stringArrayToString($nodes, ",");}proc string[] csvAsNodes(string $input) {string $nodes[];tokenize $input "," $nodes;if (`size $nodes` == 1 && !`size $nodes[0]`) clear $nodes;return $nodes;}proc string[] getSourceConnectionNodes(string $nodes[],string $types[],int $isExact) {string $tmpNodes[];for ($n in $nodes) {if (!`objExists $n`) continue;$tmpNodes = stringArrayCatenate($tmpNodes,`listConnections -d false -p false -s true $n`);}$tmpNodes = stringArrayRemoveDuplicates($tmpNodes);string $sourceNodes[];for ($i = 0; $i < `size $tmpNodes`; $i++) {string $tmpNode = longNameOf($tmpNodes[$i]);if (isType($tmpNode, $types, $isExact)) {$sourceNodes[`size $sourceNodes`] = $tmpNode;}}$sourceNodes = `sort $sourceNodes`;return $sourceNodes;}proc string[] getDestConnectionNodes(string $nodes[],string $types[],int $isExact) {string $tmpNodes[];for ($n in $nodes) {if (!`objExists $n`) continue;$tmpNodes = stringArrayCatenate($tmpNodes,`listConnections -d true -p false -s false $n`);}$tmpNodes = stringArrayRemoveDuplicates($tmpNodes);string $destNodes[];for ($i = 0; $i < `size $tmpNodes`; $i++) {string $tmpNode = longNameOf($tmpNodes[$i]);if (isType($tmpNode, $types, $isExact)) {$destNodes[`size $destNodes`] = $tmpNode;}}$destNodes = `sort $destNodes`;return $destNodes;}proc string buildDagNode(string $n,string $name,string $parentNode,int $maintainOffset,string $matchTransformNode,int $matchFlags[]) {if (!isDagNode($n) || isNodeReferenced($n)) return $n;string $nodeId = toUUID($n);$n = uuidToLongName($nodeId);if (isDagNode($matchTransformNode)) {int $numMatchFlags = `size $matchFlags`;if (!`size $matchFlags`) {matchTransform $n $matchTransformNode;}else {if ($matchFlags[0]) matchTransform -pos $n $matchTransformNode;if ($matchFlags[1]) matchTransform -rot $n $matchTransformNode;if ($matchFlags[2]) matchTransform -scl $n $matchTransformNode;}}string $selection[] = `ls -l -sl`;int $shouldSelect = isSelected($n);if ($shouldSelect) {$selection = stringArrayRemove({$n}, $selection);}if (isDagNode($parentNode)) {if ($maintainOffset) {parent -a $n $parentNode;}else {parent -r $n $parentNode;}$n = uuidToLongName($nodeId);}if ($shouldSelect) {$selection[`size $selection`] = $n;}select -r $selection;if (`size $name`) {rename $n $name;$n = uuidToLongName($nodeId);}return $n;}proc string createJoint(string $name,string $parentNode,int $maintainOffset,string $matchTransformNode,int $matchFlags[]) {return (buildDagNode(longNameOf(`createNode -ss "joint"`),$name,$parentNode,$maintainOffset,$matchTransformNode,$matchFlags));}proc string createLocator(string $name,string $parentNode,int $maintainOffset,string $matchTransformNode,int $matchFlags[]) {return (buildDagNode(getParentNode(longNameOf(`createNode -ss "locator"`)),$name,$parentNode,$maintainOffset,$matchTransformNode,$matchFlags));}proc string createTransform(string $name,string $parentNode,int $maintainOffset,string $matchTransformNode,int $matchFlags[]) {return (buildDagNode(longNameOf(`createNode -ss "transform"`),$name,$parentNode,$maintainOffset,$matchTransformNode,$matchFlags));}proc string getTopLevelNode(string $topLevelName,int $shouldCreate,int $ignoreReference) {string $n;if (!`size $topLevelName`) return "";string $nodes[] = `ls -l ("::" + $topLevelName)`;int $numNodes = `size $nodes`;if ($ignoreReference) {for ($i = $numNodes - 1; $i >= 0; $i--) {if (isNodeReferenced($nodes[$i])) {$nodes = `stringArrayRemove {$nodes[$i]} $nodes`;$numNodes--;}}}if ($numNodes > 1) return "";$n = ($numNodes == 1) ? $nodes[0] : "";if (`objExists $n`) return $n;if ($shouldCreate) {$n = createTransform($topLevelName, "", true, "", {});}return $n;}proc string getSecondLevelNode(string $topLevelName,string $secondLevelName,int $shouldCreate,int $ignoreReference) {string $n;if (!`size $topLevelName` || !`size $secondLevelName`) return "";string $nodes[] = `ls -l ("|::" + $topLevelName + "|::" + $secondLevelName)`;int $numNodes = `size $nodes`;if ($ignoreReference) {for ($i = $numNodes - 1; $i >= 0; $i--) {if (isNodeReferenced($nodes[$i])) {$nodes = `stringArrayRemove {$nodes[$i]} $nodes`;$numNodes--;}}}if ($numNodes > 1) return "";$n = ($numNodes == 1) ? $nodes[0] : "";if (`objExists $n`) return $n;if ($shouldCreate) {string $topLevelNode = getTopLevelNode($topLevelName,$shouldCreate,$ignoreReference);if (!`objExists $topLevelNode`) return "";$n = createTransform($secondLevelName, $topLevelNode, true, "", {});}return $n;}proc string getThirdLevelNode(string $topLevelName,string $secondLevelName,string $thirdLevelName,int $shouldCreate,int $ignoreReference) {string $n;if ( !`size $topLevelName` || !`size $secondLevelName` || !`size $thirdLevelName`) return "";string $nodes[] = `ls -l ("|::" + $topLevelName + "|::" + $secondLevelName + "|::" + $thirdLevelName)`;int $numNodes = `size $nodes`;if ($ignoreReference) {for ($i = $numNodes - 1; $i >= 0; $i--) {if (isNodeReferenced($nodes[$i])) {$nodes = `stringArrayRemove {$nodes[$i]} $nodes`;$numNodes--;}}}if ($numNodes > 1) return "";$n = ($numNodes == 1) ? $nodes[0] : "";if (`objExists $n`) return $n;if ($shouldCreate) {string $secondLevelNode = getSecondLevelNode($topLevelName,$secondLevelName,$shouldCreate,$ignoreReference);if (!`objExists $secondLevelNode`) return "";$n = createTransform($thirdLevelName, $secondLevelNode, true, "", {});}return $n;}proc freezeTransform(string $nodes[], int $preserveFlags[]) {string $dagNodes[];for ($n in $nodes) {if (isDagNode($n)) $dagNodes[`size $dagNodes`] = $n;}if (`size $dagNodes`) {makeIdentity -a true -n 0 -pn true -t (!$preserveFlags[0]) -r (!$preserveFlags[1]) -s (!$preserveFlags[2])$dagNodes;}}
/*1.0.0:Numeric*/proc int isInRangeFloat(float $value, float $min, float $max) {return ($min <= $value && $value <= $max);}proc int isInRangeInt(int $value, int $min, int $max) {return ($min <= $value && $value <= $max);}
/*1.1.0:Observer*/global string $nkObservers[];proc string escapeStringParam(string $input) {string $escapedText;int $size = `size $input`;for ($i = 1; $i <= $size; $i++) {string $c = `substring $input $i $i`;switch ($c) {case "\\": $escapedText += "\\\\"; break;case "\"": $escapedText += "\\\""; break;case "\n": $escapedText += "\\n"; break;case "\r": $escapedText += "\\r"; break;case "\t": $escapedText += "\\t"; break;default: $escapedText += $c; break;}}return $escapedText;}proc string[] escapeStringParams(string $input[]) {string $escapedArray[];for ($s in $input) {$escapedArray[`size $escapedArray`] = escapeStringParam($s);}return $escapedArray;}proc string floatParamsToString(float $params[]) {string $param = "{";int $numParams = `size $params`;for ($i = 0; $i < $numParams; $i++) {string $floatString = (string) $params[$i];if (!`gmatch $floatString "*.*"`) $floatString += ".0";$param += $floatString + (($i < $numParams - 1) ? ", " : "");}$param += "}";return $param;}proc string intParamsToString(int $params[]) {string $param = "{}";if (`size $param`) {$param = "{" + intArrayToString($params, ", ") + "}";}return $param;}proc string stringParamsToString(string $params[]) {string $param = "{}";if (`size $params`) {$param = "{\"" + stringArrayToString(escapeStringParams($params), "\", \"") + "\"}";}return $param;}proc clearObservers() {global string $nkObservers[];clear $nkObservers;}proc int isValidObserverEvent(string $event) {return (isValidString($event, "^[^;]+$"));}proc int isValidObserverProc(string $proc) {return (isValidString($proc, "^[a-zA-Z\|:\._][a-zA-Z0-9\|:\._]*$"));}proc int isValidObserver(string $observer) {return (isValidString($observer, "^[^;]+;[a-zA-Z\|:\._][a-zA-Z0-9\|:\._]*$"));}proc string makeObserver(string $event, string $proc) {string $observer;if (isValidObserverEvent($event) && isValidObserverProc($proc)) {$observer = $event + ";" + $proc;}return $observer;}proc string extractObserverEvent(string $observer) {string $event;string $buffer[];if (`tokenize $observer ";" $buffer` == 2) {$event = $buffer[0];}return $event;}proc string extractObserverProc(string $observer) {string $proc;string $buffer[];if (`tokenize $observer ";" $buffer` == 2) {$proc = $buffer[1];}return $proc;}proc int findObserver(string $observer) {global string $nkObservers[];int $index = -1;for ($i = 0; $i < `size $nkObservers`; $i++) {if ($observer == $nkObservers[$i]) {$index = $i;break;}}return $index;}proc int existsObserver(string $observer) {return (findObserver($observer) >= 0);}proc string[] getObserverProcs(string $event) {global string $nkObservers[];string $procs[];if (!isValidObserverEvent($event)) return $procs;for ($observer in $nkObservers) {if (extractObserverEvent($observer) == $event) {$procs[`size $procs`] = extractObserverProc($observer);}}return $procs;}proc int subscribe(string $event, string $proc) {global string $nkObservers[];string $observer = makeObserver($event, $proc);if (!isValidObserver($observer)) return false;if (existsObserver($observer)) return false;$nkObservers[`size $nkObservers`] = $observer;return true;}proc int unsubscribe(string $event, string $proc) {global string $nkObservers[];string $observer = makeObserver($event, $proc);if (!isValidObserver($observer)) return false;int $index = findObserver($observer);if ($index < 0) return false;stringArrayRemoveAtIndex($index, $nkObservers);return true;}proc notify(string $event) {string $procs[] = getObserverProcs($event);for ($proc in $procs) {if (`exists $proc`) {eval $proc;}}}proc notifyFloat(string $event, float $param) {string $procs[] = getObserverProcs($event);for ($proc in $procs) {if (`exists $proc`) {eval $proc $param;}}}proc notifyInt(string $event, int $param) {string $procs[] = getObserverProcs($event);for ($proc in $procs) {if (`exists $proc`) {eval $proc $param;}}}proc notifyString(string $event, string $param) {string $procs[] = getObserverProcs($event);for ($proc in $procs) {if (`exists $proc`) {eval $proc ("\"" + $param + "\"");}}}proc notifyFloatArray(string $event, float $params[]) {string $param = floatParamsToString($params);string $procs[] = getObserverProcs($event);for ($proc in $procs) {if (`exists $proc`) {eval ($proc + "(" + $param + ")");}}}proc notifyIntArray(string $event, int $params[]) {string $param = intParamsToString($params);string $procs[] = getObserverProcs($event);for ($proc in $procs) {if (`exists $proc`) {eval ($proc + "(" + $param + ")");}}}proc notifyStringArray(string $event, string $params[]) {string $param = stringParamsToString($params);string $procs[] = getObserverProcs($event);for ($proc in $procs) {if (`exists $proc`) {eval ($proc + "(" + $param + ")");}}}
/*1.0.0:Quaternion*/proc int reverseRotateOrder(int $order) {int $reverseOrder[] = {5, 3, 4, 1, 2, 0};return $reverseOrder[$order];}proc float[] eulerToQuat(float $r[], int $order) {float $qx = 0.0;float $qy = 0.0;float $qz = 0.0;float $qw = 1.0;float $rx = `deg_to_rad $r[0]`;float $ry = `deg_to_rad $r[1]`;float $rz = `deg_to_rad $r[2]`;float $cx = cos(0.5 * $rx);float $cy = cos(0.5 * $ry);float $cz = cos(0.5 * $rz);float $sx = sin(0.5 * $rx);float $sy = sin(0.5 * $ry);float $sz = sin(0.5 * $rz);switch ($order) {case 0: $qx = $sx * $cy * $cz + $cx * $sy * $sz;$qy = $cx * $sy * $cz - $sx * $cy * $sz;$qz = $cx * $cy * $sz + $sx * $sy * $cz;$qw = $cx * $cy * $cz - $sx * $sy * $sz;break;case 1: $qx = $sx * $cy * $cz + $cx * $sy * $sz;$qy = $cx * $sy * $cz + $sx * $cy * $sz;$qz = $cx * $cy * $sz - $sx * $sy * $cz;$qw = $cx * $cy * $cz - $sx * $sy * $sz;break;case 2: $qx = $sx * $cy * $cz - $cx * $sy * $sz;$qy = $cx * $sy * $cz + $sx * $cy * $sz;$qz = $cx * $cy * $sz + $sx * $sy * $cz;$qw = $cx * $cy * $cz - $sx * $sy * $sz;break;case 3: $qx = $sx * $cy * $cz - $cx * $sy * $sz;$qy = $cx * $sy * $cz - $sx * $cy * $sz;$qz = $cx * $cy * $sz + $sx * $sy * $cz;$qw = $cx * $cy * $cz + $sx * $sy * $sz;break;case 4: $qx = $sx * $cy * $cz + $cx * $sy * $sz;$qy = $cx * $sy * $cz - $sx * $cy * $sz;$qz = $cx * $cy * $sz - $sx * $sy * $cz;$qw = $cx * $cy * $cz + $sx * $sy * $sz;break;case 5: $qx = $sx * $cy * $cz - $cx * $sy * $sz;$qy = $cx * $sy * $cz + $sx * $cy * $sz;$qz = $cx * $cy * $sz - $sx * $sy * $cz;$qw = $cx * $cy * $cz + $sx * $sy * $sz;break;default: break;}return {$qx, $qy, $qz, $qw};}proc float[] quatToEuler(float $q[], int $order) {float $rx = 0.0;float $ry = 0.0;float $rz = 0.0;float $qx = $q[0];float $qy = $q[1];float $qz = $q[2];float $qw = $q[3];float $sx;float $sy;float $sz;int $unlocked;switch ($order) {case 0: $sy = 2 * $qx * $qz + 2 * $qy * $qw;$unlocked = abs($sy) < 0.9999999;$rx = $unlocked ? atan2(-(2 * $qy * $qz - 2 * $qx * $qw), 2 * $qw * $qw + 2 * $qz * $qz - 1) : atan2(2 * $qy * $qz + 2 * $qx * $qw, 2 * $qw * $qw + 2 * $qy * $qy - 1);$ry = asin($sy);$rz = $unlocked ? atan2(-(2 * $qx * $qy - 2 * $qz * $qw), 2 * $qw * $qw + 2 * $qx * $qx - 1) : 0;break;case 1: $sz = 2 * $qx * $qy + 2 * $qz * $qw;$unlocked = abs($sz) < 0.9999999;$rx = $unlocked ? atan2(-(2 * $qy * $qz - 2 * $qx * $qw), 2 * $qw * $qw + 2 * $qy * $qy - 1) : 0;$ry = $unlocked ? atan2(-(2 * $qx * $qz - 2 * $qy * $qw), 2 * $qw * $qw + 2 * $qx * $qx - 1) : atan2(2 * $qx * $qz + 2 * $qy * $qw, 2 * $qw * $qw + 2 * $qz * $qz - 1);$rz = asin($sz);break;case 2: $sx = 2 * $qy * $qz + 2 * $qx * $qw;$unlocked = abs($sx) < 0.9999999;$rx = asin($sx);$ry = $unlocked ? atan2(-(2 * $qx * $qz - 2 * $qy * $qw), 2 * $qw * $qw + 2 * $qz * $qz - 1) : 0;$rz = $unlocked ? atan2(-(2 * $qx * $qy - 2 * $qz * $qw), 2 * $qw * $qw + 2 * $qy * $qy - 1) : atan2(2 * $qx * $qy + 2 * $qz * $qw, 2 * $qw * $qw + 2 * $qx * $qx - 1);break;case 3: $sz = -(2 * $qx * $qy - 2 * $qz * $qw);$unlocked = abs($sz) < 0.9999999;$rx = $unlocked ? atan2(2 * $qy * $qz + 2 * $qx * $qw, 2 * $qw * $qw + 2 * $qy * $qy - 1) : atan2(-(2 * $qy * $qz - 2 * $qx * $qw), 2 * $qw * $qw + 2 * $qz * $qz - 1);$ry = $unlocked ? atan2(2 * $qx * $qz + 2 * $qy * $qw, 2 * $qw * $qw + 2 * $qx * $qx - 1) : 0;$rz = asin($sz);break;case 4: $sx = -(2 * $qy * $qz - 2 * $qx * $qw);$unlocked = abs($sx) < 0.9999999;$rx = asin($sx);$ry = $unlocked ? atan2(2 * $qx * $qz + 2 * $qy * $qw, 2 * $qw * $qw + 2 * $qz * $qz - 1) : atan2(-(2 * $qx * $qz - 2 * $qy * $qw), 2 * $qw * $qw + 2 * $qx * $qx - 1);$rz = $unlocked ? atan2(2 * $qx * $qy + 2 * $qz * $qw, 2 * $qw * $qw + 2 * $qy * $qy - 1) : 0;break;case 5: $sy = -(2 * $qx * $qz - 2 * $qy * $qw);$unlocked = abs($sy) < 0.9999999;$rx = $unlocked ? atan2(2 * $qy * $qz + 2 * $qx * $qw, 2 * $qw * $qw + 2 * $qz * $qz - 1) : 0;$ry = asin($sy);$rz = $unlocked ? atan2(2 * $qx * $qy + 2 * $qz * $qw, 2 * $qw * $qw + 2 * $qx * $qx - 1) : atan2(-(2 * $qx * $qy - 2 * $qz * $qw), 2 * $qw * $qw + 2 * $qy * $qy - 1);break;default: break;}$rx = `rad_to_deg $rx`;$ry = `rad_to_deg $ry`;$rz = `rad_to_deg $rz`;return {$rx, $ry, $rz};}proc float[] angleAxisToQuat(float $degree, float $axis[]) {float $ha = `deg_to_rad $degree` * 0.5;float $s = sin($ha);float $qx = $axis[0] * $s;float $qy = $axis[1] * $s;float $qz = $axis[2] * $s;float $qw = cos($ha);return {$qx, $qy, $qz, $qw};}proc float[] quatAdd(float $q1[], float $q2[]) {float $q1x = $q1[0];float $q1y = $q1[1];float $q1z = $q1[2];float $q1w = $q1[3];float $q2x = $q2[0];float $q2y = $q2[1];float $q2z = $q2[2];float $q2w = $q2[3];float $qx = $q1x + $q2x;float $qy = $q1y + $q2y;float $qz = $q1z + $q2z;float $qw = $q1w + $q2w;return {$qx, $qy, $qz, $qw};}proc float[] quatSubtract(float $q1[], float $q2[]) {float $q1x = $q1[0];float $q1y = $q1[1];float $q1z = $q1[2];float $q1w = $q1[3];float $q2x = $q2[0];float $q2y = $q2[1];float $q2z = $q2[2];float $q2w = $q2[3];float $qx = $q1x - $q2x;float $qy = $q1y - $q2y;float $qz = $q1z - $q2z;float $qw = $q1w - $q2w;return {$qx, $qy, $qz, $qw};}proc float[] quatMultiply(float $q1[], float $q2[]) {float $q1x = $q1[0];float $q1y = $q1[1];float $q1z = $q1[2];float $q1w = $q1[3];float $q2x = $q2[0];float $q2y = $q2[1];float $q2z = $q2[2];float $q2w = $q2[3];float $qx = $q1x * $q2w + $q1w * $q2x + $q1y * $q2z - $q1z * $q2y;float $qy = $q1y * $q2w + $q1w * $q2y + $q1z * $q2x - $q1x * $q2z;float $qz = $q1z * $q2w + $q1w * $q2z + $q1x * $q2y - $q1y * $q2x;float $qw = $q1w * $q2w - $q1x * $q2x - $q1y * $q2y - $q1z * $q2z;return {$qx, $qy, $qz, $qw};}proc float[] quatInverse(float $q[]) {return {$q[0] * -1, $q[1] * -1, $q[2] * -1, $q[3]};}proc float[] rotateVectorByQuat(float $v[], float $q[]) {float $iq[] = quatInverse($q);float $vq[] = {$v[0], $v[1], $v[2], 0};$vq = quatMultiply(quatMultiply($q, $vq), $iq);return {$vq[0], $vq[1], $vq[2]};}proc float[] quatFlip(float $q[], float $axis[]) {float $flipQ[] = angleAxisToQuat(180.0, $axis);return quatMultiply($flipQ, $q);}
/*1.6.0:String*/proc string escapeStringForLiteral(string $input) {string $escapedText;int $size = `size $input`;for ($i = 1; $i <= $size; $i++) {string $c = `substring $input $i $i`;switch ($c) {case "\"": $escapedText += "\\\""; break;case "\\": $escapedText += "\\\\"; break;case "\n": $escapedText += "\\n"; break;case "\r": $escapedText += "\\r"; break;case "\t": $escapedText += "\\t"; break;default: $escapedText += $c; break;}}return $escapedText;}proc string booleanAsStringLiteral(int $value) {return (($value == 0) ? "false" : "true");}proc string floatAsStringLiteral(float $value) {string $literal = (string) $value;if (!`gmatch $literal "*e*"` && !`gmatch $literal "*.*"`) $literal += ".0";return $literal;}proc string intAsStringLiteral(int $value) {return ((string) $value);}proc string stringAsStringLiteral(string $value) {return ("\"" + escapeStringForLiteral($value) + "\"");}proc string booleanArrayAsStringLiteral(int $values[]) {string $stringValues[];for ($i = 0; $i < `size $values`; $i++) {$stringValues[$i] = booleanAsStringLiteral($values[$i]);}return ("{" + stringArrayToString($stringValues, ", ") + "}");}proc string floatArrayAsStringLiteral(float $values[]) {string $stringValues[];for ($i = 0; $i < `size $values`; $i++) {$stringValues[$i] = floatAsStringLiteral($values[$i]);}return ("{" + stringArrayToString($stringValues, ", ") + "}");}proc string intArrayAsStringLiteral(int $values[]) {return ("{" + intArrayToString($values, ", ") + "}");}proc string stringArrayAsStringLiteral(string $values[]) {string $stringValues[];for ($i = 0; $i < `size $values`; $i++) {$stringValues[$i] = stringAsStringLiteral($values[$i]);}return ("{" + stringArrayToString($stringValues, ", ") + "}");}proc string join(string $inputs[], string $separator, int $ignoreEmpty) {int $numInputs = `size $inputs`;if (!$numInputs || ($numInputs == 1 && !`size $inputs[0]`)) return "";if ($ignoreEmpty) {string $buffer[];for ($input in $inputs) {if (`size $input`) $buffer[`size $buffer`] = $input;}return stringArrayToString($buffer, $separator);}else {return stringArrayToString($inputs, $separator);}}proc string strip(string $input) {return `python(convertStringForPythonString($input) + ".strip()")`;}proc string regexSearchGroup(string $pattern, string $input, string $flags) {$flags = (`size $flags`) ? "(?" + $flags + ")" : "";python("import re");string $result = `python("(lambda m: m.group() if m else None)(re.search(" + convertStringForPythonString($flags + $pattern) + ", " + convertStringForPythonString($input) + "))")`;return $result;}proc int[] regexSearchSpan(string $pattern, string $input, string $flags) {$flags = (`size $flags`) ? "(?" + $flags + ")" : "";python("import re");int $result[] = `python("(lambda m: m.span() if m else None)(re.search(" + convertStringForPythonString($flags + $pattern) + ", " + convertStringForPythonString($input) + "))")`;return $result;}proc string[] regexMatchGroups(string $pattern, string $input, string $flags) {$flags = (`size $flags`) ? "(?" + $flags + ")" : "";python("import re");string $result[] = `python("tuple([m.group() for m in re.finditer(" + convertStringForPythonString($flags + $pattern) + ", " + convertStringForPythonString($input) + ")])")`;return $result;}proc string[] regexMatchSubGroups(string $pattern, string $input, string $flags) {$flags = (`size $flags`) ? "(?" + $flags + ")" : "";python("import re");string $result[] = `python("sum([m.groups() for m in re.finditer(" + convertStringForPythonString($flags + $pattern) + ", " + convertStringForPythonString($input) + ")], ())")`;return $result;}proc int[] regexMatchSpans(string $pattern, string $input, string $flags) {$flags = (`size $flags`) ? "(?" + $flags + ")" : "";python("import re");int $result[] = `python("sum([m.span() for m in re.finditer(" + convertStringForPythonString($flags + $pattern) + ", " + convertStringForPythonString($input) + ")], ())")`;return $result;}proc int regexIsMatch(string $pattern, string $input, string $flags) {return (`size (regexSearchGroup($pattern, $input, $flags))` > 0);}proc string[] regexSplit(string $pattern, string $input, string $flags) {$flags = (`size $flags`) ? "(?" + $flags + ")" : "";python("import re");string $result[] = `python("tuple(re.split(" + convertStringForPythonString($flags + $pattern) + ", " + convertStringForPythonString($input) + "))")`;return $result;}proc string regexReplace(string $pattern,string $replacement,string $input,string $flags) {$flags = (`size $flags`) ? "(?" + $flags + ")" : "";python("import re");string $result = `python("re.sub(" + convertStringForPythonString($flags + $pattern) + ", " + convertStringForPythonString($replacement) + ", " + convertStringForPythonString($input) + ")")`;return $result;}proc string getClipboardText() {python("from PySide2 import QtGui");return python("QtGui.QClipboard().text()");}proc setClipboardText(string $text) {python("from PySide2 import QtGui");python("QtGui.QClipboard().setText(" + convertStringForPythonString($text) + ")");}proc string dictSanitize(string $input) {string $pattern = "[=;]";if (regexIsMatch($pattern, $input, "")) {return regexReplace($pattern, "_", $input, "");}else {return $input;}}proc string[] dictSanitizeArray(string $input[]) {string $result[];for ($i = 0; $i < `size $input`; $i++) {$result[$i] = dictSanitize($input[$i]);}return $result;}proc string[] dictExtractItems(string $dict) {string $items[];string $buffer[] = regexSplit(";", $dict, "");for ($item in $buffer) {if (!`size $item`) continue;$items[`size $items`] = $item;}return $items;}proc int dictIsKeyEquals(string $item, string $key) {return (`size $key` && `gmatch $item ($key + "=*")`);}proc string dictExtractKey(string $item) {if (!`gmatch $item "?*=*"`) return "";return regexReplace("^([^=]+)=.*", "\\1", $item, "");}proc string dictExtractValue(string $item) {if (!`gmatch $item "?*=*"`) return "";return regexReplace("^[^=]+=", "", $item, "");}proc string dictGetValue(string $dict, string $key) {string $value;if (!`size $key`) return $value;string $items[] = dictExtractItems($dict);for ($item in $items) {if (dictIsKeyEquals($item, $key)) {$value = dictExtractValue($item);break;}}return $value;}proc string[] dictKeys(string $dict) {string $keys[];string $items[] = dictExtractItems($dict);for ($item in $items) {string $key = dictExtractKey($item);if (!`size $key`) continue;$keys[`size $keys`] = $key;}return $keys;}proc int dictContainsKey(string $dict, string $key) {if (!`size $key`) return false;string $keys[] = dictKeys($dict);return stringArrayContains($key, $keys);}proc string dictAddItem(string $dict, string $key, string $value) {if (!`size $key`) return $dict;string $newDict;int $isOverwrite;string $items[] = dictExtractItems($dict);for ($item in $items) {if (dictIsKeyEquals($item, $key)) {$isOverwrite = true;$newDict += $key + "=" + $value + ";";}else {$newDict += $item + ";";}}if (!$isOverwrite) {$newDict += $key + "=" + $value + ";";}return $newDict;}proc string dictAddBoolean(string $dict, string $key, int $value) {return dictAddItem($dict, dictSanitize($key), booleanAsStringLiteral($value));}proc string dictAddFloat(string $dict, string $key, float $value) {return dictAddItem($dict, dictSanitize($key), floatAsStringLiteral($value));}proc string dictAddInt(string $dict, string $key, int $value) {return dictAddItem($dict, dictSanitize($key), intAsStringLiteral($value));}proc string dictAddString(string $dict, string $key, string $value) {$value = dictSanitize($value);return dictAddItem($dict, dictSanitize($key), stringAsStringLiteral($value));}proc string dictAddBooleanArray(string $dict, string $key, int $value[]) {return dictAddItem($dict, dictSanitize($key), booleanArrayAsStringLiteral($value));}proc string dictAddFloatArray(string $dict, string $key, float $value[]) {return dictAddItem($dict, dictSanitize($key), floatArrayAsStringLiteral($value));}proc string dictAddIntArray(string $dict, string $key, int $value[]) {return dictAddItem($dict, dictSanitize($key), intArrayAsStringLiteral($value));}proc string dictAddStringArray(string $dict, string $key, string $value[]) {$value = dictSanitizeArray($value);return dictAddItem($dict, dictSanitize($key), stringArrayAsStringLiteral($value));}proc int dictGetBoolean(string $dict, string $key, int $default) {string $value = dictGetValue($dict, $key);if ($value == "true") {return true;}else if ($value == "false") {return false;}return $default;}proc float dictGetFloat(string $dict, string $key, float $default) {string $value = dictGetValue($dict, $key);if (`size $value`) return ((float) $value);return $default;}proc int dictGetInt(string $dict, string $key, int $default) {string $value = dictGetValue($dict, $key);if (`size $value`) return ((int) $value);return $default;}proc string dictGetString(string $dict, string $key, string $default) {string $value = dictGetValue($dict, $key);if (`size $value`) return `eval ("format -s " + $value + " \"^1s\";")`;return $default;}global int $dictBooleanArrayBuffer[];global float $dictFloatArrayBuffer[];global int $dictIntArrayBuffer[];global string $dictStringArrayBuffer[];proc int[] dictGetBooleanArray(string $dict, string $key, int $default[]) {global int $dictBooleanArrayBuffer[];clear $dictBooleanArrayBuffer;string $value = dictGetValue($dict, $key);if (`size $value`) {eval ("$dictBooleanArrayBuffer = " + $value + ";");return $dictBooleanArrayBuffer;}return $default;}proc float[] dictGetFloatArray(string $dict, string $key, float $default[]) {global float $dictFloatArrayBuffer[];clear $dictFloatArrayBuffer;string $value = dictGetValue($dict, $key);if (`size $value`) {eval ("$dictFloatArrayBuffer = " + $value + ";");return $dictFloatArrayBuffer;}return $default;}proc int[] dictGetIntArray(string $dict, string $key, int $default[]) {global int $dictIntArrayBuffer[];clear $dictIntArrayBuffer;string $value = dictGetValue($dict, $key);if (`size $value`) {eval ("$dictIntArrayBuffer = " + $value + ";");return $dictIntArrayBuffer;}return $default;}proc string[] dictGetStringArray(string $dict, string $key, string $default[]) {global string $dictStringArrayBuffer[];clear $dictStringArrayBuffer;string $value = dictGetValue($dict, $key);if (`size $value`) {eval ("$dictStringArrayBuffer = " + $value + ";");return $dictStringArrayBuffer;}return $default;}proc string dictRemove(string $dict, string $key) {if (!`size $key`) return $dict;string $newDict;string $items[] = dictExtractItems($dict);for ($item in $items) {string $itemKey = dictExtractKey($item);if ($itemKey == $key) continue;$newDict += $item + ";";}return $newDict;}
/*2.2.1:UIControl*/global string $nkUIControls[];proc appendUIControls(string $controls[]) {global string $nkUIControls[];for ($control in $controls) {$nkUIControls[`size $nkUIControls`] = $control;}}proc string getUIControl(string $root, string $end) {global string $nkUIControls[];string $path;for ($control in $nkUIControls) {string $buffer[];int $depth = `tokenize $control "|" $buffer`;string $first = ($depth > 0) ? $buffer[0] : "";string $last = ($depth > 0) ? $buffer[$depth - 1] : "";if ($first == $root && $last == $end) {$path = $control;break;}}return $path;}proc removeUIControls(string $root, string $end) {global string $nkUIControls[];string $paths[];for ($control in $nkUIControls) {string $buffer[];int $depth = `tokenize $control "|" $buffer`;string $first = ($depth > 0) ? $buffer[0] : "";string $last = ($depth > 0) ? $buffer[$depth - 1] : "";int $shouldRemove = (!`size $end`) ? $first == $root : $first == $root && $last == $end;if ($shouldRemove) $paths[`size $paths`] = $control;}if (`size $paths` > 0) {$nkUIControls = stringArrayRemove($paths, $nkUIControls);}}proc string uiControlTypeOf(string $control) {string $type;if (!`size $control`) return $type;$type = `objectTypeUI $control`;if ($type == "floatingWindow") $type = "window";return $type;}proc int qEnable(string $control) {string $type = uiControlTypeOf($control);if ($type == "window" || $type == "workspaceControl") return true;return `control -q -en $control`;}proc eEnable(int $bValue, string $control) {string $type = uiControlTypeOf($control);if ($type == "window" || $type == "workspaceControl") return;control -e -en $bValue $control;}proc int qExists(string $control) {return `control -q -ex $control`;}proc int qVisible(string $control) {return `control -q -vis $control`;}proc eVisible(int $bValue, string $control) {control -e -vis $bValue $control;}proc float qFloat(string $type, string $flag, string $control) {return `eval $type "-q" $flag $control`;}proc eFloat(string $type, string $flag, float $fValue, string $control) {eval $type "-e" $flag $fValue $control;}proc int qInt(string $type, string $flag, string $control) {return `eval $type "-q" $flag $control`;}proc eInt(string $type, string $flag, int $iValue, string $control) {eval $type "-e" $flag $iValue $control;}proc string qString(string $type, string $flag, string $control) {return `eval $type "-q" $flag $control`;}proc eString(string $type, string $flag, string $sValue, string $control) {eval $type "-e" $flag ("\"" + $sValue + "\"") $control;}proc float[] qFloatArray(string $type, string $flag, string $control) {return `eval $type "-q" $flag $control`;}proc int[] qIntArray(string $type, string $flag, string $control) {return `eval $type "-q" $flag $control`;}proc string[] qStringArray(string $type, string $flag, string $control) {return `eval $type "-q" $flag $control`;}proc eFloat2Array(string $type, string $flag, float $fValues[], string $control) {eval $type "-e" $flag $fValues[0] $fValues[1] $control;}proc eFloat3Array(string $type, string $flag, float $fValues[], string $control) {eval $type "-e" $flag $fValues[0] $fValues[1] $fValues[2] $control;}proc eFloat4Array(string $type, string $flag, float $fValues[], string $control) {eval $type "-e" $flag $fValues[0] $fValues[1] $fValues[2] $fValues[3] $control;}proc eStringArray(string $type, string $flag, string $sValues[], string $control) {for ($sValue in $sValues) {eString($type, $flag, $sValue, $control);}}proc eOrderedFloat(string $type, string $flag, float $fValues[], string $control) {for ($i = 0; $i < `size $fValues`; $i++) {eFloat($type, ($flag + ($i + 1)), $fValues[$i], $control);}}proc eOrderedInt(string $type, string $flag, int $iValues[], string $control) {for ($i = 0; $i < `size $iValues`; $i++) {eInt($type, ($flag + ($i + 1)), $iValues[$i], $control);}}proc eOrderedString(string $type, string $flag, string $sValues[], string $control) {for ($i = 0; $i < `size $sValues`; $i++) {eString($type, ($flag + ($i + 1)), $sValues[$i], $control);}}proc int qIndex(string $type, string $flag, string $control) {return (qInt($type, $flag, $control) - 1);}proc eIndex(string $type, string $flag, int $index, string $control) {eInt($type, $flag, ($index + 1), $control);}proc int[] qIndexArray(string $type, string $flag, string $control) {int $indices[] = qIntArray($type, $flag, $control);for ($i = 0; $i < `size $indices`; $i++) $indices[$i] -= 1;return $indices;}proc eIndexArray(string $type, string $flag, int $indices[], string $control) {for ($i in $indices) {eInt($type, $flag, $i + 1, $control);}}proc int qFirstIndex(string $type, string $flag, string $control) {int $indices[] = qIndexArray($type, $flag, $control);return ((`size $indices`) ? $indices[0] : -1);}proc string qFirstString(string $type, string $flag, string $control) {string $sValues[] = qStringArray($type, $flag, $control);return ((`size $sValues`) ? $sValues[0] : "");}proc eIntString(string $type, string $flag, int $iValue, string $sValue, string $control) {eval $type "-e" $flag $iValue ("\"" + $sValue + "\"") $control;}proc eIndexString(string $type, string $flag, int $index, string $sValue, string $control) {eIntString($type, $flag, $index + 1, $sValue, $control);}proc eStringInt(string $type, string $flag, string $sValue, int $iValue, string $control) {eval $type "-e" $flag ("\"" + $sValue + "\"") $iValue $control;}proc executeUIControl(string $type, string $flag, string $control) {eval $type "-e" $flag $control;}proc string getParentableWindow(string $control) {if (uiControlTypeOf($control) == "workspaceControl" && !qInt("workspaceControl", "-fl", $control)) {return "MayaWindow";}else {return $control;}}proc windowClose(string $control) {if (qExists($control)) {string $type = uiControlTypeOf($control);switch ($type) {case "window": deleteUI $control; break;case "workspaceControl": executeUIControl("workspaceControl", "-cl", $control);break;default: break;}}}proc windowPrefRemove(string $type, string $control) {if (qExists($control)) windowClose($control);switch ($type) {case "window": if (qInt("windowPref", "-ex", $control)) {windowPref -r $control;}break;case "workspaceControl": if (qInt("workspaceControlState", "-ex", $control)) {workspaceControlState -r $control;}break;default: break;}}proc string buildWorkspaceControl(string $workspaceControlName,string $label,string $buildProcName,string $buildProcFilename) {string $control = $workspaceControlName;if (!qExists($workspaceControlName)) {string $uiScript = "if (!`exists " + $buildProcName + "`)" + " source \"" + $buildProcFilename + "\"; " + $buildProcName + "();";$control = `workspaceControl -dup false -fl true -l $label -rt false -ui $uiScript$workspaceControlName`;}return $control;}
// /////////////////////////////////////////////////////////////////////////////
// ドメイン
// /////////////////////////////////////////////////////////////////////////////
/*-
@returns <string>
*/
proc string getPoseVersion() {
return "1";
}
/*-
@var <boolean[3]>
*/
global int $nkPoseStackInitPasteSetting[];
/*-
@var <string[2]>
*/
global string $nkPoseStackInitSelectSetting[];
/*-
@var <int[5]>
*/
global int $nkPoseStackInitMirrorSetting[];
/*-
@returns <>
*/
proc initializeInitParameters() {
// print("initializeInitParameters\n"); // debug
global int $nkPoseStackInitPasteSetting[];
global string $nkPoseStackInitSelectSetting[];
global int $nkPoseStackInitMirrorSetting[];
if (!`size $nkPoseStackInitPasteSetting`) {
$nkPoseStackInitPasteSetting = {true, true, false};
// print(" nkPoseStackInitPasteSetting :{" + intArrayToString($nkPoseStackInitPasteSetting, ", ") + "}\n"); // debug
}
if (!`size $nkPoseStackInitSelectSetting`) {
$nkPoseStackInitSelectSetting = {"_L", "_R"};
// print(" nkPoseStackInitSelectSetting:{" + stringArrayToString($nkPoseStackInitSelectSetting, ", ") + "}\n"); // debug
}
if (!`size $nkPoseStackInitMirrorSetting`) {
$nkPoseStackInitMirrorSetting = {0, 0, 1, false, false};
// print(" nkPoseStackInitMirrorSetting:{" + intArrayToString($nkPoseStackInitMirrorSetting, ", ") + "}\n"); // debug
}
}
// -----------------------------------------------------------------------------
// データ変換
// -----------------------------------------------------------------------------
/*-
@param $values <string[]>
@returns <string>
*/
proc string serialize(string $values[]) {
string $lines[];
for ($value in $values) {
if (!`size $value`) continue;
$lines[`size $lines`] = $value;
}
string $text = stringArrayToString($lines, "\n");
if (`size $lines`) {
$text = getPoseVersion() + "\n" + $text + "\n";
}
return $text;
}
/*-
@param $input <string>
@returns <string[]>
*/
proc string[] deserialize(string $input) {
string $buffer[];
tokenize $input "\n" $buffer;
string $lines[];
for ($line in $buffer) {
if (!`size $line`) continue;
$lines[`size $lines`] = $line;
}
return $lines;
}
/*-
@param $pasteSetting <boolean[3]>
@param $selectSetting <string[2]>
@param $mirrorSetting <int[5]>
@returns <string>
*/
proc string makePoseSetting(
int $pasteSetting[],
string $selectSetting[],
int $mirrorSetting[]
) {
string $poseSetting = intArrayToString($pasteSetting, ",");
$poseSetting += "/" + stringArrayToString($selectSetting, ",");
$poseSetting += "/" + intArrayToString($mirrorSetting, ",");
return $poseSetting;
}
/*-
@param $n <string>
@param $poseSetting <string>
@returns <string>
*/
proc string makeTransformHeader(string $n, string $poseSetting) {
return ($n + "[" + $poseSetting + "]");
}
/*-
@param $header <string>
@param $values <float[]>
@returns <string>
*/
proc string makePoseTransform(string $header, float $values[]) {
return ($header + floatArrayToString($values, ","));
}
/*-
@param $poseName <string>
@param $poseTransforms <string[]>
@returns <string>
*/
proc string makePose(string $poseName, string $poseTransforms[]) {
string $pose;
if (!`size $poseName` || !`size $poseTransforms`) return $pose;
$pose += $poseName + "=";
$pose += stringArrayToString($poseTransforms, ";") + ";";
return $pose;
}
/*-
@param $pose <string>
@returns <string>
*/
proc string extractPoseName(string $pose) {
string $poseName;
string $buffer[];
if (`tokenize $pose "=" $buffer` == 2) {
$poseName = $buffer[0];
}
return $poseName;
}
/*-
@param $pose <string>
@returns <string[]>
*/
proc string[] extractPoseTransforms(string $pose) {
string $poseTransforms[];
string $buffer1[];
if (`tokenize $pose "=" $buffer1` == 2) {
string $buffer2[];
if (`tokenize $buffer1[1] ";" $buffer2` > 0) {
$poseTransforms = $buffer2;
}
}
return $poseTransforms;
}
/*-
@param $poseTransform <string>
@returns <string[2]>
*/
proc string[] extractTransformHeader(string $poseTransform) {
string $header[];
string $buffer1[];
if (`tokenize $poseTransform "]" $buffer1` == 2) {
string $buffer2[];
if (`tokenize $buffer1[0] "[" $buffer2` == 2) {
$header = $buffer2;
}
}
return $header;
}
/*-
@param $poseTransform <string>
@returns <string>
*/
proc string extractTransformNode(string $poseTransform) {
string $node;
string $header[] = extractTransformHeader($poseTransform);
if (`size $header` == 2) $node = $header[0];
return $node;
}
/*-
@param $poseTransform <string>
@returns <string>
*/
proc string extractPoseSetting(string $poseTransform) {
string $poseSetting;
string $header[] = extractTransformHeader($poseTransform);
if (`size $header` == 2) $poseSetting = $header[1];
return $poseSetting;
}
/*-
@param $poseSetting <string>
@returns <string[3]>
*/
proc string[] extractPoseSettings(string $poseSetting) {
string $poseSettings[];
string $buffer[];
if (`tokenize $poseSetting "/" $buffer` == 3) {
$poseSettings = $buffer;
}
return $poseSettings;
}
/*-
@param $poseSetting <string>
@returns <boolean[3]>
*/
proc int[] extractPasteSetting(string $poseSetting) {
int $pasteSetting[] = {1, 1, 0};
string $poseSettings[] = extractPoseSettings($poseSetting);
string $buffer[];
if (`tokenize $poseSettings[0] "," $buffer` == 3) {
for ($i = 0; $i < 3; $i++) {
$pasteSetting[$i] = (int) $buffer[$i];
}
}
return $pasteSetting;
}
/*-
@param $poseSetting <string>
@returns <string[2]>
*/
proc string[] extractSelectSetting(string $poseSetting) {
string $selectSetting[] = {"_L", "_R"};
string $poseSettings[] = extractPoseSettings($poseSetting);
string $buffer[];
if (`tokenize $poseSettings[1] "," $buffer` == 2) {
for ($i = 0; $i < 2; $i++) {
$selectSetting[$i] = $buffer[$i];
}
}
return $selectSetting;
}
/*-
@param $poseSetting <string>
@returns <int[5]>
*/
proc int[] extractMirrorSetting(string $poseSetting) {
int $mirrorSetting[] = {0, 0, 1, 0, 0};
string $poseSettings[] = extractPoseSettings($poseSetting);
string $buffer[];
if (`tokenize $poseSettings[2] "," $buffer` == 5) {
for ($i = 0; $i < 5; $i++) {
$mirrorSetting[$i] = (int) $buffer[$i];
}
}
return $mirrorSetting;
}
/*-
@param $poseTransform <string>
@returns <float[13]>
*/
proc float[] extractTransformValues(string $poseTransform) {
float $values[] = {
0, 0, 0,
0, 0, 0, 1,
1, 1, 1,
0, 0, 0
};
string $buffer1[];
if (`tokenize $poseTransform "]" $buffer1` == 2) {
string $buffer2[];
if (`tokenize $buffer1[1] "," $buffer2` == 13) {
for ($i = 0; $i < 13; $i++) {
$values[$i] = (float) $buffer2[$i];
}
}
}
return $values;
}
/*-
@param $value <string>
@returns <string>
@remarks 戻り値にポーズバージョンは含まれない。
*/
proc string convertDataVersion(string $value) {
// print("convertDataVersion\n"); // debug
// print(" value:" + $value + "\n"); // debug
string $newValue;
if (!`size $value`) return $newValue;
string $lines[] = deserialize($value);
if (`size $lines` < 2) return $newValue;
string $poseVersion = getPoseVersion();
int $valueVersion = (int) $lines[0];
int $currentVersion = (int) $poseVersion;
// print(" valueVersion :" + $valueVersion + "\n"); // debug
// print(" currentVersion:" + $currentVersion + "\n"); // debug
if (!stringArrayRemoveAtIndex(0, $lines)) return $newValue;
switch ($valueVersion) {
case 0: // テスト用
switch ($currentVersion) {
case 1: for ($line in $lines) $newValue += "x" + $line + "\n"; break;
default: break;
}
break;
case 1:
switch ($currentVersion) {
case 1: $newValue = stringArrayToString($lines, "\n") + "\n"; break;
default: break;
}
break;
default: break;
}
return $newValue;
}
/*-
@param $n <string>
@param $poses <string[]>
@returns <string[]>
*/
proc string[] resolveNamespace(string $n, string $poses[]) {
// print("resolveNamespace\n"); // debug
// print(" n :" + $n + "\n"); // debug
// print(" poses:{\n " + stringArrayToString($poses, ",\n ") + "\n }\n"); // debug
if (!`objExists $n` || !`size $poses`) return $poses;
string $names[] = `ls -l -sns $n`;
if (`size $names` != 2) return $poses;
string $namespace = $names[1];
// print(" namespace:" + $namespace + "\n"); // debug
if ($namespace == ":") return $poses;
string $replacement = "|" + $namespace + ":";
for ($i = 0; $i < `size $poses`; $i++) {
string $pose = $poses[$i];
string $poseName = extractPoseName($pose);
string $poseTransforms[] = extractPoseTransforms($pose);
// print(" pose:" + $pose + "\n"); // debug
// print(" poseName :" + $poseName + "\n"); // debug
// print(" poseTransforms:{\n " + stringArrayToString($poseTransforms, ",\n ") + "\n }\n"); // debug
for ($j = 0; $j < `size $poseTransforms`; $j++) {
string $poseTransform = $poseTransforms[$j];
string $transformNode = extractTransformNode($poseTransform);
string $poseSetting = extractPoseSetting($poseTransform);
float $transformValues[] = extractTransformValues($poseTransform);
// print(" poseTransform:" + $poseTransform + "\n"); // debug
// print(" transformNode :" + $transformNode + "\n"); // debug
// print(" poseSetting :" + $poseSetting + "\n"); // debug
// print(" transformValues:{" + floatArrayToString($transformValues, ", ") + "}\n"); // debug
$transformNode = regexReplace("\\|", $replacement, $transformNode, "");
string $header = makeTransformHeader($transformNode, $poseSetting);
$poseTransforms[$j] = makePoseTransform($header, $transformValues);
}
$poses[$i] = makePose($poseName, $poseTransforms);
}
return $poses;
}
// -----------------------------------------------------------------------------
// トランスフォーム
// -----------------------------------------------------------------------------
/*-
@param $n <string>
@returns <float[13]>
*/
proc float[] getTransformAttributeValues(string $n) {
// print("getTransformAttributeValues\n"); // debug
// print(" n:" + $n + "\n"); // debug
float $values[] = {
0, 0, 0,
0, 0, 0, 1,
1, 1, 1,
0, 0, 0
};
string $type = `nodeType $n`;
if (!($type == "transform" || $type == "joint")) return $values;
float $t[] = `getAttr ($n + ".translate")`;
float $r[] = `getAttr ($n + ".rotate")`;
float $s[] = `getAttr ($n + ".scale")`;
float $h[] = `getAttr ($n + ".shear")`;
// print(" t :{" + floatArrayToString($t, ", ") + "}\n"); // debug
// print(" r :{" + floatArrayToString($r, ", ") + "}\n"); // debug
// print(" s :{" + floatArrayToString($s, ", ") + "}\n"); // debug
// print(" h :{" + floatArrayToString($h, ", ") + "}\n"); // debug
int $o = `getAttr ($n + ".rotateOrder")`;
$o = reverseRotateOrder($o);
// `rotateAxis`と`jointOrient`の回転順序は常にXYZ
int $oXYZ = reverseRotateOrder(0);
float $rq[] = eulerToQuat($r, $o);
float $ra[] = `getAttr ($n + ".rotateAxis")`;
$ra = eulerToQuat($ra, $oXYZ);
float $jo[] = {0, 0, 0, 1};
if (`attributeQuery -n $n -ex "jointOrient"`) {
$jo = `getAttr ($n + ".jointOrient")`;
$jo = eulerToQuat($jo, $oXYZ);
}
float $q[] = quatMultiply($jo, quatMultiply($ra, $rq));
// print(" o :" + $o + "\n"); // debug
// print(" rq:{" + floatArrayToString($rq, ", ") + "}\n"); // debug
// print(" ra:{" + floatArrayToString($ra, ", ") + "}\n"); // debug
// print(" jo:{" + floatArrayToString($jo, ", ") + "}\n"); // debug
// print(" q :{" + floatArrayToString($q, ", ") + "}\n"); // debug
$values = {
$t[0], $t[1], $t[2],
$q[0], $q[1], $q[2], $q[3],
$s[0], $s[1], $s[2],
$h[0], $h[1], $h[2]
};
return $values;
}
/*-
@param $nodes <string[]>
@param $poseSettings <string[]>
@returns <string[]>
*/
proc string[] makePoseTransforms(string $nodes[], string $poseSettings[]) {
// print("makePoseTransforms\n"); // debug
// print(" nodes :{\n " + stringArrayToString($nodes, ",\n ") + "\n }\n"); // debug
// print(" poseSettings:{\n " + stringArrayToString($poseSettings, ",\n ") + "\n }\n"); // debug
string $poseTransforms[];
int $numTransforms = minStringArrayCount($nodes, $poseSettings);
for ($i = 0; $i < $numTransforms; $i++) {
string $n = $nodes[$i];
// print(" n:" + $n + "\n"); // debug
if (`objExists $n`) {
string $header = makeTransformHeader($n, $poseSettings[$i]);
float $values[] = getTransformAttributeValues($n);
string $poseTransform = makePoseTransform($header, $values);
$poseTransforms[$i] = $poseTransform;
}
else {
$poseTransforms[$i] = "";
}
// print(" poseTransform:" + $poseTransforms[$i] + "\n"); // debug
}
return $poseTransforms;
}
/*-
@param $n <string>
@param $m <float[12]>
@param $shouldSetT <boolean>
@param $shouldSetR <boolean>
@param $shouldSetS <boolean>
@returns <>
*/
proc setTransformAttributes(
string $n,
float $m[],
int $shouldApplyT,
int $shouldApplyR,
int $shouldApplyS
) {
// print("setTransformAttributes\n"); // debug
// print(" n :" + $n + "\n"); // debug
// print(" m :{" + floatArrayToString($m, ", ") + "}\n"); // debug
// print(" shouldApplyT:" + $shouldApplyT + "\n"); // debug
// print(" shouldApplyR:" + $shouldApplyR + "\n"); // debug
// print(" shouldApplyS:" + $shouldApplyS + "\n"); // debug
if (!(`objExists $n` && `size $m` == 12)) return;
float $t[] = {$m[0], $m[1], $m[2]};
float $r[] = {$m[3], $m[4], $m[5]};
float $s[] = {$m[6], $m[7], $m[8]};
float $h[] = {$m[9], $m[10], $m[11]};
// print(" t:{" + floatArrayToString($t, ", ") + "}\n"); // debug
// print(" r:{" + floatArrayToString($r, ", ") + "}\n"); // debug
// print(" s:{" + floatArrayToString($s, ", ") + "}\n"); // debug
// print(" h:{" + floatArrayToString($h, ", ") + "}\n"); // debug
string $tx = $n + ".tx";
string $ty = $n + ".ty";
string $tz = $n + ".tz";
string $rx = $n + ".rx";
string $ry = $n + ".ry";
string $rz = $n + ".rz";
string $sx = $n + ".sx";
string $sy = $n + ".sy";
string $sz = $n + ".sz";
if ($shouldApplyT) {
if (!`getAttr -l $tx`) setAttr $tx $t[0];
if (!`getAttr -l $ty`) setAttr $ty $t[1];
if (!`getAttr -l $tz`) setAttr $tz $t[2];
}
if ($shouldApplyR) {
if (!`getAttr -l $rx`) setAttr $rx $r[0];
if (!`getAttr -l $ry`) setAttr $ry $r[1];
if (!`getAttr -l $rz`) setAttr $rz $r[2];
}
if ($shouldApplyS) {
if (!`getAttr -l $sx`) setAttr $sx $s[0];
if (!`getAttr -l $sy`) setAttr $sy $s[1];
if (!`getAttr -l $sz`) setAttr $sz $s[2];
}
}
/*-
@param $n <string>
@param $m <float[13]>
@returns <float[12]>
*/
proc float[] asIsTransform(string $n, float $m[]) {
// print("asIsTransform\n"); // debug
// print(" n :" + $n + "\n"); // debug
// print(" m :{" + floatArrayToString($m, ", ") + "}\n"); // debug
float $t[] = {$m[0], $m[1], $m[2]};
float $q[] = {$m[3], $m[4], $m[5], $m[6]};
float $s[] = {$m[7], $m[8], $m[9]};
float $h[] = {$m[10], $m[11], $m[12]};
// print(" t :{" + floatArrayToString($t, ", ") + "}\n"); // debug
// print(" q :{" + floatArrayToString($q, ", ") + "}\n"); // debug
// print(" s :{" + floatArrayToString($s, ", ") + "}\n"); // debug
// print(" h :{" + floatArrayToString($h, ", ") + "}\n"); // debug
int $o = `getAttr ($n + ".rotateOrder")`;
$o = reverseRotateOrder($o);
// `rotateAxis`と`jointOrient`の回転順序は常にXYZ
int $oXYZ = reverseRotateOrder(0);
float $ra[] = `getAttr ($n + ".rotateAxis")`;
$ra = quatInverse(eulerToQuat($ra, $oXYZ));
float $jo[] = {0, 0, 0, 1};
if (`attributeQuery -n $n -ex "jointOrient"`) {
$jo = `getAttr ($n + ".jointOrient")`;
$jo = quatInverse(eulerToQuat($jo, $oXYZ));
}
float $rq[] = quatMultiply($jo, quatMultiply($ra, $q));
float $r[] = quatToEuler($rq, $o);
// print(" o :" + $o + "\n"); // debug
// print(" q :{" + floatArrayToString($q, ", ") + "}\n"); // debug
// print(" ra:{" + floatArrayToString($ra, ", ") + "}\n"); // debug
// print(" jo:{" + floatArrayToString($jo, ", ") + "}\n"); // debug
// print(" rq:{" + floatArrayToString($rq, ", ") + "}\n"); // debug
// print(" r :{" + floatArrayToString($r, ", ") + "}\n"); // debug
float $values[] = {
$t[0], $t[1], $t[2],
$r[0], $r[1], $r[2],
$s[0], $s[1], $s[2],
$h[0], $h[1], $h[2]
};
// print(" values:{" + floatArrayToString($values, ", ") + "}\n"); // debug
return $values;
}
/*-
@param $n <string>
@param $m <float[13]>
@param $hasCommonParent <boolean>
@param $mirrorAxis <int>
@param $primaryAxis <int>
@param $secondaryAxis <int>
@param $invertPrimaryAxis <boolean>
@param $invertSecondaryAxis <boolean>
@returns <float[12]>
*/
proc float[] mirrorTransform(
string $n,
float $m[],
int $hasCommonParent,
int $mirrorAxis,
int $primaryAxis,
int $secondaryAxis,
int $invertPrimaryAxis,
int $invertSecondaryAxis
) {
// print("mirrorTransform\n"); // debug
// print(" n :" + $n + "\n"); // debug
// print(" m :{" + floatArrayToString($m, ", ") + "}\n"); // debug
// print(" hasCommonParent :" + $hasCommonParent + "\n"); // debug
// print(" mirrorAxis :" + $mirrorAxis + "\n"); // debug
// print(" primaryAxis :" + $primaryAxis + "\n"); // debug
// print(" secondaryAxis :" + $secondaryAxis + "\n"); // debug
// print(" invertPrimaryAxis :" + $invertPrimaryAxis + "\n"); // debug
// print(" invertSecondaryAxis:" + $invertSecondaryAxis + "\n"); // debug
float $t[] = {$m[0], $m[1], $m[2]};
float $q[] = {$m[3], $m[4], $m[5], $m[6]};
float $s[] = {$m[7], $m[8], $m[9]};
float $h[] = {$m[10], $m[11], $m[12]};
// print(" t :{" + floatArrayToString($t, ", ") + "}\n"); // debug
// print(" q :{" + floatArrayToString($q, ", ") + "}\n"); // debug
// print(" s :{" + floatArrayToString($s, ", ") + "}\n"); // debug
// print(" h :{" + floatArrayToString($h, ", ") + "}\n"); // debug
// 位置のミラーリング
if ($hasCommonParent) {
$t[$mirrorAxis] *= -1;
}
else {
if ($invertPrimaryAxis) $t[$primaryAxis] *= -1;
if ($invertSecondaryAxis) $t[$secondaryAxis] *= -1;
if ($invertPrimaryAxis == $invertSecondaryAxis) {
// 第三の軸を反転
int $usedAxis[];
$usedAxis[$primaryAxis] = 1;
$usedAxis[$secondaryAxis] = 1;
int $i;
for ($i = 0; $i < 3; $i++) if (!$usedAxis[$i]) break;
$t[$i] *= -1;
}
}
// 回転のミラーリング
int $o = `getAttr ($n + ".rotateOrder")`;
$o = reverseRotateOrder($o);
// `rotateAxis`と`jointOrient`の回転順序は常にXYZ
int $oXYZ = reverseRotateOrder(0);
float $ra[] = `getAttr ($n + ".rotateAxis")`;
$ra = quatInverse(eulerToQuat($ra, $oXYZ));
float $jo[] = {0, 0, 0, 1};
if (`attributeQuery -n $n -ex "jointOrient"`) {
$jo = `getAttr ($n + ".jointOrient")`;
$jo = quatInverse(eulerToQuat($jo, $oXYZ));
}
float $mq[] = $q;
$mq[$mirrorAxis] *= -1;
$mq[3] *= -1;
float $cq[] = quatMultiply($jo, quatMultiply($ra, $mq));
// print(" o :" + $o + "\n"); // debug
// print(" q :{" + floatArrayToString($q, ", ") + "}\n"); // debug
// print(" ra:{" + floatArrayToString($ra, ", ") + "}\n"); // debug
// print(" jo:{" + floatArrayToString($jo, ", ") + "}\n"); // debug
// print(" mq:{" + floatArrayToString($mq, ", ") + "}\n"); // debug
// ソースとターゲットの親が異なる場合は親ノードの反転をリセットしておく
if (!$hasCommonParent) {
if ($mirrorAxis == $primaryAxis || $mirrorAxis == $secondaryAxis) {
float $flipAxis[] = {0, 0, 0};
if ($mirrorAxis == $primaryAxis) {
$flipAxis[$secondaryAxis] = 1;
}
else if ($mirrorAxis == $secondaryAxis) {
$flipAxis[$primaryAxis] = 1;
}
$cq = quatFlip($cq, $flipAxis);
}
if ($invertPrimaryAxis) {
float $flipAxis[] = {0, 0, 0};
$flipAxis[$secondaryAxis] = 1;
$cq = quatFlip($cq, $flipAxis);
}
if ($invertSecondaryAxis) {
float $flipAxis[] = {0, 0, 0};
$flipAxis[$primaryAxis] = 1;
$cq = quatFlip($cq, $flipAxis);
}
}
// プライマリとセカンダリを対称化するための反転
if ($mirrorAxis == $primaryAxis || $mirrorAxis == $secondaryAxis) {
float $flipAxis[] = {0, 0, 0};
if ($mirrorAxis == $primaryAxis) {
$flipAxis[$secondaryAxis] = 1;
}
else if ($mirrorAxis == $secondaryAxis) {
$flipAxis[$primaryAxis] = 1;
}
$flipAxis = rotateVectorByQuat($flipAxis, $cq);
$cq = quatFlip($cq, $flipAxis);
}
// 任意の反転
if ($invertPrimaryAxis) {
float $flipAxis[] = {0, 0, 0};
$flipAxis[$secondaryAxis] = 1;
$flipAxis = rotateVectorByQuat($flipAxis, $cq);
$cq = quatFlip($cq, $flipAxis);
}
if ($invertSecondaryAxis) {
float $flipAxis[] = {0, 0, 0};
$flipAxis[$primaryAxis] = 1;
$flipAxis = rotateVectorByQuat($flipAxis, $cq);
$cq = quatFlip($cq, $flipAxis);
}
float $r[] = quatToEuler($cq, $o);
// print(" cq:{" + floatArrayToString($cq, ", ") + "}\n"); // debug
// print(" r :{" + floatArrayToString($r, ", ") + "}\n"); // debug
float $values[] = {
$t[0], $t[1], $t[2],
$r[0], $r[1], $r[2],
$s[0], $s[1], $s[2],
$h[0], $h[1], $h[2]
};
// print(" values:{" + floatArrayToString($values, ", ") + "}\n"); // debug
return $values;
}
// -----------------------------------------------------------------------------
// スクリプトノード
// -----------------------------------------------------------------------------
/*-
@param $n <string>
@returns <int>
*/
proc int isValidScriptNode(string $n) {
return (
`objExists $n`
&& `nodeType $n` == "script"
&& `attributeQuery -n $n -ex "psd"`
);
}
/*-
@returns <string>
*/
proc string createScriptNode() {
// print("createScriptNode\n"); // debug
string $n = `scriptNode -n "nkPoseStackData"`;
addAttr -dt "string" -ln "nkPoseStackData" -nn "PoseStack Data" -sn "psd" $n;
return $n;
}
/*-
@param $n <string>
@returns <string>
*/
proc string getPoseStackDataAttr(string $n) {
// print("getPoseStackDataAttr\n"); // debug
string $value;
if (isValidScriptNode($n)) {
$value = `getAttr ($n + ".psd")`;
}
return $value;
}
/*-
@param $n <string>
@param $value <string>
@returns <>
*/
proc setPoseStackDataAttr(string $n, string $value) {
// print("setPoseStackDataAttr\n"); // debug
if (isValidScriptNode($n)) {
setAttr ($n + ".psd") -typ "string" $value;
}
}
/*-
@param $nodes <string[]>
@returns <string>
@remarks 全てのデータが空の場合はマージを行わずにノードを削除する。
*/
proc string mergeScriptNodes(string $nodes[]) {
// print("mergeScriptNodes\n"); // debug
// print(" nodes:{\n " + stringArrayToString($nodes, ",\n ") + "\n }\n"); // debug
string $mergedNode;
int $numNodes = `size $nodes`;
if (!$numNodes) return $mergedNode;
string $value;
for ($n in $nodes) {
if (isValidScriptNode($n) && !isNodeReferenced($n)) {
// データバージョンの確認とコンバート
$value += convertDataVersion(getPoseStackDataAttr($n));
}
}
// print(" value:" + $value + "\n"); // debug
if (`size $value`) {
$mergedNode = ($numNodes == 1) ? $nodes[0] : createScriptNode();
if (isValidScriptNode($mergedNode) && !isNodeReferenced($mergedNode)) {
setPoseStackDataAttr($mergedNode, getPoseVersion() + "\n" + $value);
}
}
for ($n in $nodes) {
if ($n == $mergedNode) continue;
if (isValidScriptNode($n) && !isNodeReferenced($n)) delete $n;
}
return $mergedNode;
}
/*-
@returns <string[]>
*/
proc string[] getScriptNodes() {
// print("getScriptNodes\n"); // debug
string $nodes[];
string $sceneNodes[];
string $allNodes[] = `ls -l "::nkPoseStackData*"`;
$allNodes = `sort $allNodes`;
for ($n in $allNodes) {
if (!isValidScriptNode($n)) continue;
if (isNodeReferenced($n)) {
$nodes[`size $nodes`] = $n;
}
else {
$sceneNodes[`size $sceneNodes`] = $n;
}
}
// print(" referencedNodes:{\n " + stringArrayToString($nodes, ",\n ") + "\n }\n"); // debug
// print(" sceneNodes:{\n " + stringArrayToString($sceneNodes, ",\n ") + "\n }\n"); // debug
if (`size $sceneNodes`) {
string $mergeNode = mergeScriptNodes($sceneNodes);
if (isValidScriptNode($mergeNode)) {
$nodes[`size $nodes`] = $mergeNode;
}
}
// print(" nodes:{\n " + stringArrayToString($nodes, ",\n ") + "\n }\n"); // debug
notifyStringArray("nkPoseStackScriptNodesRetrieved", $nodes);
return $nodes;
}
/*-
@param $nodes <string[]> 空配列の場合は`getScriptNodes`の結果を使用する。
@returns <string>
*/
proc string getEditableScriptNode(string $nodes[]) {
// print("getEditableScriptNode\n"); // debug
// print(" nodes:{\n " + stringArrayToString($nodes, ",\n ") + "\n }\n"); // debug
if (!`size $nodes`) $nodes = getScriptNodes();
string $scriptNodes[];
for ($n in $nodes) {
if (isValidScriptNode($n) && !isNodeReferenced($n)) {
$scriptNodes[`size $scriptNodes`] = $n;
}
}
// print(" scriptNodes:{\n " + stringArrayToString($scriptNodes, ",\n ") + "\n }\n"); // debug
int $numScriptNodes = `size $scriptNodes`;
if ($numScriptNodes > 1) {
warning -n "nkPoseStack: Multiple editable nodes exist.";
}
return (($numScriptNodes == 1) ? $scriptNodes[0] : "");
}
/*-
@returns <>
*/
proc deleteScriptNodes() {
// print("deleteScriptNodes\n"); // debug
string $nodes[] = getScriptNodes();
for ($n in $nodes) {
if (isValidScriptNode($n) && !isNodeReferenced($n)) delete $n;
}
}
// -----------------------------------------------------------------------------
// スクリプトノードアトリビュート
// -----------------------------------------------------------------------------
/*-
@param $pose <string>
@returns <boolean>
*/
proc int isPoseReferenced(string $pose) {
return `gmatch $pose "!?*"`;
}
/*-
@param $nodes <string[]> 空配列の場合は`getScriptNodes`の結果を使用する。
@returns <string[]>
*/
proc string[] readAttrPoses(string $nodes[]) {
// print("readAttrPoses\n"); // debug
// print(" nodes:{\n " + stringArrayToString($nodes, ",\n ") + "\n }\n"); // debug
string $poses[];
if (!`size $nodes`) $nodes = getScriptNodes();
for ($n in $nodes) {
if (!isValidScriptNode($n)) continue;
// データバージョンの確認とコンバート
string $beforeData = getPoseStackDataAttr($n);
string $afterData = convertDataVersion($beforeData);
string $nPoses[] = deserialize($afterData);
if (isNodeReferenced($n)) {
// リファレンスネームスペースの解決
resolveNamespace($n, $nPoses);
stringArrayAddPrefix($nPoses, "!");
}
else {
// バージョンが異なる場合は保存
if ($afterData != $beforeData) {
setPoseStackDataAttr($n, getPoseVersion() + "\n" + $afterData);
}
}
// print(" n:" + $n + "\n"); // debug
// print(" nPoses:{\n " + stringArrayToString($nPoses, ",\n ") + "\n }\n"); // debug
$poses = stringArrayCatenate($poses, $nPoses);
}
return $poses;
}
/*-
@param $poses <string[]>
@returns <boolean> 成功した場合は`true`、失敗した場合は`false`。
*/
proc int appendAttrPoses(string $poses[]) {
// print("appendAttrPoses\n"); // debug
// print(" poses:{\n " + stringArrayToString($poses, ",\n ") + "\n }\n"); // debug
if (!`size $poses`) return false;
string $editableNode = getEditableScriptNode({});
if (!isValidScriptNode($editableNode)) $editableNode = createScriptNode();
if (!isValidScriptNode($editableNode)) return false;
// データバージョンの確認とコンバート
string $newPoses[] = deserialize(
convertDataVersion(getPoseStackDataAttr($editableNode))
);
$newPoses = stringArrayCatenate($newPoses, $poses);
// print(" newPoses:{\n " + stringArrayToString($newPoses, ",\n ") + "\n }\n"); // debug
setPoseStackDataAttr($editableNode, serialize($newPoses));
return true;
}
/*-
@param $poses <string[]>
@returns <boolean> 成功した場合は`true`、失敗した場合は`false`。
@remarks 空配列を渡した場合はスクリプトノードを削除して成功とする。
*/
proc int writeAttrPoses(string $poses[]) {
// print("writeAttrPoses\n"); // debug
// print(" poses:{\n " + stringArrayToString($poses, ",\n ") + "\n }\n"); // debug
if (!`size $poses`) {
deleteScriptNodes();
return true;
}
string $editableNode = getEditableScriptNode({});
if (!isValidScriptNode($editableNode)) $editableNode = createScriptNode();
if (!isValidScriptNode($editableNode)) return false;
setPoseStackDataAttr($editableNode, serialize($poses));
return true;
}
/*-
@param $nodes <string[]>
@param $poses <string[]> 編集可能なポーズを格納する配列。
@returns <int> 編集可能なポーズの開始インデックス。基数は`0`。
*/
proc int makeEditablePoses(string $nodes[], string $poses[]) {
// print("makeEditablePoses\n"); // debug
// print(" nodes:{\n " + stringArrayToString($nodes, ",\n ") + "\n }\n"); // debug
clear $poses;
string $allPoses[] = readAttrPoses($nodes);
int $indexOffset;
for ($i = 0; $i < `size $allPoses`; $i++) {
if (!isPoseReferenced($allPoses[$i])) {
int $numPoses = `size $poses`;
if (!$numPoses) $indexOffset = $i;
$poses[$numPoses] = $allPoses[$i];
}
}
return $indexOffset;
}
/*-
@param $index <int> 基数`0`の整数。
@param $pose <string>
@returns <boolean> 成功した場合は`true`、失敗した場合は`false`。
*/
proc int insertPose(int $index, string $pose) {
// print("insertPose\n"); // debug
// print(" index:" + $index + "\n"); // debug
// print(" pose :" + $pose + "\n"); // debug
if (!`size $pose`) return false;
string $nodes[] = getScriptNodes();
string $editableNode = getEditableScriptNode($nodes);
if (!isValidScriptNode($editableNode)) $editableNode = createScriptNode();
if (!isValidScriptNode($editableNode)) return false;
// print(" editableNode:" + $editableNode + "\n"); // debug