static string processTransform(Transform transform, bool makeSubmeshes) { StringBuilder meshString = new StringBuilder(); meshString.Append("#" + transform.name + "\n#-------" + "\n"); if (makeSubmeshes) { meshString.Append("g ").Append(transform.name).Append("\n"); } MeshFilter mf = transform.GetComponent <MeshFilter>(); if (mf) { meshString.Append(ObjExporterScript.MeshToString(mf, transform)); } for (int i = 0; i < transform.childCount; i++) { meshString.Append(processTransform(transform.GetChild(i), makeSubmeshes)); } return(meshString.ToString()); }
private void exportToFile() { if (GUILayout.Button("export")) { ObjExporterScript.DoExport(true); AssetDatabase.Refresh(); } }
public static void DoExport(bool makeSubmeshes) { if (Selection.gameObjects.Length == 0) { Debug.Log("Didn't Export Any Meshes; Nothing was selected!"); return; } string meshName = Selection.gameObjects[0].name; string fileName = EditorUtility.SaveFilePanel("Export .obj file", "", meshName, "obj"); ObjExporterScript.Start(); StringBuilder meshString = new StringBuilder(); meshString.Append("#" + meshName + ".obj" + "\n#" + System.DateTime.Now.ToLongDateString() + "\n#" + System.DateTime.Now.ToLongTimeString() + "\n#-------" + "\n\n"); Transform transform = Selection.gameObjects[0].transform; Vector3 originalPosition = transform.position; transform.position = Vector3.zero; if (!makeSubmeshes) { meshString.Append("g ").Append(transform.name).Append("\n"); } meshString.Append(processTransform(transform, makeSubmeshes)); WriteToFile(meshString.ToString(), fileName); transform.position = originalPosition; ObjExporterScript.End(); Debug.Log("Exported Mesh: " + fileName); }