I use your Unity FBX Exporter 4.0.1 package and I have to export objects via scripting, like:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
class TestCode
{
[MenuItem("BugReport/Export selected GameObject as FBX")]
static void DoMenuItem()
{
UnityEditor.Formats.Fbx.Exporter.ModelExporter.ExportObject("Assets/MyExport.fbx", Selection.activeGameObject);
UnityEditor.AssetDatabase.Refresh();
}
}
However, the exported FBX file is in ASCII format always. The Export Format settings under Project Settings > Fbx Export don’t affect the exported format.
Right-clicking the object in the Hierarchy and choosing Export to FBX... actually does export the file in binary. I looked through the FBX Exporter code and you pass an additional SettingsObject to the ExportObjects method.
All of this functionality is internal only. Please make the API public instead, I need to export objects via editor-scripting. The reason why I need to export binary is that the ASCII format is just too big, the mesh export is 150MB, which isn’t great for import times in the editor and version control.
I also submitted a bug-report for you:
(Case 1338169) 2019.4: FBX Exporter: Export Binary not working
var exportOptions = new ExportModelSettingsSerialize();
exportOptions.SetPreserveImportSettings(true);
ModelExporter.ExportObject(filename, cube, exportOptions);
var exportOptions = new ExportModelSettingsSerialize();
The export works but the FBX does not keep the position at all and export at (0,0,0) but the rotation is ok. Any idea?
I want to export a GameObject at the root of the scene in World Absolute position but it always export it Local Pivot even if it is “World Absolute” in Project Settings :
I tried added “objectPosition” “objectsPosition” I even tried “include” but only your field “exportFormat” works. How can you the names of the fields? @LemonLube_1
resurrecting this post since I came across this recently. Here’s some addition to the reflection code above if you need to export more than a single mesh as an fbx with binary format. Requiring passing a dictionary with a private type took a bit to figure out the right syntax for so I’ll pass this on in case anyone else needs it.
/////// this is some absolute clown shit.....
Type[] types = AppDomain.CurrentDomain.GetAssemblies().First(x => x.FullName == "Unity.Formats.Fbx.Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").GetTypes();
Type optionsInterfaceType = types.First(x => x.Name == "IExportOptions");
Type optionsType = types.First(x => x.Name == "ExportOptionsSettingsSerializeBase");
Type exportDataType = types.First(x => x.Name == "IExportData");
Type dictionaryType = typeof(Dictionary<,>).MakeGenericType(typeof(GameObject), exportDataType);
// Instantiate a settings object instance
MethodInfo optionsProperty = typeof(ModelExporter).GetProperty("DefaultOptions", BindingFlags.Static | BindingFlags.NonPublic).GetGetMethod(true);
object optionsInstance = optionsProperty.Invoke(null, null);
// Change the export setting from ASCII to binary
FieldInfo exportFormatField = optionsType.GetField("exportFormat", BindingFlags.Instance | BindingFlags.NonPublic);
exportFormatField.SetValue(optionsInstance, 1);
// Invoke the ExportObjects method
MethodInfo exportObjectMethod = typeof(ModelExporter).GetMethod("ExportObjects", BindingFlags.Static | BindingFlags.NonPublic, Type.DefaultBinder, new Type[] { typeof(string), typeof(UnityEngine.Object[]), optionsInterfaceType, dictionaryType }, null);
exportObjectMethod.Invoke(null, new object[] { fbxPath, objectsToExport, optionsInstance, null });
frankly ridiculous that this hasn’t been fixed in the 3 years since this was posted. It seems like it should be a 5 minute fix to add a new public method that takes the export type as input.