Skip to content

Commit 2b0a5ea

Browse files
committed
add button to export model only
- also clean up functionality by grouping functions with structs
1 parent 3e50a89 commit 2b0a5ea

File tree

1 file changed

+97
-72
lines changed

1 file changed

+97
-72
lines changed

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

Lines changed: 97 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,17 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
182182
)
183183
)
184184
)
185-
macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"
185+
macroScript UnityExport category:"Unity" tooltip:"Export models and animation to Unity"
186+
(
187+
UnityExportHelpers.exportSelection modelOnly:false
188+
)
189+
190+
macroScript UnityExportModel category:"Unity" tooltip:"Export models to Unity"
186191
(
192+
UnityExportHelpers.exportSelection modelOnly:true
193+
)
194+
195+
struct UnityExportHelpers (
187196
fn unitToScaleFactor unit = (
188197
case unit of (
189198
#Inches: 2.54
@@ -194,15 +203,15 @@ macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"
194203
#Meters: 100
195204
default: 1
196205
)
197-
);
206+
),
198207

199208
fn loadUnityFbxExportSettings = (
200209
fbxExportSettings = getINISetting (GetMAXIniFile()) "Unity" "UnityFbxExportSettings"
201210
if fbxExportSettings != undefined and doesFileExist fbxExportSettings then(
202211
filein fbxExportSettings
203212
)
204-
FbxExporterSetParam "ScaleFactor" (unitToScaleFactor units.SystemType)
205-
);
213+
FbxExporterSetParam "ScaleFactor" (UnityExportHelpers.unitToScaleFactor units.SystemType)
214+
),
206215

207216
fn getUnityExportSets = (
208217
local unityExportSets = #()
@@ -215,8 +224,8 @@ macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"
215224
)
216225
)
217226
unityExportSets
218-
)
219-
227+
),
228+
220229
fn exportUnitySet expSet = (
221230
select expSet
222231

@@ -237,75 +246,84 @@ macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"
237246
if exportFileName != undefined then (
238247
exportFile exportFileName #noPrompt selectedOnly:true using:FBXEXP
239248
)
240-
)
249+
),
241250

242-
-- Make sure the FbxExporter plugin is loaded
243-
pluginManager.loadClass FbxExporter
244-
245-
loadUnityFbxExportSettings()
246-
247-
origSelection = getCurrentSelection()
248-
249-
local origUnits = units.SystemType
250-
units.SystemType = #Centimeters
251-
252-
-- get all the unity export sets
253-
local unityExportSets = getUnityExportSets()
254-
255-
-- find all sets that contain at least one object from the current selection
256-
local setsToExport = #()
257-
for expSet in unityExportSets do (
258-
for obj in origSelection do (
259-
if (findItem expSet obj > 0) do (
260-
appendIfUnique setsToExport expSet
261-
break
251+
fn exportSelection modelOnly:false = (
252+
-- Make sure the FbxExporter plugin is loaded
253+
pluginManager.loadClass FbxExporter
254+
255+
UnityExportHelpers.loadUnityFbxExportSettings()
256+
257+
if(modelOnly) do (
258+
FbxExporterSetParam "Animation" false
259+
)
260+
261+
origSelection = getCurrentSelection()
262+
263+
local origUnits = units.SystemType
264+
units.SystemType = #Centimeters
265+
266+
-- get all the unity export sets
267+
local unityExportSets = UnityExportHelpers.getUnityExportSets()
268+
269+
-- find all sets that contain at least one object from the current selection
270+
local setsToExport = #()
271+
for expSet in unityExportSets do (
272+
for obj in origSelection do (
273+
if (findItem expSet obj > 0) do (
274+
appendIfUnique setsToExport expSet
275+
break
276+
)
262277
)
263278
)
264-
)
265-
266-
-- if no sets are selected, then export selection, otherwise export each set to its corresponding file
267-
if (setsToExport.count <= 0) then (
268-
local unityProjectPath = getINISetting (GetMAXIniFile()) "Unity" "UnityProject"
269-
local exportFileName = getSaveFileName caption:"Export FBX to Unity" filename:(unityProjectPath + "/Assets/") types:"FBX (*.fbx)|*.fbx|"
270-
if exportFileName != undefined do (
271-
exportFile exportFileName #noPrompt selectedOnly:true using:FBXEXP
279+
280+
-- if no sets are selected, then export selection, otherwise export each set to its corresponding file
281+
if (setsToExport.count <= 0) then (
282+
local unityProjectPath = getINISetting (GetMAXIniFile()) "Unity" "UnityProject"
283+
local exportFileName = getSaveFileName caption:"Export FBX to Unity" filename:(unityProjectPath + "/Assets/") types:"FBX (*.fbx)|*.fbx|"
284+
if exportFileName != undefined do (
285+
exportFile exportFileName #noPrompt selectedOnly:true using:FBXEXP
286+
)
272287
)
273-
)
274-
else (
275-
for expSet in setsToExport do (
276-
exportUnitySet expSet
288+
else (
289+
for expSet in setsToExport do (
290+
UnityExportHelpers.exportUnitySet expSet
291+
)
292+
)
293+
294+
units.SystemType = origUnits
295+
296+
if origSelection != undefined then (
297+
select origSelection
277298
)
278-
)
279-
280-
units.SystemType = origUnits
281-
282-
if origSelection != undefined then (
283-
select origSelection
284299
)
285300
)
286301

287-
fn createUnityActionItem macroName category title parentMenu = (
288-
local unityAction = menuMan.createActionItem macroName category; --create an ActionItem from the MacroScript
289-
unityAction.setTitle title;
290-
unityAction.setUseCustomTitle true;
291-
parentMenu.addItem unityAction -1;
292-
unityAction
293-
);
302+
struct UnityHelpers (
303+
fn createUnityActionItem macroName category title parentMenu = (
304+
local unityAction = menuMan.createActionItem macroName category; --create an ActionItem from the MacroScript
305+
unityAction.setTitle title;
306+
unityAction.setUseCustomTitle true;
307+
parentMenu.addItem unityAction -1;
308+
unityAction
309+
),
294310

295-
fn createUnityImportAction title parentMenu = (
296-
createUnityActionItem "UnityImport" "Unity" title parentMenu;
297-
);
311+
fn createUnityImportAction title parentMenu = (
312+
UnityHelpers.createUnityActionItem "UnityImport" "Unity" title parentMenu;
313+
),
298314

299-
fn createUnityExportAction title parentMenu = (
300-
createUnityActionItem "UnityExport" "Unity" title parentMenu;
301-
);
315+
fn createUnityExportAction title parentMenu = (
316+
UnityHelpers.createUnityActionItem "UnityExport" "Unity" title parentMenu;
317+
),
318+
319+
fn createUnityExportModelAction title parentMenu = (
320+
UnityHelpers.createUnityActionItem "UnityExportModel" "Unity" title parentMenu;
321+
),
302322

303-
global unityResetExportOptions;
304-
fn unityResetExportOptions = (
305-
unityFbxFilePathAttr=undefined;
306-
unityFbxFileNameAttr=undefined;
307-
unityAskSetUnits=undefined;
308-
);
323+
fn unityResetExportOptions = (
324+
unityAskSetUnits=undefined;
325+
)
326+
)
309327

310328
-- Setup UI in existing Import/Export menus if using 3ds Max 2018+
311329
if (maxVersion())[1] >= 20000 then(
@@ -332,6 +350,7 @@ if (maxVersion())[1] >= 20000 then(
332350
(
333351
local unityImportTitle = "Import from Unity"
334352
local unityExportTitle = "Export to Unity"
353+
local unityExportModelTitle = "Export Model Only to Unity"
335354

336355
-- check if menu items already exist, delete if they do
337356
local foundUnityImport = false
@@ -354,8 +373,9 @@ if (maxVersion())[1] >= 20000 then(
354373
id = genClassID returnValue:true
355374
if menuMan.registerMenuContext id[1] then
356375
(
357-
global unityImportAction = createUnityImportAction unityImportTitle importMenu
358-
global unityExportAction = createUnityExportAction unityExportTitle exportMenu
376+
global unityImportAction = UnityHelpers.createUnityImportAction unityImportTitle importMenu
377+
global unityExportAction = UnityHelpers.createUnityExportAction unityExportTitle exportMenu
378+
global unityExportModelAction = UnityHelpers.createUnityExportModelAction unityExportModelTitle exportMenu
359379

360380
menuMan.updateMenuBar() --update the menu bar
361381
)
@@ -372,13 +392,16 @@ if (maxVersion())[1] >= 20000 then(
372392
) \
373393
if exportMenu != undefined and unityExportAction != undefined then( \
374394
exportMenu.removeItem unityExportAction; \
395+
) \
396+
if exportMenu != undefined and unityExportModelAction != undefined then( \
397+
exportMenu.removeItem unityExportModelAction; \
375398
)"
376399
)
377400

378401
-- when opening a new scene, reset the export options to make
379402
-- sure we don't accidentally overwrite anything
380-
callbacks.addScript #postSceneReset ("unityResetExportOptions()")
381-
callbacks.addScript #systemPreNew ("unityResetExportOptions()")
403+
callbacks.addScript #postSceneReset ("UnityHelpers.unityResetExportOptions()")
404+
callbacks.addScript #systemPreNew ("UnityHelpers.unityResetExportOptions()")
382405
)
383406
else if (maxVersion())[1] == 19000 then (
384407
-- for 3ds Max 2017
@@ -395,6 +418,7 @@ else if (maxVersion())[1] == 19000 then (
395418
local unityMenu = getUnityMenu()
396419
local unityImportTitle = "Import"
397420
local unityExportTitle = "Export"
421+
local unityExportModelTitle = "Export Model Only"
398422
if unityMenu != undefined do
399423
(
400424
-- remove the menu if it still exists
@@ -409,8 +433,9 @@ else if (maxVersion())[1] == 19000 then (
409433
local unityMenuItem = menuMan.createSubMenuItem unityMenuName unityMenu
410434
mainMenuBar.addItem unityMenuItem (mainMenuBar.numItems())
411435

412-
createUnityImportAction unityImportTitle unityMenu
413-
createUnityExportAction unityExportTitle unityMenu
436+
UnityHelpers.createUnityImportAction unityImportTitle unityMenu
437+
UnityHelpers.createUnityExportAction unityExportTitle unityMenu
438+
UnityHelpers.createUnityExportModelAction unityExportModelTitle unityMenu
414439

415440
menuMan.updateMenuBar() --update the menu bar
416441
)
@@ -427,8 +452,8 @@ else if (maxVersion())[1] == 19000 then (
427452

428453
-- when opening a new scene, reset the export options to make
429454
-- sure we don't accidentally overwrite anything
430-
callbacks.addScript #postSceneReset ("unityResetExportOptions()")
431-
callbacks.addScript #systemPreNew ("unityResetExportOptions()")
455+
callbacks.addScript #postSceneReset ("UnityHelpers.unityResetExportOptions()")
456+
callbacks.addScript #systemPreNew ("UnityHelpers.unityResetExportOptions()")
432457
)
433458
else(
434459
print "Error: Unity Integration only supports 3ds Max 2017 or later"

0 commit comments

Comments
 (0)