How mkkellogg/gaussiansplats3d works
Based on an in-depth look at both the file tree and the README, this project is clearly a Three.js–based renderer and viewer for 3D Gaussian splatting. Its purpose is to load 3D scenes built from 2D images (using formats like .ply, .splat, and the custom .ksplat) and render them in a web environment with real-time interactivity, including support for WebXR. The system is heavily modularized into ES modules, which makes it easier to adapt components (e.g., file loaders, UI components, rendering logic) independently.
Main System Components
• Viewer Module: At the heart is the Viewer (src/Viewer.js) along with its drop-in variant (src/DropInViewer.js) and support classes (helpers, UI, controls).
• File Loaders: There is an entire suite of loaders (located in src/loaders/) handling various file formats:
– PLY loaders (e.g., PlyLoader.js, various PLY parsers)
– Standard Splat loaders (src/loaders/splat)
– Custom KSplat loaders (src/loaders/ksplat)
– Compression and utility modules for loading (e.g., Compression.js, LoaderStatus.js)
• UI Components: Dedicated UI modules (src/ui) such as InfoPanel, LoadingProgressBar, and LoadingSpinner manage user feedback.
• Rendering Helpers and Controls: Modules like the OrbitControls, ArrowHelper, and SceneHelper coordinate camera and scene manipulations.
• Raycaster: Modules in src/raycaster (Ray, Raycaster, Hit) for selecting/interacting with objects.
• Splat Mesh & Tree: Components in src/splatmesh and src/splattree handle assembling the actual rendered splat objects and optimizing which splats are drawn.
• WebXR and Three.js Shim: Modules in src/webxr and src/three-shim that provide support for WebXR features and handle low-level WebGL capabilities.
• Worker & WASM Components: A worker module (under src/worker) executes heavy computation (splat sorting via WASM) off the main thread.
• Demo Code: The demo folder shows practical implementation examples (HTML files and assets) of the viewer.
• Utility and Build Files: Additional utilities (in util/) and configuration files (rollup.config.js, package.json, etc.) that provide build scripts and serve the application.
Relationships and Interactions
• The Viewer component acts as the coordinator:
• It initializes a Three.js rendering loop.
• It integrates one or more splat scenes loaded by the loader modules, managing conversion and optimization options.
• The File Loader Modules interact closely with the Viewer:
• They parse 3D scene data from various file types.
• Once processed, data is fed into the splat mesh/tree modules.
• The Rendering Components (splat mesh, scene helpers, and UI) dynamically update based on user input and the computed data.
• The Worker (with WASM based sort algorithms) offloads the heavy computation for sorting splats to ensure smooth interactive rendering.
• UI Components provide real-time feedback (loading progress, info panels, etc.) and control mechanisms for scene navigation (mouse/keyboard or WebXR input).
• The drop-in mode (DropInViewer) shows how the core rendering capabilities can be embedded into any existing Three.js scene.
• Additionally, support files (in util/, demo/) and instructions in the README ease deployment and integration, such as local server setup with proper CORS headers for enabling shared memory.
Architectural Patterns and Design Principles
• Modular Design: The code is segmented into clear modules (viewer, loaders, UI, workers) using ES modules, making the project easily extendable and maintainable.
• Separation of Concerns: Rendering logic, file parsing, UI feedback, and worker computations are clearly decoupled.
• Asynchronous Processing: File loading, WASM-based splat sort operations, and progressive scene rendering are performed asynchronously for responsive user interactivity.
• Integration with Third-Party Libraries: Three.js is the core graphics library, with additional integrations for VR/AR and web workers, ensuring performance optimization and modern rendering features.
• Extensibility and Configurability: The project supports a range of parameters (via constructor options for the Viewer) to easily tweak rendering, sort methods, and file formats.
Relevant Technologies and Frameworks
• Three.js for 3D rendering.
• WebGL and WebXR for low-level graphics and mixed-reality support.
• ES Modules for code organization.
• Web Workers and WebAssembly (WASM) for off-main-thread computations and optimized splat sorting.
• Build tools such as Rollup for bundling, with npm-based build scripts.
• Utility libraries and minor helper scripts handling tasks such as server initialization (with CORS headers).
Elements
• Viewer (with subcomponents for DropIn Viewer and default Viewer)
• File Loaders (grouped by file types: PLY, SPLAT, KSplat)
• Splat Mesh & Splat Tree (rendering optimizations)
• UI Components (InfoPanel, LoadingSpinner, etc.)
• Raycaster module (for scene interaction)
• WebXR & Three.js Shim layers
• Worker & WASM Modules, possibly encapsulated as an "Asynchronous Processing" block
• Demo/Entry Point (HTML pages in demo/)
• Supporting utilities and configuration (e.g., build scripts, util/)
• Data flow from file loaders → splat mesh/tree → viewer → rendering to display.
• Interaction inputs from UI / controls → viewer.