@@ -182,8 +182,17 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
182
182
)
183
183
)
184
184
)
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"
186
191
(
192
+ UnityExportHelpers.exportSelection modelOnly: true
193
+ )
194
+
195
+ struct UnityExportHelpers (
187
196
fn unitToScaleFactor unit = (
188
197
case unit of (
189
198
#Inches : 2.54
@@ -194,15 +203,15 @@ macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"
194
203
#Meters : 100
195
204
default: 1
196
205
)
197
- );
206
+ ),
198
207
199
208
fn loadUnityFbxExportSettings = (
200
209
fbxExportSettings = getINISetting (GetMAXIniFile()) " Unity" " UnityFbxExportSettings"
201
210
if fbxExportSettings != undefined and doesFileExist fbxExportSettings then (
202
211
filein fbxExportSettings
203
212
)
204
- FbxExporterSetParam " ScaleFactor" (unitToScaleFactor units.SystemType)
205
- );
213
+ FbxExporterSetParam " ScaleFactor" (UnityExportHelpers. unitToScaleFactor units.SystemType)
214
+ ),
206
215
207
216
fn getUnityExportSets = (
208
217
local unityExportSets = #()
@@ -215,8 +224,8 @@ macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"
215
224
)
216
225
)
217
226
unityExportSets
218
- )
219
-
227
+ ),
228
+
220
229
fn exportUnitySet expSet = (
221
230
select expSet
222
231
@@ -237,75 +246,84 @@ macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"
237
246
if exportFileName != undefined then (
238
247
exportFile exportFileName #noPrompt selectedOnly: true using: FBXEXP
239
248
)
240
- )
249
+ ),
241
250
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
+ )
262
277
)
263
278
)
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
+ )
272
287
)
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
277
298
)
278
- )
279
-
280
- units.SystemType = origUnits
281
-
282
- if origSelection != undefined then (
283
- select origSelection
284
299
)
285
300
)
286
301
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
+ ),
294
310
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
+ ),
298
314
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
+ ),
302
322
303
- global unityResetExportOptions;
304
- fn unityResetExportOptions = (
305
- unityFbxFilePathAttr= undefined ;
306
- unityFbxFileNameAttr= undefined ;
307
- unityAskSetUnits= undefined ;
308
- );
323
+ fn unityResetExportOptions = (
324
+ unityAskSetUnits= undefined ;
325
+ )
326
+ )
309
327
310
328
-- Setup UI in existing Import/Export menus if using 3ds Max 2018+
311
329
if (maxVersion())[1 ] >= 20000 then (
@@ -332,6 +350,7 @@ if (maxVersion())[1] >= 20000 then(
332
350
(
333
351
local unityImportTitle = " Import from Unity"
334
352
local unityExportTitle = " Export to Unity"
353
+ local unityExportModelTitle = " Export Model Only to Unity"
335
354
336
355
-- check if menu items already exist, delete if they do
337
356
local foundUnityImport = false
@@ -354,8 +373,9 @@ if (maxVersion())[1] >= 20000 then(
354
373
id = genClassID returnValue: true
355
374
if menuMan.registerMenuContext id[1 ] then
356
375
(
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
359
379
360
380
menuMan.updateMenuBar() -- update the menu bar
361
381
)
@@ -372,13 +392,16 @@ if (maxVersion())[1] >= 20000 then(
372
392
) \
373
393
if exportMenu != undefined and unityExportAction != undefined then( \
374
394
exportMenu.removeItem unityExportAction; \
395
+ ) \
396
+ if exportMenu != undefined and unityExportModelAction != undefined then( \
397
+ exportMenu.removeItem unityExportModelAction; \
375
398
)"
376
399
)
377
400
378
401
-- when opening a new scene, reset the export options to make
379
402
-- 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()" )
382
405
)
383
406
else if (maxVersion())[1 ] == 19000 then (
384
407
-- for 3ds Max 2017
@@ -395,6 +418,7 @@ else if (maxVersion())[1] == 19000 then (
395
418
local unityMenu = getUnityMenu()
396
419
local unityImportTitle = " Import"
397
420
local unityExportTitle = " Export"
421
+ local unityExportModelTitle = " Export Model Only"
398
422
if unityMenu != undefined do
399
423
(
400
424
-- remove the menu if it still exists
@@ -409,8 +433,9 @@ else if (maxVersion())[1] == 19000 then (
409
433
local unityMenuItem = menuMan.createSubMenuItem unityMenuName unityMenu
410
434
mainMenuBar.addItem unityMenuItem (mainMenuBar.numItems())
411
435
412
- createUnityImportAction unityImportTitle unityMenu
413
- createUnityExportAction unityExportTitle unityMenu
436
+ UnityHelpers.createUnityImportAction unityImportTitle unityMenu
437
+ UnityHelpers.createUnityExportAction unityExportTitle unityMenu
438
+ UnityHelpers.createUnityExportModelAction unityExportModelTitle unityMenu
414
439
415
440
menuMan.updateMenuBar() -- update the menu bar
416
441
)
@@ -427,8 +452,8 @@ else if (maxVersion())[1] == 19000 then (
427
452
428
453
-- when opening a new scene, reset the export options to make
429
454
-- 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()" )
432
457
)
433
458
else (
434
459
print " Error: Unity Integration only supports 3ds Max 2017 or later"
0 commit comments