Gaussian Splatting From Zero · Episode 07
Loading Real Splats
Loading Real Splats is Episode 07 of Gaussian Splatting From Zero, a MasterAllArts free interactive lesson for artists learning creative 3D on the web.
Part of the MasterAllArts Creative 3D Roadmap .
Every splat so far has been born in JavaScript. Real captures arrive as files — a
.ply straight out of the trainer, or a compact .splat for the web —
and "loading a splat" means decoding a tight little binary record per Gaussian into the exact
attributes our renderer already eats. This episode dissects those bytes. The demo below
encodes our planet into a real .splat buffer, dumps its hex, and parses
it back with the same loader you'd point at a two-gigabyte scan — and renders the
result, proving the round-trip.
Here's the live byte-level inspector for the splat index you pick above — the raw 32 bytes as they sit in the file, and the values our parser pulls out of them:
Two formats: .ply (source of truth) and .splat (web delivery)
A trainer emits a .ply — the same Stanford format used for
meshes, repurposed. It's the authoritative, lossless representation: full float precision and
all the spherical-harmonic coefficients. It has a human-readable ASCII header that ends with
end_header, followed by tightly packed binary rows, one per splat:
ply
format binary_little_endian 1.0
element vertex 1059000
property float x
property float y
property float z
property float nx // normals (often unused/zero)
property float ny
property float nz
property float f_dc_0 // SH degree-0 color (R,G,B)
property float f_dc_1
property float f_dc_2
property float f_rest_0 // SH degrees 1–3: 45 more floats
... // f_rest_0 … f_rest_44
property float opacity // pre-sigmoid (logit)
property float scale_0 // log-scale, three axes
property float scale_1
property float scale_2
property float rot_0 // quaternion (w,x,y,z), pre-normalize
property float rot_1
property float rot_2
property float rot_3
end_header
<binary blob: 1,059,000 rows × 248 bytes>
Three gotchas that bite everyone, and that you must apply on load:
- Opacity is a logit. Apply a sigmoid:
opacity = 1/(1+exp(−x)). - Scale is logged. Exponentiate:
scale = exp(scale_i). (That's why a raw scale of−5isn't a giant splat — it'se⁻⁵ ≈ 0.0067.) - Color is SH. Decode the DC term as in Episode 06:
rgb = 0.5 + 0.28209·f_dc, and the quaternion needs normalizing.
Parsing a binary PLY in the browser is just header-scan + a DataView:
function parsePly(buffer) {
const text = new TextDecoder().decode(new Uint8Array(buffer, 0, 2048));
const end = text.indexOf('end_header\n') + 'end_header\n'.length;
const count = +text.match(/element vertex (\d+)/)[1];
// build {name → byteOffset} from the property list, compute rowStride…
const dv = new DataView(buffer, end);
for (let i = 0; i < count; i++) {
const base = i * rowStride;
pos[i] = [dv.getFloat32(base + off.x, true), /* y, z */];
scale[i] = Math.exp(dv.getFloat32(base + off.scale_0, true));
// …sigmoid(opacity), 0.5 + 0.28209*f_dc, normalize(rot)…
}
}
The .splat format: 32 bytes, no header, web-ready
A 1-million-splat PLY at degree 3 is ~250 MB — a non-starter for a web page. The community
settled on a stripped .splat format (from antimatter15's viewer):
drop the higher SH bands, quantize, and pack each splat into a fixed 32 bytes
with no header at all. The file is simply count = byteLength / 32 records of:
| Offset | Bytes | Field | Type | Decode |
|---|---|---|---|---|
| 0 | 12 | position x,y,z | 3 × float32 | as-is |
| 12 | 12 | scale x,y,z | 3 × float32 | as-is (already exp'd) |
| 24 | 4 | color r,g,b,a | 4 × uint8 | / 255 |
| 28 | 4 | rotation | 4 × uint8 | (b − 128) / 128 |
No logits, no logs, no SH — the producer already applied sigmoid/exp and baked the DC color
into 8-bit RGB, with opacity in the alpha byte and the normalized quaternion squeezed into four
bytes. That's why .splat loads instantly and .ply is the archival
master. Decoding is a tight loop over a DataView — this is the entire parser, and
it's exactly what painted the planet above:
function parseSplat(buffer) {
const n = buffer.byteLength / 32;
const dv = new DataView(buffer);
const u8 = new Uint8Array(buffer);
for (let i = 0; i < n; i++) {
const b = i * 32;
center[i*3+0] = dv.getFloat32(b + 0, true);
center[i*3+1] = dv.getFloat32(b + 4, true);
center[i*3+2] = dv.getFloat32(b + 8, true);
scale[i*3+0] = dv.getFloat32(b + 12, true);
scale[i*3+1] = dv.getFloat32(b + 16, true);
scale[i*3+2] = dv.getFloat32(b + 20, true);
color[i*3+0] = u8[b + 24] / 255;
color[i*3+1] = u8[b + 25] / 255;
color[i*3+2] = u8[b + 26] / 255;
opacity[i] = u8[b + 27] / 255;
quat[i*4+0] = (u8[b + 28] - 128) / 128; // x
quat[i*4+1] = (u8[b + 29] - 128) / 128; // y
quat[i*4+2] = (u8[b + 30] - 128) / 128; // z
quat[i*4+3] = (u8[b + 31] - 128) / 128; // w
}
}
Click "parse & render" in the demo: it throws away the live planet, runs exactly this loop over the encoded buffer, and rebuilds the cloud from raw bytes. It looks identical because it is identical — that's the proof your loader is correct.
Newer formats trade up from.splat:.ksplat(mkkellogg) adds compression levels and SH;.spz(Niantic, open source) is ~10× smaller than PLY with Gaussian-aware quantization and is becoming the de-facto delivery format; and there are draft glTF (KHR_gaussian_splatting) and MPEG standards. They differ in bit-packing, not in concept — every one decodes to the same five attributes you've been rendering since Episode 03.
Where to get real captures
- Make one: phone apps like Polycam, Scaniverse, or KIRI Engine export
.ply/.splatdirectly. (Capture technique is Episode 09.) - Train one: Postshot, Brush, or nerfstudio's
gsplatturn a photo/video set into a.ply. - Download one: the original 3DGS paper's scenes, Luma/Polycam galleries, and Hugging Face splat datasets. Mind the licenses.
Whichever you grab, the loader above (or a library's) turns it into the exact
iCenter / iColor / iOpacity / iScale / iQuat attributes our from-scratch renderer
has used the whole season. Nothing about the renderer changes. That's the
payoff of building from scratch: a real capture is just our planet with someone else's numbers.
Common pitfalls
- Grey or black blobs. You skipped the SH/opacity/scale decode on a PLY (raw logit opacity ≈ 0.5 everywhere, raw log-scale ≈ huge). Apply sigmoid, exp, and the 0.28209 DC decode.
- Splats in a tangled ball. Quaternion component order. PLY stores
(w,x,y,z)(scalar first); Three.js wants(x,y,z,w). Swap, then normalize. - Everything mirrored or upside-down. Coordinate-system handedness — many trainers use a Y-down / Z-forward convention. Flip the axis the producer used.
- RangeError reading the buffer. Wrong stride. For PLY, sum every
property's size for the row stride; for
.splatit's exactly 32. An off-by-one property and every row after the first is garbage. - Endianness. Always pass
true(little-endian) toDataView.getFloat32. The format is little-endian; the default is big. - Main thread freezes for seconds. Parsing millions of splats blocks the UI. Real loaders parse in a Web Worker and stream splats in as they're decoded.
Exercises
- Add a real file input (
<input type="file">→arrayBuffer()) and drag a.splatfrom a phone capture onto the page. The parser above will render it as-is. - Write the matching encoder (we did, to make the buffer) and round-trip a PLY →
.splat. Measure the size drop and the quality loss from 8-bit color. - Move
parseSplatinto a Web Worker and post the typed arrays back with transferables. Confirm the page no longer hitches on load. - Extend the parser to read
.plyheaders generically (build the offset table from thepropertylines) so it survives trainers that reorder fields.
What's next
Episode 08 — Making It Fast (Season Finale). We push to half a million splats, add frustum culling and a perf HUD, drop a real lit Three.js mesh into the splat scene to prove they depth-composite correctly, and tie the whole renderer together into one scene that holds 60fps. Then Season 2 leaves the sandbox: capturing, editing, compressing, animating, and shipping real splats.