diff --git a/.github/workflows/test-lod-conversion.yml b/.github/workflows/test-lod-conversion.yml index 5a1831ca..217d2ce6 100644 --- a/.github/workflows/test-lod-conversion.yml +++ b/.github/workflows/test-lod-conversion.yml @@ -14,10 +14,10 @@ jobs: include: - lodLevelsToTest: ["500", "3"] files: "QmTpsFiaJVPv5mU6ERBzkDcZ39Lyq9sEfiLw9Ep3VQAFgK_3.fbx" - sizes: "1613824" + sizes: "5378768" - lodLevelsToTest: ["7000;3000;1000;500", "0"] files: "QmTpsFiaJVPv5mU6ERBzkDcZ39Lyq9sEfiLw9Ep3VQAFgK_0.fbx QmTpsFiaJVPv5mU6ERBzkDcZ39Lyq9sEfiLw9Ep3VQAFgK_1.fbx QmTpsFiaJVPv5mU6ERBzkDcZ39Lyq9sEfiLw9Ep3VQAFgK_2.fbx QmTpsFiaJVPv5mU6ERBzkDcZ39Lyq9sEfiLw9Ep3VQAFgK_3.fbx" - sizes: "48934912 3428352 2424832 1613824" + sizes: "35727600 9031680 7032832 5378768" steps: - uses: actions/checkout@v2 @@ -85,7 +85,7 @@ jobs: basePath="${GITHUB_WORKSPACE}/publish/OutputDirectoryPath/${{ env.COORDS }}" files=(${{ join(matrix.files, ' ') }}) sizes=(${{ join(matrix.sizes, ' ') }}) - toleranceB=20000 # 10 KB tolerance + toleranceB=40000 # 40 KB tolerance for i in "${!files[@]}"; do filePath="$basePath/${files[$i]}" diff --git a/DCL_PiXYZ/DCL_PiXYZ.csproj b/DCL_PiXYZ/DCL_PiXYZ.csproj index c5284fbc..e85fef58 100644 --- a/DCL_PiXYZ/DCL_PiXYZ.csproj +++ b/DCL_PiXYZ/DCL_PiXYZ.csproj @@ -32,7 +32,7 @@ - + diff --git a/DCL_PiXYZ/PXZClient.cs b/DCL_PiXYZ/PXZClient.cs index ee0186e1..a4aec02a 100644 --- a/DCL_PiXYZ/PXZClient.cs +++ b/DCL_PiXYZ/PXZClient.cs @@ -109,7 +109,7 @@ private async Task DoConversion(PXZConversionParams pxzParams, SceneConversionIn //Check if they were converted stopwatch.Restart(); FileWriter.WriteToConsole($"BEGIN CONVERTING {scene} WITH {pxzParams.DecimationValue}"); - await ConvertScene(pxzParams, pathHandler, sceneConversionInfo); + ConvertScene(pxzParams, pathHandler, sceneConversionInfo); stopwatch.Stop(); string elapsedTime = string.Format("{0:00}:{1:00}:{2:00}", @@ -198,7 +198,7 @@ private async Task GenerateManifest(SceneConversionPathHandler pathHandler return false; } - private async Task ConvertScene(PXZConversionParams pxzParams, SceneConversionPathHandler pathHandler, SceneConversionInfo sceneConversionInfo) + private void ConvertScene(PXZConversionParams pxzParams, SceneConversionPathHandler pathHandler, SceneConversionInfo sceneConversionInfo) { SceneRepositioner.SceneRepositioner sceneRepositioner = new SceneRepositioner.SceneRepositioner(pxzParams.SceneContent, pxz, pathHandler, pxzParams.LodLevel); @@ -208,6 +208,9 @@ private async Task ConvertScene(PXZConversionParams pxzParams, SceneConversionPa modifiers.Add(new PXZBeginCleanMaterials()); modifiers.Add(new PXZRepairMesh(models)); modifiers.Add(new PXZMaterialNameRandomizer()); + modifiers.Add(new PXZDeleteEmptyOccurrences()); + modifiers.Add(new PXZDeleteAllAnimations()); + modifiers.Add(new PXZDeleteInvalidTransforms()); if (pxzParams.LodLevel != 0) { @@ -216,8 +219,14 @@ private async Task ConvertScene(PXZConversionParams pxzParams, SceneConversionPa modifiers.Add(new PXZDecimator(sceneConversionInfo.SceneImporter.GetSceneBasePointer(), pxzParams.DecimationType, pxzParams.DecimationValue, pxzParams.ParcelAmount, pathHandler)); modifiers.Add(new PXZMergeMeshes(pxzParams.LodLevel)); + + //Cleanup after merge + modifiers.Add(new PXZDeleteEmptyOccurrences()); + + modifiers.Add(new PXZFlattenHierarchy()); } + modifiers.Add(new PXZExporter(pxzParams, pathHandler, sceneConversionInfo)); PXZStopwatch stopwatch = new PXZStopwatch(); diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZDeleteAllAnimations.cs b/DCL_PiXYZ/PiXYZWorflow/PXZDeleteAllAnimations.cs new file mode 100644 index 00000000..d9185d17 --- /dev/null +++ b/DCL_PiXYZ/PiXYZWorflow/PXZDeleteAllAnimations.cs @@ -0,0 +1,17 @@ +using UnityEngine.Pixyz.API; +using UnityEngine.Pixyz.Scene; + +namespace DCL_PiXYZ +{ + public class PXZDeleteAllAnimations : IPXZModifier + { + public void ApplyModification(PiXYZAPI pxz) + { + AnimationList animationList = pxz.Scene.ListAnimations(); + foreach (var animation in animationList.list) + { + pxz.Scene.DeleteAnimation(animation); + } + } + } +} \ No newline at end of file diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZDeleteEmptyOccurrences.cs b/DCL_PiXYZ/PiXYZWorflow/PXZDeleteEmptyOccurrences.cs new file mode 100644 index 00000000..9e9f3b0c --- /dev/null +++ b/DCL_PiXYZ/PiXYZWorflow/PXZDeleteEmptyOccurrences.cs @@ -0,0 +1,12 @@ +using UnityEngine.Pixyz.API; + +namespace DCL_PiXYZ +{ + public class PXZDeleteEmptyOccurrences : IPXZModifier + { + public void ApplyModification(PiXYZAPI pxz) + { + pxz.Scene.DeleteEmptyOccurrences(pxz.Scene.GetRoot()); + } + } +} \ No newline at end of file diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZDeleteInvalidTransforms.cs b/DCL_PiXYZ/PiXYZWorflow/PXZDeleteInvalidTransforms.cs new file mode 100644 index 00000000..f46dee66 --- /dev/null +++ b/DCL_PiXYZ/PiXYZWorflow/PXZDeleteInvalidTransforms.cs @@ -0,0 +1,14 @@ +using UnityEngine.Pixyz.API; +using UnityEngine.Pixyz.Scene; + +namespace DCL_PiXYZ +{ + public class PXZDeleteInvalidTransforms : IPXZModifier + { + public void ApplyModification(PiXYZAPI pxz) + { + OccurrenceList occs = pxz.Scene.GetFilteredOccurrences("Property(\"Transform\").Matches(\".*nan.*\")") ; + pxz.Scene.DeleteOccurrences(occs); + } + } +} \ No newline at end of file diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs b/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs index 1fef331a..b019cf00 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs @@ -28,14 +28,6 @@ public PXZExporter(PXZConversionParams pxzParams, SceneConversionPathHandler pat public void ApplyModification(PiXYZAPI pxz) { FileWriter.WriteToConsole($"BEGIN PXZ EXPORT {Path.Combine(path, $"{filename}.fbx")}"); - //Use it to flatten the hierarchy - if (lodLevel != 0) - { - pxz.Scene.MergeOccurrencesByTreeLevel(new OccurrenceList(new[] - { - pxz.Scene.GetRoot() - }), 1); - } pxz.IO.ExportScene(Path.Combine(path, $"{filename}.fbx"), pxz.Scene.GetRoot()); } diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZFlattenHierarchy.cs b/DCL_PiXYZ/PiXYZWorflow/PXZFlattenHierarchy.cs new file mode 100644 index 00000000..8f51a2a4 --- /dev/null +++ b/DCL_PiXYZ/PiXYZWorflow/PXZFlattenHierarchy.cs @@ -0,0 +1,16 @@ +using UnityEngine.Pixyz.API; +using UnityEngine.Pixyz.Scene; + +namespace DCL_PiXYZ +{ + public class PXZFlattenHierarchy : IPXZModifier + { + public void ApplyModification(PiXYZAPI pxz) + { + pxz.Scene.MergeOccurrencesByTreeLevel(new OccurrenceList(new[] + { + pxz.Scene.GetRoot() + }), 1, MergeHiddenPartsMode.Destroy); + } + } +} \ No newline at end of file diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs b/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs index ac14197a..ab801d27 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs @@ -1,9 +1,4 @@ using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Threading.Tasks; -using DCL_PiXYZ.SceneRepositioner.JsonParsing; using DCL_PiXYZ.Utils; using UnityEngine.Pixyz.Algo; using UnityEngine.Pixyz.API; @@ -28,12 +23,12 @@ public PXZMergeMeshes(int lodLevel) opaquesToMerge.list = new uint[]{}; transparentsToMerge = new OccurrenceList(); transparentsToMerge.list = new uint[]{}; - maxVertexCountPerMerge = 200000; + maxVertexCountPerMerge = 200_000; bakeOption = new BakeOption(); BakeMaps bakeMaps = new BakeMaps(); bakeMaps.diffuse = true; - bakeOption.bakingMethod = BakingMethod.RayOnly; + bakeOption.resolution = 1024; this.lodLevel = lodLevel; bakeOption.padding = 1; bakeOption.textures = bakeMaps; @@ -90,18 +85,11 @@ private void DoMerge(ulong currentVertexCount, OccurrenceList toMerge, bool isOp if (toMerge.list.Length == 0) return; - //TODO: What would be the best option here? - bakeOption.resolution = 1024; - if (lodLevel == 1 && currentVertexCount < 150000) - bakeOption.resolution = 512; - else if (lodLevel >= 2 && currentVertexCount < 150000) - bakeOption.resolution = 256; - FileWriter.WriteToConsole($"Merging meshes {(isOpaque ? "OPAQUE" : "TRANSPARENT")} {toMerge.list.Length} vertex count {currentVertexCount}"); - - uint combineMeshes = pxz.Algo.CombineMeshes(toMerge, bakeOption); + uint combineMeshes = pxz.Scene.MergePartOccurrences(toMerge)[0]; pxz.Core.SetProperty(combineMeshes, "Name", $"MERGED MESH {index} {(isOpaque ? "OPAQUE" : PXZConstants.FORCED_TRANSPARENT_MATERIAL)}"); + pxz.Algo.CombineMaterials(toMerge, bakeOption); FileWriter.WriteToConsole("Copying Material"); //Apply a copy of the material not to lose the reference @@ -114,7 +102,6 @@ private void DoMerge(ulong currentVertexCount, OccurrenceList toMerge, bool isOp pxz.Scene.SetOccurrenceMaterial(combineMeshes,copyMaterial); FileWriter.WriteToConsole("Setting Material"); } - }