Skip to content

Commit

Permalink
Do full dump from service panels
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodypenguin committed Jul 7, 2019
1 parent a17af43 commit 1a535ad
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 124 deletions.
108 changes: 9 additions & 99 deletions Debugger/Explorer/GUIButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private static void SetupButtonsForPrefab(PrefabInfo prefabInfo)
SetupPlopButton(prefabInfo);
SetupMeshPreviewButtons(buildingInfo.name, buildingInfo.m_mesh, buildingInfo.m_material, buildingInfo.m_lodMesh, buildingInfo.m_lodMaterial);
SetupBuildingFullDumpButton(buildingInfo.name, buildingInfo.m_mesh, buildingInfo.m_material, buildingInfo.m_lodMesh, buildingInfo.m_lodMaterial,
buildingInfo.m_subMeshes);
buildingInfo.m_subMeshes, buildingInfo.m_subBuildings);
break;

case PropInfo propInfo:
Expand All @@ -155,51 +155,20 @@ private static void SetupButtonsForPrefab(PrefabInfo prefabInfo)
}
}

private static void SetupBuildingFullDumpButton(string prefabName,
private static void SetupBuildingFullDumpButton(string assetName,
Mesh mesh, Material material,
Mesh lodMesh, Material lodMaterial,
BuildingInfo.MeshInfo[] subMeshes)
BuildingInfo.MeshInfo[] subMeshes,
BuildingInfo.SubInfo[] subInfos)
{
if (!GUILayout.Button("Full dump"))
{
return;
}

if (mesh != null)
{
DumpUtil.DumpMeshAndTextures(prefabName, mesh, material);
}

if (lodMesh != null)
{
DumpUtil.DumpMeshAndTextures(prefabName + "_lod", lodMesh, lodMaterial);
}

if (subMeshes == null)
{
return;
}
for (var i = 0; i < subMeshes.Length; i++)
{
var subInfo = subMeshes[i]?.m_subInfo;
if (subInfo == null)
{
continue;
}
if (subInfo.m_mesh != null)
{
DumpUtil.DumpMeshAndTextures($"{prefabName}_sub_mesh_{i}", subInfo.m_mesh, subInfo.m_material);
}

if (subInfo.m_lodMesh != null)
{
DumpUtil.DumpMeshAndTextures($"{prefabName}_sub_mesh_{i}_lod", subInfo.m_lodMesh, subInfo.m_lodMaterial);
}
}

AssetDumpUtil.DumpBuilding(assetName, mesh, material, lodMesh, lodMaterial, subMeshes);
}

private static void SetupVehicleFullDumpButton(string prefabName,
private static void SetupVehicleFullDumpButton(string assetName,
Mesh mesh, Material material,
Mesh lodMesh, Material lodMaterial,
VehicleInfo.MeshInfo[] subMeshes)
Expand All @@ -208,75 +177,16 @@ private static void SetupVehicleFullDumpButton(string prefabName,
{
return;
}

if (mesh != null)
{
DumpUtil.DumpMeshAndTextures(prefabName, mesh, material);
}

if (lodMesh != null)
{
DumpUtil.DumpMeshAndTextures(prefabName + "_lod", lodMesh, lodMaterial);
}

if (subMeshes == null)
{
return;
}
for (var i = 0; i < subMeshes.Length; i++)
{
var subInfo = subMeshes[i]?.m_subInfo;
if (subInfo == null)
{
continue;
}
if (subInfo.m_mesh != null)
{
DumpUtil.DumpMeshAndTextures($"{prefabName}_sub_mesh_{i}", subInfo.m_mesh, subInfo.m_material);
}

if (subInfo.m_lodMesh != null)
{
DumpUtil.DumpMeshAndTextures($"{prefabName}_sub_mesh_{i}_lod", subInfo.m_lodMesh, subInfo.m_lodMaterial);
}
}

AssetDumpUtil.DumpVehicle(assetName, mesh, material, lodMesh, lodMaterial, subMeshes);
}

private static void SetupNetworkFullDumpButton(string netInfoName, NetInfo.Segment[] segments, NetInfo.Node[] nodes)
private static void SetupNetworkFullDumpButton(string assetName, NetInfo.Segment[] segments, NetInfo.Node[] nodes)
{
if (!GUILayout.Button("Full dump"))
{
return;
}
if (segments != null)
{
for (var index = 0; index < segments.Length; index++)
{
var segment = segments[index];
if (segment == null)
{
continue;
}
DumpUtil.DumpMeshAndTextures($"{netInfoName}_segment_{index}", segment.m_mesh,
segment.m_material);
DumpUtil.DumpMeshAndTextures($"{netInfoName}_segment_{index}_lod", segment.m_lodMesh,
segment.m_lodMaterial);
}
}
if (nodes != null)
{
for (var index = 0; index < nodes.Length; index++)
{
var node = nodes[index];
if (node == null)
{
continue;
}
DumpUtil.DumpMeshAndTextures($"{netInfoName}_node_{index}", node.m_mesh, node.m_material);
DumpUtil.DumpMeshAndTextures($"{netInfoName}_node_{index}_lod", node.m_lodMesh, node.m_lodMaterial);
}
}
AssetDumpUtil.DumpNetwork(assetName, segments, nodes);
}

private static void SetupMeshPreviewButtons(string name, Mesh mesh, Material material, Mesh lodMesh, Material lodMaterial)
Expand Down
30 changes: 23 additions & 7 deletions Debugger/GamePanels/GamePanelExtension.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using ColossalFramework.IO;
using ColossalFramework.UI;
using ModTools.Explorer;
using ModTools.Utils;
using UnityEngine;
using static System.IO.Path;

namespace ModTools.GamePanels
{
Expand Down Expand Up @@ -165,15 +168,26 @@ private static void DumpBuilding(InstanceID instanceId)
var buildingInfo = BuildingManager.instance.m_buildings.m_buffer[buildingId].Info;
if (buildingInfo != null)
{
DumpUtil.DumpAsset(
var assetName = AssetDumpUtil.DumpBuilding(
buildingInfo.name,
buildingInfo.m_mesh,
buildingInfo.m_material,
buildingInfo.m_lodMesh,
buildingInfo.m_lodMaterial);
buildingInfo.m_lodMaterial,
buildingInfo.m_subMeshes);
ShowAssetDumpModal(assetName);
}
}

private static void ShowAssetDumpModal(string assetName)
{
var path = Combine(DataLocation.addonsPath, "Import");
UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage(
"Asset dump completed",
$"Asset \"{assetName}\" was successfully dumped to:\n{path}",
false);
}

private static void DumpVehicle(InstanceID instanceId)
{
var vehicleId = instanceId.Vehicle;
Expand All @@ -194,12 +208,14 @@ private static void DumpVehicle(InstanceID instanceId)

if (vehicleInfo != null)
{
DumpUtil.DumpAsset(
var assetName = AssetDumpUtil.DumpVehicle(
vehicleInfo.name,
vehicleInfo.m_mesh,
vehicleInfo.m_material,
vehicleInfo.m_lodMesh,
vehicleInfo.m_lodMaterial);
vehicleInfo.m_lodMaterial,
vehicleInfo.m_subMeshes);
ShowAssetDumpModal(assetName);
}
}

Expand Down Expand Up @@ -238,7 +254,7 @@ private void CreateBuildingPanel<T>()
var name = "(Library) " + typeof(T).Name;
var buttons = new Dictionary<string, Action<InstanceID>>
{
["Dump asset"] = DumpBuilding,
["Dump asset (without sub-buildings)"] = DumpBuilding,
};

var buildingPanel = ButtonsInfoPanelExtension<T>.Create(name, GetBuildingAssetName, ShowBuilding, buttons);
Expand All @@ -251,7 +267,7 @@ private void CreateVehiclePanel<T>()
var name = "(Library) " + typeof(T).Name;
var buttons = new Dictionary<string, Action<InstanceID>>
{
["Dump asset"] = DumpVehicle,
["Dump asset (without trailers)"] = DumpVehicle,
};

var vehiclePanel = ButtonsInfoPanelExtension<T>.Create(name, GetVehicleAssetName, ShowVehicle, buttons);
Expand All @@ -265,7 +281,7 @@ private void CreateCitizenPanel<T>()
var buttons = new Dictionary<string, Action<InstanceID>>
{
["Show instance in Scene Explorer"] = ShowCitizenInstance,
["Show unit in Scene Explorer"] = ShowCitizenUnit,
["Show unit in Scene Explorer"] = ShowCitizenUnit
};

var vehiclePanel = ButtonsInfoPanelExtension<T>.Create(name, GetCitizenAssetName, ShowCitizen, buttons);
Expand Down
1 change: 1 addition & 0 deletions Debugger/ModTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="UI\GUIStackTrace.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Scripting\ScriptEditorFile.cs" />
<Compile Include="Utils\AssetDumpUtil.cs" />
<Compile Include="Utils\ColorUtil.cs" />
<Compile Include="ModConfiguration.cs" />
<Compile Include="Console\CustomConsole.cs" />
Expand Down
156 changes: 156 additions & 0 deletions Debugger/Utils/AssetDumpUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
using System.IO;
using ColossalFramework.IO;
using ColossalFramework.UI;
using UnityEngine;

namespace ModTools.Utils
{
internal static class AssetDumpUtil
{
public static string DumpGenericAsset(
string assetName,
Mesh mesh,
Material material,
Mesh lodMesh = null,
Material lodMaterial = null)
{
assetName = assetName.Replace("_Data", string.Empty);
Logger.Warning($"Dumping asset \"{assetName}\"...");

DumpUtil.DumpMeshAndTextures(assetName, mesh, material);
DumpUtil.DumpMeshAndTextures($"{assetName}_lod", lodMesh, lodMaterial);
Logger.Warning($"Successfully dumped asset \"{assetName}\"");
return assetName;
}

public static string DumpBuilding(string assetName,
Mesh mesh,
Material material,
Mesh lodMesh,
Material lodMaterial,
BuildingInfo.MeshInfo[] subMeshes)
{
assetName = assetName.Replace("_Data", string.Empty);
Logger.Warning($"Dumping asset \"{assetName}\"...");
if (mesh != null)
{
DumpUtil.DumpMeshAndTextures(assetName, mesh, material);
}

if (lodMesh != null)
{
DumpUtil.DumpMeshAndTextures(assetName + "_lod", lodMesh, lodMaterial);
}

if (subMeshes != null)
{
for (var i = 0; i < subMeshes.Length; i++)
{
var subInfo = subMeshes[i]?.m_subInfo;
if (subInfo == null)
{
continue;
}

if (subInfo.m_mesh != null)
{
DumpUtil.DumpMeshAndTextures($"{assetName}_sub_mesh_{i}", subInfo.m_mesh, subInfo.m_material);
}

if (subInfo.m_lodMesh != null)
{
DumpUtil.DumpMeshAndTextures($"{assetName}_sub_mesh_{i}_lod", subInfo.m_lodMesh,
subInfo.m_lodMaterial);
}
}
}
return assetName;
}

public static string DumpVehicle(string assetName,
Mesh mesh, Material material,
Mesh lodMesh, Material lodMaterial,
VehicleInfo.MeshInfo[] subMeshes)
{
assetName = assetName.Replace("_Data", string.Empty);
Logger.Warning($"Dumping asset \"{assetName}\"...");

if (mesh != null)
{
DumpUtil.DumpMeshAndTextures(assetName, mesh, material);
}

if (lodMesh != null)
{
DumpUtil.DumpMeshAndTextures(assetName + "_lod", lodMesh, lodMaterial);
}

if (subMeshes != null)
{
for (var i = 0; i < subMeshes.Length; i++)
{
var subInfo = subMeshes[i]?.m_subInfo;
if (subInfo == null)
{
continue;
}

if (subInfo.m_mesh != null)
{
DumpUtil.DumpMeshAndTextures($"{assetName}_sub_mesh_{i}", subInfo.m_mesh,
subInfo.m_material);
}

if (subInfo.m_lodMesh != null)
{
DumpUtil.DumpMeshAndTextures($"{assetName}_sub_mesh_{i}_lod", subInfo.m_lodMesh,
subInfo.m_lodMaterial);
}
}
}

return assetName;
}

public static string DumpNetwork(string assetName, NetInfo.Segment[] segments, NetInfo.Node[] nodes)
{
assetName = assetName.Replace("_Data", string.Empty);
Logger.Warning($"Dumping asset \"{assetName}\"...");

if (segments != null)
{
for (var index = 0; index < segments.Length; index++)
{
var segment = segments[index];
if (segment == null)
{
continue;
}

DumpUtil.DumpMeshAndTextures($"{assetName}_segment_{index}", segment.m_mesh,
segment.m_material);
DumpUtil.DumpMeshAndTextures($"{assetName}_segment_{index}_lod", segment.m_lodMesh,
segment.m_lodMaterial);
}
}

if (nodes != null)
{
for (var index = 0; index < nodes.Length; index++)
{
var node = nodes[index];
if (node == null)
{
continue;
}

DumpUtil.DumpMeshAndTextures($"{assetName}_node_{index}", node.m_mesh, node.m_material);
DumpUtil.DumpMeshAndTextures($"{assetName}_node_{index}_lod", node.m_lodMesh,
node.m_lodMaterial);
}
}

return assetName;
}
}
}
Loading

0 comments on commit 1a535ad

Please sign in to comment.