Skip to content

Commit

Permalink
feat(front): misc improvements to streamer
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Jul 28, 2024
1 parent a18a5b6 commit 4abff07
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/front/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thatopen/components-front",
"description": "Collection of frontend tools to author BIM apps.",
"version": "2.1.10",
"version": "2.1.11",
"author": "That Open Company",
"contributors": [
"Antonio Gonzalez Viegas (https://github.com/agviegas)",
Expand Down
53 changes: 35 additions & 18 deletions packages/front/src/fragments/IfcStreamer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {
this.components.add(IfcStreamer.uuid, this);
this.dbCleaner = new StreamerDbCleaner(this._fileCache);

const fragments = this.components.get(OBC.FragmentsManager);
fragments.onFragmentsDisposed.add(this.disposeStreamedGroup);

// const hardlyGeometry = new THREE.BoxGeometry();
// this._hardlySeenGeometries = new THREE.InstancedMesh();
}
Expand All @@ -184,6 +187,9 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {

this._ramCache.clear();

const fragments = this.components.get(OBC.FragmentsManager);
fragments.onFragmentsDisposed.remove(this.disposeStreamedGroup);

this.models = {};
this._geometryInstances = {};
// Disposed by fragment manager
Expand Down Expand Up @@ -221,6 +227,10 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {
const groupBuffer = new Uint8Array(groupArrayBuffer);
const fragments = this.components.get(OBC.FragmentsManager);
const group = fragments.load(groupBuffer, { coordinate });

group.name = globalDataFileId.replace("-processed-global", "");

group.isStreamed = true;
this.world.scene.three.add(group);

const { opaque, transparent } = group.geometryIDs;
Expand Down Expand Up @@ -306,29 +316,15 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {
* Removes a fragment group from the scene.
*
* @param modelID - The unique identifier of the fragment group to remove.
*
* @deprecated use OBC.FragmentsManager.disposeGroup instead.
*/
remove(modelID: string) {
this._isDisposing = true;

const fragments = this.components.get(OBC.FragmentsManager);
const group = fragments.groups.get(modelID);
if (group === undefined) {
console.log("Group to delete not found.");
return;
}

delete this.models[modelID];
delete this._geometryInstances[modelID];
delete this._loadedFragments[modelID];

const ids = group.keyFragments.values();
for (const id of ids) {
this.fragIDData.delete(id);
if (group) {
fragments.disposeGroup(group);
}

this.culler.remove(modelID);

this._isDisposing = false;
}

/**
Expand Down Expand Up @@ -698,4 +694,25 @@ export class IfcStreamer extends OBC.Component implements OBC.Disposable {

result.push(fragment);
}

private disposeStreamedGroup = (data: {
groupID: string;
fragmentIDs: string[];
}) => {
this._isDisposing = true;

const { groupID, fragmentIDs } = data;

delete this.models[groupID];
delete this._geometryInstances[groupID];
delete this._loadedFragments[groupID];

for (const id of fragmentIDs) {
this.fragIDData.delete(id);
}

this.culler.remove(groupID);

this._isDisposing = false;
};
}

0 comments on commit 4abff07

Please sign in to comment.