예제 #1
0
        //future refactor here with other methods?
        public static void ShowErrorWindow(string header, string message)
        {
            ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");

            panel.SetMessage(header, message, false);
            panel.GetComponentInChildren <UISprite>().spriteName = "IconError";
        }
예제 #2
0
        public string[] DumpNetworks(bool endPopup = true)
        {
            try
            {
                string networkName_init = sim.m_editPrefabInfo.name;
                FindMesh(networkName_init);
                var source = material.GetTexture("_MainTex") as Texture2D;
                var target = new Texture2D(source.width, source.height, TextureFormat.RGBAFloat, true);
                target.SetPixels(source.GetPixels());
                target.anisoLevel = source.anisoLevel; target.filterMode = source.filterMode;
                target.wrapMode   = source.wrapMode; target.Apply();
                UnityEngine.Object.FindObjectOfType <NetProperties>().m_downwardDiffuse = target;

                bool      flippingTextures = NetDumpPanel.instance.GetIfFlippedTextures;
                Texture2D aprsource        = aprmaterial.GetTexture("_APRMap") as Texture2D;

                if (NetDumpPanel.instance.GetDumpMeshOnly && NetDumpPanel.instance.GetDumpDiffuseOnly)
                {
                    DumpTexture2D(FlipTexture(target, false, flippingTextures), diffuseTexturePath);
                    DumpMeshToOBJ(roadMesh, meshPath, loadedPrefab);
                    DumpMeshToOBJ(roadMeshLod, lodMeshPath, loadedPrefab);
                }
                else if (NetDumpPanel.instance.GetDumpDiffuseOnly)
                {
                    DumpTexture2D(FlipTexture(target, false, flippingTextures), diffuseTexturePath);
                }
                else if (NetDumpPanel.instance.GetDumpMeshOnly)
                {
                    DumpMeshToOBJ(roadMesh, meshPath, loadedPrefab);
                    DumpMeshToOBJ(roadMeshLod, lodMeshPath, loadedPrefab);
                }
                else
                {
                    DumpTexture2D(FlipTexture(target, false, flippingTextures), diffuseTexturePath);
                    DumpAPR(filename, FlipTexture(aprsource, false, flippingTextures), aFilePath, pFilePath, rFilePath, true);
                    //dump meshes
                    DumpMeshToOBJ(roadMesh, meshPath, loadedPrefab);
                    DumpMeshToOBJ(roadMeshLod, lodMeshPath, loadedPrefab);
                    DumpAPR(filename, FlipTexture(aprsource, false, flippingTextures), aFilePath, pFilePath, rFilePath, true);
                }
                //for workshop roads display disclaimer!
                //also add log for apr textures!
                if (!NetDumpPanel.instance.roadexportnames.Contains(filename))
                {
                    NetDumpPanel.instance.roadexportnames.Add(filename);
                }
                else
                {
                    NetDumpPanel.instance.roadexportnames.Add(filename + "_node");
                }
                //make sure to clear for each button?

                ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");

                string[] combinedPaths = { diffuseTexturePath, meshPath, lodMeshPath, aFilePath, pFilePath, rFilePath };
                exportedFilePaths = "";

                if (NetDumpPanel.instance.GetDumpMeshOnly)
                {
                    exportedFilePaths = "Mesh Dump Only\n" + meshPath + "\n" + lodMeshPath;
                    filesExported    += 2;
                }
                else
                {
                    for (int i = 0; i < combinedPaths.Length; i++)
                    {
                        if (File.Exists(combinedPaths[i]))
                        {
                            exportedFilePaths += "\n" + combinedPaths[i];
                            filesExported     += 1;
                        }
                    }
                }

                if (endPopup == true)
                {
                    panel.SetMessage("Network Dump Successful", "Network Name: " + networkName + "\n\nDumped Items:\n" + exportedFilePaths, false);
                }
            }
            catch (Exception e)
            {
                if (endPopup == true)
                {
                    ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");
                    panel.SetMessage("Network Dump Failed", "" + e, false);
                    panel.GetComponentInChildren <UISprite>().spriteName = "IconError";
                    filesExported = 0;
                }
                else
                {
                    bulkErrorText = e.ToString();
                }
            }

            var lodFilepathPart = diffuseTexturePath.Substring(0, diffuseTexturePath.LastIndexOf("_"));

            string[] returnArray = { filesExported.ToString(), exportedFilePaths, lodFilepathPart };


            if (NetDumpPanel.instance.autoExportLodImages.isChecked)
            {
                Debug.Log("Dump with LOD pngs Checked!");
                LodImageGenerator lodgen = new LodImageGenerator();
                lodgen.GenerateLodImages(lodFilepathPart);
            }

            return(returnArray);
        }
        public void GenerateLodImages(string filepath)
        {
            Texture2D texture1;

            string[] textureFileExtensions = { "_d.png", "_a.png", "_p.png", "_r.png" };

            try
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "filename: " + filepath);
                if (filepath == "")
                {
                    if (NetDumpPanel.instance.GetCustomFilePrefix() != "")
                    {
                        string importFolder = Path.Combine(DataLocation.addonsPath, "Import");
                        filepath = Path.Combine(importFolder, NetDumpPanel.instance.GetCustomFilePrefix());
                    }
                    else
                    {
                        throw new System.Exception("No File Path Found! \nDump a network first or put a custom filename in the custom file prefix field\n");
                    }
                }
                for (int i = 0; i < textureFileExtensions.Length; i++)
                {
                    if (File.Exists(filepath + textureFileExtensions[i]))
                    {
                        texture1 = new Texture2D(1, 1);
                        texture1.LoadImage(File.ReadAllBytes(filepath + textureFileExtensions[i]));
                        texture1.anisoLevel = 16;
                        texture1.MakeReadable();
                        TextureScaler.scale(texture1, 64, 64);
                        //turn off if elevated?
                        if (NetDumpPanel.instance.GetNetEleIndex == 0)
                        {
                            texture1 = FlipTexture(texture1, false);
                            DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "flipped texture1!");
                        }
                        string fileExt     = "_lod" + textureFileExtensions[i];
                        string lodFilepath = filepath + fileExt;

                        DumpTexture2D(texture1, lodFilepath);
                        filePathsLog += lodFilepath + "\n";
                        NetDumpPanel.instance.dumpedFiles += lodFilepath + "\n";
                    }
                    else
                    { //make this try/catch?
                        Debug.Log(textureFileExtensions[i] + " failed");
                    }
                }

                if (NetDumpPanel.instance.GetNetEleIndex != 0)
                {
                    //bit of hack since for some reason uv maps are often completely different on lod meshes than main mesh on some vanilla elevations - ok since elevated sections are not used that much on a map anyway for custom roads. - do properly later maybe?
                    File.Copy(filepath + ".obj", filepath + "_lod.obj", true);
                }

                ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");
                panel.SetMessage("LOD File Generation Successful", "Files Exported:\n" + filePathsLog, false);
            }
            catch (Exception e)
            {
                ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");
                panel.SetMessage("LOD File Generation Failed", "" + e, false);
                panel.GetComponentInChildren <UISprite>().spriteName = "IconError";
            }
        }