Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dalkia committed Feb 26, 2024
1 parent ae8a698 commit edb0d91
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 50 deletions.
56 changes: 26 additions & 30 deletions DCL_PiXYZ/PXZEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,7 +46,7 @@ private static async Task RunLODBuilder(string[] args)

List<string> roadCoordinates = LoadRoads();
CreateDirectories(sceneConversionInfo);
FrameworkInitialization(pathHandler.ManifestProjectDirectory);
FrameworkInitialization(pathHandler.ManifestProjectDirectory, isDebug);

foreach (string currentScene in sceneConversionInfo.ScenesToAnalyze)
{
Expand All @@ -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)
{
Expand All @@ -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)
Expand All @@ -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}",
Expand Down Expand Up @@ -153,17 +162,6 @@ private static async Task<bool> 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
Expand Down Expand Up @@ -206,11 +204,10 @@ private static async Task<bool> 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);
Expand All @@ -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)
Expand All @@ -257,15 +254,14 @@ private static List<string> LoadRoads()
string filePath = Path.Combine(Directory.GetCurrentDirectory(), "RoadCoordinates.json");
return JsonConvert.DeserializeObject<List<string>>(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()
Expand Down
12 changes: 5 additions & 7 deletions DCL_PiXYZ/PXZParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace DCL_PiXYZ
{
public struct PXZParams
{
public string SceneHash { get; set; }
public string ScenePointer { get; set; }
public Dictionary<string, string> SceneContent { get; set; }
public int ParcelAmount { get; set; }
public double DecimationValue { get; set; }
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion DCL_PiXYZ/PiXYZWorflow/PXZBeginCleanMaterials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ uint copyMaterial
}
}*/

Console.WriteLine("END PXZ CLEAN MATERIALS");
}
}
}
1 change: 0 additions & 1 deletion DCL_PiXYZ/PiXYZWorflow/PXZDecimateAndBake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
1 change: 0 additions & 1 deletion DCL_PiXYZ/PiXYZWorflow/PXZDecimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion DCL_PiXYZ/PiXYZWorflow/PXZDeleteByName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
5 changes: 2 additions & 3 deletions DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>() { ".fbx", ".glb" };
path = pathHandler.OutputPath;
filename = $"{pxzParams.SceneHash}_{pxzParams.LodLevel}";
filename = $"{sceneConversionInfo.SceneImporter.GetSceneHash()}_{pxzParams.LodLevel}";
lodLevel = pxzParams.LodLevel;
}

Expand Down Expand Up @@ -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 ");
}
}
}
2 changes: 0 additions & 2 deletions DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion DCL_PiXYZ/PiXYZWorflow/PXZRepairMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
2 changes: 0 additions & 2 deletions DCL_PiXYZ/SceneImporter/SceneImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public async Task DownloadSceneDefinition()
SetResult(sceneDefinitions[0].id);
}
}
Console.WriteLine("END SCENE DEFINITION DOWNLOAD");
}
catch (Exception e)
{
Expand Down Expand Up @@ -103,7 +102,6 @@ public async Task<bool> DownloadAllContent(SceneConversionPathHandler pathHandle
return false;
}
}
Console.WriteLine("END FILE CONTENT DOWNLOAD");
return true;
}

Expand Down
1 change: 0 additions & 1 deletion DCL_PiXYZ/SceneRepositioner/SceneRepositioner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public async Task<List<PXZModel>> SetupSceneInPiXYZ()
foreach (KeyValuePair<int, DCLRendereableEntity> dclRendereableEntity in renderableEntitiesDictionary)
models.Add(dclRendereableEntity.Value.PositionAndInstantiteMesh(sceneContent, renderableEntitiesDictionary, _pathHandler, lodLevel));

Console.WriteLine("END REPOSITIONING");

return models;
}
Expand Down

0 comments on commit edb0d91

Please sign in to comment.