Display a Potree point cloud.

100% © Potree
index.js
import { Vector3 } from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';

import Instance from '@giro3d/giro3d/core/Instance.js';
import PotreePointCloud from '@giro3d/giro3d/entities/PotreePointCloud.js';
import Inspector from '@giro3d/giro3d/gui/Inspector.js';
import PotreeSource from '@giro3d/giro3d/sources/PotreeSource.js';

const viewerDiv = document.getElementById('viewerDiv');

const source = new PotreeSource(
    'https://3d.oslandia.com/potree/pointclouds/lion_takanawa',
    'cloud.js',
);

const potree = new PotreePointCloud('potree', source);

const instance = new Instance(viewerDiv, { crs: 'EPSG:3857', renderer: { clearColor: 'bisque' } });

function placeCamera() {
    const camera = instance.camera.camera3D;

    // create controls
    const controls = new OrbitControls(camera, instance.domElement);
    controls.enableDamping = true;
    controls.dampingFactor = 0.25;

    const pos = new Vector3(6.757520397934977, -10.102934086721376, 7.402449241148831);

    const lookAt = new Vector3(0.5, 0.5, 5);

    camera.lookAt(lookAt);
    controls.target.copy(lookAt);
    camera.position.copy(pos);

    instance.useTHREEControls(controls);
    
}

instance.add(potree).then(placeCamera);
instance.notifyChange(instance.camera.camera3D);

Inspector.attach(document.getElementById('panelDiv'), instance);

instance.domElement.addEventListener('dblclick', e => {
    console.log(instance.pickObjectsAt(e, { radius: 5, limit: 10 }));
});
index.html
<!doctype html>
<html lang="en">
    <head>
        <title>Potree Point Cloud</title>
        <meta charset="UTF-8" />
        <meta name="name" content="potree_pointcloud" />
        <meta name="description" content="Display a Potree point cloud." />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <link rel="icon" href="https://giro3d.org/images/favicon.svg" />
        <link href="https://giro3d.org/assets/bootstrap-custom.css" rel="stylesheet" />
        <script src="https://giro3d.org/assets/bootstrap.bundle.min.js"></script>
        <link
            rel="stylesheet"
            type="text/css"
            href="https://giro3d.org/latest/css/example.css"
        />

        
    </head>

    <body>
        <div id="viewerDiv" class="m-0 p-0 w-100 h-100"></div>
        <div id="panelDiv" class="position-absolute top-0 start-0 mh-100 overflow-auto"></div>

        

        <script type="module" src="index.js"></script>
        <script>
            /* activate popovers */
            const popoverTriggerList = [].slice.call(
                document.querySelectorAll('[data-bs-toggle="popover"]'),
            );
            popoverTriggerList.map(
                // bootstrap is used as script in the template, disable warning about undef
                // eslint-disable-next-line no-undef
                popoverTriggerEl =>
                    new bootstrap.Popover(popoverTriggerEl, {
                        trigger: 'hover',
                        placement: 'left',
                        content: document.getElementById(
                            popoverTriggerEl.getAttribute('data-bs-content'),
                        ).innerHTML,
                        html: true,
                    }),
            );
        </script>
    </body>
</html>
package.json
{
    "name": "potree_pointcloud",
    "dependencies": {
        "@giro3d/giro3d": "0.37.2"
    },
    "devDependencies": {
        "vite": "^3.2.3"
    },
    "scripts": {
        "start": "vite",
        "build": "vite build"
    }
}