Potree Core 2.0

repository·master·Indexed 42 days ago

https://github.com/tentone/potree-core

A lightweight, independent library for visualizing large-scale point clouds in web browsers using Three.js. Version 2.0.15 provides core loading and rendering capabilities, including advanced clipping with boxes, spheres, and planes, and specialized materials like EyeDomeLighting and various color gradients, while removing the heavy GUI elements of the original Potree Viewer.

Tokens
2K
Snippets
6
Records
8
Agent score
4%

What's inside Potree Core

  1. How clipping works with boxes, spheres, and planes

    master

    Potree Core uses a unified visibility rule for clipping. Clipping volumes can be defined as include (keep what is inside) or exclude (remove what is inside).

    Clipping Modes

    • ClipMode.DISABLED: A global master switch that disables all clipping/highlighting.
    • include: Clip-outside semantics (the volume's interior remains visible).
    • exclude: Clip-inside semantics (the volume's interior is removed).
    • If a volume's mode is undefined, it inherits the global pco.material.clipMode.
    • ClipMode.HIGHLIGHT_INSIDE: Highlights the interior without changing visibility.

    Clipping Primitives

    1. Clip Boxes: Created via createClipBox(size, position, mode?). Returns an IClipBox.
    2. Clip Spheres: Created via createClipSphere(center, radius, mode?). Returns an IClipSphere.
    3. Clip Planes: These do not have individual modes; they always use the inherited global material mode. They are evaluated as insideAllPlanes (point is on the positive side of all planes).

    To apply clipping to a point cloud, use pco.material.setClipBoxes([...]) or pco.material.setClipSpheres([...]).

    import { ClipMode, createClipBox, createClipSphere } from 'potree-core';
    import { Vector3 } from 'three';
    
    // Set global fallback
    pco.material.clipMode = ClipMode.CLIP_OUTSIDE;
    
    // Clip Boxes
    const includeA = createClipBox(new Vector3(10, 10, 10), new Vector3(0, 0, 0), 'include');
    const excludeB = createClipBox(new Vector3(4, 4, 4), new Vector3(0, 0, 0), 'exclude');
    const inheritedD = createClipBox(new Vector3(3, 3, 3), new Vector3(-3, 0, 0)); // inherits CLIP_OUTSIDE
    pco.material.setClipBoxes([includeA, excludeB, inheritedD]);
    
    // Clip Spheres
    pco.material.clipMode = ClipMode.HIGHLIGHT_INSIDE;
    const sphereA = createClipSphere(new Vector3(0, 1, 0), 3, 'exclude');
    const sphereB = createClipSphere(new Vector3(5, 1, 0), 2); // inherits HIGHLIGHT_INSIDE
    pco.material.setClipSpheres([sphereA, sphereB]);
  2. Install and integrate Potree Core

    master

    Potree Core is an ES module that can be imported into other projects.

    Prerequisites

    • three.js: Must be available as a peer dependency.
    • Worker Files: You must include the worker folder (found in the source folder) alongside the build in your project directory.
    • GL Extensions: Some features require EXT_frag_depth, WEBGL_depth_texture, and OES_vertex_array_object.

    Installation

    You can add it to your project using NPM or download the build from the build folder.

    To build the project from source:

    npm install
    npm run build
  3. Convert text files to LAS/LAZ using TXT2LAS

    master

    Potree Converter only supports LAS and LAZ files. If you have text-based formats like .pts or .xyz, you must first convert them using the txt2las64 tool from the LAStools repository.

    .\txt2las64 -i input.pts -ipts -parse xyziRGB  -set_scale 0.001 0.001 0.001 -set_version 1.4 -o output.laz
  4. Prepare point cloud data with Potree Converter

    master

    Potree Core requires a specific hierarchical structure to render point clouds. Use the Potree Converter to convert LAS, LAZ, or BIN files into this format.

    Usage

    To generate a folder output from an input file:

    .\PotreeConverter '..\input.laz' -o ../output

    Version Differences

    • v1.8: Creates a multi-file structure where each node is an individual file.
    • v2.1: Creates a single file for all points and separate files for the hierarchy index. This version is faster but requires an HTTP server configured for file streaming.
  5. Load a Potree point cloud in Three.js

    master

    To use Potree Core, instantiate the Potree class, use loadPointCloud to fetch your data, and call updatePointClouds within your animation loop to ensure the point cloud is rendered and updated relative to the camera and renderer.

    Note that loadPointCloud accepts a URL and a callback function to resolve the base URL (e.g., to prepend a base path).

    const scene = new Scene();
    const camera = new PerspectiveCamera(60, 1, 0.1, 10000);
    const canvas = document.getElementById("canvas");
    const renderer = new WebGLRenderer({canvas:canvas});
    
    // ... setup scene objects ...
    
    const pointClouds = [];
    const baseUrl = "data/test/";
    const potree = new Potree();
    
    // Load the point cloud
    potree.loadPointCloud("cloud.js", url => `${baseUrl}${url}`,).then(function(pco) {
       scene.add(pco);
       pointClouds.push(pco);
    });
    
    function loop()
    {
       // Crucial: Update point clouds every frame
       potree.updatePointClouds(pointClouds, camera, renderer);
    
       renderer.render(scene, camera);
       requestAnimationFrame(loop);
    };
    loop();
  6. Implement a Custom Request Manager

    master

    The library uses a custom request manager to handle point cloud data loading. You can replace this with your own implementation (e.g., for custom caching or specialized request handling) by implementing the RequestManager interface.

    class CustomRequestManager implements RequestManager 
    {
       fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
          throw new Error("Method not implemented.")
       }
    
       async getUrl(url: string): Promise<string> {
          return url;
       }
    }
  7. Access Point Cloud Materials and Shading API

    master

    The source/materials/index.ts module serves as the central entry point for all point cloud material, shading, and texture generation capabilities in Potree Core. It aggregates several specialized modules:

    • Core Materials: PointcloudMaterial and related shading logic.
    • Lighting & Effects: EyeDomeLightingMaterial and BlurMaterial for advanced visual effects.
    • Clipping: Tools for clipping point clouds using boxes, spheres, or planes.
    • Visual Styling: Gradients and TextureGeneration for custom point coloring and appearance.
    • Types & Enums: All supporting TypeScript types and enumerations used for configuring materials.