Skip to content

Commit

Permalink
fix: Fix the issue of creating frames
Browse files Browse the repository at this point in the history
  • Loading branch information
Original-Recipe committed Oct 17, 2024
1 parent 1322f7c commit 0c19d61
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/lb-annotation/src/core/pointCloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof setTimeout> | null = null;

constructor({
container,
noAppend,
Expand Down Expand Up @@ -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 });
};
});
Expand Down

0 comments on commit 0c19d61

Please sign in to comment.