From abab538c0d9021a6e823dd539ea380ea1168ca38 Mon Sep 17 00:00:00 2001 From: Cgameworld Date: Sat, 21 Mar 2020 23:27:28 -0700 Subject: [PATCH 1/2] part 1 to lod fix --- RoadDumpTools/DumpProcessing.cs | 109 ++++++++++++++++++++++---------- RoadDumpTools/NetDumpPanel.cs | 4 ++ RoadDumpTools/lib/DumpUtil.cs | 6 +- 3 files changed, 83 insertions(+), 36 deletions(-) diff --git a/RoadDumpTools/DumpProcessing.cs b/RoadDumpTools/DumpProcessing.cs index ffa8736..8b65bdf 100644 --- a/RoadDumpTools/DumpProcessing.cs +++ b/RoadDumpTools/DumpProcessing.cs @@ -20,6 +20,8 @@ public class DumpProcessing string filename; Material material; Material aprmaterial; + Material materialLOD; + Material aprmaterialLOD; Mesh roadMesh; Mesh roadMeshLod; int meshnum; @@ -35,6 +37,10 @@ public class DumpProcessing Vector3[] newvertices; public string bulkErrorText; + string diffuseLODTexturePath; + string aLODFilePath; + string pLODFilePath; + string rLODFilePath; public string[] DumpNetworks(bool endPopup = true) { @@ -47,11 +53,20 @@ public string[] DumpNetworks(bool endPopup = true) target.SetPixels(source.GetPixels()); target.anisoLevel = source.anisoLevel; target.filterMode = source.filterMode; target.wrapMode = source.wrapMode; target.Apply(); - UnityEngine.Object.FindObjectOfType().m_downwardDiffuse = target; bool flippingTextures = NetDumpPanel.instance.GetIfFlippedTextures; Texture2D aprsource = aprmaterial.GetTexture("_APRMap") as Texture2D; + //LOD + var sourceLOD = materialLOD.GetTexture("_MainTex") as Texture2D; + var targetLOD = new Texture2D(sourceLOD.width, sourceLOD.height, TextureFormat.RGBAFloat, true); + targetLOD.SetPixels(sourceLOD.GetPixels()); + targetLOD.anisoLevel = sourceLOD.anisoLevel; targetLOD.filterMode = sourceLOD.filterMode; + targetLOD.wrapMode = sourceLOD.wrapMode; targetLOD.Apply(); + Texture2D aprLODsource = aprmaterialLOD.GetTexture("_APRMap") as Texture2D; + Debug.Log("diffusetextpath:" + diffuseLODTexturePath); + + if (NetDumpPanel.instance.GetDumpMeshOnly && NetDumpPanel.instance.GetDumpDiffuseOnly) { DumpTexture2D(FlipTexture(target, false, flippingTextures), diffuseTexturePath); @@ -69,12 +84,16 @@ public string[] DumpNetworks(bool endPopup = true) } else { - DumpTexture2D(FlipTexture(target, false, flippingTextures), diffuseTexturePath); - DumpAPR(filename, FlipTexture(aprsource, false, flippingTextures), aFilePath, pFilePath, rFilePath, true); + DumpTexture2D(FlipTexture(target, false, false), diffuseTexturePath); //dump meshes DumpMeshToOBJ(roadMesh, meshPath, loadedPrefab); DumpMeshToOBJ(roadMeshLod, lodMeshPath, loadedPrefab); - DumpAPR(filename, FlipTexture(aprsource, false, flippingTextures), aFilePath, pFilePath, rFilePath, true); + DumpAPR(filename, FlipTexture(aprsource, false, false), aFilePath, pFilePath, rFilePath, true); + + //lod need to be flipped for main edit image only to apply to all + DumpTexture2D(FlipTexture(targetLOD, false, true), diffuseLODTexturePath); + DumpAPR(filename, FlipTexture(aprLODsource, false, true), aLODFilePath, pLODFilePath, rLODFilePath, true); + } //for workshop roads display disclaimer! // display message @@ -124,7 +143,7 @@ public string[] DumpNetworks(bool endPopup = true) } } - string[] returnArray = { filesExported.ToString(), exportedFilePaths, diffuseTexturePath.Substring(0, diffuseTexturePath.LastIndexOf("_"))}; + string[] returnArray = { filesExported.ToString(), exportedFilePaths, diffuseTexturePath.Substring(0, diffuseTexturePath.LastIndexOf("_")) }; return returnArray; } @@ -182,7 +201,7 @@ public void FindMesh(string networkName_init) throw new Exception("Elevated Elevation Does Not Exist"); } if (!NetDumpPanel.instance.GetRemoveSuffix) - filename += " Elevated"; + filename += " Elevated"; break; case 2: Console.WriteLine("Bridge"); @@ -192,7 +211,7 @@ public void FindMesh(string networkName_init) throw new Exception("Bridge Elevation Does Not Exist"); } if (!NetDumpPanel.instance.GetRemoveSuffix) - filename += " Bridge"; + filename += " Bridge"; break; case 3: loadedPrefab = AssetEditorRoadUtils.TryGetSlope(loadedPrefab); @@ -201,7 +220,7 @@ public void FindMesh(string networkName_init) throw new Exception("Slope Elevation Does Not Exist"); } if (!NetDumpPanel.instance.GetRemoveSuffix) - filename += " Slope"; + filename += " Slope"; break; case 4: loadedPrefab = AssetEditorRoadUtils.TryGetTunnel(loadedPrefab); @@ -210,7 +229,7 @@ public void FindMesh(string networkName_init) throw new Exception("Tunnel Elevation Does Not Exist"); } if (!NetDumpPanel.instance.GetRemoveSuffix) - filename += " Tunnel"; + filename += " Tunnel"; break; default: throw new System.ArgumentOutOfRangeException("No Elevations Found"); @@ -226,54 +245,71 @@ public void FindMesh(string networkName_init) aFilePath = Path.Combine(importFolder, filename); pFilePath = Path.Combine(importFolder, filename); rFilePath = Path.Combine(importFolder, filename); - + + diffuseLODTexturePath = Path.Combine(importFolder, filename); + aLODFilePath = Path.Combine(importFolder, filename); + pLODFilePath = Path.Combine(importFolder, filename); + rLODFilePath = Path.Combine(importFolder, filename); + if (NetDumpPanel.instance.NetworkType == "Segment") { material = loadedPrefab.m_segments[meshnum].m_segmentMaterial; - diffuseTexturePath += "_d.png"; - meshPath += ".obj"; - lodMeshPath += "_lod.obj"; - aFilePath += "_a.png"; - pFilePath += "_p.png"; - rFilePath += "_r.png"; + FillFilePath(); roadMesh = loadedPrefab.m_segments[meshnum].m_mesh; roadMeshLod = loadedPrefab.m_segments[meshnum].m_lodMesh; aprmaterial = loadedPrefab.m_segments[meshnum].m_segmentMaterial; + //LOD + materialLOD = loadedPrefab.m_segments[meshnum].m_lodMaterial; + aprmaterialLOD = materialLOD; } else if (NetDumpPanel.instance.NetworkType == "Node") { material = loadedPrefab.m_nodes[meshnum].m_nodeMaterial; if (NetDumpPanel.instance.GetRemoveSuffix) { - diffuseTexturePath += "_d.png"; - meshPath += ".obj"; - lodMeshPath += "_lod.obj"; - aFilePath += "_a.png"; - pFilePath += "_p.png"; - rFilePath += "_r.png"; + FillFilePath(); } else { - diffuseTexturePath += "_node_d.png"; - meshPath += "_node.obj"; - lodMeshPath += "_node_lod.obj"; - aFilePath += "_node_a.png"; - pFilePath += "_node_p.png"; - rFilePath += "_node_r.png"; + FillFilePath("node"); } roadMesh = loadedPrefab.m_nodes[meshnum].m_mesh; roadMeshLod = loadedPrefab.m_nodes[meshnum].m_lodMesh; aprmaterial = loadedPrefab.m_nodes[meshnum].m_nodeMaterial; + + //LOD + materialLOD = loadedPrefab.m_nodes[meshnum].m_lodMaterial; + aprmaterialLOD = materialLOD; } else { throw new System.ArgumentException("Invalid network selection type"); } - } + private void FillFilePath(string a = null) + { + string adder = ""; + if (a == "node") + { + adder = a; + } + diffuseTexturePath += adder + "_d.png"; + diffuseLODTexturePath += adder + "_LOD_d.png"; + meshPath += adder + ".obj"; + //lodMeshPath += adder + "_lod.obj"; + lodMeshPath += adder + "_LOD.obj"; + aFilePath += adder + "_a.png"; + pFilePath += adder + "_p.png"; + rFilePath += adder + "_r.png"; + + aLODFilePath += adder + "_LOD_a.png"; + pLODFilePath += adder + "_LOD_p.png"; + rLODFilePath += adder + "_LOD_r.png"; + } + public Vector3[] VerticesFromMesh() { string networkName_init = sim.m_editPrefabInfo.name; @@ -333,10 +369,13 @@ private static void DumpAPR(string assetName, Texture2D aprMap, string ap, strin aprMap.ExtractChannels(a1, p1, r1, null, true, true, true, true, true, false, false); //checks to see if the textures are the default color + + /* disabled for auto lod texture if (IsAlphaDefault(a1.ColorsToTexture(aprMap.width, aprMap.height)) == false) { TextureUtil.DumpTextureToPNG(a1.ColorsToTexture(aprMap.width, aprMap.height), ap); } + if (IsPavementOrRoadDefault(p1.ColorsToTexture(aprMap.width, aprMap.height)) == false) { @@ -346,7 +385,11 @@ private static void DumpAPR(string assetName, Texture2D aprMap, string ap, strin { TextureUtil.DumpTextureToPNG(r1.ColorsToTexture(aprMap.width, aprMap.height), rp); } + */ + TextureUtil.DumpTextureToPNG(a1.ColorsToTexture(aprMap.width, aprMap.height), ap); + TextureUtil.DumpTextureToPNG(p1.ColorsToTexture(aprMap.width, aprMap.height), pp); + TextureUtil.DumpTextureToPNG(r1.ColorsToTexture(aprMap.width, aprMap.height), rp); } else { @@ -416,7 +459,7 @@ public void DumpMeshToOBJ(Mesh mesh, string fileName, NetInfo loadedPb, bool isD File.Delete(fileName); } - // Debug.Log("dumpobj" + filename); + // Debug.Log("dumpobj" + filename); try { // copy the relevant data to the temporary mesh @@ -433,21 +476,21 @@ public void DumpMeshToOBJ(Mesh mesh, string fileName, NetInfo loadedPb, bool isD name = mesh.name //name = mesh.name.Split('_')[0] //removes extra _0 at end of displayed name }; meshToDump.RecalculateBounds(); - + if (NetDumpPanel.instance.enableMeshResize.isChecked) { newvertices = meshToDump.vertices; //get vertices for other method float[] enteredVals = NetDumpPanel.instance.enteredMeshPoints(); float[] newVertsX = new float[newvertices.Length]; float[] newVertsY = new float[newvertices.Length]; - for (int a = 0; a("Continue"); + //m_ContinueButton.SimulateClick(); } }; diff --git a/RoadDumpTools/lib/DumpUtil.cs b/RoadDumpTools/lib/DumpUtil.cs index 328c1a8..bb65d5f 100644 --- a/RoadDumpTools/lib/DumpUtil.cs +++ b/RoadDumpTools/lib/DumpUtil.cs @@ -77,7 +77,7 @@ public static void DumpMeshToOBJ(Mesh mesh, string fileName) } } - private static void DumpMainTex(string assetName, Texture2D mainTex, bool extract = true) + public static void DumpMainTex(string assetName, Texture2D mainTex, bool extract = true) { if (mainTex == null) { @@ -97,7 +97,7 @@ private static void DumpMainTex(string assetName, Texture2D mainTex, bool extrac } } - private static void DumpACI(string assetName, Texture2D aciMap, bool extract = true) + public static void DumpACI(string assetName, Texture2D aciMap, bool extract = true) { if (aciMap == null) { @@ -167,7 +167,7 @@ private static void DumpXYCA(string assetName, Texture2D xycaMap, bool extract = } } - private static void DumpAPR(string assetName, Texture2D aprMap, bool extract = true) + public static void DumpAPR(string assetName, Texture2D aprMap, bool extract = true) { if (aprMap == null) { From a8525f55af348aed755e51cc714620974656dc00 Mon Sep 17 00:00:00 2001 From: Cgameworld <49973689+Cgameworld@users.noreply.github.com> Date: Sat, 25 Apr 2020 14:09:07 -0700 Subject: [PATCH 2/2] part2 --- RoadDumpTools/NetDumpPanel.cs | 7 ++++--- RoadDumpTools/ThreadingExt.cs | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/RoadDumpTools/NetDumpPanel.cs b/RoadDumpTools/NetDumpPanel.cs index c08864f..fb13ccd 100644 --- a/RoadDumpTools/NetDumpPanel.cs +++ b/RoadDumpTools/NetDumpPanel.cs @@ -757,7 +757,7 @@ public override void Start() dumpNet.tooltip = "Dumps the network"; lodGen = UIUtils.CreateButton(bottomButtons); - lodGen.text = "Make _lod.png Files"; + lodGen.text = "rebuild LOD?"; lodGen.textScale = 1f; lodGen.relativePosition = new Vector2(40, 40); lodGen.width = 200; @@ -767,9 +767,10 @@ public override void Start() { if (isVisible) { - LodImageGenerator lodgen = new LodImageGenerator(); + //LodImageGenerator lodgen = new LodImageGenerator(); //string filepath = "C:\\Users\\Cam\\AppData\\Local\\Colossal Order\\Cities_Skylines\\Addons\\Import\\test11_d.png"; - lodgen.GenerateLodImages(lodFilePath); + //lodgen.GenerateLodImages(lodFilePath); + NetManager.instance.RebuildLods(); } }; diff --git a/RoadDumpTools/ThreadingExt.cs b/RoadDumpTools/ThreadingExt.cs index c2e7ffb..4a5c719 100644 --- a/RoadDumpTools/ThreadingExt.cs +++ b/RoadDumpTools/ThreadingExt.cs @@ -20,6 +20,7 @@ public override void OnLevelLoaded(LoadMode mode) GameObject.FindObjectOfType().eventEditPrefabChanged += (info) => { + Debug.Log("eventeditprefabchanged! " + info); if (info.GetType().ToString() == "NetInfo") { NetDumpPanel.instance.Show();