Skip to content
Open
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions package/Editor/Utils/GaussianFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public static unsafe void ReadFile(string filePath, out NativeArray<InputSplatDa
if (!string.IsNullOrEmpty(attrError))
throw new IOException($"PLY file is probably not a Gaussian Splat file? Missing properties: {attrError}");
splats = PLYDataToSplats(plyRawData, splatCount, vertexStride, attributes);
ReorderSHs(splatCount, (float*)splats.GetUnsafePtr());

int shCount = 15; //default 15
// Count how many f_rest_* attributes are present
int restCount = attributes.Count(a => 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;
}
Expand Down Expand Up @@ -164,6 +169,7 @@ static unsafe NativeArray<InputSplatData> PLYDataToSplats(NativeArray<byte> inpu

NativeArray<InputSplatData> dst = new NativeArray<InputSplatData>(count, Allocator.Persistent);
ReorderPLYData(count, (byte*)input.GetUnsafeReadOnlyPtr(), stride, (byte*)dst.GetUnsafePtr(), UnsafeUtility.SizeOf<InputSplatData>(), (int*)srcOffsets.GetUnsafeReadOnlyPtr());

return dst;
}

Expand All @@ -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<InputSplatData>() / 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)
Expand Down