@@ -2,7 +2,7 @@ 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 = "unityFbxNamespace ";
5
+ global string $UnityFbxNamespaceAttr = "unityFbxStripAllNamespaces ";
6
6
global string $UnityExportSetNameFormat = "^1s_UnityExportSet";
7
7
8
8
global int $UnityFbxFilePathIndex = 0;
@@ -57,9 +57,15 @@ proc string getAttribute(string $node, string $attr){
57
57
return "";
58
58
}
59
59
60
+ proc storeBoolAttribute(string $node, string $attr, int $attrValue){
61
+ if (!attributeExists($attr, $node)){
62
+ addAttr -shortName $attr -storable true -attributeType bool $node;
63
+ }
64
+ setAttr ($node+"."+$attr) $attrValue;
65
+ }
60
66
61
- proc storeAttribute (string $node, string $attr, string $attrValue){
62
- $attrType= "string";
67
+ proc storeStringAttribute (string $node, string $attr, string $attrValue){
68
+ $attrType = "string";
63
69
if (!attributeExists($attr, $node)){
64
70
addAttr -shortName $attr -storable true -dataType $attrType $node;
65
71
}
@@ -121,24 +127,6 @@ proc string getNewNamespace(string $n1, string $n2){
121
127
return $newNamespace;
122
128
}
123
129
124
- proc string checkNamespaceNeedsUpdate(string $unitySet, string $unityFbxNamespace, string $objectNamespace){
125
- global string $UnityFbxNamespaceAttr;
126
-
127
- string $newNamespace = getNewNamespace($unityFbxNamespace, $objectNamespace);
128
- if($unityFbxNamespace != $newNamespace){
129
- // popup asking to change namespace value to new namespace
130
- if(showConfirmDialog($unitySet,
131
- "Set namespace has been modified from "+$unityFbxNamespace+" to "+$newNamespace+", update export set namespace attribute?",
132
- "Yes", "No"
133
- )){
134
- storeAttribute($unitySet, $UnityFbxNamespaceAttr, $newNamespace);
135
-
136
- return $newNamespace;
137
- }
138
- }
139
- return $unityFbxNamespace;
140
- }
141
-
142
130
// =======================
143
131
144
132
// Determine the export attributes to be used by the export set for the given export path.
@@ -200,31 +188,6 @@ proc string getTargetNamespaceName(string $fileNameWithoutExt){
200
188
return $targetNamespace;
201
189
}
202
190
203
- // Get the name of the namespace containing the contents of the given export set
204
- // or "" if none.
205
- // The name of the namespace is stored as an attribute on the set.
206
- proc string getSetNamespace(string $unityExportSet){
207
- global string $UnityFbxNamespaceAttr;
208
-
209
- if (!setExists($unityExportSet)){
210
- return "";
211
- }
212
-
213
- string $unitySetContents[] = `listConnections $unityExportSet`;
214
-
215
- // get namespace from set
216
- $setNamespace = getAttribute($unityExportSet, $UnityFbxNamespaceAttr);
217
- if(size($unitySetContents) > 0){
218
- $setNamespace = checkNamespaceNeedsUpdate($unityExportSet, $setNamespace, getObjectNamespace($unitySetContents[0]));
219
- }
220
-
221
- // check if the namespace exists
222
- if($setNamespace != "" && `namespace -exists $setNamespace`){
223
- return $setNamespace;
224
- }
225
- return "";
226
- }
227
-
228
191
// Get or create the export set in the root namespace.
229
192
// Return true if a set has been created, and false if it already exists.
230
193
proc int getOrCreateExportSet(string $unityExportSet, string $origNamespace){
@@ -258,8 +221,10 @@ proc int getOrCreateExportSet(string $unityExportSet, string $origNamespace){
258
221
// - export animation file name
259
222
// - target namespace name (namespace that the contents of set belong to)
260
223
proc setExportSetAttributes(
261
- string $unityExportSet, int $isAnimFile, int $setCreated, string $exportAttrs[], string $targetNamespace
224
+ string $unityExportSet, int $isAnimFile, int $setCreated,
225
+ string $exportAttrs[], int $stripNamespaces
262
226
){
227
+
263
228
global string $UnityFbxFilePathAttr;
264
229
global string $UnityFbxFileNameAttr;
265
230
global string $UnityFbxAnimFilePathAttr;
@@ -282,24 +247,22 @@ proc setExportSetAttributes(
282
247
lockNode -lock false $unityExportSet;
283
248
284
249
if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $exportDir != ""){
285
- storeAttribute ($unityExportSet, $UnityFbxFilePathAttr, $exportDir);
250
+ storeStringAttribute ($unityExportSet, $UnityFbxFilePathAttr, $exportDir);
286
251
}
287
252
288
253
if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $exportFileName != ""){
289
- storeAttribute ($unityExportSet,$UnityFbxFileNameAttr,$exportFileName);
254
+ storeStringAttribute ($unityExportSet,$UnityFbxFileNameAttr,$exportFileName);
290
255
}
291
256
292
257
if($exportAnimDir != ""){
293
- storeAttribute ($unityExportSet,$UnityFbxAnimFilePathAttr,$exportAnimDir);
258
+ storeStringAttribute ($unityExportSet,$UnityFbxAnimFilePathAttr,$exportAnimDir);
294
259
}
295
260
296
261
if($exportAnimFileName != ""){
297
- storeAttribute($unityExportSet,$UnityFbxAnimFileNameAttr,$exportAnimFileName);
298
- }
299
-
300
- if($fileNameWithoutExt != ""){
301
- storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, $targetNamespace);
262
+ storeStringAttribute($unityExportSet,$UnityFbxAnimFileNameAttr,$exportAnimFileName);
302
263
}
264
+
265
+ storeBoolAttribute($unityExportSet, $UnityFbxNamespaceAttr, $stripNamespaces);
303
266
304
267
// lock set so it doesn't get deleted when empty
305
268
lockNode -lock true $unityExportSet;
@@ -333,7 +296,6 @@ proc importFile(string $filePathStr){
333
296
global string $UnityFbxFileNameAttr;
334
297
global string $UnityFbxAnimFilePathAttr;
335
298
global string $UnityFbxAnimFileNameAttr;
336
- global string $UnityFbxNamespaceAttr;
337
299
338
300
global int $UnityFbxFilePathIndex;
339
301
global int $UnityFbxFileNameIndex;
@@ -360,25 +322,18 @@ proc importFile(string $filePathStr){
360
322
string $origNamespace = `namespaceInfo -cur -an`;
361
323
string $targetNamespace = getTargetNamespaceName($fileNameWithoutExt);
362
324
363
- $setNamespace = getSetNamespace($unityExportSet);
364
- $setNamespaceExists = ($setNamespace != "");
365
- if($setNamespaceExists){
366
- $targetNamespace = $setNamespace;
325
+ // warn if namespace already exists
326
+ if(`namespace -exists $targetNamespace`){
327
+ if(!showConfirmDialog("Warning: " + $fileName,
328
+ $targetNamespace + " namespace already exists, the imported objects will be added to the existing namespace and export set.",
329
+ "Continue", "Cancel"
330
+ )){
331
+ // cancelled, don't import this fbx
332
+ return;
333
+ }
367
334
}
368
335
else{
369
- // warn if namespace already exists
370
- if(`namespace -exists $targetNamespace`){
371
- if(!showConfirmDialog("Warning: " + $fileName,
372
- $targetNamespace + " namespace already exists, the imported objects will be added to the existing namespace and export set.",
373
- "Continue", "Cancel"
374
- )){
375
- // cancelled, don't import this fbx
376
- return;
377
- }
378
- }
379
- else{
380
- namespace -add $targetNamespace;
381
- }
336
+ namespace -add $targetNamespace;
382
337
}
383
338
384
339
// Gather everything that is in the scene
@@ -392,9 +347,8 @@ proc importFile(string $filePathStr){
392
347
393
348
if(!$isAnimFile){
394
349
// reset attribute values, in case import fails
395
- storeAttribute($unityExportSet, $UnityFbxFilePathAttr, "");
396
- storeAttribute($unityExportSet, $UnityFbxFileNameAttr, "");
397
- storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, "");
350
+ storeStringAttribute($unityExportSet, $UnityFbxFilePathAttr, "");
351
+ storeStringAttribute($unityExportSet, $UnityFbxFileNameAttr, "");
398
352
}
399
353
400
354
if(`namespaceInfo -cur -an` != $targetNamespace){
@@ -406,7 +360,7 @@ proc importFile(string $filePathStr){
406
360
namespace -set $origNamespace;
407
361
}
408
362
409
- setExportSetAttributes($unityExportSet, $isAnimFile, $setCreated, $exportAttrs, $targetNamespace );
363
+ setExportSetAttributes($unityExportSet, $isAnimFile, $setCreated, $exportAttrs, /*strip namespaces*/ true );
410
364
411
365
if (setExists($unityExportSet) == true){
412
366
// figure out what has been added after import
@@ -494,11 +448,7 @@ proc exportSet(string $unitySet, int $exportAnim){
494
448
global string $UnityFbxNamespaceAttr;
495
449
496
450
string $unitySetContents[] = `listConnections $unitySet`;
497
- string $unityFbxNamespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
498
-
499
- if(size($unitySetContents) > 0){
500
- $unityFbxNamespace = checkNamespaceNeedsUpdate($unitySet, $unityFbxNamespace, getObjectNamespace($unitySetContents[0]));
501
- }
451
+ int $stripNamespaces = getAttribute($unitySet, $UnityFbxNamespaceAttr);
502
452
503
453
string $animatedObjectSet = "";
504
454
if($exportAnim){
@@ -534,8 +484,8 @@ proc exportSet(string $unitySet, int $exportAnim){
534
484
$strCmd = "";
535
485
if ($unityFbxFilePath != "" && $unityFbxFileName != ""){
536
486
// export selected, relative to given namespace
537
- string $exportFormat = "file -force -options \"\" -typ \"FBX export\" -relativeNamespace \"^1s\" - es \"^2s/^3s\"";
538
- $strCmd = `format -s $unityFbxNamespace -s $ unityFbxFilePath -s $unityFbxFileName $exportFormat`;
487
+ string $exportFormat = "file -force -options \"\" -typ \"FBX export\" -es \"^2s/^3s\"";
488
+ $strCmd = `format -s $unityFbxFilePath -s $unityFbxFileName $exportFormat`;
539
489
eval $strCmd;
540
490
}
541
491
@@ -584,6 +534,7 @@ proc setupNewExportSet(
584
534
string $modelFilename,
585
535
string $animPath,
586
536
string $animFilename,
537
+ int $stripNamespaces,
587
538
string $selectedObjects[]){
588
539
589
540
// make sure all necessary variables are set
@@ -656,7 +607,7 @@ proc setupNewExportSet(
656
607
$exportAttrs[$UnityFbxAnimFileNameIndex] = $animFilename;
657
608
$exportAttrs[$UnityFileNameWithoutExtIndex] = $exportFileNameWithoutExt;
658
609
659
- setExportSetAttributes($unityExportSet, /*isAnimOnly*/ false, $setCreated, $exportAttrs, $namespace );
610
+ setExportSetAttributes($unityExportSet, /*isAnimOnly*/ false, $setCreated, $exportAttrs, $stripNamespaces );
660
611
661
612
if (setExists($unityExportSet) == true){
662
613
// clear contents of set
@@ -693,7 +644,8 @@ global proc unityOnCreateExportSet(
693
644
string $modelPathField,
694
645
string $modelFileField,
695
646
string $animPathField,
696
- string $animFileField){
647
+ string $animFileField,
648
+ string $stripNamespaceCheckbox){
697
649
698
650
$origSelection = `ls -sl`;
699
651
if(size($origSelection) <= 0){
@@ -737,13 +689,16 @@ global proc unityOnCreateExportSet(
737
689
error ("Unity FBX Export Set Creation: Missing filepath for export.");
738
690
return;
739
691
}
692
+
693
+ int $stripNamespaces = `checkBox -q -value $stripNamespaceCheckbox`;
740
694
741
695
setupNewExportSet(
742
696
$namespace,
743
697
$modelPath,
744
698
$modelFilename,
745
699
$animPath,
746
700
$animFilename,
701
+ $stripNamespaces,
747
702
$origSelection);
748
703
749
704
deleteUI -window $window;
@@ -792,6 +747,17 @@ proc string createTextFieldWithLabel(string $label, string $parent, int $labelSi
792
747
return $textField;
793
748
}
794
749
750
+ proc string createCheckboxWithLabelLeft(string $label, string $parent, int $labelSize, int $fieldSize){
751
+ rowLayout
752
+ -numberOfColumns 2
753
+ -columnWidth2 $labelSize $fieldSize
754
+ -columnAlign2 "left" "left"
755
+ -p $parent;
756
+
757
+ text -label $label;
758
+ return `checkBox -value true -label " "`;
759
+ }
760
+
795
761
// Find the most common namespace among the selected objects. If there are multiple (because of nested namespaces),
796
762
// prefer the most specific. For example if you have:
797
763
//
@@ -866,7 +832,7 @@ proc createExportSetDialog(int $exportType){
866
832
}
867
833
868
834
// open up a dialog for choosing the export set options
869
- string $window = `window -title "Unity FBX Export Options" -iconName "Short Name" -widthHeight 475 250`;
835
+ string $window = `window -title "Unity FBX Export Options" -iconName "Short Name" -widthHeight 500 250`;
870
836
871
837
string $container = `formLayout -numberOfDivisions 100`;
872
838
@@ -898,7 +864,7 @@ proc createExportSetDialog(int $exportType){
898
864
}
899
865
}
900
866
901
- int $labelSize = 120 ;
867
+ int $labelSize = 145 ;
902
868
int $textFieldSize = 300;
903
869
904
870
// get namespace
@@ -920,15 +886,17 @@ proc createExportSetDialog(int $exportType){
920
886
textField -e -text ($modelFilename + "@Take1.fbx") $animFileNameField;
921
887
$animFilePath = " " + $animFilePathField + " " + $animFileNameField;
922
888
}
889
+
890
+ string $stripNamespaceCheckbox = createCheckboxWithLabelLeft("Strip Namespaces on Export", $mainOptions, $labelSize, $textFieldSize);
923
891
924
- int $buttonWidth = 158 ;
892
+ int $buttonWidth = 166 ;
925
893
string $buttons = `rowLayout
926
894
-numberOfColumns 3
927
895
-adjustableColumn3 1
928
896
-columnWidth3 $buttonWidth $buttonWidth $buttonWidth
929
897
-columnAlign3 "center" "center" "center" -p $container`;
930
898
931
- string $createExportSetCommand = "unityOnCreateExportSet " + $window + " " + $namespaceField + $modelFilePath + $animFilePath;
899
+ string $createExportSetCommand = "unityOnCreateExportSet " + $window + " " + $namespaceField + $modelFilePath + $animFilePath + " " + $stripNamespaceCheckbox ;
932
900
933
901
button -label "Create Set and Export"
934
902
-width $buttonWidth
0 commit comments