Skip to content

Commit

Permalink
Merge pull request #1728 from xeokit/feature/storeys-with-model-id
Browse files Browse the repository at this point in the history
Add support for model ids when there are multiple models on the scene
  • Loading branch information
xeolabs authored Nov 6, 2024
2 parents 459f5a6 + 7b87bd0 commit af25f78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
30 changes: 20 additions & 10 deletions src/plugins/StoreyViewsPlugin/StoreyViewsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,10 @@ class StoreyViewsPlugin extends Plugin {
* @param {Number[]} worldPos 3D World-space position.
* @returns {String} ID of the storey containing the position, or null if the position falls outside all the storeys.
*/
getStoreyContainingWorldPos(worldPos) {
for (var storeyId in this.storeys) {
const storey = this.storeys[storeyId];
getStoreyContainingWorldPos(worldPos, modelId = null) {
const storeys = modelId ? this._filterStoreys(modelId) : this.storeys;
for (let storeyId in storeys) {
const storey = storeys[storeyId];
if (math.point3AABB3AbsoluteIntersect(storey.storeyAABB, worldPos)) {
return storeyId;
}
Expand All @@ -696,9 +697,10 @@ class StoreyViewsPlugin extends Plugin {
* @param {Number[]} worldPos 3D World-space position.
* @returns {String} ID of the storey containing the position, or null if the position falls outside all the storeys.
*/
getStoreyInVerticalRange(worldPos) {
for (let storeyId in this.storeys) {
const storey = this.storeys[storeyId];
getStoreyInVerticalRange(worldPos, modelId = null) {
const storeys = modelId ? this._filterStoreys(modelId) : this.storeys;
for (let storeyId in storeys) {
const storey = storeys[storeyId];
const aabb = [0, 0, 0, 0, 0, 0], pos = [0, 0, 0];
aabb[1] = storey.storeyAABB[1];
aabb[4] = storey.storeyAABB[4];
Expand All @@ -716,12 +718,14 @@ class StoreyViewsPlugin extends Plugin {
* @param {Number[]} worldPos 3D World-space position.
* @returns {String} ID of the lowest/highest story or null.
*/
isPositionAboveOrBelowBuilding(worldPos) {
const keys = Object.keys(this.storeys);
isPositionAboveOrBelowBuilding(worldPos, modelId = null) {
const storeys = modelId ? this._filterStoreys(modelId) : this.storeys;
const keys = Object.keys(storeys);
if(keys.length <= 0) return null;
const ids = [keys[0], keys[keys.length - 1]];
if (worldPos[1] < this.storeys[ids[0]].storeyAABB[1])
if (worldPos[1] < storeys[ids[0]].storeyAABB[1])
return ids[0];
else if (worldPos[1] > this.storeys[ids[1]].storeyAABB[4])
else if (worldPos[1] > storeys[ids[1]].storeyAABB[4])
return ids[1];
return null;
}
Expand Down Expand Up @@ -865,6 +869,12 @@ class StoreyViewsPlugin extends Plugin {
}
});
}

_filterStoreys(modelId) {
return Object.fromEntries(
Object.entries(this.storeys).filter(([_, value]) => value.modelId === modelId)
);
}
}

export {StoreyViewsPlugin}
6 changes: 3 additions & 3 deletions types/plugins/StoreyViewsPlugin/StoreyViewsPlugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ export declare class StoreyViewsPlugin extends Plugin {
* @param {Number[]} worldPos 3D World-space position.
* @returns {String} ID of the storey containing the position, or null if the position falls outside all the storeys.
*/
getStoreyContainingWorldPos(worldPos: number[]): string;
getStoreyContainingWorldPos(worldPos: number[], modelId: null | string): string;

/**
* Gets the ID of the storey which's bounding box contains the y point of the world position
*
* @param {Number[]} worldPos 3D World-space position.
* @returns {String} ID of the storey containing the position, or null if the position falls outside all the storeys.
*/
getStoreyInVerticalRange(worldPos: number[]): string;
getStoreyInVerticalRange(worldPos: number[], modelId: null | string): string;


/**
Expand All @@ -133,7 +133,7 @@ export declare class StoreyViewsPlugin extends Plugin {
* @param {Number[]} worldPos 3D World-space position.
* @returns {String} ID of the lowest/highest story or null.
*/
isPositionAboveOrBelowBuilding(worldPos: number[]): string;
isPositionAboveOrBelowBuilding(worldPos: number[], modelId: null | string): string;

/**
* Converts a 3D World-space position to a 2D position within a StoreyMap image.
Expand Down

0 comments on commit af25f78

Please sign in to comment.