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

feat: test case #48

Merged
merged 37 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
edb0d91
Some cleanup
dalkia Feb 26, 2024
558379f
Added test case scenario
dalkia Feb 26, 2024
af97397
Modified test script
dalkia Feb 26, 2024
1f272c5
Fixed indentation
dalkia Feb 26, 2024
804f722
Copying files manually
dalkia Feb 26, 2024
73b6401
Adding license copy
dalkia Feb 26, 2024
b6344da
Changted copy to pwsh
dalkia Feb 26, 2024
4ec682b
Separating copies and debugging
dalkia Feb 26, 2024
3f98bd8
Fixed indentation
dalkia Feb 26, 2024
2573986
Changed ls to powershel
dalkia Feb 26, 2024
1859d38
Removed additional /
dalkia Feb 26, 2024
fd69142
Re-added license key to check export
dalkia Feb 26, 2024
1687cbc
Fixed ouput path for size checking
dalkia Feb 26, 2024
03b9020
Upgraded tolerance for file size
dalkia Feb 26, 2024
376abdc
Corrected log
dalkia Feb 26, 2024
1d73090
Reduced tolerance
dalkia Feb 26, 2024
944f7c6
Increased tolearance to 5KB
dalkia Feb 26, 2024
db08e9c
Write the file size
dalkia Feb 26, 2024
b90816f
Cleaned DCLGLTFMesh
dalkia Feb 26, 2024
fda4e4d
reclean of DCLGLTFMesh.cs
dalkia Feb 26, 2024
911a0de
Increased tolerance
dalkia Feb 26, 2024
cc73148
Added converted scene external file
dalkia Feb 26, 2024
3b6c0e6
Added possibility for outside bulk conversion
dalkia Feb 26, 2024
01a99f7
Added extra parameter in lod conversion test
dalkia Feb 26, 2024
54e6e7b
Better logging description for DCLGLTFMesh
dalkia Feb 28, 2024
7b37f7a
Added case insensitive fix
dalkia Feb 28, 2024
e1aafad
Added remote license
dalkia Feb 29, 2024
af9bbe6
Merge branch 'main' into feat/test-case
dalkia Feb 29, 2024
49ac8d3
removed copy of license file
dalkia Feb 29, 2024
91a8ff0
Add wanted tokens
dalkia Mar 6, 2024
5afc4bd
Setting token via env variable
dalkia Mar 6, 2024
8a114d9
Changed case of env variable name
dalkia Mar 6, 2024
5db41a3
Update test-lod-conversion.yml
dalkia Mar 6, 2024
507ea6c
fix: properly remove license-builder component
aleortega Mar 7, 2024
c269ff2
refactor: trigger test lod conversion only on PRs
aleortega Mar 7, 2024
795b1f3
Update test-lod-conversion.yml
dalkia Mar 7, 2024
19d9e43
fix: docker build by removing unused lic
aleortega Mar 7, 2024
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
83 changes: 83 additions & 0 deletions .github/workflows/test-lod-conversion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Test LOD Conversion

on:
pull_request:

jobs:
build-and-run:
runs-on: windows-2019

steps:
- uses: actions/checkout@v2
with:
lfs: true

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'

- name: Publish with dotnet
run: dotnet publish -c Release -r win10-x64 -o ./publish --self-contained true

- name: Copy manifest builder to publish directory
run: |
Copy-Item -Path "${{ github.workspace }}\DCL_PiXYZ\bin\Release\netcoreapp3.1\win10-x64\scene-lod-entities-manifest-builder" -Destination "${{ github.workspace }}\publish\scene-lod-entities-manifest-builder" -Recurse
shell: pwsh

- name: Copy road coordinates
run: |
Copy-Item -Path "${{ github.workspace }}\DCL_PiXYZ\bin\Release\netcoreapp3.1\win10-x64\RoadCoordinates.json" -Destination "${{ github.workspace }}\publish"
shell: pwsh

- name: Install Vulkan SDK
uses: jakoch/[email protected]
with:
vulkan_version: 1.3.268.0
optional_components: com.lunarg.vulkan.vma
install_runtime: true
cache: true
destination: ${{ github.workspace }}/vulkan-sdt

- name: Move Vulkan DLL to output directory
run: |
mv ./vulkan-sdt/1.3.268.0/runtime/x64/vulkan-1.dll ./publish/
shell: bash

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18.14.2'

- name: Run the application
env:
PIXYZPRODUCTNAME: ${{ secrets.PIXYZPRODUCTNAME }}
PIXYZTOKEN: ${{ secrets.PIXYZTOKEN }}
run: .\publish\DCL_PiXYZ.exe "coords" "5,19" "${{ github.workspace }}\publish\OutputDirectoryPath" "${{ github.workspace }}\publish\scene-lod-entities-manifest-builder" "false" "true"

- name: Check Output Files with Size Tolerance in KB
run: |
$basePath = "${{ github.workspace }}\publish\OutputDirectoryPath\5,19"
$files = @(
"bafkreictrpcnce5eoink3tdtrm74vgbniho7afl6xoi46lk3iag2u7aju4_0.fbx", # Hash output for 5,19
"bafkreictrpcnce5eoink3tdtrm74vgbniho7afl6xoi46lk3iag2u7aju4_1.fbx",
"bafkreictrpcnce5eoink3tdtrm74vgbniho7afl6xoi46lk3iag2u7aju4_2.fbx"
)
$expectedSizesB = @(6210224, 631424, 219776 ) # Expected sizes in bytes
$toleranceB = 3000 # 2 KB tolerance

foreach ($i in 0..2) {
$filePath = Join-Path -Path $basePath -ChildPath $files[$i]
if (-Not (Test-Path $filePath)) {
throw "File not found: $filePath"
}

$fileSizeInBytes = (Get-Item $filePath).length
$lowerBoundB = $expectedSizesB[$i] - $toleranceB
$upperBoundB = $expectedSizesB[$i] + $toleranceB
if ($fileSizeInBytes -lt $lowerBoundB -or $fileSizeInBytes -gt $upperBoundB) {
throw "File size mismatch for $filePath. Expected: $($expectedSizesB[$i]) B (+/- 3000 B), Found: $fileSizeInBytes bytes"
}
}
Write-Host "All files exist and are within the acceptable size range in KB."
shell: pwsh
118 changes: 68 additions & 50 deletions DCL_PiXYZ/PXZEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Newtonsoft.Json;
using SceneImporter;
using UnityEngine.Pixyz.API;
using UnityEngine.Pixyz.Core;

namespace DCL_PiXYZ
{
Expand All @@ -27,57 +28,58 @@ private static async Task RunLODBuilder(string[] args)
string defaultSceneLodManifestDirectory = Path.Combine(Directory.GetCurrentDirectory(), "scene-lod-entities-manifest-builder/");

bool isDebug = true;
bool installNPM = true;


if (args.Length > 0)
{
defaultScene = args[1];
defaultOutputPath = args[2];
defaultSceneLodManifestDirectory = args[3];
isDebug = false;
bool.TryParse(args[4], out isDebug);
bool.TryParse(args[5], out installNPM);
}

//Conversion type can be single or bulk
//If its single, we pass as many scenes as we want to parse separated by ;
//If its bulk, a single number will represent a square to parse, going from -value to value
//If its bulk, a single number will represent a square to parse, going from -value to value.
//Comment (Juani): Im living bulk implementation for reference, but currently Im invoking the creation of all the scenes through an external program
//PiXYZ was crashing and exiting the application if it was called form the same program

//Scenes param is single coordinates or bulk value. Single scenes are separated by
var sceneConversionInfo = new SceneConversionInfo("7000;3000;1000", "triangle", "coords", "single", defaultScene);
var pathHandler = new SceneConversionPathHandler(isDebug, defaultOutputPath, defaultSceneLodManifestDirectory, "SuccessScenes.txt", "FailScenes.txt", "PolygonCount.txt" , "FailedGLBImport.txt" , defaultScene);

List<string> roadCoordinates = LoadRoads();
var convertedScenes = LoadConvertedScenes();
CreateDirectories(sceneConversionInfo);
FrameworkInitialization(pathHandler.ManifestProjectDirectory);
FrameworkInitialization(pathHandler.ManifestProjectDirectory, installNPM);

foreach (string currentScene in sceneConversionInfo.ScenesToAnalyze)
{
if (IsRoad(roadCoordinates, currentScene)) continue;
if (HasSceneBeenAnalyzed(sceneConversionInfo.AnalyzedScenes, currentScene)) continue;

if (HasSceneBeenAnalyzed(convertedScenes, currentScene)) continue;

sceneConversionInfo.SceneImporter = new SceneImporter(sceneConversionInfo.ConversionType, currentScene, sceneConversionInfo.WebRequestsHandler);
if (!await SceneDefinitionDownloadSuccesfully(sceneConversionInfo, currentScene, pathHandler)) continue;

pathHandler.SetOutputPath(sceneConversionInfo.SceneImporter);

if (HasSceneBeenConverted(pathHandler, currentScene)) continue;
if (HasSceneBeenConverted(convertedScenes, sceneConversionInfo.SceneImporter.GetSceneBasePointer())) continue;

if (CheckEmptyScene(sceneConversionInfo.SceneImporter.GetCurrentScenePointersList(), currentScene)) continue;

pathHandler.SetOutputPath(sceneConversionInfo.SceneImporter);

//Add it to the analyzed scenes array
foreach (string pointer in sceneConversionInfo.SceneImporter.GetCurrentScenePointersList())
sceneConversionInfo.AnalyzedScenes.Add(pointer);

if (CheckFaillingDebugScenes(sceneConversionInfo.SceneImporter.GetCurrentScenePointersList(), currentScene)) continue;
convertedScenes.Add(pointer);

Console.WriteLine("BEGIN SCENE CONVERSION FOR " + currentScene);
if (!await ManifestGeneratedSuccesfully(sceneConversionInfo, pathHandler, currentScene)) continue;

if (!await sceneConversionInfo.SceneImporter.DownloadAllContent(pathHandler)) continue;

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 +89,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);
UpdateConvertedScenesFile(convertedScenes);
}
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 +115,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 All @@ -115,10 +129,9 @@ private static async Task DoConversion(PXZParams pxzParams, SceneConversionInfo
}
}

private static bool HasSceneBeenConverted(SceneConversionPathHandler pathHandler, string scene)
private static bool HasSceneBeenConverted(List<string> convertedScenes, string scene)
{
var d = new DirectoryInfo(pathHandler.OutputPath);
if (d.Exists && d.GetFiles().Length > 0)
if (convertedScenes.Contains(scene))
{
Console.WriteLine($"Skipping scene {scene} since its already converted");
return true;
Expand Down Expand Up @@ -153,17 +166,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,31 +208,28 @@ 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);
List<PXZModel> models = await sceneRepositioner.SetupSceneInPiXYZ();


List<IPXZModifier> modifiers = new List<IPXZModifier>();
modifiers.Add(new PXZBeginCleanMaterials());
modifiers.Add(new PXZRepairMesh(models));


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,31 +256,50 @@ 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 List<string> LoadConvertedScenes()
{
string convertedScenePathFile = Path.Combine(Directory.GetCurrentDirectory(), "ConvertedScenes.json");
if (File.Exists(convertedScenePathFile))
{
return JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(convertedScenePathFile));
}

return new List<string>();
}

private static void UpdateConvertedScenesFile(List<string> convertedScenes)
{
string convertedScenePathFile = Path.Combine(Directory.GetCurrentDirectory(), "ConvertedScenes.json");
File.WriteAllText(convertedScenePathFile, JsonConvert.SerializeObject(convertedScenes));
}

private static void FrameworkInitialization(string sceneManifestDirectory, bool installAndBuildNPM)
{
Console.WriteLine("INSTALLING AND BUILDING NPM");
NPMUtils.DoNPMInstall(sceneManifestDirectory);
Console.WriteLine("END INSTALLING AND BUILDING NPM");
if (installAndBuildNPM)
{
Console.WriteLine("INSTALLING AND BUILDING NPM");
NPMUtils.DoNPMInstall(sceneManifestDirectory);
}
Console.WriteLine("INITIALIZING PIXYZ");
InitializePiXYZ();
Console.WriteLine("END INITIALIZING PIXYZ");
}

private static void InitializePiXYZ()
{
pxz =
PiXYZAPI.Initialize("PixyzSDKCSharp",
"204dda67aa3ea8bcb22a76bff9aa1224823b253144396405300e235e434c4711591892c19069c7");
pxz = PiXYZAPI.Initialize(Environment.GetEnvironmentVariable("PIXYZPRODUCTNAME"), Environment.GetEnvironmentVariable("PIXYZTOKEN"));

foreach (string s in pxz.Core.ListTokens().list)
pxz.Core.AddWantedToken(s);

// if no license is found, try to configure a license server
if (!pxz.Core.CheckLicense())
pxz.Core.InstallLicense("pixyzsdk-29022024.lic");
pxz.Core.ConfigureLicenseServer("18.204.36.86", 27000);
}

private static void CreateDirectories(SceneConversionInfo sceneConversionInfo)
{
Directory.CreateDirectory(PXYZConstants.RESOURCES_DIRECTORY);

}

public static void CloseApplication(string errorMessage)
Expand Down
14 changes: 5 additions & 9 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 All @@ -25,7 +23,6 @@ public struct SceneConversionInfo
public string DecimationType { get; }
public string DecimationValues { get; }
public List<string> ScenesToAnalyze { get; set; }
public List<string> AnalyzedScenes { get; set; }
public List<double> DecimationToAnalyze { get; set; }

public SceneImporter SceneImporter;
Expand All @@ -40,7 +37,6 @@ public SceneConversionInfo(string decimationValues, string decimationType, strin
DecimationType = decimationType;
DecimationValues = decimationValues;
ScenesToAnalyze = new List<string>();
AnalyzedScenes = new List<string>();
DecimationToAnalyze = new List<double>();
SceneImporter = null;
WebRequestsHandler = new WebRequestsHandler();
Expand Down Expand Up @@ -95,19 +91,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 +119,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 @@ -19,7 +19,7 @@
materialDictionary = new Dictionary<string, uint>();
}

public async Task ApplyModification(PiXYZAPI pxz)

Check warning on line 22 in DCL_PiXYZ/PiXYZWorflow/PXZBeginCleanMaterials.cs

View workflow job for this annotation

GitHub Actions / build-and-run

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Console.WriteLine("BEGIN PXZ CLEAN MATERIALS");
pxz.Scene.MergeImages();
Expand Down Expand Up @@ -56,7 +56,6 @@
}
}*/

Console.WriteLine("END PXZ CLEAN MATERIALS");
}
}
}
Loading
Loading