Visitar URL original
feat(front): implement fragment load cancel · ThatOpen/engine_components@f9b8b4e · GitHub
Skip to content

Commit f9b8b4e

Browse files
committed
feat(front): implement fragment load cancel
1 parent 8be541e commit f9b8b4e

4 files changed

Lines changed: 84 additions & 30 deletions

File tree

‎packages/front/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thatopen/components-front",
33
"description": "Collection of frontend tools to author BIM apps.",
4-
"version": "2.3.0-alpha.10",
4+
"version": "2.3.0-alpha.11",
55
"author": "That Open Company",
66
"contributors": [
77
"Antonio Gonzalez Viegas (https://github.com/agviegas)",

‎packages/front/src/fragments/IfcStreamer/index.ts‎

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {
6565
*/
6666
useCache = true;
6767

68+
/**
69+
* Flag to cancel the files that are being currently loaded.
70+
*/
71+
cancel = false;
72+
6873
fetch = async (fileName: string): Promise<Response | File> => {
6974
return fetch(this.url + fileName);
7075
};
@@ -422,8 +427,28 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {
422427
},
423428
visible = true,
424429
) {
430+
this.cancel = false;
431+
432+
const cancelled: { [modelID: string]: Set<number> } = {};
433+
for (const modelID in seen) {
434+
const idsOfModel = new Set<number>();
435+
for (const [, ids] of seen[modelID]) {
436+
for (const id of ids) {
437+
idsOfModel.add(id);
438+
}
439+
}
440+
cancelled[modelID] = idsOfModel;
441+
}
442+
425443
for (const modelID in seen) {
426-
if (this._isDisposing) return;
444+
if (this._isDisposing) {
445+
return;
446+
}
447+
448+
if (this.cancel) {
449+
this.cancelLoading(cancelled);
450+
return;
451+
}
427452

428453
const fragments = this.components.get(OBC.FragmentsManager);
429454
const group = fragments.groups.get(modelID);
@@ -441,6 +466,11 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {
441466

442467
for (const [priority, ids] of seen[modelID]) {
443468
for (const id of ids) {
469+
if (this.cancel) {
470+
this.cancelLoading(cancelled);
471+
return;
472+
}
473+
444474
allIDs.add(id);
445475
const geometry = geometries[id];
446476
if (!geometry) {
@@ -449,6 +479,7 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {
449479
if (geometry.geometryFile) {
450480
const file = geometry.geometryFile;
451481
const value = files.get(file) || 0;
482+
// This adds up the pixels of all fragments in a file to determine its priority
452483
files.set(file, value + priority);
453484
}
454485
}
@@ -497,7 +528,17 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {
497528

498529
if (result) {
499530
for (const [geometryID, { position, index, normal }] of result.data) {
500-
if (this._isDisposing) return;
531+
if (this._isDisposing) {
532+
return;
533+
}
534+
535+
if (this.cancel) {
536+
this.cancelLoading(cancelled);
537+
return;
538+
}
539+
540+
// This fragment can be cancelled, it will be loaded
541+
cancelled[modelID].delete(geometryID);
501542

502543
if (!allIDs.has(geometryID)) continue;
503544

@@ -759,4 +800,9 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {
759800

760801
this._isDisposing = false;
761802
};
803+
804+
private cancelLoading(items: { [modelID: string]: Set<number> }) {
805+
this.cancel = false;
806+
this.culler.cancel(items);
807+
}
762808
}

‎packages/front/src/fragments/IfcStreamer/src/geometry-culler-renderer.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,31 @@ export class GeometryCullerRenderer extends OBC.CullerRenderer {
516516
}
517517
}
518518

519+
cancel(items: { [modelID: string]: Set<number> }) {
520+
for (const modelID in items) {
521+
const modelIndex = this._modelIDIndex.get(modelID);
522+
if (modelIndex === undefined) {
523+
throw new Error("Model not found.");
524+
}
525+
const map = this.codes.get(modelIndex);
526+
if (map === undefined) {
527+
throw new Error("Codes not found.");
528+
}
529+
for (const id of items[modelID]) {
530+
const colorCode = map.get(id);
531+
if (colorCode === undefined) {
532+
throw new Error("Color code not found.");
533+
}
534+
this._geometriesInMemory.delete(colorCode);
535+
const found = this._geometries.get(colorCode);
536+
if (!found) {
537+
throw new Error("Geometry not found.");
538+
}
539+
found.exists = false;
540+
}
541+
}
542+
}
543+
519544
private setGeometryVisibility(
520545
geometry: CullerBoundingBox,
521546
visible: boolean,
@@ -545,7 +570,6 @@ export class GeometryCullerRenderer extends OBC.CullerRenderer {
545570
const colors = event.data.colors as Map<string, number>;
546571

547572
const toLoad: { [modelID: string]: Map<number, Set<number>> } = {};
548-
549573
const toRemove: { [modelID: string]: Set<number> } = {};
550574
const toHide: { [modelID: string]: Set<number> } = {};
551575
const toShow: { [modelID: string]: Set<number> } = {};

‎yarn.lock‎

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ __metadata:
621621
version: 0.0.0-use.local
622622
resolution: "@thatopen/components-front@workspace:packages/front"
623623
dependencies:
624-
"@thatopen/components": 2.3.0-alpha.1
625-
"@thatopen/fragments": 2.3.0-alpha.1
624+
"@thatopen/components": ">=2.3.0-alpha"
625+
"@thatopen/fragments": ">=2.3.0-alpha"
626626
"@thatopen/ui": ~2.2.0
627627
"@thatopen/ui-obc": ~2.2.0
628628
"@types/earcut": ^2.1.4
@@ -635,33 +635,17 @@ __metadata:
635635
three: ^0.160.1
636636
web-ifc: 0.0.57
637637
peerDependencies:
638-
"@thatopen/fragments": 2.3.0-alpha.1
638+
"@thatopen/fragments": ">=2.3.0-alpha"
639639
three: ^0.160.1
640640
web-ifc: 0.0.57
641641
languageName: unknown
642642
linkType: soft
643643

644-
"@thatopen/components@npm:2.3.0-alpha.1":
645-
version: 2.3.0-alpha.1
646-
resolution: "@thatopen/components@npm:2.3.0-alpha.1"
647-
dependencies:
648-
camera-controls: 2.7.3
649-
fast-xml-parser: 4.4.1
650-
jszip: 3.10.1
651-
three-mesh-bvh: 0.7.0
652-
peerDependencies:
653-
"@thatopen/fragments": ~2.2.0
654-
three: ^0.160.1
655-
web-ifc: 0.0.57
656-
checksum: 00faa025507aacf82be2f9388bb6f65abc3d57565b4d540d4ee7e9a621b3e7bb9983798f83b041d46f59dedadd25627f1a58be112316333f33edc53e329f90b3
657-
languageName: node
658-
linkType: hard
659-
660-
"@thatopen/components@workspace:packages/core":
644+
"@thatopen/components@>=2.3.0-alpha, @thatopen/components@workspace:packages/core":
661645
version: 0.0.0-use.local
662646
resolution: "@thatopen/components@workspace:packages/core"
663647
dependencies:
664-
"@thatopen/fragments": 2.3.0-alpha.1
648+
"@thatopen/fragments": ">=2.3.0-alpha"
665649
"@thatopen/ui": ~2.2.0
666650
"@types/three": 0.160.0
667651
camera-controls: 2.7.3
@@ -672,21 +656,21 @@ __metadata:
672656
three-mesh-bvh: 0.7.0
673657
web-ifc: 0.0.57
674658
peerDependencies:
675-
"@thatopen/fragments": 2.3.0-alpha.1
659+
"@thatopen/fragments": ">=2.3.0-alpha"
676660
three: ^0.160.1
677661
web-ifc: 0.0.57
678662
languageName: unknown
679663
linkType: soft
680664

681-
"@thatopen/fragments@npm:2.3.0-alpha.1":
682-
version: 2.3.0-alpha.1
683-
resolution: "@thatopen/fragments@npm:2.3.0-alpha.1"
665+
"@thatopen/fragments@npm:>=2.3.0-alpha":
666+
version: 2.3.0-alpha.2
667+
resolution: "@thatopen/fragments@npm:2.3.0-alpha.2"
684668
dependencies:
685669
flatbuffers: 23.3.3
686670
three-mesh-bvh: 0.7.0
687671
peerDependencies:
688672
three: ^0.160.1
689-
checksum: a2263a03cfee1800372e733983417978c344677382574549898a402efa1a40c0387b2d756d40accd2e2bfbd4449d91e314e11791511734344cf380bdf86457a1
673+
checksum: 537887ffe869e0618c50f668c8513d91b3605810e7ed1355e9cf6ca3c83154e823b8461bc0d90ad72c011f4645689963b9e052f76f746663dc547e5374937832
690674
languageName: node
691675
linkType: hard
692676

0 commit comments

Comments
 (0)