Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lod fix #1

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 76 additions & 33 deletions RoadDumpTools/DumpProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class DumpProcessing
string filename;
Material material;
Material aprmaterial;
Material materialLOD;
Material aprmaterialLOD;
Mesh roadMesh;
Mesh roadMeshLod;
int meshnum;
Expand All @@ -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)
{
Expand All @@ -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<NetProperties>().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);
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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
Expand All @@ -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<newvertices.Length; a++)
for (int a = 0; a < newvertices.Length; a++)
{
newVertsX[a] = newvertices[a].x;
for (int b = 0; b < enteredVals.Length; b = b + 2)
{
if (Mathf.Approximately(newVertsX[a], enteredVals[b]))
{
newvertices[a].x = enteredVals[b+1];
newvertices[a].x = enteredVals[b + 1];
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions RoadDumpTools/NetDumpPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class NetDumpPanel : UIPanel
private UIPanel roadExtrasButtons;
private int exportRoadExtrasOffset;
private UIButton dumpLaneArrows;
private UIButton m_ContinueButton;

public static NetDumpPanel instance
{
Expand Down Expand Up @@ -756,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;
Expand All @@ -766,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();
}
};

Expand All @@ -793,6 +795,9 @@ public override void Start()
dumpedFiles += dumpProcess.DumpNetworks()[1] + "\n";
lodFilePath = dumpProcess.DumpNetworks()[2];
dumpedTotal.text = "Total Dumped Items: (" + dumpedSessionItems.ToString() + ")";

//m_ContinueButton = Find<UIButton>("Continue");
//m_ContinueButton.SimulateClick();
}
};

Expand Down
1 change: 1 addition & 0 deletions RoadDumpTools/ThreadingExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public override void OnLevelLoaded(LoadMode mode)

GameObject.FindObjectOfType<ToolController>().eventEditPrefabChanged += (info) =>
{
Debug.Log("eventeditprefabchanged! " + info);
if (info.GetType().ToString() == "NetInfo")
{
NetDumpPanel.instance.Show();
Expand Down
6 changes: 3 additions & 3 deletions RoadDumpTools/lib/DumpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down