Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use elevation property to clip overlapping bounding boxes #1741

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/plugins/StoreyViewsPlugin/StoreyViewsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,43 @@ class StoreyViewsPlugin extends Plugin {
this.modelStoreys[modelId][storeyId] = storey;
}
}
this._clipBoundingBoxes();
}

_clipBoundingBoxes() {
const storeysList = this.storeysList;
const metaScene = this.viewer.metaScene;
const camera = this.viewer.camera;
const worldUp = camera.worldUp;
const xUp = worldUp[0] > worldUp[1] && worldUp[0] > worldUp[2];
const yUp = !xUp && worldUp[1] > worldUp[0] && worldUp[1] > worldUp[2];
const zUp = !xUp && !yUp && worldUp[2] > worldUp[0] && worldUp[2] > worldUp[1];

let bbIndex;

if(xUp) bbIndex = 0;
else if(yUp) bbIndex = 1;
else bbIndex = 2;

for (let i = 0, len = storeysList.length; i < len; i++) {

const storeyMetaObjectCur = metaScene.metaObjects[storeysList[i].storeyId];
const elevationCur = storeyMetaObjectCur.attributes.elevation;

if(isNaN(elevationCur)) return;

const bb = storeysList[i].storeyAABB;
bb[bbIndex] = Math.max(bb[1], parseFloat(elevationCur) / 1000);

if (i > 0) {
const storeyMetaObjectNext = metaScene.metaObjects[storeysList[i - 1].storeyId];
const elevationNext = storeyMetaObjectNext.attributes.elevation;
bb[4] = Math.min(bb[bbIndex + 3], parseFloat(elevationNext) / 1000);
}

this.storeys[storeysList[i].storeyId].storeyAABB = bb;
}

}

_deregisterModelStoreys(modelId) {
Expand Down
Loading