Export to obj >> help needed

I am using this script -

I want to press this button to export mesh with textures and bitmaps, name of the mesh is - charaBase

what do i have to called here- MeshToFile();

void OnGUI(){
		if (GUI.Button(new Rect(550, 70, 100, 30), "Export to obj")){
			//MeshToFile(WHAT SHOULD I WRITE HERE ?? );
		}

How can i do this ??

using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;
 
public class ObjExporter : MonoBehaviour {
 
    public static string MeshToString(MeshFilter mf) {
        Mesh m = mf.mesh;
        Material[] mats = mf.renderer.sharedMaterials;
 
        StringBuilder sb = new StringBuilder();
 
        sb.Append("g ").Append(mf.name).Append("\n");
        foreach(Vector3 v in m.vertices) {
            sb.Append(string.Format("v {0} {1} {2}\n",v.x,v.y,v.z));
        }
        sb.Append("\n");
        foreach(Vector3 v in m.normals) {
            sb.Append(string.Format("vn {0} {1} {2}\n",v.x,v.y,v.z));
        }
        sb.Append("\n");
        foreach(Vector3 v in m.uv) {
            sb.Append(string.Format("vt {0} {1}\n",v.x,v.y));
        }
        for (int material=0; material < m.subMeshCount; material ++) {
            sb.Append("\n");
            sb.Append("usemtl ").Append(mats[material].name).Append("\n");
            sb.Append("usemap ").Append(mats[material].name).Append("\n");
 
            int[] triangles = m.GetTriangles(material);
            for (int i=0;i<triangles.Length;i+=3) {
                sb.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", 
                    triangles[i]+1, triangles[i+1]+1, triangles[i+2]+1));
            }
        }
        return sb.ToString();
    }
 
    public static void MeshToFile(MeshFilter mf, string filename) {
        using (StreamWriter sw = new StreamWriter(filename)) 
        {
			 
            sw.Write(MeshToString(mf));
			
        }
    }
	
	void OnGUI(){
		if (GUI.Button(new Rect(550, 70, 100, 30), "Export to obj")){
			//MeshToFile();
		}
	}
}

Use the correct version:

http://wiki.unity3d.com/index.php?title=ObjExporter

There’s an extended version EditorObjExporter.cs, I tried that a while ago and it worked pretty well.

I dont want to export from editor extension, i wanna do this in runtime

bump

The runtime exporter is on the same page in case you haven’t noticed.

Glockenbeat already provided you a really good answer! Just look through the code and delete unnecessary methods and there you have your runtime solution

You are right, but i am using the same script if you notice, i have a query on how to use it…kindly look at my query.

and any help on how do i export the animations on that character ?

OBJ format doesn’t support animation. As for the argument question - the MeshFilter is the mesh you’re exporting and the string is the name of the file…not sure what else you need to know.