From 1a535adf1ffff43292e878c189ebb2ba2a3d14fe Mon Sep 17 00:00:00 2001 From: Bloody Penguin Date: Sun, 7 Jul 2019 11:39:30 +0200 Subject: [PATCH] Do full dump from service panels --- Debugger/Explorer/GUIButtons.cs | 108 ++------------- Debugger/GamePanels/GamePanelExtension.cs | 30 ++++- Debugger/ModTools.csproj | 1 + Debugger/Utils/AssetDumpUtil.cs | 156 ++++++++++++++++++++++ Debugger/Utils/DumpUtil.cs | 19 +-- 5 files changed, 190 insertions(+), 124 deletions(-) create mode 100644 Debugger/Utils/AssetDumpUtil.cs diff --git a/Debugger/Explorer/GUIButtons.cs b/Debugger/Explorer/GUIButtons.cs index b021fc4..c3ad254 100644 --- a/Debugger/Explorer/GUIButtons.cs +++ b/Debugger/Explorer/GUIButtons.cs @@ -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: @@ -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) @@ -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) diff --git a/Debugger/GamePanels/GamePanelExtension.cs b/Debugger/GamePanels/GamePanelExtension.cs index f533a36..47a3caf 100644 --- a/Debugger/GamePanels/GamePanelExtension.cs +++ b/Debugger/GamePanels/GamePanelExtension.cs @@ -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 { @@ -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").SetMessage( + "Asset dump completed", + $"Asset \"{assetName}\" was successfully dumped to:\n{path}", + false); + } + private static void DumpVehicle(InstanceID instanceId) { var vehicleId = instanceId.Vehicle; @@ -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); } } @@ -238,7 +254,7 @@ private void CreateBuildingPanel() var name = "(Library) " + typeof(T).Name; var buttons = new Dictionary> { - ["Dump asset"] = DumpBuilding, + ["Dump asset (without sub-buildings)"] = DumpBuilding, }; var buildingPanel = ButtonsInfoPanelExtension.Create(name, GetBuildingAssetName, ShowBuilding, buttons); @@ -251,7 +267,7 @@ private void CreateVehiclePanel() var name = "(Library) " + typeof(T).Name; var buttons = new Dictionary> { - ["Dump asset"] = DumpVehicle, + ["Dump asset (without trailers)"] = DumpVehicle, }; var vehiclePanel = ButtonsInfoPanelExtension.Create(name, GetVehicleAssetName, ShowVehicle, buttons); @@ -265,7 +281,7 @@ private void CreateCitizenPanel() var buttons = new Dictionary> { ["Show instance in Scene Explorer"] = ShowCitizenInstance, - ["Show unit in Scene Explorer"] = ShowCitizenUnit, + ["Show unit in Scene Explorer"] = ShowCitizenUnit }; var vehiclePanel = ButtonsInfoPanelExtension.Create(name, GetCitizenAssetName, ShowCitizen, buttons); diff --git a/Debugger/ModTools.csproj b/Debugger/ModTools.csproj index 80bdb98..de8162d 100644 --- a/Debugger/ModTools.csproj +++ b/Debugger/ModTools.csproj @@ -73,6 +73,7 @@ + diff --git a/Debugger/Utils/AssetDumpUtil.cs b/Debugger/Utils/AssetDumpUtil.cs new file mode 100644 index 0000000..6577535 --- /dev/null +++ b/Debugger/Utils/AssetDumpUtil.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/Debugger/Utils/DumpUtil.cs b/Debugger/Utils/DumpUtil.cs index c5f3ce6..46170db 100644 --- a/Debugger/Utils/DumpUtil.cs +++ b/Debugger/Utils/DumpUtil.cs @@ -9,24 +9,7 @@ namespace ModTools.Utils { internal static class DumpUtil { - public static void DumpAsset( - string assetName, - Mesh mesh, - Material material, - Mesh lodMesh = null, - Material lodMaterial = null) - { - assetName = assetName.Replace("_Data", string.Empty); - Logger.Warning($"Dumping asset \"{assetName}\"..."); - DumpMeshAndTextures(assetName, mesh, material); - DumpMeshAndTextures($"{assetName}_lod", lodMesh, lodMaterial); - Logger.Warning($"Successfully dumped asset \"{assetName}\""); - var path = Path.Combine(DataLocation.addonsPath, "Import"); - UIView.library.ShowModal("ExceptionPanel").SetMessage( - "Asset dump completed", - $"Asset \"{assetName}\" was successfully dumped to:\n{path}", - false); - } + public static void DumpMeshAndTextures(string assetName, Mesh mesh, Material material = null) {