Three.js LIDAR Point Cloud Viewer (LAS, PLY, XYZ)

Point cloud viewer in Three.js with a synthetic airborne LIDAR scan and local LAS, PLY and XYZ loading, offering elevation, ASPRS classification, intensity and RGB coloring, class filters and height clipping on the GPU.

Key topics: three.js point cloud, lidar viewer, las file, ply loader, asprs classification, gis, 3d scanning

What this code does

- Synthetic Scan: wavy scan lines take the first return over terrain, roofs, tree canopies, a road and a pond, with some last returns through foliage.
- Occlusion Shadows: the empty patches beside buildings are footprints the laser never reached from above, just like real airborne data.
- ASPRS Classes: ground (2), high vegetation (5), building (6), water (9) and road surface (11) can each be toggled.
- GPU Filtering: class masks and the height clip set gl_PointSize to 0 in the vertex shader, so no buffers are rebuilt.
- File Loading: LAS 1.0–1.4 (point formats 0–3 and 6–8) is parsed with a `DataView`, PLY uses `PLYLoader` and XYZ is plain text; all files stay in the browser.
- Controls: color mode, point size, height clip, class toggles, scan spacing, new scene and file loading.

Continue Learning

JavaScript Implementation

ES6+
// Points with per-point classification → color, filtered in the vertex shader
const n = 200000
const positions = new Float32Array(n * 3)
const classes = new Float32Array(n)
for (let i = 0; i < n; i++) {
  const x = (Math.random() - 0.5) * 200
  const z = (Math.random() - 0.5) * 200
  const isBuilding = Math.abs(x % 40) < 12 && Math.abs(z % 40) < 12
  positions.set([x, isBuilding ? 15 : Math.sin(x / 20) * 3, z], i * 3)
  classes[i] = isBuilding ? 6 : 2 // ASPRS: 2 ground, 6 building
}
const geometry = new THREE.BufferGeometry()
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3))
geometry.setAttribute('aClass', new THREE.BufferAttribute(classes, 1))

const material = new THREE.ShaderMaterial({
  uniforms: { uShowBuildings: { value: 1 } },
  vertexShader: `
    attribute float aClass; uniform float uShowBuildings; varying vec3 vColor;
    void main () {
      bool building = aClass > 5.5;
      vColor = building ? vec3(0.94, 0.27, 0.27) : vec3(0.63, 0.38, 0.03);
      vec4 mv = modelViewMatrix * vec4(position, 1.0);
      gl_PointSize = (building && uShowBuildings < 0.5) ? 0.0 : 200.0 / -mv.z;
      gl_Position = projectionMatrix * mv;
    }`,
  fragmentShader: 'varying vec3 vColor; void main () { if (length(gl_PointCoord - 0.5) > 0.5) discard; gl_FragColor = vec4(vColor, 1.0); }'
})
scene.add(new THREE.Points(geometry, material))