@@ -6,6 +6,49 @@ global string $UnityFbxStripNamespaceAttr = "unityFbxStripNamespaces";
6
6
global string $UnityFbxNamespaceAttr = "unityFbxNamespace";
7
7
global string $UnityExportSetNameFormat = "^1s_UnityExportSet";
8
8
9
+ global string $UnityModuleName = "UnityFbxForMaya";
10
+
11
+ global string $UnityImportSettingsOptionVar = "UnityFbxImportSettings";
12
+ global string $UnityExportSettingsOptionVar = "UnityFbxExportSettings";
13
+
14
+ global string $UnityDefaultImportSettingsFileName = "unityFbxImportSettings.mel";
15
+ global string $UnityDefaultExportSettingsFileName = "unityFbxExportSettings.mel";
16
+
17
+ global string $UnityDefaultImportSettings = "\
18
+ FBXResetImport;\n\
19
+ FBXImportAxisConversionEnable -v true;\n\
20
+ FBXImportCameras -v true;\n\
21
+ FBXImportLights -v true;\n\
22
+ FBXImportSetTake -takeIndex -1;\n\
23
+ // Add and update animation\n\
24
+ FBXImportMode -v merge;";
25
+
26
+ global string $UnityDefaultExportSettings = "\
27
+ FBXResetExport;\n\
28
+ // FBX file format\n\
29
+ FBXExportInAscii -v false;\n\
30
+ FBXExportFileVersion -v FBX201600;\n\
31
+ \n\
32
+ // Geometry\n\
33
+ FBXExportSmoothMesh -v false;\n\
34
+ FBXExportInstances -v true;\n\
35
+ FBXExportReferencedAssetsContent -v false;\n\
36
+ \n\
37
+ // Animation\n\
38
+ FBXExportAnimationOnly -v false;\n\
39
+ \n\
40
+ FBXExportCameras -v true;\n\
41
+ FBXExportLights -v true;\n\
42
+ \n\
43
+ FBXExportEmbeddedTextures -v false;\n\
44
+ \n\
45
+ // Units\n\
46
+ FBXExportScaleFactor 1;\n\
47
+ FBXExportConvertUnitString cm;\n\
48
+ \n\
49
+ // Axis Conversion\n\
50
+ FBXExportUpAxis y;";
51
+
9
52
global int $UnityFbxFilePathIndex = 0;
10
53
global int $UnityFbxFileNameIndex = 1;
11
54
global int $UnityFbxAnimFilePathIndex = 2;
@@ -26,28 +69,67 @@ global proc unityRemoveNativeMenuOnLoad(){
26
69
}
27
70
28
71
// Load a specified settings file
29
- proc int loadUnityFbxSettings(string $fileName, string $settingType){
72
+ proc int loadUnityFbxSettings(string $settingType, string $optionVarName, string $defaultSettingsFileName, string $defaultSettings){
73
+ global string $UnityModuleName;
74
+
75
+ $fileName = `optionVar -q $optionVarName`;
76
+
77
+ // if no filename set (optionVar cleared), reset it to default filename
78
+ if ($fileName == 0){
79
+ $modulePath = `moduleInfo -moduleName $UnityModuleName -path`;
80
+ // {$modulePath}/scripts/{$defaultSettingsFileName}
81
+ $modulePath = $modulePath + "/scripts/" + $defaultSettingsFileName;
82
+
83
+ $fileName = $modulePath;
84
+ optionVar -stringValue $optionVarName $fileName;
85
+ }
86
+
30
87
// check if the file exists
31
88
if (`file -q -ex $fileName` == false){
32
- error ("Failed to find Unity Fbx "+$settingType+" Settings at: " + $fileName);
33
- return false;
89
+ // create file with default settings
90
+ $fileId = `fopen $fileName "w"`;
91
+ fprint $fileId $defaultSettings;
92
+ fclose $fileId;
34
93
}
94
+
95
+ // if the file still doesn't exist (failed to create)
96
+ // load the default settings and print a warning
97
+ if (`file -q -ex $fileName` == false){
98
+ warning ("Failed to find Unity Fbx "+$settingType+" Settings at: " + $fileName + ", loading default settings.");
99
+ eval ($defaultSettings);
100
+ return true;
101
+ }
102
+
35
103
eval ("source \"" + $fileName + "\"");
36
104
return true;
37
105
}
38
106
39
107
40
108
// Load the Export Settings from file
41
109
proc int loadUnityFbxExportSettings(){
42
- $fileName = `optionVar -q "UnityFbxExportSettings"`;
43
- return loadUnityFbxSettings($fileName, "Export");
110
+ global string $UnityExportSettingsOptionVar;
111
+ global string $UnityDefaultExportSettings;
112
+ global string $UnityDefaultExportSettingsFileName;
113
+ return loadUnityFbxSettings(
114
+ "Export",
115
+ $UnityExportSettingsOptionVar,
116
+ $UnityDefaultExportSettingsFileName,
117
+ $UnityDefaultExportSettings
118
+ );
44
119
}
45
120
46
121
47
122
// Load the Import Settings from a file
48
123
proc int loadUnityFbxImportSettings(){
49
- $fileName = `optionVar -q "UnityFbxImportSettings"`;
50
- return loadUnityFbxSettings($fileName, "Import");
124
+ global string $UnityImportSettingsOptionVar;
125
+ global string $UnityDefaultImportSettings;
126
+ global string $UnityDefaultImportSettingsFileName;
127
+ return loadUnityFbxSettings(
128
+ "Import",
129
+ $UnityImportSettingsOptionVar,
130
+ $UnityDefaultImportSettingsFileName,
131
+ $UnityDefaultImportSettings
132
+ );
51
133
}
52
134
53
135
0 commit comments