From ed12267bfef13941d354b34939e178417f0fadd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Gonz=C3=A1lez=20Viegas?= Date: Tue, 29 Oct 2024 21:51:20 +0100 Subject: [PATCH] fix(core): make geometry tiler split geometries according to limit --- packages/core/package.json | 2 +- .../src/fragments/IfcGeometryTiler/index.ts | 28 +++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 20a48950..02ef6549 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,7 +1,7 @@ { "name": "@thatopen/components", "description": "Collection of core functionalities to author BIM apps.", - "version": "2.4.0-alpha.15", + "version": "2.4.0-alpha.17", "author": "That Open Company", "contributors": [ "Antonio Gonzalez Viegas (https://github.com/agviegas)", diff --git a/packages/core/src/fragments/IfcGeometryTiler/index.ts b/packages/core/src/fragments/IfcGeometryTiler/index.ts index 4507d56f..6fbe4e30 100644 --- a/packages/core/src/fragments/IfcGeometryTiler/index.ts +++ b/packages/core/src/fragments/IfcGeometryTiler/index.ts @@ -502,19 +502,29 @@ export class IfcGeometryTiler extends Component implements Disposable { } private async streamGeometries() { - let buffer = this._streamSerializer.export(this._geometries) as Uint8Array; + const exportMap: typeof this._geometries = new Map(); - let data: StreamedGeometries = {}; + // Split geometries to control the maximum size of fragment files + for (const [id, value] of this._geometries) { + exportMap.set(id, value); - for (const [id, { boundingBox, hasHoles }] of this._geometries) { - data[id] = { boundingBox, hasHoles }; - } + if (exportMap.size > this.settings.minGeometrySize) { + let buffer = this._streamSerializer.export(exportMap) as Uint8Array; + let data: StreamedGeometries = {}; + + for (const [id, { boundingBox, hasHoles }] of exportMap) { + data[id] = { boundingBox, hasHoles }; + } - await this.onGeometryStreamed.trigger({ data, buffer }); + await this.onGeometryStreamed.trigger({ data, buffer }); + + // Force memory disposal of all created items + data = null as any; + buffer = null as any; + exportMap.clear(); + } + } - // Force memory disposal of all created items - data = null as any; - buffer = null as any; this._geometries.clear(); this._geometryCount = 0; }