Skip to content

Commit 25c8ad7

Browse files
committed
load max Fbx export settings from file
1 parent 963d67f commit 25c8ad7

File tree

4 files changed

+60
-8
lines changed

4 files changed

+60
-8
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,34 +392,49 @@ public static void InstallMayaIntegration ()
392392

393393
class MaxIntegration
394394
{
395+
private const string MaxScriptsPath = "FbxExporters/Integrations/Autodesk/max/scripts/";
396+
395397
private const string PluginName = "UnityFbxForMaxPlugin.ms";
396-
private const string PluginPath = "FbxExporters/Integrations/Autodesk/max/scripts/" + PluginName;
398+
private const string PluginPath = MaxScriptsPath + PluginName;
399+
400+
private const string ConfigureMaxScript = MaxScriptsPath + "configureUnityFbxForMax.ms";
397401

398-
private const string ConfigureMaxScript = "FbxExporters/Integrations/Autodesk/max/scripts/configureUnityFbxForMax.ms";
402+
private const string ExportSettingsFile = MaxScriptsPath + "unityFbxExportSettings.ms";
399403

400404
private const string PluginSourceTag = "UnityPluginScript_Source";
401405
private const string PluginNameTag = "UnityPluginScript_Name";
402406
private const string ProjectTag = "UnityProject";
407+
private const string ExportSettingsTag = "UnityFbxExportSettings";
403408

404409
// TODO: get this from the export settings
405410
private static string GetMaxExe(){
406411
return "C:/Program Files/Autodesk/3ds Max 2018/3dsmax.exe";
407412
}
408413

414+
/// <summary>
415+
/// Gets the absolute Unity path for relative path in Assets folder.
416+
/// </summary>
417+
/// <returns>The absolute path.</returns>
418+
/// <param name="relPath">Relative path.</param>
419+
public static string GetAbsPath(string relPath){
420+
return Application.dataPath + "/" + relPath;
421+
}
422+
409423
private static string GetInstallScript(){
410424
Dictionary<string,string> Tokens = new Dictionary<string,string>()
411425
{
412-
{PluginSourceTag, (Application.dataPath + "/" + PluginPath) },
426+
{PluginSourceTag, GetAbsPath(PluginPath) },
413427
{PluginNameTag, PluginName },
414-
{ProjectTag, Application.dataPath + "/"}
428+
{ProjectTag,GetAbsPath("")},
429+
{ExportSettingsTag, GetAbsPath(ExportSettingsFile) }
415430
};
416431

417432
var installScript = "";
418433
// setup the variables to be used in the configure max script
419434
foreach (var t in Tokens) {
420435
installScript += string.Format (@"global {0} = @\""{1}\"";", t.Key, t.Value);
421436
}
422-
installScript += string.Format(@"filein \""{0}/{1}\""", Application.dataPath, ConfigureMaxScript);
437+
installScript += string.Format(@"filein \""{0}\""", GetAbsPath(ConfigureMaxScript));
423438
return installScript;
424439
}
425440

Assets/FbxExporters/Integrations/Autodesk/max/scripts/UnityFbxForMaxPlugin.ms

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,18 @@ print "I do nothing, but I should Preview!"
5151
)
5252
macroScript Export category:"Unity"
5353
(
54+
fn loadUnityFbxExportSettings = (
55+
fbxExportSettings = getINISetting (GetMAXIniFile()) "Unity" "UnityFbxExportSettings"
56+
if fbxExportSettings != undefined and doesFileExist fbxExportSettings then(
57+
filein fbxExportSettings
58+
)
59+
)
60+
5461
-- Make sure the FbxExporter plugin is loaded
5562
pluginManager.loadClass FbxExporter
5663

64+
loadUnityFbxExportSettings()
65+
5766
origSelection = getCurrentSelection()
5867
exportSet = selectionSets["UnityFbxExportSet"]
5968
if not isdeleted exportSet and exportSet != undefined then(
@@ -65,11 +74,12 @@ macroScript Export category:"Unity"
6574
exportFileName = unityFbxFilePathAttr + unityFbxFileNameAttr
6675
)
6776
else(
68-
exportFileName = getSaveFileName caption:"Export FBX to Unity" filename:"C:/Users/Viktoria/Desktop/" types:"FBX (*.fbx)|*.fbx|"
77+
unityProjectPath = getINISetting (GetMAXIniFile()) "Unity" "UnityProject"
78+
exportFileName = getSaveFileName caption:"Export FBX to Unity" filename:unityProjectPath types:"FBX (*.fbx)|*.fbx|"
6979
)
7080

7181
if exportFileName != undefined then (
72-
exportFile exportFileName selectedOnly:true using:FBXEXP
82+
exportFile exportFileName #noPrompt selectedOnly:true using:FBXEXP
7383
)
7484

7585
if origSelection != undefined then (

Assets/FbxExporters/Integrations/Autodesk/max/scripts/configureUnityFbxForMax.ms

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ temp = pathConfig.GetDir(#userStartupScripts) + "/" + UnityPluginScript_Name;
22
deleteFile temp;
33
copyFile UnityPluginScript_Source temp;
44

5-
setINISetting (GetMAXIniFile()) "Unity" "UnityProject" UnityProject
5+
maxIniFile = (GetMAXIniFile())
6+
unityCategory = "Unity"
7+
setINISetting maxIniFile unityCategory "UnityProject" UnityProject
8+
setINISetting maxIniFile unityCategory "UnityFbxExportSettings" UnityFbxExportSettings
69

710
quitMax()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FbxExporterSetParam "ResetExport"
2+
3+
-- FBX file format
4+
FbxExporterSetParam "ASCII" false
5+
FbxExporterSetParam "FileVersion" "FBX201600"
6+
7+
-- Geometry
8+
FbxExporterSetParam "SmoothMeshExport" false
9+
FbxExporterSetParam "Preserveinstances" true
10+
11+
-- Animation
12+
FbxExporterSetParam "Animation" false
13+
14+
FbxExporterSetParam "Cameras" true
15+
FbxExporterSetParam "Lights" true
16+
17+
FbxExporterSetParam "EmbedTextures" false
18+
19+
-- Units
20+
--FbxExporterSetParam "ScaleFactor" 1
21+
FbxExporterSetParam "ConvertUnit" "cm"
22+
23+
-- Axis Conversion
24+
FbxExporterSetParam "UpAxis" "Y"

0 commit comments

Comments
 (0)