Skip to content

Instantly share code, notes, and snippets.

@8chan-co
Last active July 29, 2024 21:19
Show Gist options
  • Save 8chan-co/d0bd34032d11784d2da09fd4e5565378 to your computer and use it in GitHub Desktop.
Save 8chan-co/d0bd34032d11784d2da09fd4e5565378 to your computer and use it in GitHub Desktop.
namespace AteChan.co
{
using Autodesk.Fbx;
using UnityEditor;
internal static class BinaryFbxExporter
{
[MenuItem("Tools/Convert FBX To Binary")]
private static void ConvertToBinary()
{
using var manager = FbxManager.Create();
using var importer = FbxImporter.Create(manager, string.Empty);
var path = AssetDatabase.GetAssetPath(Selection.activeObject);
importer.Initialize(path);
using var document = importer.GetScene() ?? FbxDocument.Create(manager, string.Empty);
importer.Import(document);
using var exporter = FbxExporter.Create(manager, string.Empty);
using var registry = manager.GetIOPluginRegistry();
var destination = AssetDatabase.GenerateUniqueAssetPath(path);
var format = registry.FindWriterIDByDescription("FBX binary (*.fbx)");
exporter.Initialize(destination, format);
exporter.Export(document);
AssetDatabase.ImportAsset(destination);
var instanceID = UnityEditor.Search.SearchUtils.GetMainAssetInstanceID(destination);
EditorGUIUtility.PingObject(instanceID);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment