From ebaca6854f278a987ac47095197e65ab7aacb45e Mon Sep 17 00:00:00 2001 From: Zhenya Yang Date: Sat, 13 Sep 2025 09:31:16 +1000 Subject: [PATCH] Correctly read Sh order coeffs from order < 3, which can be generated by nerfstudio --- package/Editor/Utils/GaussianFileReader.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/package/Editor/Utils/GaussianFileReader.cs b/package/Editor/Utils/GaussianFileReader.cs index 187b7b59..7f86f6c2 100644 --- a/package/Editor/Utils/GaussianFileReader.cs +++ b/package/Editor/Utils/GaussianFileReader.cs @@ -53,7 +53,12 @@ public static unsafe void ReadFile(string filePath, out NativeArray a.Item1.StartsWith("f_rest_") && a.Item2 == PLYFileReader.ElementType.Float); + shCount = restCount / 3; // Each SH band per channel (R,G,B) + ReorderSHs(splatCount, (float*)splats.GetUnsafePtr(), shCount); LinearizeData(splats); return; } @@ -164,6 +169,7 @@ static unsafe NativeArray PLYDataToSplats(NativeArray inpu NativeArray dst = new NativeArray(count, Allocator.Persistent); ReorderPLYData(count, (byte*)input.GetUnsafeReadOnlyPtr(), stride, (byte*)dst.GetUnsafePtr(), UnsafeUtility.SizeOf(), (int*)srcOffsets.GetUnsafeReadOnlyPtr()); + return dst; } @@ -183,10 +189,10 @@ static unsafe void ReorderPLYData(int splatCount, byte* src, int srcStride, byte } [BurstCompile] - static unsafe void ReorderSHs(int splatCount, float* data) + static unsafe void ReorderSHs(int splatCount, float* data, int shCount) { int splatStride = UnsafeUtility.SizeOf() / 4; - int shStartOffset = 9, shCount = 15; + int shStartOffset = 9; float* tmp = stackalloc float[shCount * 3]; int idx = shStartOffset; for (int i = 0; i < splatCount; ++i)