From edb0d91f6fc899a7e11d875d4264067b6bdc31fc Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Mon, 26 Feb 2024 10:33:06 -0300 Subject: [PATCH] Some cleanup --- DCL_PiXYZ/PXZEntryPoint.cs | 56 +++++++++---------- DCL_PiXYZ/PXZParams.cs | 12 ++-- .../PiXYZWorflow/PXZBeginCleanMaterials.cs | 1 - DCL_PiXYZ/PiXYZWorflow/PXZDecimateAndBake.cs | 1 - DCL_PiXYZ/PiXYZWorflow/PXZDecimator.cs | 1 - DCL_PiXYZ/PiXYZWorflow/PXZDeleteByName.cs | 1 - DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs | 5 +- DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs | 2 - DCL_PiXYZ/PiXYZWorflow/PXZRepairMesh.cs | 1 - DCL_PiXYZ/SceneImporter/SceneImporter.cs | 2 - .../SceneRepositioner/SceneRepositioner.cs | 1 - 11 files changed, 33 insertions(+), 50 deletions(-) diff --git a/DCL_PiXYZ/PXZEntryPoint.cs b/DCL_PiXYZ/PXZEntryPoint.cs index 390ebae1..9f82458c 100644 --- a/DCL_PiXYZ/PXZEntryPoint.cs +++ b/DCL_PiXYZ/PXZEntryPoint.cs @@ -33,7 +33,7 @@ private static async Task RunLODBuilder(string[] args) defaultScene = args[1]; defaultOutputPath = args[2]; defaultSceneLodManifestDirectory = args[3]; - isDebug = false; + bool.TryParse(args[4], out isDebug); } //Conversion type can be single or bulk @@ -46,7 +46,7 @@ private static async Task RunLODBuilder(string[] args) List roadCoordinates = LoadRoads(); CreateDirectories(sceneConversionInfo); - FrameworkInitialization(pathHandler.ManifestProjectDirectory); + FrameworkInitialization(pathHandler.ManifestProjectDirectory, isDebug); foreach (string currentScene in sceneConversionInfo.ScenesToAnalyze) { @@ -67,17 +67,14 @@ private static async Task RunLODBuilder(string[] args) foreach (string pointer in sceneConversionInfo.SceneImporter.GetCurrentScenePointersList()) sceneConversionInfo.AnalyzedScenes.Add(pointer); - if (CheckFaillingDebugScenes(sceneConversionInfo.SceneImporter.GetCurrentScenePointersList(), currentScene)) continue; - if (!await ManifestGeneratedSuccesfully(sceneConversionInfo, pathHandler, currentScene)) continue; if (!await sceneConversionInfo.SceneImporter.DownloadAllContent(pathHandler)) continue; - Console.WriteLine("Begin scene conversion for " + currentScene); + Console.WriteLine("BEGIN SCENE CONVERSION FOR " + currentScene); var pxzParams = new PXZParams { - DecimationType = sceneConversionInfo.DecimationType, ParcelAmount = sceneConversionInfo.SceneImporter.GetCurrentScenePointersList().Length, SceneContent = sceneConversionInfo.SceneImporter.sceneContent, SceneHash = sceneConversionInfo.SceneImporter.GetSceneHash(), - ScenePointer = sceneConversionInfo.SceneImporter.GetSceneBasePointer() + DecimationType = sceneConversionInfo.DecimationType, ParcelAmount = sceneConversionInfo.SceneImporter.GetCurrentScenePointersList().Length, SceneContent = sceneConversionInfo.SceneImporter.sceneContent }; foreach (var decimationValue in sceneConversionInfo.DecimationToAnalyze) { @@ -87,8 +84,21 @@ private static async Task RunLODBuilder(string[] args) pxzParams.LodLevel += 1; } GC.Collect(); - Console.WriteLine("END SCENE CONVERSION FOR SCENE " + currentScene); + Console.WriteLine("END SCENE CONVERSION FOR " + currentScene); } + + DoManifestCleanup(isDebug, pathHandler); + } + + private static void DoManifestCleanup(bool isDebug, SceneConversionPathHandler pathHandler) + { + if (isDebug) + return; + + var dir = new DirectoryInfo(pathHandler.ManifestOutputJsonDirectory); + + foreach (var fi in dir.GetFiles()) + fi.Delete(); } private static async Task DoConversion(PXZParams pxzParams, SceneConversionInfo sceneConversionInfo, string scene, SceneConversionPathHandler pathHandler) @@ -100,8 +110,7 @@ private static async Task DoConversion(PXZParams pxzParams, SceneConversionInfo //Check if they were converted stopwatch.Restart(); Console.WriteLine($"BEGIN CONVERTING {scene} WITH {pxzParams.DecimationValue}"); - await ConvertScene(pxzParams, pathHandler); - Console.WriteLine($"END CONVERTING {scene} WITH {pxzParams.DecimationValue}"); + await ConvertScene(pxzParams, pathHandler, sceneConversionInfo); stopwatch.Stop(); string elapsedTime = string.Format("{0:00}:{1:00}:{2:00}", @@ -153,17 +162,6 @@ private static async Task SceneDefinitionDownloadSuccesfully(SceneConversi return true; } - private static bool CheckFaillingDebugScenes(string[] currentPointersList, string scene) - { - if (currentPointersList[0].Equals("-15,-39") || currentPointersList[0].Equals("-27,-17") || currentPointersList[0].Equals("-75,-9") || currentPointersList[0].Equals("-5,36") || currentPointersList[0].Equals("16,34")) - { - Console.WriteLine($"Skipping scene {scene} because it was causing an exit without exception"); - return true; - } - - return false; - } - private static bool CheckEmptyScene(string[] currentPointersList, string scene) { //Check empty scenes @@ -206,11 +204,10 @@ private static async Task GenerateManifest(string sceneType, string sceneV } } - Console.WriteLine($"END MANIFEST GENERATION FOR SCENE {sceneValue}"); return true; // Return true as default, indicating success if no unignorable error was found. } - private static async Task ConvertScene(PXZParams pxzParams, SceneConversionPathHandler pathHandler) + private static async Task ConvertScene(PXZParams pxzParams, SceneConversionPathHandler pathHandler, SceneConversionInfo sceneConversionInfo) { SceneRepositioner.SceneRepositioner sceneRepositioner = new SceneRepositioner.SceneRepositioner(pathHandler.ManifestOutputJsonFile, pxzParams.SceneContent, pxz, pathHandler, pxzParams.LodLevel); @@ -225,12 +222,12 @@ private static async Task ConvertScene(PXZParams pxzParams, SceneConversionPathH if (pxzParams.LodLevel != 0) { modifiers.Add(new PXZDeleteByName(".*collider.*")); - modifiers.Add(new PXZDecimator(pxzParams.ScenePointer, pxzParams.DecimationType, + modifiers.Add(new PXZDecimator(sceneConversionInfo.SceneImporter.GetSceneBasePointer(), pxzParams.DecimationType, pxzParams.DecimationValue, pxzParams.ParcelAmount, pathHandler)); modifiers.Add(new PXZMergeMeshes(pxzParams.LodLevel)); } - modifiers.Add(new PXZExporter(pxzParams, pathHandler)); + modifiers.Add(new PXZExporter(pxzParams, pathHandler, sceneConversionInfo)); PXZStopwatch stopwatch = new PXZStopwatch(); foreach (var pxzModifier in modifiers) @@ -257,15 +254,14 @@ private static List LoadRoads() string filePath = Path.Combine(Directory.GetCurrentDirectory(), "RoadCoordinates.json"); return JsonConvert.DeserializeObject>(File.ReadAllText(filePath)); } - - private static void FrameworkInitialization(string sceneManifestDirectory) + + private static void FrameworkInitialization(string sceneManifestDirectory, bool isDebug) { Console.WriteLine("INSTALLING AND BUILDING NPM"); - NPMUtils.DoNPMInstall(sceneManifestDirectory); - Console.WriteLine("END INSTALLING AND BUILDING NPM"); + if (!isDebug) + NPMUtils.DoNPMInstall(sceneManifestDirectory); Console.WriteLine("INITIALIZING PIXYZ"); InitializePiXYZ(); - Console.WriteLine("END INITIALIZING PIXYZ"); } private static void InitializePiXYZ() diff --git a/DCL_PiXYZ/PXZParams.cs b/DCL_PiXYZ/PXZParams.cs index ff4c4893..bef8b8b4 100644 --- a/DCL_PiXYZ/PXZParams.cs +++ b/DCL_PiXYZ/PXZParams.cs @@ -8,8 +8,6 @@ namespace DCL_PiXYZ { public struct PXZParams { - public string SceneHash { get; set; } - public string ScenePointer { get; set; } public Dictionary SceneContent { get; set; } public int ParcelAmount { get; set; } public double DecimationValue { get; set; } @@ -95,19 +93,17 @@ public struct SceneConversionPathHandler public string FailGLBImporterFile; public string OutputPath; public string ManifestOutputJsonFile; + public string ManifestOutputJsonDirectory; public string ManifestProjectDirectory; private readonly string DefaultOutputPath; - public bool IsDebug; - public SceneConversionPathHandler(bool isDebug, string defaultOutputPath, string manifestProjectDirectory, string successFile, string failFile, string vertexCountFile, string failGlbImporterFile, string scene) { - IsDebug = isDebug; DefaultOutputPath = defaultOutputPath; ManifestProjectDirectory = manifestProjectDirectory; - if (IsDebug) + if (isDebug) { SuccessFile = Path.Combine(defaultOutputPath, successFile); FailFile = Path.Combine(defaultOutputPath, failFile); @@ -125,12 +121,14 @@ public SceneConversionPathHandler(bool isDebug, string defaultOutputPath, string OutputPath = ""; ManifestOutputJsonFile = ""; + ManifestOutputJsonDirectory = ""; } public void SetOutputPath(SceneImporter sceneSceneImporter) { OutputPath = Path.Combine(DefaultOutputPath, sceneSceneImporter.GetSceneBasePointer()); - ManifestOutputJsonFile = Path.Combine(ManifestProjectDirectory, "output-manifests", sceneSceneImporter.GetSceneHash() + "-lod-manifest.json"); + ManifestOutputJsonDirectory = Path.Combine(ManifestProjectDirectory, "output-manifests"); + ManifestOutputJsonFile = Path.Combine(ManifestOutputJsonDirectory, sceneSceneImporter.GetSceneHash() + "-lod-manifest.json"); Directory.CreateDirectory(DefaultOutputPath); Directory.CreateDirectory(OutputPath); diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZBeginCleanMaterials.cs b/DCL_PiXYZ/PiXYZWorflow/PXZBeginCleanMaterials.cs index bd7c6f49..cb8a8b0a 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZBeginCleanMaterials.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZBeginCleanMaterials.cs @@ -56,7 +56,6 @@ uint copyMaterial } }*/ - Console.WriteLine("END PXZ CLEAN MATERIALS"); } } } \ No newline at end of file diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZDecimateAndBake.cs b/DCL_PiXYZ/PiXYZWorflow/PXZDecimateAndBake.cs index ce6b60c1..6a226f7e 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZDecimateAndBake.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZDecimateAndBake.cs @@ -91,7 +91,6 @@ public async Task ApplyModification(PiXYZAPI pxz) { pxz.Core.SetProperty(occurence, "Name", "DecimateTargetBake " + pxz.Core.GetProperty(occurence, "Id")); }*/ - Console.WriteLine("END PXZ DECIMATE AND BAKE"); } } } \ No newline at end of file diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZDecimator.cs b/DCL_PiXYZ/PiXYZWorflow/PXZDecimator.cs index f381ae7c..affd2305 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZDecimator.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZDecimator.cs @@ -42,7 +42,6 @@ public async Task ApplyModification(PiXYZAPI pxz) pxz.Scene.GetPolygonCount(new OccurrenceList(new uint[] { pxz.Scene.GetRoot() }), true); pxz.Algo.DecimateTarget(new OccurrenceList(new uint[]{pxz.Scene.GetRoot()}), decimate); WriteFinalVertexAmount(pxz.Scene.GetPolygonCount(new OccurrenceList(new uint[] { pxz.Scene.GetRoot() }),true)); - Console.WriteLine("END PXZ MODIFIER DECIMATOR"); } private void WriteFinalVertexAmount(ulong polygonCount) diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZDeleteByName.cs b/DCL_PiXYZ/PiXYZWorflow/PXZDeleteByName.cs index 1fa78ccf..d7dc6d2a 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZDeleteByName.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZDeleteByName.cs @@ -22,7 +22,6 @@ public async Task ApplyModification(PiXYZAPI pxz) OccurrenceList occurenceToDelete = pxz.Scene.FindOccurrencesByProperty("Name", regex); foreach (uint u in occurenceToDelete.list) pxz.Scene.DeleteComponentByType(ComponentType.Part, u); - Console.WriteLine("END PXZ DELETE BY NAME FOR REGEX " + regex); } } } \ No newline at end of file diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs b/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs index 135dc640..cc9aa2ce 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs @@ -18,12 +18,12 @@ public class PXZExporter : IPXZModifier private readonly int lodLevel; private readonly SceneConversionPathHandler pathHandler; - public PXZExporter(PXZParams pxzParams, SceneConversionPathHandler pathHandler) + public PXZExporter(PXZParams pxzParams, SceneConversionPathHandler pathHandler, SceneConversionInfo sceneConversionInfo) { this.pathHandler = pathHandler; extensions = new List() { ".fbx", ".glb" }; path = pathHandler.OutputPath; - filename = $"{pxzParams.SceneHash}_{pxzParams.LodLevel}"; + filename = $"{sceneConversionInfo.SceneImporter.GetSceneHash()}_{pxzParams.LodLevel}"; lodLevel = pxzParams.LodLevel; } @@ -69,7 +69,6 @@ private void DoExportWithExtension(PiXYZAPI pxz, string extension) }), 1); } pxz.IO.ExportScene(Path.Combine(path, $"{filename}{extension}"), pxz.Scene.GetRoot()); - Console.WriteLine("END PXZ EXPORT "); } } } \ No newline at end of file diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs b/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs index 04db3476..1c944a31 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs @@ -53,7 +53,6 @@ public async Task ApplyModification(PiXYZAPI pxz) { Console.WriteLine(e); } - Console.WriteLine("END PXZ MERGE MESHES"); } private void MergeSubMeshes(OccurrenceList listToMerge, bool isOpaque) @@ -103,7 +102,6 @@ private void DoMerge(ulong currentVertexCount, OccurrenceList toMerge, bool isOp uint combineMeshes = pxz.Algo.CombineMeshes(toMerge, bakeOption); pxz.Core.SetProperty(combineMeshes, "Name", $"MERGED MESH {index} {(isOpaque ? "OPAQUE" : "FORCED_TRANSPARENT")}"); - Console.WriteLine("End merging meshes "); Console.WriteLine("Copying Material"); //Apply a copy of the material not to lose the reference diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZRepairMesh.cs b/DCL_PiXYZ/PiXYZWorflow/PXZRepairMesh.cs index 66f99c9e..27546253 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZRepairMesh.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZRepairMesh.cs @@ -24,7 +24,6 @@ public async Task ApplyModification(PiXYZAPI pxz) if (pxzModel.needsRepair) pxz.Algo.RepairMesh(new OccurrenceList(new uint[]{pxzModel.modelOcurrence}), 0.1, true, false); } - Console.WriteLine($"END PXZ MESH REPAIR"); } } } \ No newline at end of file diff --git a/DCL_PiXYZ/SceneImporter/SceneImporter.cs b/DCL_PiXYZ/SceneImporter/SceneImporter.cs index 94f5a27a..aeb8ed36 100644 --- a/DCL_PiXYZ/SceneImporter/SceneImporter.cs +++ b/DCL_PiXYZ/SceneImporter/SceneImporter.cs @@ -62,7 +62,6 @@ public async Task DownloadSceneDefinition() SetResult(sceneDefinitions[0].id); } } - Console.WriteLine("END SCENE DEFINITION DOWNLOAD"); } catch (Exception e) { @@ -103,7 +102,6 @@ public async Task DownloadAllContent(SceneConversionPathHandler pathHandle return false; } } - Console.WriteLine("END FILE CONTENT DOWNLOAD"); return true; } diff --git a/DCL_PiXYZ/SceneRepositioner/SceneRepositioner.cs b/DCL_PiXYZ/SceneRepositioner/SceneRepositioner.cs index 63b7e2b2..5e51d641 100644 --- a/DCL_PiXYZ/SceneRepositioner/SceneRepositioner.cs +++ b/DCL_PiXYZ/SceneRepositioner/SceneRepositioner.cs @@ -51,7 +51,6 @@ public async Task> SetupSceneInPiXYZ() foreach (KeyValuePair dclRendereableEntity in renderableEntitiesDictionary) models.Add(dclRendereableEntity.Value.PositionAndInstantiteMesh(sceneContent, renderableEntitiesDictionary, _pathHandler, lodLevel)); - Console.WriteLine("END REPOSITIONING"); return models; }