Skip to content

Commit

Permalink
Merge branch 'main' into chore/bump-pipeline-upload-artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
dalkia committed Jan 15, 2025
2 parents 3f6f0da + 7ed437b commit b94a850
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-lod-conversion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]}"
Expand Down
2 changes: 1 addition & 1 deletion DCL_PiXYZ/DCL_PiXYZ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="PiXYZCSharpAPI" Version="2024.1.0.17-win64" />
<PackageReference Include="PiXYZCSharpAPI" Version="2024.3.0.8-win64" />
<PackageReference Include="SharpGLTF.Core" Version="1.0.0-alpha0031" />
<PackageReference Include="SharpGLTF.Toolkit" Version="1.0.0-alpha0031" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
Expand Down
13 changes: 11 additions & 2 deletions DCL_PiXYZ/PXZClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -198,7 +198,7 @@ private async Task<bool> 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);
Expand All @@ -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)
{
Expand All @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions DCL_PiXYZ/PiXYZWorflow/PXZDeleteAllAnimations.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
12 changes: 12 additions & 0 deletions DCL_PiXYZ/PiXYZWorflow/PXZDeleteEmptyOccurrences.cs
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
14 changes: 14 additions & 0 deletions DCL_PiXYZ/PiXYZWorflow/PXZDeleteInvalidTransforms.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
8 changes: 0 additions & 8 deletions DCL_PiXYZ/PiXYZWorflow/PXZExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
16 changes: 16 additions & 0 deletions DCL_PiXYZ/PiXYZWorflow/PXZFlattenHierarchy.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
21 changes: 4 additions & 17 deletions DCL_PiXYZ/PiXYZWorflow/PXZMergeMeshes.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -114,7 +102,6 @@ private void DoMerge(ulong currentVertexCount, OccurrenceList toMerge, bool isOp
pxz.Scene.SetOccurrenceMaterial(combineMeshes,copyMaterial);
FileWriter.WriteToConsole("Setting Material");
}

}


Expand Down

0 comments on commit b94a850

Please sign in to comment.