Skip to content

Commit

Permalink
chore: remove unused Potree code (#4942)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonflatval-cognite authored Dec 11, 2024
1 parent bb694a9 commit c7a7033
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 59 deletions.
39 changes: 8 additions & 31 deletions viewer/packages/pointclouds/src/potree-three-loader/Potree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -47,7 +46,7 @@ type VisibilityUpdateInfo = {
exceededMaxLoadsToGPU: boolean;
nodeLoadFailed: boolean;
numVisiblePoints: number;
unloadedGeometry: IPointCloudTreeGeometryNode[];
notLoadedGeometry: IPointCloudTreeGeometryNode[];
visibleNodes: IPointCloudTreeNodeBase[];
priorityQueue: BinaryHeap<QueueItem>;
};
Expand Down Expand Up @@ -146,7 +145,6 @@ export class Potree implements IPotree {

pointCloud.material.updateMaterial(octreeMaterialParams, visibilityTextureData, camera);
pointCloud.updateVisibleBounds();
pointCloud.updateBoundingBoxes();
}

this.lru.freeMemory();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -254,7 +252,7 @@ export class Potree implements IPotree {
exceededMaxLoadsToGPU: false,
nodeLoadFailed: false,
numVisiblePoints: 0,
unloadedGeometry: [],
notLoadedGeometry: [],
visibleNodes: [],
priorityQueue
};
Expand Down Expand Up @@ -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<void>[] = [];
for (let i = 0; i < numNodesToLoad; i++) {
nodeLoadPromises.push(
updateInfo.unloadedGeometry[i].load().then(() => {
updateInfo.notLoadedGeometry[i].load().then(() => {
this._throttledUpdateFunc(pointClouds, camera, renderer);
})
);
Expand All @@ -314,8 +312,6 @@ export class Potree implements IPotree {

visibleNodes.push(node);
pointCloud.visibleNodes.push(node);

this.updateBoundingBoxVisibility(pointCloud, node);
}

private updateChildVisibility(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export interface IPointCloudTreeNodeBase {
numPoints: number;
isTreeNode: boolean;

boundingBoxNode?: THREE.Object3D;

readonly children: Array<IPointCloudTreeNodeBase | null>;
readonly isLeafNode: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down

0 comments on commit c7a7033

Please sign in to comment.