Example #1
0
        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 meshFilter = transform.GetComponent <MeshFilter>();

            if (meshFilter != null)
            {
                meshString.Append(ZOObjExporterScript.MeshToString(meshFilter, transform));
            }

            for (int i = 0; i < transform.childCount; i++)
            {
                meshString.Append(ProcessTransform(transform.GetChild(i), makeSubmeshes));
            }

            return(meshString.ToString());
        }
Example #2
0
        public static void DoExport(bool makeSubmeshes, string fileName, bool zeroPosition = true)
        {
            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");

            ZOObjExporterScript.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;

            if (zeroPosition == true)
            {
                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;

            ZOObjExporterScript.End();
            Debug.Log("Exported Mesh: " + fileName);
        }