Last active
July 29, 2024 21:19
-
-
Save 8chan-co/d0bd34032d11784d2da09fd4e5565378 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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