diff --git a/packages/lb-annotation/src/core/pointCloud/index.ts b/packages/lb-annotation/src/core/pointCloud/index.ts index 09c7ddcf..c1094785 100644 --- a/packages/lb-annotation/src/core/pointCloud/index.ts +++ b/packages/lb-annotation/src/core/pointCloud/index.ts @@ -159,10 +159,12 @@ export class PointCloud extends EventListener { private hiddenText = false; - private filterBoxWorker: Worker; + private filterBoxWorker: Worker | null; private geometry: THREE.BufferGeometry; + private filterBoxWorkerTimer: ReturnType | null = null; + constructor({ container, noAppend, @@ -815,18 +817,29 @@ export class PointCloud extends EventListener { }; if (!this.filterBoxWorker) { - return Promise.resolve(undefined); + this.filterBoxWorker = new FilterBoxWorker(); } return new Promise((resolve) => { - this.filterBoxWorker.postMessage(params); - this.filterBoxWorker.onmessage = (e: any) => { + this.filterBoxWorker?.postMessage(params); + this.filterBoxWorker!.onmessage = (e: any) => { const { color: newColor, position: newPosition, num } = e.data; this.geometry.dispose(); this.geometry.setAttribute('position', new THREE.Float32BufferAttribute(newPosition, 3)); this.geometry.setAttribute('color', new THREE.Float32BufferAttribute(newColor, 3)); this.geometry.computeBoundingSphere(); - this.filterBoxWorker.terminate(); + + if (this.filterBoxWorkerTimer) { + clearTimeout(this.filterBoxWorkerTimer); + } + + this.filterBoxWorkerTimer = setTimeout(() => { + if (this.filterBoxWorker) { + this.filterBoxWorker.terminate(); + this.filterBoxWorker = null; + } + }, 3000); + resolve({ geometry: this.geometry, num }); }; });