@@ -525,7 +525,12 @@ proc exportSet(string $unitySet, int $exportAnim){
525
525
526
526
string $unityFbxFilePath = getAttribute($unitySet, $pathAttr);
527
527
string $unityFbxFileName = getAttribute($unitySet, $nameAttr);
528
-
528
+
529
+ // make sure the file path exists
530
+ if(!(`filetest -d $unityFbxFilePath`)){
531
+ sysFile -makeDir $unityFbxFilePath;
532
+ }
533
+
529
534
$strCmd = "";
530
535
if ($unityFbxFilePath != "" && $unityFbxFileName != ""){
531
536
// export selected, relative to given namespace
@@ -616,20 +621,7 @@ proc setupNewExportSet(
616
621
617
622
string $origNamespace = `namespaceInfo -cur -an`;
618
623
619
- if($namespace == ":"){
620
- // do nothing
621
- }
622
- // warn if namespace already exists
623
- else if(`namespace -exists $namespace`){
624
- if(!showConfirmDialog("Warning: " + $modelFilename,
625
- $namespace + " namespace already exists, the selected objects will be added to the existing namespace and export set.",
626
- "Continue", "Cancel"
627
- )){
628
- // cancelled, don't import this fbx
629
- return;
630
- }
631
- }
632
- else{
624
+ if($namespace != ":" && !(`namespace -exists $namespace`)){
633
625
namespace -add $namespace;
634
626
}
635
627
@@ -676,9 +668,14 @@ proc setupNewExportSet(
676
668
677
669
// add to the targetNamespace
678
670
// iterate over all selected objects and rename
679
- if ($namespace != ""){
671
+ if ($namespace != ":"){
672
+ // remove the colon from the beginning of the namespace
673
+ // because the $object name does not start with a colon.
674
+ $namespace = `substring $namespace 2 (size($namespace))`;
680
675
for($object in $selectedObjects){
681
- rename $object ($namespace + ":" + $object);
676
+ if(!startsWith($object, $namespace)){
677
+ rename $object ($namespace + ":" + $object);
678
+ }
682
679
}
683
680
}
684
681
@@ -752,65 +749,37 @@ global proc unityOpenFileDialog(string $textField)
752
749
textField -e -text $exportFilePath $textField;
753
750
}
754
751
755
- proc string createFilePathField(string $label, string $parent){
752
+ proc string createFilePathField(string $label, string $parent, int $labelSize, int $textFieldSize ){
756
753
rowLayout
757
754
-numberOfColumns 3
758
- -columnWidth3 150 250 50
755
+ -columnWidth3 $labelSize $textFieldSize 50
759
756
-columnAlign3 "right" "left" "left"
760
757
-p $parent;
761
758
762
759
string $unityProject = `optionVar -q "UnityProject"`;
763
760
$unityProject = $unityProject + "/Assets";
764
761
765
762
text -label $label;
766
- string $textField = `textField -width 250 -text $unityProject`;
763
+ string $textField = `textField -width $textFieldSize -text $unityProject`;
767
764
button -label "..." -recomputeSize false -height 15 -command ("unityOpenFileDialog " + $textField);
768
765
769
766
return $textField;
770
767
}
771
768
772
- proc string createTextFieldWithLabel(string $label, string $parent)
769
+ proc string createTextFieldWithLabel(string $label, string $parent, int $labelSize, int $textFieldSize )
773
770
{
774
771
rowLayout
775
772
-numberOfColumns 2
776
- -columnWidth2 150 250
773
+ -columnWidth2 $labelSize $textFieldSize
777
774
-columnAlign2 "right" "left"
778
775
-p $parent;
779
776
780
777
text -label $label;
781
- string $textField = `textField -width 250 `;
778
+ string $textField = `textField -width $textFieldSize `;
782
779
return $textField;
783
780
}
784
781
785
- proc createExportSetDialog(int $exportType){
786
- $origSelection = `ls -sl`;
787
- if(size($origSelection) <= 0){
788
- // nothing selected
789
- print ("Nothing selected");
790
- return;
791
- }
792
-
793
- $exportAnim = false;
794
- $exportAnimOnly = false;
795
- switch($exportType){
796
- case 0 /* export animation only */:
797
- $exportAnim = true;
798
- $exportAnimOnly = true;
799
- break;
800
- case 1 /* export model only */:
801
- break;
802
- default: /* export model + animation */
803
- $exportAnim = true;
804
- break;
805
- }
806
-
807
- // open up a dialog for choosing the export set options
808
- string $window = `window -title "FBX Export Options" -iconName "Short Name" -widthHeight 475 250`;
809
-
810
- string $container = `formLayout -numberOfDivisions 100`;
811
-
812
- string $mainOptions = `columnLayout -adjustableColumn true -p $container`;
813
-
782
+ proc string getCommonNamespace(string $origSelection[]){
814
783
// gather up all the unique namespaces
815
784
string $selectedNamespaces[];
816
785
for($i = 0; $i < size($origSelection); $i++){
@@ -836,29 +805,91 @@ proc createExportSetDialog(int $exportType){
836
805
int $intersectionSize = size($intersection);
837
806
if($intersectionSize > $maxNamespaceCount ||
838
807
// prefer more specific namespaces
839
- ($maxNamespaceCount > 0 &&
808
+ ($maxNamespaceCount > 0 &&
840
809
$intersectionSize == $maxNamespaceCount &&
841
810
size($currNamespace) > size($commonNamespace))){
842
811
$commonNamespace = $currNamespace;
843
812
$maxNamespaceCount = $intersectionSize;
844
813
}
845
814
}
815
+ return $commonNamespace;
816
+ }
817
+
818
+ proc createExportSetDialog(int $exportType){
819
+ $origSelection = `ls -sl`;
820
+ if(size($origSelection) <= 0){
821
+ // nothing selected
822
+ print ("Nothing selected");
823
+ return;
824
+ }
825
+
826
+ $exportAnim = false;
827
+ $exportAnimOnly = false;
828
+ switch($exportType){
829
+ case 0 /* export animation only */:
830
+ $exportAnim = true;
831
+ $exportAnimOnly = true;
832
+ break;
833
+ case 1 /* export model only */:
834
+ break;
835
+ default: /* export model + animation */
836
+ $exportAnim = true;
837
+ break;
838
+ }
839
+
840
+ // open up a dialog for choosing the export set options
841
+ string $window = `window -title "Unity FBX Export Options" -iconName "Short Name" -widthHeight 475 250`;
842
+
843
+ string $container = `formLayout -numberOfDivisions 100`;
846
844
845
+ string $mainOptions = `columnLayout -adjustableColumn true -p $container`;
846
+
847
+ // go through selection to find common namespace to set as default
848
+ string $commonNamespace = getCommonNamespace($origSelection);
849
+
850
+ string $modelFilename = "Untitled";
851
+ // if one item selected, take the name of it as the filename
852
+ if (size($origSelection) == 1){
853
+ // take the name of the selection without the namespace
854
+ string $nTokens[];
855
+ int $nNumTokens = `tokenize ("" + $origSelection[0]) ":" $nTokens`;
856
+ $modelFilename = $nTokens[$nNumTokens-1];
857
+ }
858
+ else{
859
+ // if multi items selected, but one of them is the root, then take the name of the root as the filename
860
+ for($i = 0; $i < size($origSelection); $i++){
861
+ string $descendents[] = `listRelatives -type "transform" -allDescendents $origSelection[$i]`;
862
+ string $intersection[] = getIntersection($origSelection, $descendents);
863
+ if (size($intersection) == size($origSelection)-1){
864
+ // take the name of the selection without the namespace
865
+ string $nTokens[];
866
+ int $nNumTokens = `tokenize ("" + $origSelection[$i]) ":" $nTokens`;
867
+ $modelFilename = $nTokens[$nNumTokens-1];
868
+ break;
869
+ }
870
+ }
871
+ }
872
+
873
+ int $labelSize = 120;
874
+ int $textFieldSize = 300;
875
+
847
876
// get namespace
848
- string $namespaceField = createTextFieldWithLabel("Unity FBX namespace ", $mainOptions);
877
+ string $namespaceField = createTextFieldWithLabel("Namespace ", $mainOptions, $labelSize, $textFieldSize );
849
878
textField -e -text $commonNamespace $namespaceField;
850
879
851
880
string $modelFilePath = " 0 0";
852
881
if(!$exportAnimOnly){
853
- string $modelFilePathField = createFilePathField("Unity FBX Model File Path", $mainOptions);
854
- string $modelFileNameField = createTextFieldWithLabel("Unity FBX Model File Name", $mainOptions);
882
+ string $modelFilePathField = createFilePathField("Model File Path", $mainOptions, $labelSize, $textFieldSize);
883
+ string $modelFileNameField = createTextFieldWithLabel("Model File Name", $mainOptions, $labelSize, $textFieldSize);
884
+ textField -e -text ($modelFilename + ".fbx") $modelFileNameField;
855
885
$modelFilePath = " " + $modelFilePathField + " " + $modelFileNameField;
856
886
}
857
887
858
888
string $animFilePath = " 0 0";
859
889
if($exportAnim){
860
- string $animFilePathField = createFilePathField("Unity FBX Anim File Path", $mainOptions);
861
- string $animFileNameField = createTextFieldWithLabel("Unity FBX Anim File Name", $mainOptions);
890
+ string $animFilePathField = createFilePathField("Anim File Path", $mainOptions, $labelSize, $textFieldSize);
891
+ string $animFileNameField = createTextFieldWithLabel("Anim File Name", $mainOptions, $labelSize, $textFieldSize);
892
+ textField -e -text ($modelFilename + "@Take1.fbx") $animFileNameField;
862
893
$animFilePath = " " + $animFilePathField + " " + $animFileNameField;
863
894
}
864
895
0 commit comments