From 0c19d6104e15c24f183551c64c9b1ecdd19e61de Mon Sep 17 00:00:00 2001 From: Original-Recipe-Chicken Date: Thu, 17 Oct 2024 19:20:52 +0800 Subject: [PATCH] fix: Fix the issue of creating frames --- .../src/core/pointCloud/index.ts | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) 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 }); }; });