static string processTransform(Transform t, bool makeSubmeshes) { StringBuilder meshString = new StringBuilder(); meshString.Append("#" + t.name + "\n#-------" + "\n"); if (makeSubmeshes) { meshString.Append("g ").Append(t.name).Append("\n"); } MeshFilter mf = t.GetComponent <MeshFilter>(); if (mf) { meshString.Append(ObjExporterScript.MeshToString(mf, t)); } for (int i = 0; i < t.childCount; i++) { meshString.Append(processTransform(t.GetChild(i), makeSubmeshes)); } return(meshString.ToString()); }
/* * [MenuItem("File/Export/Wavefront OBJ")] * static void DoExportWSubmeshes() { * DoExport(true); * } * * [MenuItem("File/Export/Wavefront OBJ (No Submeshes)")] * static void DoExportWOSubmeshes() { * DoExport(false); * } * * 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"); * * StringBuilder meshString = makeObj(makeSubmeshes, meshName, Selection.gameObjects[0]); * * WriteToFile(meshString.ToString(), fileName); * Debug.Log("Exported Mesh: " + fileName); * } */ public static StringBuilder makeObj(bool makeSubmeshes, string meshName, GameObject root) { ObjExporterScript.Start(); StringBuilder meshString = new StringBuilder(); meshString.Append("#" + meshName + ".obj" + "\n#" + System.DateTime.Now.ToLongDateString() + "\n#" + System.DateTime.Now.ToLongTimeString() + "\n#-------" + "\n\n"); Transform t = root.transform; Vector3 originalPosition = t.position; t.position = Vector3.zero; if (!makeSubmeshes) { meshString.Append("g ").Append(t.name).Append("\n"); } meshString.Append(processTransform(t, makeSubmeshes)); t.position = originalPosition; ObjExporterScript.End(); return(meshString); }