In Unity3D I have a script-generated Mesh
object. I've serialized it as an .asset
file using AssetDatabase.CreateAsset
, so now I have /Asset/ExampleMesh.asset
.
However since external programs cannot open unity assets, I'm looking for a way to convert it to an fbx. In other words, I would like to be able to create /Asset/ExampleMesh.fbx
.
In script, given a Mesh
reference, is there any way to output an .fbx
asset? I'm looking to write a helper function like this:
public static void ExportToFBXFile(Mesh mesh, string filepath)
{
byte[] bytes = EncodeMeshToFBX(mesh);
File.WriteAllBytes(Application.dataPath + "/" + filepath + ".fbx", bytes);
}
Where EncodeMeshToFBX
would generate the byte representation of the mesh as an FBX.
I don't care about materials, animations, etc. I just want to go from a Mesh
to a .fbx
file.
Note: I've seen some plugin solutions that can take a gameobject and save it's hierarchy as an FBX. This is not what I'm looking for. I just want to export a Mesh type itself.