Skip to content

Commit

Permalink
Merge pull request #1711 from xeokit/treeviews-elevation-sort
Browse files Browse the repository at this point in the history
[FIX] TreeViewPlugin sortNodes fix
  • Loading branch information
xeolabs authored Oct 25, 2024
2 parents d22c8db + 54888f2 commit 0702bb3
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 109 deletions.
42 changes: 18 additions & 24 deletions dist/xeokit-sdk.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -127477,7 +127477,7 @@ class TreeViewPlugin extends Plugin {
return;
}
const firstChild = children[0];
if (this._hierarchy === "storeys" && firstChild.type === "IfcBuildingStorey") {
if ((this._hierarchy === "storeys" || this._hierarchy === "containment") && firstChild.type === "IfcBuildingStorey") {
children.sort(this._getSpatialSortFunc());
} else {
children.sort(this._alphaSortFunc);
Expand All @@ -127488,36 +127488,30 @@ class TreeViewPlugin extends Plugin {
}
}

_getSpatialSortFunc() { // Creates cached sort func with Viewer in scope
_getSpatialSortFunc() {
const viewer = this.viewer;
const scene = viewer.scene;
const camera = scene.camera;
const metaScene = viewer.metaScene;
return this._spatialSortFunc || (this._spatialSortFunc = (node1, node2) => {
if (!node1.aabb || !node2.aabb) {
// Sorting on lowest point of the AABB is likely more more robust when objects could overlap storeys
if (!node1.aabb) {
node1.aabb = scene.getAABB(metaScene.getObjectIDsInSubtree(node1.objectId));
return this._spatialSortFunc || (this._spatialSortFunc = (storey1, storey2) => {
if (camera.xUp) ; else if (camera.yUp) ; else ;
const metaScene = this.viewer.metaScene;
const storey1MetaObject = metaScene.metaObjects[storey1.objectId];
const storey2MetaObject = metaScene.metaObjects[storey2.objectId];

if (storey1MetaObject && (storey1MetaObject.attributes && storey1MetaObject.attributes.elevation !== undefined) &&
storey2MetaObject && (storey2MetaObject.attributes && storey2MetaObject.attributes.elevation !== undefined)) {
const elevation1 = storey1MetaObject.attributes.elevation;
const elevation2 = storey2MetaObject.attributes.elevation;
if (elevation1 > elevation2) {
return -1;
}
if (!node2.aabb) {
node2.aabb = scene.getAABB(metaScene.getObjectIDsInSubtree(node2.objectId));
if (elevation1 < elevation2) {
return 1;
}
}
let idx = 0;
if (camera.xUp) {
idx = 0;
} else if (camera.yUp) {
idx = 1;
return 0;
} else {
idx = 2;
}
if (node1.aabb[idx] > node2.aabb[idx]) {
return -1;
}
if (node1.aabb[idx] < node2.aabb[idx]) {
return 1;
return 0;
}
return 0;
});
}

Expand Down
42 changes: 18 additions & 24 deletions dist/xeokit-sdk.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -127473,7 +127473,7 @@ class TreeViewPlugin extends Plugin {
return;
}
const firstChild = children[0];
if (this._hierarchy === "storeys" && firstChild.type === "IfcBuildingStorey") {
if ((this._hierarchy === "storeys" || this._hierarchy === "containment") && firstChild.type === "IfcBuildingStorey") {
children.sort(this._getSpatialSortFunc());
} else {
children.sort(this._alphaSortFunc);
Expand All @@ -127484,36 +127484,30 @@ class TreeViewPlugin extends Plugin {
}
}

_getSpatialSortFunc() { // Creates cached sort func with Viewer in scope
_getSpatialSortFunc() {
const viewer = this.viewer;
const scene = viewer.scene;
const camera = scene.camera;
const metaScene = viewer.metaScene;
return this._spatialSortFunc || (this._spatialSortFunc = (node1, node2) => {
if (!node1.aabb || !node2.aabb) {
// Sorting on lowest point of the AABB is likely more more robust when objects could overlap storeys
if (!node1.aabb) {
node1.aabb = scene.getAABB(metaScene.getObjectIDsInSubtree(node1.objectId));
return this._spatialSortFunc || (this._spatialSortFunc = (storey1, storey2) => {
if (camera.xUp) ; else if (camera.yUp) ; else ;
const metaScene = this.viewer.metaScene;
const storey1MetaObject = metaScene.metaObjects[storey1.objectId];
const storey2MetaObject = metaScene.metaObjects[storey2.objectId];

if (storey1MetaObject && (storey1MetaObject.attributes && storey1MetaObject.attributes.elevation !== undefined) &&
storey2MetaObject && (storey2MetaObject.attributes && storey2MetaObject.attributes.elevation !== undefined)) {
const elevation1 = storey1MetaObject.attributes.elevation;
const elevation2 = storey2MetaObject.attributes.elevation;
if (elevation1 > elevation2) {
return -1;
}
if (!node2.aabb) {
node2.aabb = scene.getAABB(metaScene.getObjectIDsInSubtree(node2.objectId));
if (elevation1 < elevation2) {
return 1;
}
}
let idx = 0;
if (camera.xUp) {
idx = 0;
} else if (camera.yUp) {
idx = 1;
return 0;
} else {
idx = 2;
}
if (node1.aabb[idx] > node2.aabb[idx]) {
return -1;
}
if (node1.aabb[idx] < node2.aabb[idx]) {
return 1;
return 0;
}
return 0;
});
}

Expand Down
76 changes: 37 additions & 39 deletions dist/xeokit-sdk.es5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/xeokit-sdk.min.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/xeokit-sdk.min.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/xeokit-sdk.min.es5.js

Large diffs are not rendered by default.

Loading

0 comments on commit 0702bb3

Please sign in to comment.