Skip to content

Commit f13fb69

Browse files
committed
create default import/export option files if they don't exist
1 parent 94b2640 commit f13fb69

File tree

1 file changed

+82
-17
lines changed

1 file changed

+82
-17
lines changed

Integrations/Autodesk/maya/scripts/unityCommands.mel

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,49 @@ global string $UnityFbxAnimFileNameAttr = "unityFbxAnimFileName";
55
global string $UnityFbxNamespaceAttr = "unityFbxNamespace";
66
global string $UnityExportSetNameFormat = "^1s_UnityExportSet";
77

8-
// global string $UnityModuleName = "UnityFbxForMaya";
8+
global string $UnityModuleName = "UnityFbxForMaya";
9+
10+
global string $UnityImportSettingsOptionVar = "UnityFbxImportSettings";
11+
global string $UnityExportSettingsOptionVar = "UnityFbxExportSettings";
912

1013
global string $UnityDefaultImportSettingsFileName = "unityFbxImportSettings.mel";
1114
global string $UnityDefaultExportSettingsFileName = "unityFbxExportSettings.mel";
1215

16+
global string $UnityDefaultImportSettings = "\
17+
FBXResetImport;\n\
18+
FBXImportAxisConversionEnable -v true;\n\
19+
FBXImportCameras -v true;\n\
20+
FBXImportLights -v true;\n\
21+
FBXImportSetTake -takeIndex -1;\n\
22+
// Add and update animation\n\
23+
FBXImportMode -v merge;";
24+
25+
global string $UnityDefaultExportSettings = "\
26+
FBXResetExport;\n\
27+
// FBX file format\n\
28+
FBXExportInAscii -v false;\n\
29+
FBXExportFileVersion -v FBX201600;\n\
30+
\n\
31+
// Geometry\n\
32+
FBXExportSmoothMesh -v false;\n\
33+
FBXExportInstances -v true;\n\
34+
FBXExportReferencedAssetsContent -v false;\n\
35+
\n\
36+
// Animation\n\
37+
FBXExportAnimationOnly -v false;\n\
38+
\n\
39+
FBXExportCameras -v true;\n\
40+
FBXExportLights -v true;\n\
41+
\n\
42+
FBXExportEmbeddedTextures -v false;\n\
43+
\n\
44+
// Units\n\
45+
FBXExportScaleFactor 1;\n\
46+
FBXExportConvertUnitString cm;\n\
47+
\n\
48+
// Axis Conversion\n\
49+
FBXExportUpAxis y;";
50+
1351
global int $UnityFbxFilePathIndex = 0;
1452
global int $UnityFbxFileNameIndex = 1;
1553
global int $UnityFbxAnimFilePathIndex = 2;
@@ -30,13 +68,34 @@ global proc unityRemoveNativeMenuOnLoad(){
3068
}
3169

3270
// Load a specified settings file
33-
proc int loadUnityFbxSettings(string $fileName, string $settingType){
71+
proc int loadUnityFbxSettings(string $settingType, string $optionVarName, string $defaultSettingsFileName, string $defaultSettings){
72+
global string $UnityModuleName;
73+
74+
$fileName = `optionVar -q $optionVarName`;
75+
76+
// if no filename set (optionVar cleared), reset it to default filename
77+
if ($fileName == 0){
78+
$modulePath = `moduleInfo -moduleName $UnityModuleName -path`;
79+
// {$modulePath}/scripts/{$defaultSettingsFileName}
80+
$modulePath = $modulePath + "/scripts/" + $defaultSettingsFileName;
81+
82+
$fileName = $modulePath;
83+
optionVar -stringValue $optionVarName $fileName;
84+
}
85+
3486
// check if the file exists
3587
if (`file -q -ex $fileName` == false){
36-
//error ("Failed to find Unity Fbx "+$settingType+" Settings at: " + $fileName);
37-
//return false;
38-
3988
// create file with default settings
89+
$fileId = `fopen $fileName "w"`;
90+
fprint $fileId $defaultSettings;
91+
fclose $fileId;
92+
}
93+
94+
// if the file still doesn't exist (failed to create)
95+
// print an error message.
96+
if (`file -q -ex $fileName` == false){
97+
error ("Failed to find Unity Fbx "+$settingType+" Settings at: " + $fileName);
98+
return false;
4099
}
41100

42101
eval ("source \"" + $fileName + "\"");
@@ -46,23 +105,29 @@ proc int loadUnityFbxSettings(string $fileName, string $settingType){
46105

47106
// Load the Export Settings from file
48107
proc int loadUnityFbxExportSettings(){
49-
$fileName = `optionVar -q "UnityFbxExportSettings"`;
50-
return loadUnityFbxSettings($fileName, "Export");
108+
global string $UnityExportSettingsOptionVar;
109+
global string $UnityDefaultExportSettings;
110+
global string $UnityDefaultExportSettingsFileName;
111+
return loadUnityFbxSettings(
112+
"Export",
113+
$UnityExportSettingsOptionVar,
114+
$UnityDefaultExportSettingsFileName,
115+
$UnityDefaultExportSettings
116+
);
51117
}
52118

53119

54120
// Load the Import Settings from a file
55121
proc int loadUnityFbxImportSettings(){
56-
$fileName = `optionVar -q "UnityFbxImportSettings"`;
57-
58-
// if no filename set (optionVar cleared), reset it to default filename
59-
if ($fileName == 0){
60-
//$modulePath = `moduleInfo -moduleName $UnityModuleName -path`;
61-
// {$modulePath}/scripts/{$UnityDefaultImportSettingsFileName}
62-
63-
}
64-
65-
return loadUnityFbxSettings($fileName, "Import");
122+
global string $UnityImportSettingsOptionVar;
123+
global string $UnityDefaultImportSettings;
124+
global string $UnityDefaultImportSettingsFileName;
125+
return loadUnityFbxSettings(
126+
"Import",
127+
$UnityImportSettingsOptionVar,
128+
$UnityDefaultImportSettingsFileName,
129+
$UnityDefaultImportSettings
130+
);
66131
}
67132

68133

0 commit comments

Comments
 (0)