From c7a7033eb1954d6f679f6f16afdc1bc5d97f30f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= <70905152+haakonflatval-cognite@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:16:44 +0100 Subject: [PATCH] chore: remove unused Potree code (#4942) --- .../src/potree-three-loader/Potree.ts | 39 ++++--------------- .../tree/IPointCloudTreeNodeBase.ts | 2 - .../tree/PointCloudOctree.ts | 24 ------------ .../tree/PointCloudOctreeNode.ts | 3 +- 4 files changed, 9 insertions(+), 59 deletions(-) diff --git a/viewer/packages/pointclouds/src/potree-three-loader/Potree.ts b/viewer/packages/pointclouds/src/potree-three-loader/Potree.ts index f71c32d0f25..069d0762d73 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/Potree.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/Potree.ts @@ -27,7 +27,6 @@ import { IPointCloudTreeNodeBase } from './tree/IPointCloudTreeNodeBase'; import { IPointCloudTreeNode } from './tree/IPointCloudTreeNode'; import { IPointCloudTreeGeometryNode } from './geometry/IPointCloudTreeGeometryNode'; import { BinaryHeap } from './utils/BinaryHeap'; -import { Box3Helper } from './utils/box3-helper'; import { LRU } from './utils/lru'; import { ModelDataProvider, StylableObject } from '@reveal/data-providers'; import throttle from 'lodash/throttle'; @@ -47,7 +46,7 @@ type VisibilityUpdateInfo = { exceededMaxLoadsToGPU: boolean; nodeLoadFailed: boolean; numVisiblePoints: number; - unloadedGeometry: IPointCloudTreeGeometryNode[]; + notLoadedGeometry: IPointCloudTreeGeometryNode[]; visibleNodes: IPointCloudTreeNodeBase[]; priorityQueue: BinaryHeap; }; @@ -146,7 +145,6 @@ export class Potree implements IPotree { pointCloud.material.updateMaterial(octreeMaterialParams, visibilityTextureData, camera); pointCloud.updateVisibleBounds(); - pointCloud.updateBoundingBoxes(); } this.lru.freeMemory(); @@ -201,7 +199,7 @@ export class Potree implements IPotree { if (node.loaded && updateInfo.loadedToGPUThisFrame >= MAX_LOADS_TO_GPU) { updateInfo.exceededMaxLoadsToGPU = true; } - updateInfo.unloadedGeometry.push(node); + updateInfo.notLoadedGeometry.push(node); pointCloud.visibleGeometry.push(node); } else { updateInfo.nodeLoadFailed = true; @@ -254,7 +252,7 @@ export class Potree implements IPotree { exceededMaxLoadsToGPU: false, nodeLoadFailed: false, numVisiblePoints: 0, - unloadedGeometry: [], + notLoadedGeometry: [], visibleNodes: [], priorityQueue }; @@ -287,11 +285,11 @@ export class Potree implements IPotree { this.updateVisibilityForNode(node, updateInfo, queueItem, sceneParams); } // end priority queue loop - const numNodesToLoad = Math.min(this.maxNumNodesLoading, updateInfo.unloadedGeometry.length); + const numNodesToLoad = Math.min(this.maxNumNodesLoading, updateInfo.notLoadedGeometry.length); const nodeLoadPromises: Promise[] = []; for (let i = 0; i < numNodesToLoad; i++) { nodeLoadPromises.push( - updateInfo.unloadedGeometry[i].load().then(() => { + updateInfo.notLoadedGeometry[i].load().then(() => { this._throttledUpdateFunc(pointClouds, camera, renderer); }) ); @@ -314,8 +312,6 @@ export class Potree implements IPotree { visibleNodes.push(node); pointCloud.visibleNodes.push(node); - - this.updateBoundingBoxVisibility(pointCloud, node); } private updateChildVisibility( @@ -364,21 +360,6 @@ export class Potree implements IPotree { } } - private updateBoundingBoxVisibility(pointCloud: PointCloudOctree, node: IPointCloudTreeNode): void { - if (pointCloud.showBoundingBox && !node.boundingBoxNode) { - const boxHelper = new Box3Helper(node.boundingBox); - boxHelper.matrixAutoUpdate = false; - pointCloud.boundingBoxNodes.push(boxHelper); - node.boundingBoxNode = boxHelper; - node.boundingBoxNode.matrix.copy(pointCloud.matrixWorld); - } else if (pointCloud.showBoundingBox && node.boundingBoxNode) { - node.boundingBoxNode.visible = true; - node.boundingBoxNode.matrix.copy(pointCloud.matrixWorld); - } else if (!pointCloud.showBoundingBox && node.boundingBoxNode) { - node.boundingBoxNode.visible = false; - } - } - private readonly updateVisibilityStructures = (() => { const frustumMatrix = new Matrix4(); const inverseWorldMatrix = new Matrix4(); @@ -420,18 +401,14 @@ export class Potree implements IPotree { cameraMatrix.identity().multiply(inverseWorldMatrix).multiply(camera.matrixWorld); cameraPositions.push(new Vector3().setFromMatrixPosition(cameraMatrix)); - if (pointCloud.visible && pointCloud.root !== null) { + if (pointCloud.visible && pointCloud.root !== undefined) { const weight = Number.MAX_VALUE; - priorityQueue.push(new QueueItem(i, weight, pointCloud.root!)); + priorityQueue.push(new QueueItem(i, weight, pointCloud.root)); } // Hide any previously visible nodes. We will later show only the needed ones. if (isTreeNode(pointCloud.root)) { - pointCloud.hideDescendants(pointCloud.root!.sceneNode); - } - - for (const boundingBoxNode of pointCloud.boundingBoxNodes) { - boundingBoxNode.visible = false; + pointCloud.hideDescendants(pointCloud.root.sceneNode); } } diff --git a/viewer/packages/pointclouds/src/potree-three-loader/tree/IPointCloudTreeNodeBase.ts b/viewer/packages/pointclouds/src/potree-three-loader/tree/IPointCloudTreeNodeBase.ts index f953709de3e..7f74cb4756a 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/tree/IPointCloudTreeNodeBase.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/tree/IPointCloudTreeNodeBase.ts @@ -12,8 +12,6 @@ export interface IPointCloudTreeNodeBase { numPoints: number; isTreeNode: boolean; - boundingBoxNode?: THREE.Object3D; - readonly children: Array; readonly isLeafNode: boolean; diff --git a/viewer/packages/pointclouds/src/potree-three-loader/tree/PointCloudOctree.ts b/viewer/packages/pointclouds/src/potree-three-loader/tree/PointCloudOctree.ts index 5e37719aa5c..1b2c2a688ee 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/tree/PointCloudOctree.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/tree/PointCloudOctree.ts @@ -27,11 +27,9 @@ export class PointCloudOctree extends PointCloudTree { */ minNodePixelSize: number = DEFAULT_MIN_NODE_PIXEL_SIZE; root: IPointCloudTreeNodeBase | undefined = undefined; - boundingBoxNodes: Object3D[] = []; visibleNodes: IPointCloudTreeNode[] = []; visibleGeometry: IPointCloudTreeGeometryNode[] = []; numVisiblePoints: number = 0; - showBoundingBox: boolean = false; private readonly visibleBounds: Box3 = new Box3(); private picker: PointCloudOctreePicker | undefined; @@ -147,28 +145,6 @@ export class PointCloudOctree extends PointCloudTree { } } - updateBoundingBoxes(): void { - if (!this.showBoundingBox || !this.parent) { - return; - } - - let bbRoot: any = this.parent.getObjectByName('bbroot'); - if (!bbRoot) { - bbRoot = new Object3D(); - bbRoot.name = 'bbroot'; - this.parent.add(bbRoot); - } - - const visibleBoxes: (Object3D | null)[] = []; - for (const node of this.visibleNodes) { - if (node.boundingBoxNode !== undefined && node.isLeafNode) { - visibleBoxes.push(node.boundingBoxNode); - } - } - - bbRoot.children = visibleBoxes; - } - updateMatricesForDescendants(): void { this.traverseVisible(node => node.matrixWorld.multiplyMatrices(this.matrixWorld, node.matrix)); } diff --git a/viewer/packages/pointclouds/src/potree-three-loader/tree/PointCloudOctreeNode.ts b/viewer/packages/pointclouds/src/potree-three-loader/tree/PointCloudOctreeNode.ts index f0e08e3b528..03b8f40b065 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/tree/PointCloudOctreeNode.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/tree/PointCloudOctreeNode.ts @@ -1,4 +1,4 @@ -import { Box3, BufferGeometry, EventDispatcher, Object3D, Points, Sphere } from 'three'; +import { Box3, BufferGeometry, EventDispatcher, Points, Sphere } from 'three'; import { IPointCloudTreeGeometryNode } from '../geometry/IPointCloudTreeGeometryNode'; import { IPointCloudTreeNode } from './IPointCloudTreeNode'; import { IPointCloudTreeNodeBase } from './IPointCloudTreeNodeBase'; @@ -7,7 +7,6 @@ export class PointCloudOctreeNode extends EventDispatcher implements IPointCloud geometryNode: IPointCloudTreeGeometryNode; sceneNode: Points; pcIndex: number | undefined = undefined; - boundingBoxNode?: Object3D | undefined = undefined; readonly children: (IPointCloudTreeNodeBase | null)[]; readonly loaded = true; readonly isTreeNode: boolean = true;