Search code examples
point-clouds

Get all points from pointcloud where pointcloud is new Potree.PointCloudOctree(geometry)


I use potree to view my model i want to get list of all points in pointcloud to add event to each point depending on its index. Can I get list of all points without using measurement tools ? i want to get points from pointcloud

 Potree.loadPointCloud(cloudPointsPath, "name", e => {
                var pointcloud = e.pointcloud;
                var material = pointcloud.material;
                viewer.scene.addPointCloud(pointcloud);
                material.pointColorType = Potree.PointColorType.RGB;
                material.size = 1;
                material.pointSizeType = Potree.PointSizeType.FIXED;
                material.shape = Potree.PointShape.PARABOLOI;
                viewer.fitToScreen();
            });


Solution

  • I got list of points using this code

     function getAllPointsOfPointCloud(pointCloud) {
                var list = [];
                var array = pointCloud.pcoGeometry.root.geometry.attributes.position.array;
                var index = 0;
                for (var i = 0; i < pointCloud.pcoGeometry.root.geometry.attributes.position.length;i=i+3) {
                    var x = array[i + 0];
                    var y = array[i+ 1];
                    var z = array[i + 2];
                    let position = new THREE.Vector3(x, y, z);
                    position.applyMatrix4(pointCloud.matrixWorld);
                    list[index] = position;
                    index++;
                }
                return list;
            }