Skip to main content

Potree writers

encodePotreeDataset() encodes a complete Potree file collection using ArrayBuffer and typed arrays. PotreeWriter encodes a metadata document through the standard loaders.gl writer API.

import {encodePotreeDataset} from '@loaders.gl/tiles-3d/potree';

const dataset = await encodePotreeDataset(pointMeshOrArrowTable, {
potree: {version: '2.0', scale: [0.001, 0.001, 0.001], projection: 'EPSG:4978'}
});
for (const [relativePath, bytes] of dataset.files) {
// Store bytes with the application's browser or Node file service.
}

The default is 2.0 DEFAULT encoding. A single decoded unindexed point Mesh or MeshArrowTable becomes a root node. To write an existing octree, supply a connected array of {id: 'r' | 'r0' | 'r07' | ..., mesh} nodes. Rows must belong exclusively to their additive node; the writer neither samples nor duplicates them. XYZ octant bits are 4/2/1. All nodes must have matching attribute layouts and points within their native octant bounds. An application can supply nodes from a dynamic point tiler and package the resulting files separately.

Compatibility​

Requested dataset versionOutput
1.0–1.3cloud.js, embedded hierarchy, flat extensionless nodes, absolute float32 XYZ + RGBA
1.4cloud.js, embedded hierarchy, flat .bin nodes, node-relative uint32 XYZ
1.5–1.8cloud.js, paged .hrc hierarchy and nested .bin nodes
2.0metadata.json, hierarchy.bin, octree.bin, DEFAULT interleaved attributes

Modern output retains all ten scalar widths, exact 64-bit IDs and custom normalization metadata. Uint8 RGB/RGBA is promoted to uint16 with component * 257; uint16 color is preserved. JSON attribute range statistics are approximate for values above Number's exact integer range; encoded point values remain exact. Custom normalization is a loaders.gl metadata extension.

Legacy layouts accept only their declared standard attributes. The earliest layout has XYZ and RGBA only; absent color is opaque white. Later layouts include intensity, classification and supported encoded normals. Unrepresentable attributes fail with a request for explicit mapping. Legacy readers retain their existing RGB output behavior. Output does not generate LAS/LAZ node payloads or BROTLI encoding; the readers can consume those existing dataset encodings.

Options​

All options are in potree:

OptionDefaultMeaning
version2.0Dataset wire version, 1.0–1.8 or 2.0
scale[0.001, 0.001, 0.001]XYZ quantization; legacy requires equal axis scales
maxPositionErrorHalf the largest scaleMaximum rounding error, including early float32 output
hierarchyStepSize5Legacy hierarchy page/folder depth, 1–24
spacingCube width / 128, or 1Root spacing in native units
projectionUnsetExplicit CRS declaration; never inferred or applied
maxOutputBytes256 MiBAggregate encoded files
maxNodes100000Connected input node count
signalUnsetCancellation between node encodes

Input, Arrow conversion, temporary node buffers and application caches consume additional heap. The helper is an in-memory dataset writer, not an out-of-core tiling service. Coordinates must fit the declared precision and integer range; lossy attribute mappings and CRS conversion are explicit application steps. Storage, ZIP packaging, downloads and CLI services remain outside this writer.