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());
    }
    public void Export()
    {
        string meshName = gameObject.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 t = gameObject.transform;

        Vector3 originalPosition = t.position;

        t.position = Vector3.zero;

        meshString.Append(processTransform(t, false));

        WriteToFile(meshString.ToString(), fileName);

        t.position = originalPosition;

        ObjExporterScript.End();
        Debug.Log("Exported Mesh: " + fileName);
    }
Beispiel #3
0
    public static void DoExportFromGame(GameObject[] saves)
    {
        string meshName      = saves[0].tag;
        string fileName      = meshName + ".obj";
        bool   makeSubmeshes = false;

        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 = saves[0].transform;
        Vector3   originalPosition = t.position;

        t.position = Vector3.zero;
        if (!makeSubmeshes)
        {
            meshString.Append("g ").Append(t.name).Append("\n");
        }
        meshString.Append(ProcessTransform(t, makeSubmeshes));
        WriteToFile(meshString.ToString(), fileName);

        t.position = originalPosition;
        ObjExporterScript.End();
        Debug.Log("Exported Mesh: " + fileName);
    }
Beispiel #4
0
    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());
    }
Beispiel #5
0
 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");
     }
 }
Beispiel #6
0
    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();
    }
Beispiel #8
0
    public static void DoExport(GameObject gameObject, bool makeSubmeshes)
    {
        string meshName = gameObject.name.Replace(':', '_');
        string fileName = "C:\\Users\\st_dg\\OneDrive\\TLD\\exported-meshes\\" + meshName + ".obj";

        Debug.Log("Exporting " + fileName);

        ObjExporterScript.Start();

        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.Append("#" + meshName + ".obj"
                             + "\n#" + System.DateTime.Now.ToLongDateString()
                             + "\n#" + System.DateTime.Now.ToLongTimeString()
                             + "\n#-------"
                             + "\n\n");

        Transform t = gameObject.transform;

        Transform  originalParent        = gameObject.transform.parent;
        Vector3    originalLocalPosition = t.localPosition;
        Quaternion originalLocalRotation = t.localRotation;
        Vector3    originalLocalScale    = t.localScale;

        t.parent        = null;
        t.position      = Vector3.zero;
        t.localScale    = Vector3.one;
        t.localRotation = Quaternion.identity;

        if (!makeSubmeshes)
        {
            stringBuilder.Append("g ").Append(t.name).Append("\n");
        }
        stringBuilder.Append(processTransform(t, makeSubmeshes));

        WriteToFile(stringBuilder.ToString(), fileName);

        t.parent        = originalParent;
        t.localPosition = originalLocalPosition;
        t.localRotation = originalLocalRotation;
        t.localScale    = originalLocalScale;

        ObjExporterScript.End();
        Debug.Log("Exported Mesh: " + fileName);
    }
    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());
    }
    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 t = Selection.gameObjects[0].transform;

        Vector3 originalPosition = t.position;

        t.position = Vector3.zero;

        if (!makeSubmeshes)
        {
            meshString.Append("g ").Append(t.name).Append("\n");
        }
        string meshDataStr = "";

        meshString.Append(processTransform(t, makeSubmeshes, ref meshDataStr));

        WriteToFile(meshString.ToString(), fileName);

        t.position = originalPosition;

        ObjExporterScript.End();
        Debug.Log("Exported Mesh: " + fileName);
    }
    public static void DoExport(bool makeSubmeshes, GameObject objToExport, string path)
    {
        if (objToExport == null)
        {
            Debug.Log("No object to export!");
            return;
        }

        string meshName = GenerateMeshName();
        string fileName = GenerateFileName(meshName, path);

        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 = objToExport.transform;

        Vector3 originalPosition = t.position;

        t.position = Vector3.zero;

        if (!makeSubmeshes)
        {
            meshString.Append("g ").Append(t.name).Append("\n");
        }
        meshString.Append(processTransform(t, makeSubmeshes));

        WriteToFile(meshString.ToString(), fileName);

        t.position = originalPosition;

        ObjExporterScript.End();
        Debug.Log("Exported Mesh: " + fileName);
    }
Beispiel #12
0
    static public void DoExport(GameObject obj, bool makeSubmeshes, string navType)
    {
        if (obj == null)
        {
            Debug.Log("Didn't Export Any Meshes; Nothing was selected!");
            return;
        }

        string meshName = obj.name;
        string fileName = "Exports/MapGen." + navType + ".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 t = obj.transform;

        Vector3 originalPosition = t.position;

        t.position = Vector3.zero;

        if (!makeSubmeshes)
        {
            meshString.Append("g ").Append(t.name).Append("\n");
        }
        meshString.Append(processTransform(t, makeSubmeshes));

        WriteToFile(meshString.ToString(), fileName);

        t.position = originalPosition;

        ObjExporterScript.End();
        Debug.Log("Exported Mesh: " + fileName);
    }
    public static void DoExport(GameObject[] selections)
    {
        if (selections.Length == 0)
        {
            Debug.Log("Didn't Export Any Meshes; Nothing was selected!");
            return;
        }

        string meshName = selections[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");

        foreach (GameObject go in selections)
        {
            Transform t = go.transform;
            Vector3   originalPosition = t.position;
            t.position = Vector3.zero;

            meshString.Append(processTransform(t));

            WriteToFile(meshString.ToString(), fileName);

            t.position = originalPosition;
        }

        ObjExporterScript.End();

        Debug.Log("Exported Mesh: " + fileName);
    }
Beispiel #14
0
    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();
    }
Beispiel #15
0
    public static void Export(GameObject export)
    {
        string meshName = export.name;

        string fileName = OpenFilePanel.Open();

        if (!string.IsNullOrEmpty(fileName))
        {
            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 = export.transform;

            Vector3 originalPosition = t.position;
            t.position = Vector3.zero;

            meshString.Append("g ").Append(t.name).Append("\n");


            meshString.Append(processTransform(t));

            WriteToFile(meshString.ToString(), fileName);

            t.position = originalPosition;

            ObjExporterScript.End();

            Debug.Log("Exported Cloud: " + fileName);
        }
    }
Beispiel #16
0
    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());
    }
Beispiel #17
0
 void Start()
 {
     objExport = gameObject.GetComponent <ObjExporterScript> ();
 }
Beispiel #18
0
 public void PrintMesh()
 {
     Debug.Log(ObjExporterScript.MeshToString(ExportMesh()));
 }