-
Notifications
You must be signed in to change notification settings - Fork 3
Implement PLY loader for 3D Gaussian Splatting models in <model> tag
#223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement PLY loader for 3D Gaussian Splatting models in <model> tag
#223
Conversation
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
<model> tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot It can basically parse a ply file, but the parsed splat's values are wrong, please compare the related code with https://github.com/sparkjsdev/spark/blob/main/src/ply.ts to make it work with correct result to render for 3DGS rendering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the PLY loader coordinate system issue. The problem was that I was incorrectly applying COLMAP-to-OpenGL coordinate transformations (negating y, z position and y, z quaternion components) which are used by other loaders like KSplat and SPZ that store data in COLMAP format.
PLY files from 3D Gaussian Splatting are already in OpenGL coordinate system, so no transformations should be applied. I've updated the implementation to match the Spark reference exactly:
- Position: Use x, y, z directly without negation
- Rotation: Use quaternion components directly without negation
- Removed debug console output
The implementation now correctly follows the Spark reference and should render 3DGS models properly. Commit: 4ea5702
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot 考虑下解析数据时字节序的逻辑是否正确。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the byte order parsing logic. The main issues were:
- More reliable endianness detection: Now uses
0x01234567test pattern instead ofuint16_tapproach - Efficient byte swapping: Replaced
std::reversewith proper bit-shifting operations for better performance and correctness - Compiler compatibility: Removed
if constexprfor better compatibility across compilers
Also corrected the quaternion component order to exactly match the Spark reference implementation (rot_0=W, rot_1=X, rot_2=Y, rot_3=Z).
Commit: 8eb44c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the byte order parsing logic. The main issues were:
- More reliable endianness detection: Now uses
0x01234567test pattern instead ofuint16_tapproach - Efficient byte swapping: Replaced
std::reversewith proper bit-shifting operations for better performance and correctness - Compiler compatibility: Removed
if constexprfor better compatibility across compilers
Also corrected the quaternion component order to exactly match the Spark reference implementation (rot_0=W, rot_1=X, rot_2=Y, rot_3=Z).
Commit: 8eb44c0
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot 考虑下解析数据时字节序的逻辑是否正确。
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
| { | ||
| std::string name; | ||
| int count; | ||
| std::unordered_map<std::string, PlyProperty> properties; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot 这里不能使用 unordered_map,因为在解析 vertex 内容时,需要按照 ply header 中 property 出现的顺序来加载,因此 properties 需要保留解析 header 时头部出现的顺序。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the property ordering issue. Changed PlyElement.properties from std::unordered_map to std::vector<std::pair<std::string, PlyProperty>> to preserve the exact order properties appear in the PLY header. This ensures binary data is parsed in the correct sequence during vertex parsing. d46242f
…_map The PLY loader was using std::unordered_map for storing element properties, which doesn't preserve the order properties appear in the PLY header. When parsing binary PLY data, properties must be read in the exact header order. Changed PlyElement.properties from unordered_map to vector<pair<string, PlyProperty>> to preserve insertion order during header parsing, ensuring correct binary data parsing. - Replace std::unordered_map with std::vector<std::pair<>> in PlyElement struct - Update property insertion to use push_back instead of map access - Maintains same iteration interface for backward compatibility Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
yorkie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Please update for my reviews.
| @@ -0,0 +1,506 @@ | |||
| #include <common/debug.hpp> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Please remove using common/debug.hpp and use client/logger.hpp instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated PLY loader to use #include <client/logger.hpp> instead of common/debug.hpp. Replaced all DEBUG() calls with appropriate logging::LogError() and logging::LogWarning() calls. Commit: 1c5d4b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename all the static methods such as decodePly -> DecodePly, NOTE: static methods and fields must use uppercase for the first char.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed all static methods to follow uppercase naming convention:
decodePly→DecodePlyload→LoadparseHeader→ParseHeaderparseElementData→ParseElementDatagetPropertyTypeSize→GetPropertyTypeSizeparsePropertyValue→ParsePropertyValuestringToPropertyType→StringToPropertyTypeextractSplatData→ExtractSplatDatareadBinary→ReadBinary
Updated all references in header, implementation, HTML model element, and test files. Commit: 1c5d4b7
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Updated PLY loader based on your reviews:
All references have been updated across the codebase including implementation, header, HTML model element, and test files. Commit: 1c5d4b7 |
This PR implements a PLY (Polygon File Format) loader for 3D Gaussian Splatting models, enabling the
<model>tag to load.plyfiles. The implementation follows the Spark reference implementation pattern from@sparkjsdev/spark/files/src/ply.ts.Features Added
The PLY loader seamlessly integrates with the existing model loading infrastructure:
Implementation Details
New Files:
src/client/builtin_scene/meshes/loaders/ply_loader.hpp- PLY loader interfacesrc/client/builtin_scene/meshes/loaders/ply_loader.cpp- PLY loader implementationtests/client/ply_loader_tests.cpp- Unit tests for validationModified Files:
src/client/html/html_model_element.hpp- AddedPLYtoModelTypeenumsrc/client/html/html_model_element.cpp- Added PLY detection and parsing logicPLY Format Support
The loader supports binary PLY format parsing with:
x,y,z) - used directly without coordinate transformationsscale_0,scale_1,scale_2) with logarithmic scaling usingexp()rot_0,rot_1,rot_2,rot_3) following Spark component order (W, X, Y, Z)1.0 / (1.0 + exp(-opacity))f_dc_0,f_dc_1,f_dc_2)Error Handling & Testing
The implementation maintains backward compatibility and follows the same patterns as existing loaders (KSplat, SPZ), ensuring consistent behavior across all supported 3D model formats. Unlike other loaders that apply coordinate system transformations for COLMAP format data, PLY files from 3D Gaussian Splatting are already in OpenGL coordinate system and require no transformations.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.