예제 #1
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(OBJExport.MeshToString(mf, t));
        }

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

        return(meshString.ToString());
    }
예제 #2
0
    public static void DoExport(GameObject go, Texture2D tex, bool makeSubmeshes)
    {
        string meshName = go.name;
        string fileName = Application.dataPath + "/../BeautifulBonsai" + System.DateTime.Now.Day.ToString() + Random.Range(0, 1000000).ToString() + ".obj";

        OBJExport.Start();

        StringBuilder meshString = new StringBuilder();

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

        File.WriteAllBytes(Application.dataPath + "/../" + tex.name + ".png", tex.EncodeToPNG());

//		WriteToFile("newmtl initialShadingGroup\n" +
//			"illum 4\n" +
//			"Kd 0.00 0.00 0.00\n" +
//			"Ka 0.00 0.00 0.00\n" +
//			"Tf 1.00 1.00 1.00\n" +
//			"map_Kd FullTreeTex.png\n" +
//			"Ni 1.00\n", fileName.Replace(".obj", ".mtl"));
//
//		// Material library!
//		meshString.Append("mtllib " + fileName.Replace(".obj", ".mtl") + "\n" );

        Transform t = go.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;

        OBJExport.End();
        Debug.Log("Exported Mesh: " + fileName);
    }
예제 #3
0
    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");

        OBJExport.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");
        }
        meshString.Append(processTransform(t, makeSubmeshes));

        WriteToFile(meshString.ToString(), fileName);

        t.position = originalPosition;

        OBJExport.End();
        Debug.Log("Exported Mesh: " + fileName);
    }
예제 #4
0
 public void OnClickMeshExport()
 {
     OBJExport.DoExport(_plantBoy.transform.parent.gameObject, _plantExportTex, false);
 }