Skip to content

Commit c40d269

Browse files
authored
Merge pull request #188 from Unity-Technologies/UNI-29041-max-2017-support
Uni 29041 max 2017 support
2 parents 7bd58b8 + 2da6eb0 commit c40d269

File tree

3 files changed

+143
-65
lines changed

3 files changed

+143
-65
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ public override void OnInspectorGUI() {
135135
ExportSettings.DCCType foundDCC = ExportSettings.DCCType.Maya;
136136
var foundDCCPath = TryFindDCC (dccPath, ext, ExportSettings.DCCType.Maya);
137137
if (foundDCCPath == null && Application.platform == RuntimePlatform.WindowsEditor) {
138-
if (!ExportSettings.IsMax2018OrLater (dccPath)) {
139-
Debug.LogError ("3DsMax 2017 or earlier is not supported");
138+
if (ExportSettings.IsEarlierThanMax2017 (dccPath)) {
139+
Debug.LogError ("Earlier than 3ds Max 2017 is not supported");
140+
UnityEditor.EditorUtility.DisplayDialog (
141+
"Error adding 3D Application",
142+
"Unity Integration only supports 3ds Max 2017 or later",
143+
"Ok");
140144
} else {
141145
foundDCCPath = TryFindDCC (dccPath, ext, ExportSettings.DCCType.Max);
142146
foundDCC = ExportSettings.DCCType.Max;
@@ -348,7 +352,7 @@ private static void FindDCCInstalls() {
348352

349353
if (product.StartsWith ("3ds max", StringComparison.InvariantCultureIgnoreCase)) {
350354
var exePath = string.Format ("{0}/{1}", productDir.FullName.Replace ("\\", "/"), "3dsmax.exe");
351-
if (!IsMax2018OrLater (exePath)) {
355+
if (IsEarlierThanMax2017 (exePath)) {
352356
continue;
353357
}
354358
string version = product.Substring ("3ds max ".Length);
@@ -505,11 +509,11 @@ public static string GetMaxOptionName(string exePath){
505509
return GetUniqueName (Path.GetFileName(Path.GetDirectoryName (exePath)));
506510
}
507511

508-
public static bool IsMax2018OrLater(string exePath){
512+
public static bool IsEarlierThanMax2017(string exePath){
509513
var name = Path.GetFileName (Path.GetDirectoryName (exePath)).ToLower();
510514
name = name.Replace ("3ds max", "").Trim();
511515
int version;
512-
return int.TryParse (name, out version) && version >= 2018;
516+
return int.TryParse (name, out version) && version < 2017;
513517
}
514518

515519
public static string GetSelectedDCCPath()

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,13 @@ public static int InstallMaxPlugin(string maxExe){
531531
myProcess.Start();
532532
myProcess.WaitForExit();
533533
ExitCode = myProcess.ExitCode;
534+
535+
// TODO (UNI-29910): figure out what exactly causes this exit code + how to resolve
536+
if(ExitCode == -1073740791){
537+
Debug.Log(string.Format("Detected 3ds max exitcode {0} -- safe to ignore", ExitCode));
538+
ExitCode = 0;
539+
}
540+
534541
Debug.Log(string.Format("Ran max: [{0}]\nWith args [{1}]\nResult {2}",
535542
maxExe, myProcess.StartInfo.Arguments, ExitCode));
536543
}

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

Lines changed: 127 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- MacroScripts that will perform actions
2-
macroScript UnityImport category:"File-Import"
2+
macroScript UnityImport category:"Unity"
33
(
44
origObjects = #()
55

@@ -45,7 +45,7 @@ macroScript UnityImport category:"File-Import"
4545
callbacks.removeScripts #postImport id:#unityPlugin
4646
)
4747
)
48-
macroScript UnityExport category:"File-Export"
48+
macroScript UnityExport category:"Unity"
4949
(
5050
fn loadUnityFbxExportSettings = (
5151
fbxExportSettings = getINISetting (GetMAXIniFile()) "Unity" "UnityFbxExportSettings"
@@ -83,68 +83,135 @@ macroScript UnityExport category:"File-Export"
8383
)
8484
)
8585

86-
-- Setup UI
87-
importMenuName = "File-Import"
88-
exportMenuName = "File-Export"
89-
fn setupUnityPluginUI = (
90-
importMenu = menuMan.findMenu importMenuName
91-
exportMenu = menuMan.findMenu exportMenuName
92-
if importMenu != undefined and exportMenu != undefined do
93-
(
94-
unityImportTitle = "Import from Unity"
95-
unityExportTitle = "Export to Unity"
96-
97-
-- check if menu items already exists
98-
foundUnityImport = false
99-
for i=1 to importMenu.numItems() do(
100-
mi = importMenu.getItem i
101-
if mi.getTitle() == unityImportTitle then(
102-
foundUnityImport = true
103-
global unityImportAction = mi
104-
break
105-
)
106-
)
107-
foundUnityExport = false
108-
for i=1 to exportMenu.numItems() do(
109-
mi = exportMenu.getItem i
110-
if mi.getTitle() == unityExportTitle then(
111-
foundUnityExport = true
112-
global unityExportAction = mi
113-
break
114-
)
115-
)
116-
117-
if foundUnityImport == false or foundUnityExport == false then(
86+
fn createUnityActionItem macroName category title parentMenu = (
87+
local unityAction = menuMan.createActionItem macroName category; --create an ActionItem from the MacroScript
88+
unityAction.setTitle title;
89+
unityAction.setUseCustomTitle true;
90+
parentMenu.addItem unityAction -1;
91+
unityAction
92+
);
93+
94+
fn createUnityImportAction title parentMenu = (
95+
createUnityActionItem "UnityImport" "Unity" title parentMenu;
96+
);
97+
98+
fn createUnityExportAction title parentMenu = (
99+
createUnityActionItem "UnityExport" "Unity" title parentMenu;
100+
);
101+
102+
-- Setup UI in existing Import/Export menus if using 3ds Max 2018+
103+
if (maxVersion())[1] >= 20000 then(
104+
global importMenuName = "File-Import"
105+
global exportMenuName = "File-Export"
106+
107+
-- get the import menu
108+
global getImportMenu
109+
fn getImportMenu = (
110+
menuMan.findMenu importMenuName
111+
);
112+
113+
-- get the export menu
114+
global getExportMenu
115+
fn getExportMenu = (
116+
menuMan.findMenu exportMenuName
117+
);
118+
119+
-- Setup UI
120+
fn setupUnityPluginUI = (
121+
local importMenu = getImportMenu()
122+
local exportMenu = getExportMenu()
123+
if importMenu != undefined and exportMenu != undefined do
124+
(
125+
local unityImportTitle = "Import from Unity"
126+
local unityExportTitle = "Export to Unity"
127+
128+
-- check if menu items already exist, delete if they do
129+
local foundUnityImport = false
130+
for i=1 to importMenu.numItems() while not foundUnityImport do(
131+
local mi = importMenu.getItem i
132+
if mi.getTitle() == unityImportTitle then(
133+
importMenu.removeItem mi
134+
foundUnityImport = true
135+
)
136+
)
137+
local foundUnityExport = false
138+
for i=1 to exportMenu.numItems() while not foundUnityExport do(
139+
local mi = exportMenu.getItem i
140+
if mi.getTitle() == unityExportTitle then(
141+
exportMenu.removeItem mi
142+
foundUnityExport = true
143+
)
144+
)
145+
118146
id = genClassID returnValue:true
119147
if menuMan.registerMenuContext id[1] then
120148
(
121-
if foundUnityImport == false do (
122-
global unityImportAction = menuMan.createActionItem "UnityImport" importMenuName; --create an ActionItem from the MacroScript
123-
unityImportAction.setTitle unityImportTitle;
124-
unityImportAction.setUseCustomTitle true;
125-
importMenu.addItem unityImportAction -1; --add the ActionItem to the menu
126-
)
127-
if foundUnityExport == false do (
128-
global unityExportAction = menuMan.createActionItem "UnityExport" exportMenuName;
129-
unityExportAction.setTitle unityExportTitle;
130-
unityExportAction.setUseCustomTitle true;
131-
exportMenu.addItem unityExportAction -1;
132-
)
149+
global unityImportAction = createUnityImportAction unityImportTitle importMenu
150+
global unityExportAction = createUnityExportAction unityExportTitle exportMenu
151+
133152
menuMan.updateMenuBar() --update the menu bar
134153
)
135-
)
136-
)
137-
);
138-
setupUnityPluginUI()
154+
)
155+
);
156+
setupUnityPluginUI()
139157

140-
-- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened
141-
callbacks.addScript #preSavingMenus (
142-
"importMenu = menuMan.findMenu \""+importMenuName+"\"; \
143-
exportMenu = menuMan.findMenu \""+exportMenuName+"\"; \
144-
if importMenu != undefined and unityImportAction != undefined then( \
145-
importMenu.removeItem unityImportAction; \
146-
) \
147-
if exportMenu != undefined and unityExportAction != undefined then( \
148-
exportMenu.removeItem unityExportAction; \
149-
)"
158+
-- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened
159+
callbacks.addScript #preSavingMenus (
160+
"importMenu = getImportMenu(); \
161+
exportMenu = getExportMenu(); \
162+
if importMenu != undefined and unityImportAction != undefined then( \
163+
importMenu.removeItem unityImportAction; \
164+
) \
165+
if exportMenu != undefined and unityExportAction != undefined then( \
166+
exportMenu.removeItem unityExportAction; \
167+
)"
168+
)
169+
)
170+
else if (maxVersion())[1] == 19000 then (
171+
-- for 3ds Max 2017
172+
173+
global unityMenuName = "Unity"
174+
175+
global getUnityMenu
176+
fn getUnityMenu = (
177+
menuMan.findMenu unityMenuName
178+
);
179+
180+
-- Setup UI
181+
fn setupUnityPluginUI = (
182+
local unityMenu = getUnityMenu()
183+
local unityImportTitle = "Import"
184+
local unityExportTitle = "Export"
185+
if unityMenu != undefined do
186+
(
187+
-- remove the menu if it still exists
188+
menuMan.unRegisterMenu unityMenu
189+
)
190+
191+
id = genClassID returnValue:true
192+
if menuMan.registerMenuContext id[1] then
193+
(
194+
local mainMenuBar = menuMan.getMainMenuBar()
195+
local unityMenu = menuMan.createMenu unityMenuName
196+
local unityMenuItem = menuMan.createSubMenuItem unityMenuName unityMenu
197+
mainMenuBar.addItem unityMenuItem -1
198+
199+
createUnityImportAction unityImportTitle unityMenu
200+
createUnityExportAction unityExportTitle unityMenu
201+
202+
menuMan.updateMenuBar() --update the menu bar
203+
)
204+
);
205+
setupUnityPluginUI()
206+
207+
-- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened
208+
callbacks.addScript #preSavingMenus (
209+
"unityMenu = getUnityMenu(); \
210+
if unityMenu != undefined do ( \
211+
menuMan.unRegisterMenu unityMenu; \
212+
)"
213+
)
214+
)
215+
else(
216+
print "Error: Unity Integration only supports 3ds Max 2017 or later"
150217
)

0 commit comments

Comments
 (0)