From 47f8daeee7e8b35679f540ef5ec1f293fd18259e Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Mon, 13 Jan 2025 12:18:13 -0300 Subject: [PATCH 1/9] Update PXZ sdk --- DCL_PiXYZ/DCL_PiXYZ.csproj | 2 +- DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) 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/PiXYZWorflow/PXZMergeMeshes.cs b/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs index ac14197a..725d8855 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,11 @@ 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; this.lodLevel = lodLevel; bakeOption.padding = 1; bakeOption.textures = bakeMaps; @@ -99,9 +93,10 @@ private void DoMerge(ulong currentVertexCount, OccurrenceList toMerge, bool isOp 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 +109,6 @@ private void DoMerge(ulong currentVertexCount, OccurrenceList toMerge, bool isOp pxz.Scene.SetOccurrenceMaterial(combineMeshes,copyMaterial); FileWriter.WriteToConsole("Setting Material"); } - } From 9cf20a6686a6ed0a29ba80d89e60bcfb5121204d Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Mon, 13 Jan 2025 12:52:08 -0300 Subject: [PATCH 2/9] Destroy lingering animations --- DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs b/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs index 1fef331a..a5ca0cad 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs @@ -34,7 +34,13 @@ public void ApplyModification(PiXYZAPI pxz) pxz.Scene.MergeOccurrencesByTreeLevel(new OccurrenceList(new[] { pxz.Scene.GetRoot() - }), 1); + }), 1);*/ + AnimationList animationList = pxz.Scene.ListAnimations(); + + foreach (var animation in animationList.list) + { + pxz.Scene.DeleteAnimation(animation); + } } pxz.IO.ExportScene(Path.Combine(path, $"{filename}.fbx"), pxz.Scene.GetRoot()); } From 1462abc863634248b3fb3fa23262f31f9974328e Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Tue, 14 Jan 2025 10:38:14 -0300 Subject: [PATCH 3/9] Force textures to 1024, delete animations, delete empty occurences, delete invalid transforms --- DCL_PiXYZ/PXZClient.cs | 9 +++++++++ .../PiXYZWorflow/PXZDeleteAllAnimations.cs | 17 +++++++++++++++++ .../PiXYZWorflow/PXZDeleteEmptyOccurrences.cs | 12 ++++++++++++ .../PiXYZWorflow/PXZDeleteInvalidTransforms.cs | 14 ++++++++++++++ DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs | 14 -------------- DCL_PiXYZ/PiXYZWorflow/PXZFlattenHierarchy.cs | 16 ++++++++++++++++ DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs | 9 +-------- 7 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 DCL_PiXYZ/PiXYZWorflow/PXZDeleteAllAnimations.cs create mode 100644 DCL_PiXYZ/PiXYZWorflow/PXZDeleteEmptyOccurrences.cs create mode 100644 DCL_PiXYZ/PiXYZWorflow/PXZDeleteInvalidTransforms.cs create mode 100644 DCL_PiXYZ/PiXYZWorflow/PXZFlattenHierarchy.cs diff --git a/DCL_PiXYZ/PXZClient.cs b/DCL_PiXYZ/PXZClient.cs index ee0186e1..5954da6a 100644 --- a/DCL_PiXYZ/PXZClient.cs +++ b/DCL_PiXYZ/PXZClient.cs @@ -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 a5ca0cad..b019cf00 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs @@ -28,20 +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);*/ - AnimationList animationList = pxz.Scene.ListAnimations(); - - foreach (var animation in animationList.list) - { - pxz.Scene.DeleteAnimation(animation); - } - } 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 725d8855..ab801d27 100644 --- a/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs +++ b/DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs @@ -28,6 +28,7 @@ public PXZMergeMeshes(int lodLevel) bakeOption = new BakeOption(); BakeMaps bakeMaps = new BakeMaps(); bakeMaps.diffuse = true; + bakeOption.resolution = 1024; this.lodLevel = lodLevel; bakeOption.padding = 1; bakeOption.textures = bakeMaps; @@ -84,16 +85,8 @@ 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.Scene.MergePartOccurrences(toMerge)[0]; pxz.Core.SetProperty(combineMeshes, "Name", $"MERGED MESH {index} {(isOpaque ? "OPAQUE" : PXZConstants.FORCED_TRANSPARENT_MATERIAL)}"); pxz.Algo.CombineMaterials(toMerge, bakeOption); From 3507f97d0cbba99a7d50b1d544363b5ec86898f8 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Wed, 15 Jan 2025 09:52:53 -0300 Subject: [PATCH 4/9] Removed await to remove warnings --- DCL_PiXYZ/PXZClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DCL_PiXYZ/PXZClient.cs b/DCL_PiXYZ/PXZClient.cs index 5954da6a..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); From c8bd529b73c1c8611e359f04ab36856eeecd7478 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Wed, 15 Jan 2025 09:56:04 -0300 Subject: [PATCH 5/9] Update test-lod-conversion.yml Signed-off-by: Juan Ignacio Molteni --- .github/workflows/test-lod-conversion.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-lod-conversion.yml b/.github/workflows/test-lod-conversion.yml index 5a1831ca..1388557a 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: "5382144" - 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 5382144" steps: - uses: actions/checkout@v2 From fb066832cacea67e251a840733f094f08d929e46 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Wed, 15 Jan 2025 10:09:57 -0300 Subject: [PATCH 6/9] Update test-lod-conversion.yml Signed-off-by: Juan Ignacio Molteni --- .github/workflows/test-lod-conversion.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-lod-conversion.yml b/.github/workflows/test-lod-conversion.yml index 1388557a..86ef9943 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: "5382144" + sizes: "5378768" - lodLevelsToTest: ["7000;3000;1000;500", "0"] files: "QmTpsFiaJVPv5mU6ERBzkDcZ39Lyq9sEfiLw9Ep3VQAFgK_0.fbx QmTpsFiaJVPv5mU6ERBzkDcZ39Lyq9sEfiLw9Ep3VQAFgK_1.fbx QmTpsFiaJVPv5mU6ERBzkDcZ39Lyq9sEfiLw9Ep3VQAFgK_2.fbx QmTpsFiaJVPv5mU6ERBzkDcZ39Lyq9sEfiLw9Ep3VQAFgK_3.fbx" - sizes: "35727600 9031680 7032832 5382144" + sizes: "35727600 9031680 7032832 5378768" steps: - uses: actions/checkout@v2 From 0d6ea6f37b46ef66fe6a9aa05be9b5eb17214dd6 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Wed, 15 Jan 2025 10:19:33 -0300 Subject: [PATCH 7/9] Update test-lod-conversion.yml Signed-off-by: Juan Ignacio Molteni --- .github/workflows/test-lod-conversion.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-lod-conversion.yml b/.github/workflows/test-lod-conversion.yml index 86ef9943..87247681 100644 --- a/.github/workflows/test-lod-conversion.yml +++ b/.github/workflows/test-lod-conversion.yml @@ -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=50000 # 50 KB tolerance for i in "${!files[@]}"; do filePath="$basePath/${files[$i]}" From af1fea482d621cc2e1a5701ed54300844b44fda9 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Wed, 15 Jan 2025 10:29:26 -0300 Subject: [PATCH 8/9] Update test-lod-conversion.yml Signed-off-by: Juan Ignacio Molteni --- .github/workflows/test-lod-conversion.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-lod-conversion.yml b/.github/workflows/test-lod-conversion.yml index 87247681..93157416 100644 --- a/.github/workflows/test-lod-conversion.yml +++ b/.github/workflows/test-lod-conversion.yml @@ -85,7 +85,7 @@ jobs: basePath="${GITHUB_WORKSPACE}/publish/OutputDirectoryPath/${{ env.COORDS }}" files=(${{ join(matrix.files, ' ') }}) sizes=(${{ join(matrix.sizes, ' ') }}) - toleranceB=50000 # 50 KB tolerance + toleranceB=30000 # 30 KB tolerance for i in "${!files[@]}"; do filePath="$basePath/${files[$i]}" From aed1f1e306a16639f0772cdea8476e2d9db110ef Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Wed, 15 Jan 2025 10:35:53 -0300 Subject: [PATCH 9/9] Update test-lod-conversion.yml Signed-off-by: Juan Ignacio Molteni --- .github/workflows/test-lod-conversion.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-lod-conversion.yml b/.github/workflows/test-lod-conversion.yml index 93157416..217d2ce6 100644 --- a/.github/workflows/test-lod-conversion.yml +++ b/.github/workflows/test-lod-conversion.yml @@ -85,7 +85,7 @@ jobs: basePath="${GITHUB_WORKSPACE}/publish/OutputDirectoryPath/${{ env.COORDS }}" files=(${{ join(matrix.files, ' ') }}) sizes=(${{ join(matrix.sizes, ' ') }}) - toleranceB=30000 # 30 KB tolerance + toleranceB=40000 # 40 KB tolerance for i in "${!files[@]}"; do filePath="$basePath/${files[$i]}"