mkkellogg / GaussianSplats3D

Three.js-based implementation of 3D Gaussian splatting
MIT License
1.09k stars 134 forks source link

Error compressing point cloud with harmonics value of 3 #259

Closed miranbrajsa closed 4 days ago

miranbrajsa commented 1 week ago

Hi! I really like the library you've put together, awesome work 👏

I've been playing around with compressing .ply files and everything works, except when I try to do a maximum compression of a .ply file with spherical harmonics set to 3. What I've seen from the README and the code, the code states that the harmonics degree support is in range 0 - 3 while the README specifies that the support is in range 0 - 2. The command I'm using is the following:

node "E:\dev\3rdParty\gaussian-splats-3d\util\create-ksplat.js" "path_to_point_cloud.ply" "path_to_compressed.ksplat" 2 5 "0,0,0" 5.0 256 3

and the error that gets produced is:

file:///E:/dev/3rdParty/gaussian-splats-3d/build/gaussian-splats-3d.module.js:1220
            const src = new Uint8Array(srcBuffer, srcOffset);
                        ^

RangeError: Start offset 9 is outside the bounds of the buffer
    at new Uint8Array (<anonymous>)
    at copyBetweenBuffers (file:///E:/dev/3rdParty/gaussian-splats-3d/build/gaussian-splats-3d.module.js:1220:25)
    at SplatBuffer.generateFromUncompressedSplatArrays (file:///E:/dev/3rdParty/gaussian-splats-3d/build/gaussian-splats-3d.module.js:1391:37)
    at SplatBufferGenerator.generateFromUncompressedSplatArray (file:///E:/dev/3rdParty/gaussian-splats-3d/build/gaussian-splats-3d.module.js:2442:28)
    at fileBufferToSplatBuffer (file:///E:/dev/3rdParty/gaussian-splats-3d/util/create-ksplat.js:40:44)
    at file:///E:/dev/3rdParty/gaussian-splats-3d/util/create-ksplat.js:24:21
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v21.4.0

I've tried a couple of different .ply files and I always end up with the same result. When going for harmonics between 0 and 2, there's no error and the compression succeeds. The point clouds in question have been exported from Postshot.

Another interesting thing I've noticed is that if I try with compression level of 0 and harmonics of 3 like with this command:

node "E:\dev\3rdParty\gaussian-splats-3d\util\create-ksplat.js" "path_to_point_cloud.ply" "path_to_compressed.ksplat" 0 5 "0,0,0" 5.0 256 3

I get a file that is smaller than the same point cloud compressed with compression level 2 and harmonics of 2:

node "E:\dev\3rdParty\gaussian-splats-3d\util\create-ksplat.js" "path_to_point_cloud.ply" "path_to_compressed.ksplat" 2 5 "0,0,0" 5.0 256 2

and this actually seems like the result is containing harmonics of degree 0.

I hope some of these insights will help.

Thank you in advance for any help you could provide.

mkkellogg commented 1 week ago

I apologize for all of the confusion, currently the viewer only supports spherical harmonics up to degree 2, so it's not surprising you're seeing problems trying include degree 3 😄 I need to correct the comment in the viewer and probably throw an error when the user tries to use anything above degree 2.

miranbrajsa commented 1 week ago

Hey @mkkellogg , no problem whatsoever, thank you for the fast reply. I'm curious though, what would need to be modified in order to support the 3rd degree. I'd be happy to take a look if you could provide a couple of guidelines/materials and if time permits 🤔

mkkellogg commented 1 week ago

The code around both loading and rendering the spherical harmonics is actually kind of complex, so it probably wouldn't be fun to try to modify (sorry, that's my fault). I eventually plan on supporting degree 3, I've just been holding off due to the substantial increase in memory (both CPU side and on the GPU) required. Hopefully I'll get around to it in the not too distance future :)

miranbrajsa commented 1 week ago

Got it. I'll see if I can do something in the meantime 👍 Thanks again!

mkkellogg commented 4 days ago

sounds good!