static string processTransform(Transform t, bool makeSubmeshes, ref string meshDataStr) { StringBuilder meshString = new StringBuilder(); //if (meshDataStr.Contains(t.name) == true) //{ // string[] separator = { t.name }; // int name_count = meshDataStr.Split(separator, System.StringSplitOptions.RemoveEmptyEntries).Length; // t.name = t.name + name_count; //} 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++) { string SubMeshDataStr = meshString.ToString(); meshString.Append(processTransform(t.GetChild(i), makeSubmeshes, ref SubMeshDataStr)); } return(meshString.ToString()); }
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()); }
void SurfaceBaked(SurfaceData sd, bool outputWritten, float elapsedBakeTimeSeconds) { if (outputWritten) { File.WriteAllText(objPath + sd.id.handle, ObjExporterScript.MeshToString(sd.outputMesh, sd.outputMesh.transform)); Console.WriteLine("written obj file"); } }
static void DoExport() { if (Selection.gameObjects.Length == 0) { Debug.Log("Didn't Export Any Meshes; Nothing was selected!"); return; } Transform t = Selection.gameObjects[0].transform; MeshFilter mf = t.GetComponent <MeshFilter>(); if (null == mf) { EditorUtility.DisplayDialog("title", "没有选择mesh", "ok"); 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"); Vector3 originalPosition = t.position; t.position = Vector3.zero; if (mf) { meshString.Append(ObjExporterScript.MeshToString(mf, t)); } WriteToFile(meshString.ToString(), fileName); t.position = originalPosition; ObjExporterScript.End(); Debug.Log("Exported Mesh: " + fileName); }
public void ExportChakraMesh(ChakraPosition cp, Mesh m) { ObjExporterScript ex = new ObjExporterScript(); ObjExporterScript.Start(); string str = ObjExporterScript.MeshToString(m, this.transform, null); int index = this.ChakraIndex(cp); string toPath = (Application.dataPath + "/ExportedMeshes/ChakraMesh_" + (index + 1) + "_" + cp.name.Trim().Replace(" ", "_") + ".obj"); Debug.Log("Saving mesh to: " + toPath); StreamWriter sw = new StreamWriter(toPath); sw.Write(str); sw.Close(); }
static string processTransform(Transform t) { StringBuilder meshString = new StringBuilder(); meshString.Append("#" + t.name + "\n#-------" + "\n"); meshString.Append("o ").Append(t.name).Append("\n"); MeshFilter mf = t.GetComponent <MeshFilter>(); if (mf) { meshString.Append(ObjExporterScript.MeshToString(mf, t)); } return(meshString.ToString()); }
public void ExportYogiMesh() { var bodyRoot = this.ChakraExcersize.Body.LeftLegEnd; while (bodyRoot.parent != null) { bodyRoot = bodyRoot.parent; } var smr = bodyRoot.GetComponentInChildren <SkinnedMeshRenderer> (); Mesh m = new Mesh(); smr.BakeMesh(m); var str = ObjExporterScript.MeshToString(m, this.transform, null); string toPath = (Application.dataPath + "/ExportedMeshes/YogiMesh_SimpleLotus.obj"); Debug.Log("Saving mesh to: " + toPath); StreamWriter sw = new StreamWriter(toPath); sw.Write(str); sw.Close(); }
static string processTransform(Transform t, bool makeSubmeshes) { Debug.Log(" Exporting " + t.gameObject.name); 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>(); Renderer renderer = t.GetComponent <Renderer>(); if (mf && renderer) { meshString.Append(ObjExporterScript.MeshToString(mf.sharedMesh, renderer.sharedMaterials, t)); } SkinnedMeshRenderer skinnedMeshRenderer = t.GetComponent <SkinnedMeshRenderer>(); if (skinnedMeshRenderer) { meshString.Append(ObjExporterScript.MeshToString(skinnedMeshRenderer.sharedMesh, skinnedMeshRenderer.sharedMaterials, t)); } for (int i = 0; i < t.childCount; i++) { meshString.Append(processTransform(t.GetChild(i), makeSubmeshes)); } return(meshString.ToString()); }
public void PrintMesh() { Debug.Log(ObjExporterScript.MeshToString(ExportMesh())); }