MeshToString() public static method

public static MeshToString ( MeshFilter mf ) : string
mf UnityEngine.MeshFilter
return string
Exemplo n.º 1
0
 //
 // Static Methods
 //
 public static void MeshToFile(MeshFilter mf, string filename, float scale)
 {
     using (StreamWriter streamWriter = new StreamWriter(filename))
     {
         streamWriter.Write(ObjExporter.MeshToString(mf, scale));
     }
 }
Exemplo n.º 2
0
    /// <summary>
    /// Saves the scene out for later loading with the model manager class. for information about the structure of thesave
    /// look as the SceneSave class
    /// </summary>
    public void SaveScene()
    {
        List <Transform> parents = new List <Transform>();
        SceneSave        save    = new SceneSave();

        count = Directory.GetFiles(Application.persistentDataPath + "/Saves/").Length;

        ObjectID[] objectList = GetComponentsInChildren <ObjectID>();
        save.OBJStrings = new string[objectList.Length];
        save.Positions  = new V3[objectList.Length];
        save.Rotations  = new V3[objectList.Length];
        save.Scales     = new V3[objectList.Length];
        save.Colors     = new float[objectList.Length, 3];
        save.Groups     = new int[objectList.Length];
        for (int i = 0; i < objectList.Length; i++)
        {
            save.OBJStrings[i] = ObjExporter.MeshToString(objectList[i].gameObject.GetComponent <MeshFilter>());
            save.Positions[i]  = new V3(objectList[i].transform.position);
            save.Rotations[i]  = new V3(objectList[i].transform.rotation.eulerAngles);
            save.Scales[i]     = new V3(objectList[i].transform.lossyScale);
            Color c = objectList[i].GetComponent <MeshRenderer>().material.color;
            save.Colors[i, 0] = c.r;
            save.Colors[i, 1] = c.g;
            save.Colors[i, 2] = c.b;
            if (objectList[i].gameObject.GetComponent <ObjectID>().HasParent)
            {
                if (parents.Contains(objectList[i].transform.parent))
                {
                    save.Groups[i] = parents.IndexOf(objectList[i].transform.parent);
                }
                else
                {
                    save.Groups[i] = parents.Count;
                    parents.Add(objectList[i].transform.parent);
                }
            }
            else
            {
                save.Groups[i] = -1;
            }
        }
        directory = string.Format(Application.persistentDataPath + "/Saves/");;
        Directory.CreateDirectory(directory);
        date = DateTime.Today;
        string     fileName = string.Format(@"{0}/Scene {1}.obj", directory, count);
        FileStream fs       = new FileStream(fileName, FileMode.Create);

        new BinaryFormatter().Serialize(fs, save);
        fs.Close();

        GameObject.Find("Tracker").GetComponent <TrackerScript>().saveSizes.Add(new System.IO.FileInfo(fileName).Length);
        ModelManager.instance.LoadScenes();
    }
Exemplo n.º 3
0
    private void OnSave()
    {
        string filename = "Export " + MeshPreviewer.instance.m_mesh.name + " " + DateTime.Now.ToFileTimeUtc() + ".obj";

        using (StreamWriter sw = new StreamWriter(PathManager.instance.BasePath + "/" + filename, false))
        {
            sw.Write(ObjExporter.MeshToString(MeshPreviewer.instance.m_mesh, new Material[] { MeshPreviewer.instance.m_material }));
        }
        UIManager.instance.ShowModal("Mesh Exporter", "Mesh exported to \r\n" + PathManager.instance.BasePath + "/" + filename,
                                     new string[] { "Open Folder", "Close" }, (i) => {
            if (i == 0)
            {
                System.Diagnostics.Process.Start(Path.GetFullPath(PathManager.instance.BasePath));
            }
        });
    }
Exemplo n.º 4
0
    public void ExportModel()
    {
        MeshEdit[]        meshEdits = GameObject.FindObjectsOfType <MeshEdit>();
        CombineInstance[] combine   = new CombineInstance[meshEdits.Length];
        for (int i = 0; i < meshEdits.Length; i++)
        {
            combine[i].mesh      = meshEdits[i].gameObject.GetComponent <MeshFilter>().sharedMesh;
            combine[i].transform = meshEdits[i].gameObject.GetComponent <MeshFilter>().transform.localToWorldMatrix;
        }
        Mesh mesh = new Mesh();

        mesh.CombineMeshes(combine);
        GameObject gameObject = new GameObject("tempMesh", typeof(MeshFilter), typeof(MeshRenderer));

        gameObject.GetComponent <MeshFilter>().mesh = mesh;
        string obj = ObjExporter.MeshToString(gameObject.GetComponent <MeshFilter>());

        File.WriteAllText(Application.dataPath + "/Model.obj", obj);
        Destroy(gameObject);
    }
Exemplo n.º 5
0
 public static void MeshToFile(SkinnedMeshRenderer sm, string filename, float scale)
 {
     using (StreamWriter streamWriter = new StreamWriter(filename)) {
         streamWriter.Write(ObjExporter.MeshToString(sm, scale));
     }
 }
    public void SaveMesh(Mesh mesh, string filename)
    {
        var stringMesh = ObjExporter.MeshToString(mesh);

        Task.Factory.StartNew(() => TryPostJsonAsync(stringMesh, filename));
    }