1

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.

Programmer
  • 121,791
  • 22
  • 236
  • 328
Johannes
  • 6,232
  • 9
  • 43
  • 59
  • I'm arguing that this is not a duplicate of https://stackoverflow.com/questions/46733430 - that question is asking about gameobject to fbx saving, and the solutions provided all accept a gameobject. This is not what I am asking. I want to specifically serialize a `Mesh` without any gameobject involved. – Johannes Jul 24 '18 at 20:32
  • It's doing extremely something similar. It takes GameObject as param, get's MeshFilter from it and converts it into an fbx format. You have two options: **1.** Create new GameObject, attach MeshFilter to it and the mesh then call the `FBXExporter.ExportGameObjToFBX` function and send that GameObject. You probably don't want to do #1 but it's simpler. **2.** Add a new function to the `FBXExporter` class. Copy the code from the `FBXExporter.ExportGameObjToFBX` function to it then change the function param to Mesh. Remove the GameObject code. Nothing complicated here. – Programmer Jul 24 '18 at 21:02

0 Answers0