@@ -2,7 +2,8 @@ global string $UnityFbxFilePathAttr = "unityFbxModelFilePath";
2
2
global string $UnityFbxFileNameAttr = "unityFbxModelFileName";
3
3
global string $UnityFbxAnimFilePathAttr = "unityFbxAnimFilePath";
4
4
global string $UnityFbxAnimFileNameAttr = "unityFbxAnimFileName";
5
- global string $UnityFbxNamespaceAttr = "unityFbxStripAllNamespaces";
5
+ global string $UnityFbxStripNamespaceAttr = "unityFbxStripNamespaces";
6
+ global string $UnityFbxNamespaceAttr = "unityFbxNamespace";
6
7
global string $UnityExportSetNameFormat = "^1s_UnityExportSet";
7
8
8
9
global int $UnityFbxFilePathIndex = 0;
@@ -57,6 +58,13 @@ proc string getAttribute(string $node, string $attr){
57
58
return "";
58
59
}
59
60
61
+ proc int getBoolAttribute(string $node, string $attr){
62
+ if (`attributeExists $attr $node`){
63
+ return `getAttr ($node + "." + $attr)`;
64
+ }
65
+ return 0;
66
+ }
67
+
60
68
proc storeBoolAttribute(string $node, string $attr, int $attrValue){
61
69
if (!attributeExists($attr, $node)){
62
70
addAttr -shortName $attr -storable true -attributeType bool $node;
@@ -107,26 +115,6 @@ proc string getObjectNamespace(string $objectName){
107
115
return $lsResult[1];
108
116
}
109
117
110
- proc string getNewNamespace(string $n1, string $n2){
111
- string $n2Tokens[];
112
- int $n2NumTokens = `tokenize $n2 ":" $n2Tokens`;
113
-
114
- string $newNamespace = ":";
115
- string $n1BaseName = `namespaceInfo -baseName $n1`;
116
-
117
- for($i=$n2NumTokens-1; $i>=0; --$i){
118
- if($n2Tokens[$i] == $n1BaseName){
119
- break;
120
- }
121
- $n2Tokens[$i] = "";
122
- }
123
- $newNamespace = $newNamespace + stringArrayToString($n2Tokens, ":");
124
- if($newNamespace == ":"){
125
- return $n2;
126
- }
127
- return $newNamespace;
128
- }
129
-
130
118
// =======================
131
119
132
120
// Determine the export attributes to be used by the export set for the given export path.
@@ -214,6 +202,24 @@ proc int getOrCreateExportSet(string $unityExportSet, string $origNamespace){
214
202
return true;
215
203
}
216
204
205
+ global proc unityOnToggleStripNamespace(string $exportSetName)
206
+ {
207
+ global string $UnityFbxStripNamespaceAttr;
208
+ global string $UnityFbxNamespaceAttr;
209
+
210
+ int $stripNamespaces = `getAttr ($exportSetName + "." + $UnityFbxStripNamespaceAttr)`;
211
+
212
+ $stripNamespaceAttrName = ($exportSetName + "." + $UnityFbxNamespaceAttr);
213
+
214
+ // temporarily unlock to be able to modify namespace attr
215
+ lockNode -lock false $exportSetName;
216
+
217
+ setAttr -lock (!$stripNamespaces) $stripNamespaceAttrName;
218
+
219
+ // lock set so it doesn't get deleted when empty
220
+ lockNode -lock true $exportSetName;
221
+ }
222
+
217
223
// Add or update the following five attributes of the given export set, to be used for exporting:
218
224
// - export directory
219
225
// - export file name
@@ -229,6 +235,7 @@ proc setExportSetAttributes(
229
235
global string $UnityFbxFileNameAttr;
230
236
global string $UnityFbxAnimFilePathAttr;
231
237
global string $UnityFbxAnimFileNameAttr;
238
+ global string $UnityFbxStripNamespaceAttr;
232
239
global string $UnityFbxNamespaceAttr;
233
240
234
241
global int $UnityFbxFilePathIndex;
@@ -262,8 +269,14 @@ proc setExportSetAttributes(
262
269
storeStringAttribute($unityExportSet,$UnityFbxAnimFileNameAttr,$exportAnimFileName);
263
270
}
264
271
265
- storeBoolAttribute($unityExportSet, $UnityFbxNamespaceAttr, $stripNamespaces);
266
-
272
+ storeBoolAttribute($unityExportSet, $UnityFbxStripNamespaceAttr, $stripNamespaces);
273
+
274
+ storeStringAttribute($unityExportSet, $UnityFbxNamespaceAttr, "");
275
+
276
+ $stripNamespaceAttrName = ($unityExportSet + "." + $UnityFbxStripNamespaceAttr);
277
+ setAttr -lock (!$stripNamespaces) $stripNamespaceAttrName;
278
+ scriptJob -attributeChange $stripNamespaceAttrName ("unityOnToggleStripNamespace " + $unityExportSet) -protected;
279
+
267
280
// lock set so it doesn't get deleted when empty
268
281
lockNode -lock true $unityExportSet;
269
282
}
@@ -440,15 +453,81 @@ proc string[] getIntersection(string $set1[], string $set2[]){
440
453
return $intersection;
441
454
}
442
455
456
+ // Find the most common namespace among the selected objects. If there are multiple (because of nested namespaces),
457
+ // prefer the most specific. For example if you have:
458
+ //
459
+ // test1:test2:sphere
460
+ // test1:test3:cube
461
+ // test1:test2:cylinder
462
+ //
463
+ // test1 will be returned because all objects have that namespace in common. However if you have:
464
+ //
465
+ // test1:test2:sphere
466
+ // test1:test2:cube
467
+ // test1:test2:cylinder
468
+ //
469
+ // Then it will return test1:test2.
470
+ proc string getCommonNamespace(string $origSelection[]){
471
+ // gather up all the unique namespaces
472
+ string $selectedNamespaces[];
473
+ for($i = 0; $i < size($origSelection); $i++){
474
+ string $currNamespace = getObjectNamespace($origSelection[$i]);
475
+ while ($currNamespace != ":" && !stringArrayContains($currNamespace, $selectedNamespaces)){
476
+ $selectedNamespaces[size($selectedNamespaces)] = $currNamespace;
477
+ $currNamespace = `namespaceInfo -p $currNamespace`;
478
+ // make sure the namespace always starts with a colon
479
+ if(!startsWith($currNamespace, ":")){
480
+ $currNamespace = ":" + $currNamespace;
481
+ }
482
+ }
483
+ }
484
+
485
+ // go through selection to find common namespace to set as default
486
+ string $commonNamespace = ":";
487
+ int $maxNamespaceCount = 0;
488
+ for($i = 0; $i < size($selectedNamespaces); $i++){
489
+ $currNamespace = $selectedNamespaces[$i];
490
+ // get contents of namespace
491
+ string $namespaceContents[] = `namespaceInfo -ls $currNamespace -r`;
492
+ string $intersection[] = getIntersection($origSelection, $namespaceContents);
493
+ int $intersectionSize = size($intersection);
494
+ if($intersectionSize > $maxNamespaceCount ||
495
+ // prefer more specific namespaces
496
+ ($maxNamespaceCount > 0 &&
497
+ $intersectionSize == $maxNamespaceCount &&
498
+ size($currNamespace) > size($commonNamespace)))
499
+ {
500
+ $commonNamespace = $currNamespace;
501
+ $maxNamespaceCount = $intersectionSize;
502
+ }
503
+ }
504
+ return $commonNamespace;
505
+ }
506
+
443
507
proc exportSet(string $unitySet, int $exportAnim){
444
508
global string $UnityFbxFilePathAttr;
445
509
global string $UnityFbxFileNameAttr;
446
510
global string $UnityFbxAnimFilePathAttr;
447
511
global string $UnityFbxAnimFileNameAttr;
512
+ global string $UnityFbxStripNamespaceAttr;
448
513
global string $UnityFbxNamespaceAttr;
449
514
450
515
string $unitySetContents[] = `listConnections $unitySet`;
451
- int $stripNamespaces = getAttribute($unitySet, $UnityFbxNamespaceAttr);
516
+ int $stripNamespaces = getBoolAttribute($unitySet, $UnityFbxStripNamespaceAttr);
517
+ string $namespaceToStrip = getAttribute($unitySet, $UnityFbxNamespaceAttr);
518
+
519
+ // if there is no namespace manually set, find the common namespace
520
+ if ($stripNamespaces){
521
+ if ($namespaceToStrip == ""){
522
+ $namespaceToStrip = getCommonNamespace($unitySetContents);
523
+ }
524
+ else {
525
+ // make sure the namespace to strip is an absolute namespace
526
+ if(!startsWith($namespaceToStrip, ":")){
527
+ $namespaceToStrip = ":" + $namespaceToStrip;
528
+ }
529
+ }
530
+ }
452
531
453
532
string $animatedObjectSet = "";
454
533
if($exportAnim){
@@ -484,8 +563,12 @@ proc exportSet(string $unitySet, int $exportAnim){
484
563
$strCmd = "";
485
564
if ($unityFbxFilePath != "" && $unityFbxFileName != ""){
486
565
// export selected, relative to given namespace
487
- string $exportFormat = "file -force -options \"\" -typ \"FBX export\" -es \"^2s/^3s\"";
488
- $strCmd = `format -s $unityFbxFilePath -s $unityFbxFileName $exportFormat`;
566
+ string $exportFormat = "file -force -options \"\" -typ \"FBX export\" -relativeNamespace \"^1s\" -es \"^2s/^3s\"";
567
+ string $relativeNamespace = ":";
568
+ if ($stripNamespaces){
569
+ $relativeNamespace = $namespaceToStrip;
570
+ }
571
+ $strCmd = `format -s $relativeNamespace -s $unityFbxFilePath -s $unityFbxFileName $exportFormat`;
489
572
eval $strCmd;
490
573
}
491
574
@@ -758,57 +841,6 @@ proc string createCheckboxWithLabelLeft(string $label, string $parent, int $labe
758
841
return `checkBox -value true -label " "`;
759
842
}
760
843
761
- // Find the most common namespace among the selected objects. If there are multiple (because of nested namespaces),
762
- // prefer the most specific. For example if you have:
763
- //
764
- // test1:test2:sphere
765
- // test1:test3:cube
766
- // test1:test2:cylinder
767
- //
768
- // test1 will be returned because all objects have that namespace in common. However if you have:
769
- //
770
- // test1:test2:sphere
771
- // test1:test2:cube
772
- // test1:test2:cylinder
773
- //
774
- // Then it will return test1:test2.
775
- proc string getCommonNamespace(string $origSelection[]){
776
- // gather up all the unique namespaces
777
- string $selectedNamespaces[];
778
- for($i = 0; $i < size($origSelection); $i++){
779
- string $currNamespace = getObjectNamespace($origSelection[$i]);
780
- while ($currNamespace != ":" && !stringArrayContains($currNamespace, $selectedNamespaces)){
781
- $selectedNamespaces[size($selectedNamespaces)] = $currNamespace;
782
- $currNamespace = `namespaceInfo -p $currNamespace`;
783
- // make sure the namespace always starts with a colon
784
- if(!startsWith($currNamespace, ":")){
785
- $currNamespace = ":" + $currNamespace;
786
- }
787
- }
788
- }
789
-
790
- // go through selection to find common namespace to set as default
791
- string $commonNamespace = ":";
792
- int $maxNamespaceCount = 0;
793
- for($i = 0; $i < size($selectedNamespaces); $i++){
794
- $currNamespace = $selectedNamespaces[$i];
795
- // get contents of namespace
796
- string $namespaceContents[] = `namespaceInfo -ls $currNamespace -r`;
797
- string $intersection[] = getIntersection($origSelection, $namespaceContents);
798
- int $intersectionSize = size($intersection);
799
- if($intersectionSize > $maxNamespaceCount ||
800
- // prefer more specific namespaces
801
- ($maxNamespaceCount > 0 &&
802
- $intersectionSize == $maxNamespaceCount &&
803
- size($currNamespace) > size($commonNamespace)))
804
- {
805
- $commonNamespace = $currNamespace;
806
- $maxNamespaceCount = $intersectionSize;
807
- }
808
- }
809
- return $commonNamespace;
810
- }
811
-
812
844
proc createExportSetDialog(int $exportType){
813
845
$origSelection = `ls -sl`;
814
846
if(size($origSelection) <= 0){
@@ -864,7 +896,7 @@ proc createExportSetDialog(int $exportType){
864
896
}
865
897
}
866
898
867
- int $labelSize = 145 ;
899
+ int $labelSize = 150 ;
868
900
int $textFieldSize = 300;
869
901
870
902
// get namespace
0 commit comments