@xeokit/xeokit-sdk 2.3.9 → 2.4.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/xeokit-sdk.cjs.js +1274 -1440
- package/dist/xeokit-sdk.es.js +1274 -1440
- package/dist/xeokit-sdk.es5.js +130 -137
- package/dist/xeokit-sdk.min.cjs.js +2 -2
- package/dist/xeokit-sdk.min.es.js +2 -2
- package/dist/xeokit-sdk.min.es5.js +1 -1
- package/package.json +1 -1
package/dist/xeokit-sdk.es.js
CHANGED
|
@@ -42,7 +42,7 @@ class Map$1 {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const idMap
|
|
45
|
+
const idMap = new Map$1();
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Internal data class that represents the state of a menu or a submenu.
|
|
@@ -326,7 +326,7 @@ class ContextMenu {
|
|
|
326
326
|
*/
|
|
327
327
|
constructor(cfg = {}) {
|
|
328
328
|
|
|
329
|
-
this._id = idMap
|
|
329
|
+
this._id = idMap.addItem();
|
|
330
330
|
this._context = null;
|
|
331
331
|
this._enabled = false; // True when the ContextMenu is enabled
|
|
332
332
|
this._itemsCfg = []; // Items as given as configs
|
|
@@ -537,7 +537,7 @@ class ContextMenu {
|
|
|
537
537
|
this._context = null;
|
|
538
538
|
this._clear();
|
|
539
539
|
if (this._id !== null) {
|
|
540
|
-
idMap
|
|
540
|
+
idMap.removeItem(this._id);
|
|
541
541
|
this._id = null;
|
|
542
542
|
}
|
|
543
543
|
}
|
|
@@ -65652,7 +65652,7 @@ class Dot {
|
|
|
65652
65652
|
dotStyle.left = 0 + "px";
|
|
65653
65653
|
dotStyle["box-shadow"] = "0 2px 5px 0 #182A3D;";
|
|
65654
65654
|
dotStyle["opacity"] = 1.0;
|
|
65655
|
-
dotStyle["pointer-events"] = "
|
|
65655
|
+
dotStyle["pointer-events"] = "all";
|
|
65656
65656
|
if (cfg.onContextMenu) ;
|
|
65657
65657
|
parentElement.appendChild(dot);
|
|
65658
65658
|
|
|
@@ -80419,7 +80419,9 @@ class BCFViewpointsPlugin extends Plugin {
|
|
|
80419
80419
|
for (let id in sectionPlanes) {
|
|
80420
80420
|
if (sectionPlanes.hasOwnProperty(id)) {
|
|
80421
80421
|
let sectionPlane = sectionPlanes[id];
|
|
80422
|
-
|
|
80422
|
+
if (!sectionPlane.active) {
|
|
80423
|
+
continue;
|
|
80424
|
+
}
|
|
80423
80425
|
let location = sectionPlane.pos;
|
|
80424
80426
|
|
|
80425
80427
|
let direction;
|
|
@@ -86376,7 +86378,7 @@ class MetaModel {
|
|
|
86376
86378
|
/**
|
|
86377
86379
|
* @private
|
|
86378
86380
|
*/
|
|
86379
|
-
constructor(metaScene, id, projectId, revisionId, author, createdAt, creatingApplication, schema, propertySets
|
|
86381
|
+
constructor(metaScene, id, projectId, revisionId, author, createdAt, creatingApplication, schema, propertySets) {
|
|
86380
86382
|
|
|
86381
86383
|
/**
|
|
86382
86384
|
* Globally-unique ID.
|
|
@@ -86468,8 +86470,17 @@ class MetaModel {
|
|
|
86468
86470
|
*
|
|
86469
86471
|
* @property rootMetaObject
|
|
86470
86472
|
* @type {MetaObject}
|
|
86473
|
+
* @deprecated
|
|
86471
86474
|
*/
|
|
86472
|
-
this.rootMetaObject =
|
|
86475
|
+
this.rootMetaObject = null;
|
|
86476
|
+
|
|
86477
|
+
/**
|
|
86478
|
+
* The root {@link MetaObject}s in this MetaModel's composition structure hierarchy.
|
|
86479
|
+
*
|
|
86480
|
+
* @property rootMetaObject
|
|
86481
|
+
* @type {MetaObject[]}
|
|
86482
|
+
*/
|
|
86483
|
+
this.rootMetaObjects = [];
|
|
86473
86484
|
}
|
|
86474
86485
|
|
|
86475
86486
|
getJSON() {
|
|
@@ -86535,9 +86546,16 @@ class MetaObject {
|
|
|
86535
86546
|
*
|
|
86536
86547
|
* @property metaModel
|
|
86537
86548
|
* @type {MetaModel}
|
|
86549
|
+
* @deprecated
|
|
86538
86550
|
*/
|
|
86539
86551
|
this.metaModel = metaModel;
|
|
86540
86552
|
|
|
86553
|
+
/**
|
|
86554
|
+
* The MetaModels that share this MetaObject.
|
|
86555
|
+
* @type {MetaModel[]}
|
|
86556
|
+
*/
|
|
86557
|
+
this.metaModels = [metaModel];
|
|
86558
|
+
|
|
86541
86559
|
/**
|
|
86542
86560
|
* Globally-unique ID.
|
|
86543
86561
|
*
|
|
@@ -86897,466 +86915,17 @@ class MetaScene {
|
|
|
86897
86915
|
this.metaObjectsByType = {};
|
|
86898
86916
|
|
|
86899
86917
|
/**
|
|
86900
|
-
*
|
|
86901
|
-
* @private
|
|
86902
|
-
*/
|
|
86903
|
-
this._typeCounts = {};
|
|
86904
|
-
|
|
86905
|
-
/**
|
|
86906
|
-
* Subscriptions to events sent with {@link fire}.
|
|
86907
|
-
* @private
|
|
86908
|
-
*/
|
|
86909
|
-
this._eventSubs = {};
|
|
86910
|
-
}
|
|
86911
|
-
|
|
86912
|
-
/**
|
|
86913
|
-
* Subscribes to an event fired at this Viewer.
|
|
86914
|
-
*
|
|
86915
|
-
* @param {String} event The event
|
|
86916
|
-
* @param {Function} callback Callback fired on the event
|
|
86917
|
-
*/
|
|
86918
|
-
on(event, callback) {
|
|
86919
|
-
let subs = this._eventSubs[event];
|
|
86920
|
-
if (!subs) {
|
|
86921
|
-
subs = [];
|
|
86922
|
-
this._eventSubs[event] = subs;
|
|
86923
|
-
}
|
|
86924
|
-
subs.push(callback);
|
|
86925
|
-
}
|
|
86926
|
-
|
|
86927
|
-
/**
|
|
86928
|
-
* Fires an event at this Viewer.
|
|
86929
|
-
*
|
|
86930
|
-
* @param {String} event Event name
|
|
86931
|
-
* @param {Object} value Event parameters
|
|
86932
|
-
*/
|
|
86933
|
-
fire(event, value) {
|
|
86934
|
-
const subs = this._eventSubs[event];
|
|
86935
|
-
if (subs) {
|
|
86936
|
-
for (let i = 0, len = subs.length; i < len; i++) {
|
|
86937
|
-
subs[i](value);
|
|
86938
|
-
}
|
|
86939
|
-
}
|
|
86940
|
-
}
|
|
86941
|
-
|
|
86942
|
-
/**
|
|
86943
|
-
* Unsubscribes from an event fired at this Viewer.
|
|
86944
|
-
* @param event
|
|
86945
|
-
*/
|
|
86946
|
-
off(event) { // TODO
|
|
86947
|
-
|
|
86948
|
-
}
|
|
86949
|
-
|
|
86950
|
-
/**
|
|
86951
|
-
* Creates a {@link MetaModel} in this MetaScene.
|
|
86952
|
-
*
|
|
86953
|
-
* The MetaModel will contain a hierarchy of {@link MetaObject}s, created from the
|
|
86954
|
-
* meta objects in ````metaModelData````.
|
|
86955
|
-
*
|
|
86956
|
-
* The meta object hierarchy in ````metaModelData```` is expected to be non-cyclic, with a single root. If the meta
|
|
86957
|
-
* objects are cyclic, then this method will log an error and attempt to recover by creating a dummy root MetaObject
|
|
86958
|
-
* of type "Model" and connecting all other MetaObjects as its direct children. If the meta objects contain multiple
|
|
86959
|
-
* roots, then this method similarly attempts to recover by creating a dummy root MetaObject of type "Model" and
|
|
86960
|
-
* connecting all the root MetaObjects as its children.
|
|
86961
|
-
*
|
|
86962
|
-
* @param {String} modelId ID for the new {@link MetaModel}, which will have {@link MetaModel#id} set to this value.
|
|
86963
|
-
* @param {Object} metaModelData Data for the {@link MetaModel}.
|
|
86964
|
-
* @param {Object} [options] Options for creating the {@link MetaModel}.
|
|
86965
|
-
* @param {Object} [options.includeTypes] When provided, only create {@link MetaObject}s with types in this list.
|
|
86966
|
-
* @param {Object} [options.excludeTypes] When provided, never create {@link MetaObject}s with types in this list.
|
|
86967
|
-
* @param {Boolean} [options.globalizeObjectIds=false] Whether to globalize each {@link MetaObject#id}. Set this ````true```` when you need to load multiple instances of the same meta model, to avoid ID clashes between the meta objects in the different instances.
|
|
86968
|
-
* @returns {MetaModel} The new MetaModel.
|
|
86969
|
-
*/
|
|
86970
|
-
createMetaModel(modelId, metaModelData, options = {}) {
|
|
86971
|
-
|
|
86972
|
-
const projectId = metaModelData.projectId || "none";
|
|
86973
|
-
const revisionId = metaModelData.revisionId || "none";
|
|
86974
|
-
const newPropertySets = metaModelData.propertySets || [];
|
|
86975
|
-
const newObjects = metaModelData.metaObjects || [];
|
|
86976
|
-
const author = metaModelData.author;
|
|
86977
|
-
const createdAt = metaModelData.createdAt;
|
|
86978
|
-
const creatingApplication = metaModelData.creatingApplication;
|
|
86979
|
-
const schema = metaModelData.schema;
|
|
86980
|
-
// if (options.excludeTypes) {
|
|
86981
|
-
// excludeTypes = {};
|
|
86982
|
-
// for (let i = 0, len = options.excludeTypes.length; i < len; i++) {
|
|
86983
|
-
// includeTypes[options.excludeTypes[i]] = true;
|
|
86984
|
-
// }
|
|
86985
|
-
// }
|
|
86986
|
-
|
|
86987
|
-
const metaModel = new MetaModel(this, modelId, projectId, revisionId, author, createdAt, creatingApplication, schema, [], null);
|
|
86988
|
-
|
|
86989
|
-
this.metaModels[modelId] = metaModel;
|
|
86990
|
-
|
|
86991
|
-
for (let i = 0, len = newPropertySets.length; i < len; i++) {
|
|
86992
|
-
const propertySetCfg = newPropertySets[i];
|
|
86993
|
-
const propertySetId = propertySetCfg.id;
|
|
86994
|
-
const propertySet = new PropertySet(propertySetId, propertySetCfg.originalSystemId, propertySetCfg.name, propertySetCfg.type, propertySetCfg.properties);
|
|
86995
|
-
metaModel.propertySets[propertySetId] = propertySet;
|
|
86996
|
-
this.propertySets[propertySetId] = propertySet;
|
|
86997
|
-
}
|
|
86998
|
-
|
|
86999
|
-
const rootMetaObjects = [];
|
|
87000
|
-
|
|
87001
|
-
for (let i = 0, len = newObjects.length; i < len; i++) {
|
|
87002
|
-
const newObject = newObjects[i];
|
|
87003
|
-
if (newObject.parent === undefined || newObject.parent === null) {
|
|
87004
|
-
rootMetaObjects.push(newObject);
|
|
87005
|
-
}
|
|
87006
|
-
}
|
|
87007
|
-
|
|
87008
|
-
if (rootMetaObjects.length === 0) {
|
|
87009
|
-
this.scene.error("Cyclic containment hierarchy found in metamodel - will flatten the hierarchy and insert fake 'Model' root");
|
|
87010
|
-
const fakeRoot = {
|
|
87011
|
-
"id": modelId + ".fakeRoot",
|
|
87012
|
-
"name": modelId,
|
|
87013
|
-
"type": "Model",
|
|
87014
|
-
"parent": null
|
|
87015
|
-
};
|
|
87016
|
-
for (let i = 0, len = newObjects.length; i < len; i++) {
|
|
87017
|
-
newObjects[i].parent = fakeRoot.id;
|
|
87018
|
-
}
|
|
87019
|
-
newObjects.push(fakeRoot);
|
|
87020
|
-
}
|
|
87021
|
-
|
|
87022
|
-
if (rootMetaObjects.length > 1) {
|
|
87023
|
-
this.scene.error("Multiple containment hierarchy root found in metamodel - will insert fake 'Model' root");
|
|
87024
|
-
const fakeRoot = {
|
|
87025
|
-
"id": modelId + ".fakeRoot",
|
|
87026
|
-
"name": modelId,
|
|
87027
|
-
"type": "Model",
|
|
87028
|
-
"parent": null
|
|
87029
|
-
};
|
|
87030
|
-
newObjects.push(fakeRoot);
|
|
87031
|
-
for (let i = 0, len = rootMetaObjects.length; i < len; i++) {
|
|
87032
|
-
rootMetaObjects[i].parent = fakeRoot.id;
|
|
87033
|
-
}
|
|
87034
|
-
}
|
|
87035
|
-
|
|
87036
|
-
for (let i = 0, len = newObjects.length; i < len; i++) {
|
|
87037
|
-
const newObject = newObjects[i];
|
|
87038
|
-
const type = newObject.type;
|
|
87039
|
-
const objectId = options.globalizeObjectIds ? math.globalizeObjectId(modelId, newObject.id) : newObject.id;
|
|
87040
|
-
const originalSystemId = newObject.id;
|
|
87041
|
-
const name = newObject.name;
|
|
87042
|
-
const propertySets = [];
|
|
87043
|
-
if (newObject.propertySetIds && newObject.propertySetIds.length > 0) {
|
|
87044
|
-
for (let j = 0, lenj = newObject.propertySetIds.length; j < lenj; j++) {
|
|
87045
|
-
const propertySetId = newObject.propertySetIds[j];
|
|
87046
|
-
const propertySet = metaModel.propertySets[propertySetId];
|
|
87047
|
-
if (propertySet) {
|
|
87048
|
-
propertySets.push(propertySet);
|
|
87049
|
-
}
|
|
87050
|
-
}
|
|
87051
|
-
}
|
|
87052
|
-
const parent = null;
|
|
87053
|
-
const children = null;
|
|
87054
|
-
const external = newObject.external;
|
|
87055
|
-
const metaObject = new MetaObject(metaModel, objectId, originalSystemId, name, type, propertySets, parent, children, external);
|
|
87056
|
-
this.metaObjects[objectId] = metaObject;
|
|
87057
|
-
(this.metaObjectsByType[type] || (this.metaObjectsByType[type] = {}))[objectId] = metaObject;
|
|
87058
|
-
if (this._typeCounts[type] === undefined) {
|
|
87059
|
-
this._typeCounts[type] = 1;
|
|
87060
|
-
} else {
|
|
87061
|
-
this._typeCounts[type]++;
|
|
87062
|
-
}
|
|
87063
|
-
}
|
|
87064
|
-
|
|
87065
|
-
for (let i = 0, len = newObjects.length; i < len; i++) {
|
|
87066
|
-
const newObject = newObjects[i];
|
|
87067
|
-
const objectId = options.globalizeObjectIds ? math.globalizeObjectId(modelId, newObject.id) : newObject.id;
|
|
87068
|
-
const metaObject = this.metaObjects[objectId];
|
|
87069
|
-
if (!metaObject) {
|
|
87070
|
-
continue;
|
|
87071
|
-
}
|
|
87072
|
-
if (newObject.parent === undefined || newObject.parent === null) {
|
|
87073
|
-
metaModel.rootMetaObject = metaObject;
|
|
87074
|
-
} else if (newObject.parent) {
|
|
87075
|
-
const parentId = options.globalizeObjectIds ? math.globalizeObjectId(modelId, newObject.parent) : newObject.parent;
|
|
87076
|
-
let parentMetaObject = this.metaObjects[parentId];
|
|
87077
|
-
if (parentMetaObject) {
|
|
87078
|
-
metaObject.parent = parentMetaObject;
|
|
87079
|
-
parentMetaObject.children = parentMetaObject.children || [];
|
|
87080
|
-
parentMetaObject.children.push(metaObject);
|
|
87081
|
-
}
|
|
87082
|
-
}
|
|
87083
|
-
}
|
|
87084
|
-
|
|
87085
|
-
this.fire("metaModelCreated", modelId);
|
|
87086
|
-
return metaModel;
|
|
87087
|
-
}
|
|
87088
|
-
|
|
87089
|
-
/**
|
|
87090
|
-
* Removes a {@link MetaModel} from this MetaScene.
|
|
87091
|
-
*
|
|
87092
|
-
* Fires a "metaModelDestroyed" event with the value of the {@link MetaModel#id}.
|
|
87093
|
-
*
|
|
87094
|
-
* @param {String} id ID of the target {@link MetaModel}.
|
|
87095
|
-
*/
|
|
87096
|
-
destroyMetaModel(id) {
|
|
87097
|
-
const metaModel = this.metaModels[id];
|
|
87098
|
-
if (!metaModel) {
|
|
87099
|
-
return;
|
|
87100
|
-
}
|
|
87101
|
-
this._removeMetaModel(metaModel);
|
|
87102
|
-
this.fire("metaModelDestroyed", id);
|
|
87103
|
-
}
|
|
87104
|
-
|
|
87105
|
-
_removeMetaModel(metaModel) {
|
|
87106
|
-
const metaObjects = this.metaObjects;
|
|
87107
|
-
const metaObjectsByType = this.metaObjectsByType;
|
|
87108
|
-
let visit = (metaObject) => {
|
|
87109
|
-
delete metaObjects[metaObject.id];
|
|
87110
|
-
const types = metaObjectsByType[metaObject.type];
|
|
87111
|
-
if (types && types[metaObject.id]) {
|
|
87112
|
-
delete types[metaObject.id];
|
|
87113
|
-
if (--this._typeCounts[metaObject.type] === 0) {
|
|
87114
|
-
delete this._typeCounts[metaObject.type];
|
|
87115
|
-
delete metaObjectsByType[metaObject.type];
|
|
87116
|
-
}
|
|
87117
|
-
}
|
|
87118
|
-
const children = metaObject.children;
|
|
87119
|
-
if (children) {
|
|
87120
|
-
for (let i = 0, len = children.length; i < len; i++) {
|
|
87121
|
-
const childMetaObject = children[i];
|
|
87122
|
-
visit(childMetaObject);
|
|
87123
|
-
}
|
|
87124
|
-
}
|
|
87125
|
-
};
|
|
87126
|
-
visit(metaModel.rootMetaObject);
|
|
87127
|
-
for (let propertySetId in metaModel.propertySets) {
|
|
87128
|
-
if (metaModel.propertySets.hasOwnProperty(propertySetId)) {
|
|
87129
|
-
delete this.propertySets[propertySetId];
|
|
87130
|
-
}
|
|
87131
|
-
}
|
|
87132
|
-
delete this.metaModels[metaModel.id];
|
|
87133
|
-
}
|
|
87134
|
-
|
|
87135
|
-
/**
|
|
87136
|
-
* Gets the {@link MetaObject#id}s of the {@link MetaObject}s that have the given {@link MetaObject#type}.
|
|
87137
|
-
*
|
|
87138
|
-
* @param {String} type The type.
|
|
87139
|
-
* @returns {String[]} Array of {@link MetaObject#id}s.
|
|
87140
|
-
*/
|
|
87141
|
-
getObjectIDsByType(type) {
|
|
87142
|
-
const metaObjects = this.metaObjectsByType[type];
|
|
87143
|
-
return metaObjects ? Object.keys(metaObjects) : [];
|
|
87144
|
-
}
|
|
87145
|
-
|
|
87146
|
-
/**
|
|
87147
|
-
* Gets the {@link MetaObject#id}s of the {@link MetaObject}s within the given subtree.
|
|
87148
|
-
*
|
|
87149
|
-
* @param {String} id ID of the root {@link MetaObject} of the given subtree.
|
|
87150
|
-
* @param {String[]} [includeTypes] Optional list of types to include.
|
|
87151
|
-
* @param {String[]} [excludeTypes] Optional list of types to exclude.
|
|
87152
|
-
* @returns {String[]} Array of {@link MetaObject#id}s.
|
|
87153
|
-
*/
|
|
87154
|
-
getObjectIDsInSubtree(id, includeTypes, excludeTypes) {
|
|
87155
|
-
const list = [];
|
|
87156
|
-
const metaObject = this.metaObjects[id];
|
|
87157
|
-
const includeMask = (includeTypes && includeTypes.length > 0) ? arrayToMap(includeTypes) : null;
|
|
87158
|
-
const excludeMask = (excludeTypes && excludeTypes.length > 0) ? arrayToMap(excludeTypes) : null;
|
|
87159
|
-
|
|
87160
|
-
function visit(metaObject) {
|
|
87161
|
-
if (!metaObject) {
|
|
87162
|
-
return;
|
|
87163
|
-
}
|
|
87164
|
-
var include = true;
|
|
87165
|
-
if (excludeMask && excludeMask[metaObject.type]) {
|
|
87166
|
-
include = false;
|
|
87167
|
-
} else if (includeMask && (!includeMask[metaObject.type])) {
|
|
87168
|
-
include = false;
|
|
87169
|
-
}
|
|
87170
|
-
if (include) {
|
|
87171
|
-
list.push(metaObject.id);
|
|
87172
|
-
}
|
|
87173
|
-
const children = metaObject.children;
|
|
87174
|
-
if (children) {
|
|
87175
|
-
for (var i = 0, len = children.length; i < len; i++) {
|
|
87176
|
-
visit(children[i]);
|
|
87177
|
-
}
|
|
87178
|
-
}
|
|
87179
|
-
}
|
|
87180
|
-
|
|
87181
|
-
visit(metaObject);
|
|
87182
|
-
return list;
|
|
87183
|
-
}
|
|
87184
|
-
|
|
87185
|
-
/**
|
|
87186
|
-
* Iterates over the {@link MetaObject}s within the subtree.
|
|
87187
|
-
*
|
|
87188
|
-
* @param {String} id ID of root {@link MetaObject}.
|
|
87189
|
-
* @param {Function} callback Callback fired at each {@link MetaObject}.
|
|
87190
|
-
*/
|
|
87191
|
-
withMetaObjectsInSubtree(id, callback) {
|
|
87192
|
-
const metaObject = this.metaObjects[id];
|
|
87193
|
-
if (!metaObject) {
|
|
87194
|
-
return;
|
|
87195
|
-
}
|
|
87196
|
-
metaObject.withMetaObjectsInSubtree(callback);
|
|
87197
|
-
}
|
|
87198
|
-
}
|
|
87199
|
-
|
|
87200
|
-
function arrayToMap(array) {
|
|
87201
|
-
const map = {};
|
|
87202
|
-
for (var i = 0, len = array.length; i < len; i++) {
|
|
87203
|
-
map[array[i]] = true;
|
|
87204
|
-
}
|
|
87205
|
-
return map;
|
|
87206
|
-
}
|
|
87207
|
-
|
|
87208
|
-
/**
|
|
87209
|
-
* The 3D Viewer at the heart of the xeokit SDK.
|
|
87210
|
-
*
|
|
87211
|
-
* * A Viewer wraps a single {@link Scene}
|
|
87212
|
-
* * Add {@link Plugin}s to a Viewer to extend its functionality.
|
|
87213
|
-
* * {@link Viewer#metaScene} holds metadata about models in the
|
|
87214
|
-
* Viewer's {@link MetaScene}.
|
|
87215
|
-
* * Use {@link Viewer#cameraFlight} to fly or jump the {@link Scene}'s
|
|
87216
|
-
* {@link Camera} to target positions, boundaries or {@link Entity}s.
|
|
87217
|
-
*
|
|
87218
|
-
* @public
|
|
87219
|
-
*/
|
|
87220
|
-
class Viewer {
|
|
87221
|
-
|
|
87222
|
-
/**
|
|
87223
|
-
* @constructor
|
|
87224
|
-
* @param {Object} cfg Viewer configuration.
|
|
87225
|
-
* @param {String} [cfg.id] Optional ID for this Viewer, defaults to the ID of {@link Viewer#scene}, which xeokit automatically generates.
|
|
87226
|
-
* @param {String} [cfg.canvasId] ID of an existing HTML canvas for the {@link Viewer#scene} - either this or canvasElement is mandatory. When both values are given, the element reference is always preferred to the ID.
|
|
87227
|
-
* @param {HTMLCanvasElement} [cfg.canvasElement] Reference of an existing HTML canvas for the {@link Viewer#scene} - either this or canvasId is mandatory. When both values are given, the element reference is always preferred to the ID.
|
|
87228
|
-
* @param {HTMLElement} [cfg.keyboardEventsElement] Optional reference to HTML element on which key events should be handled. Defaults to the HTML Document.
|
|
87229
|
-
* @param {String} [cfg.spinnerElementId] ID of existing HTML element to show the {@link Spinner} - internally creates a default element automatically if this is omitted.
|
|
87230
|
-
* @param {Number} [cfg.passes=1] The number of times the {@link Viewer#scene} renders per frame.
|
|
87231
|
-
* @param {Boolean} [cfg.clearEachPass=false] When doing multiple passes per frame, specifies if to clear the canvas before each pass (true) or just before the first pass (false).
|
|
87232
|
-
* @param {Boolean} [cfg.preserveDrawingBuffer=true] Whether or not to preserve the WebGL drawing buffer. This needs to be ````true```` for {@link Viewer#getSnapshot} to work.
|
|
87233
|
-
* @param {Boolean} [cfg.transparent=true] Whether or not the canvas is transparent.
|
|
87234
|
-
* @param {Boolean} [cfg.premultipliedAlpha=false] Whether or not you want alpha composition with premultiplied alpha. Highlighting and selection works best when this is ````false````.
|
|
87235
|
-
* @param {Boolean} [cfg.gammaInput=true] When true, expects that all textures and colors are premultiplied gamma.
|
|
87236
|
-
* @param {Boolean} [cfg.gammaOutput=false] Whether or not to render with pre-multiplied gama.
|
|
87237
|
-
* @param {Number} [cfg.gammaFactor=2.2] The gamma factor to use when rendering with pre-multiplied gamma.
|
|
87238
|
-
* @param {Number[]} [cfg.backgroundColor=[1,1,1]] Sets the canvas background color to use when ````transparent```` is false.
|
|
87239
|
-
* @param {Boolean} [cfg.backgroundColorFromAmbientLight=true] When ````transparent```` is false, set this ````true````
|
|
87240
|
-
* to derive the canvas background color from {@link AmbientLight#color}, or ````false```` to set the canvas background to ````backgroundColor````.
|
|
87241
|
-
* @param {String} [cfg.units="meters"] The measurement unit type. Accepted values are ````"meters"````, ````"metres"````, , ````"centimeters"````, ````"centimetres"````, ````"millimeters"````, ````"millimetres"````, ````"yards"````, ````"feet"```` and ````"inches"````.
|
|
87242
|
-
* @param {Number} [cfg.scale=1] The number of Real-space units in each World-space coordinate system unit.
|
|
87243
|
-
* @param {Number[]} [cfg.origin=[0,0,0]] The Real-space 3D origin, in current measurement units, at which the World-space coordinate origin ````[0,0,0]```` sits.
|
|
87244
|
-
* @param {Boolean} [cfg.saoEnabled=false] Whether to enable Scalable Ambient Obscurance (SAO) effect. See {@link SAO} for more info.
|
|
87245
|
-
* @param {Boolean} [cfg.antialias=true] Whether to enable anti-aliasing.
|
|
87246
|
-
* @throws {String} Throws an exception when both canvasId or canvasElement are missing or they aren't pointing to a valid HTMLCanvasElement.
|
|
87247
|
-
* @param {Boolean} [cfg.alphaDepthMask=true] Whether writing into the depth buffer is enabled or disabled when rendering transparent objects.
|
|
87248
|
-
* @param {Boolean} [cfg.entityOffsetsEnabled=false] Whether to enable {@link Entity#offset}. For best performance, only set this ````true```` when you need to use {@link Entity#offset}.
|
|
87249
|
-
* @param {Boolean} [cfg.pickSurfacePrecisionEnabled=false] Whether to enable full-precision accuracy when surface picking with {@link Scene#pick}. Note that when ````true````, this configuration will increase the amount of browser memory used by the Viewer. The ````pickSurfacePrecision```` option for ````Scene#pick```` only works if this is set ````true````.
|
|
87250
|
-
* @param {Boolean} [cfg.logarithmicDepthBufferEnabled=false] Whether to enable logarithmic depth buffer. When this is true,
|
|
87251
|
-
* you can set huge values for {@link Perspective#far} and {@link Ortho#far}, to push the far clipping plane back so
|
|
87252
|
-
* that it does not clip huge models.
|
|
87253
|
-
* @param {Boolean} [cfg.colorTextureEnabled=true] Whether to enable base color texture rendering.
|
|
87254
|
-
* @param {Boolean} [cfg.pbrEnabled=false] Whether to enable physically-based rendering.
|
|
87255
|
-
* @param {LocaleService} [cfg.localeService=null] Optional locale-based translation service.
|
|
87256
|
-
*/
|
|
87257
|
-
constructor(cfg) {
|
|
87258
|
-
|
|
87259
|
-
/**
|
|
87260
|
-
* The Viewer's current language setting.
|
|
87261
|
-
* @property language
|
|
87262
|
-
* @deprecated
|
|
87263
|
-
* @type {String}
|
|
87264
|
-
*/
|
|
87265
|
-
this.language = "en";
|
|
87266
|
-
|
|
87267
|
-
/**
|
|
87268
|
-
* The viewer's locale service.
|
|
87269
|
-
*
|
|
87270
|
-
* This is configured via the Viewer's constructor.
|
|
86918
|
+
* The root {@link MetaObject}s belonging to this MetaScene, each mapped to its {@link MetaObject#id}.
|
|
87271
86919
|
*
|
|
87272
|
-
*
|
|
87273
|
-
* null translations for all given strings and phrases.
|
|
87274
|
-
*
|
|
87275
|
-
* @property localeService
|
|
87276
|
-
* @type {LocaleService}
|
|
87277
|
-
* @since 2.0
|
|
87278
|
-
*/
|
|
87279
|
-
this.localeService = cfg.localeService || new LocaleService();
|
|
87280
|
-
|
|
87281
|
-
/**
|
|
87282
|
-
* The Viewer's {@link Scene}.
|
|
87283
|
-
* @property scene
|
|
87284
|
-
* @type {Scene}
|
|
87285
|
-
*/
|
|
87286
|
-
this.scene = new Scene(this, {
|
|
87287
|
-
canvasId: cfg.canvasId,
|
|
87288
|
-
canvasElement: cfg.canvasElement,
|
|
87289
|
-
keyboardEventsElement: cfg.keyboardEventsElement,
|
|
87290
|
-
contextAttr: {
|
|
87291
|
-
preserveDrawingBuffer: cfg.preserveDrawingBuffer !== false,
|
|
87292
|
-
premultipliedAlpha: (!!cfg.premultipliedAlpha),
|
|
87293
|
-
antialias: (cfg.antialias !== false)
|
|
87294
|
-
},
|
|
87295
|
-
spinnerElementId: cfg.spinnerElementId,
|
|
87296
|
-
transparent: (cfg.transparent !== false),
|
|
87297
|
-
gammaInput: true,
|
|
87298
|
-
gammaOutput: false,
|
|
87299
|
-
backgroundColor: cfg.backgroundColor,
|
|
87300
|
-
backgroundColorFromAmbientLight: cfg.backgroundColorFromAmbientLight,
|
|
87301
|
-
ticksPerRender: 1,
|
|
87302
|
-
ticksPerOcclusionTest: 20,
|
|
87303
|
-
units: cfg.units,
|
|
87304
|
-
scale: cfg.scale,
|
|
87305
|
-
origin: cfg.origin,
|
|
87306
|
-
saoEnabled: cfg.saoEnabled,
|
|
87307
|
-
alphaDepthMask: (cfg.alphaDepthMask !== false),
|
|
87308
|
-
entityOffsetsEnabled: (!!cfg.entityOffsetsEnabled),
|
|
87309
|
-
pickSurfacePrecisionEnabled: (!!cfg.pickSurfacePrecisionEnabled),
|
|
87310
|
-
logarithmicDepthBufferEnabled: (!!cfg.logarithmicDepthBufferEnabled),
|
|
87311
|
-
pbrEnabled: (!!cfg.pbrEnabled),
|
|
87312
|
-
colorTextureEnabled: (cfg.colorTextureEnabled !== false)
|
|
87313
|
-
});
|
|
87314
|
-
|
|
87315
|
-
/**
|
|
87316
|
-
* Metadata about the {@link Scene} and the models and objects within it.
|
|
87317
|
-
* @property metaScene
|
|
87318
|
-
* @type {MetaScene}
|
|
87319
|
-
* @readonly
|
|
87320
|
-
*/
|
|
87321
|
-
this.metaScene = new MetaScene(this, this.scene);
|
|
87322
|
-
|
|
87323
|
-
/**
|
|
87324
|
-
* The Viewer's ID.
|
|
87325
|
-
* @property id
|
|
87326
|
-
*
|
|
87327
|
-
* @type {String|Number}
|
|
87328
|
-
*/
|
|
87329
|
-
this.id = cfg.id || this.scene.id;
|
|
87330
|
-
|
|
87331
|
-
/**
|
|
87332
|
-
* The Viewer's {@link Camera}. This is also found on {@link Scene#camera}.
|
|
87333
|
-
* @property camera
|
|
87334
|
-
* @type {Camera}
|
|
87335
|
-
*/
|
|
87336
|
-
this.camera = this.scene.camera;
|
|
87337
|
-
|
|
87338
|
-
/**
|
|
87339
|
-
* The Viewer's {@link CameraFlightAnimation}, which
|
|
87340
|
-
* is used to fly the {@link Scene}'s {@link Camera} to given targets.
|
|
87341
|
-
* @property cameraFlight
|
|
87342
|
-
* @type {CameraFlightAnimation}
|
|
86920
|
+
* @type {{String:MetaObject}}
|
|
87343
86921
|
*/
|
|
87344
|
-
this.
|
|
87345
|
-
duration: 0.5
|
|
87346
|
-
});
|
|
86922
|
+
this.rootMetaObjects = {};
|
|
87347
86923
|
|
|
87348
86924
|
/**
|
|
87349
|
-
*
|
|
87350
|
-
*
|
|
87351
|
-
* @property cameraControl
|
|
87352
|
-
* @type {CameraControl}
|
|
86925
|
+
* Tracks number of MetaObjects of each type.
|
|
86926
|
+
* @private
|
|
87353
86927
|
*/
|
|
87354
|
-
this.
|
|
87355
|
-
// panToPointer: true,
|
|
87356
|
-
doublePickFlyTo: true
|
|
87357
|
-
});
|
|
87358
|
-
|
|
87359
|
-
this._plugins = [];
|
|
86928
|
+
this._typeCounts = {};
|
|
87360
86929
|
|
|
87361
86930
|
/**
|
|
87362
86931
|
* Subscriptions to events sent with {@link fire}.
|
|
@@ -87365,15 +86934,467 @@ class Viewer {
|
|
|
87365
86934
|
this._eventSubs = {};
|
|
87366
86935
|
}
|
|
87367
86936
|
|
|
87368
|
-
/**
|
|
87369
|
-
*
|
|
87370
|
-
*
|
|
87371
|
-
* @
|
|
87372
|
-
|
|
87373
|
-
|
|
87374
|
-
|
|
87375
|
-
|
|
87376
|
-
|
|
86937
|
+
/**
|
|
86938
|
+
* Subscribes to an event fired at this Viewer.
|
|
86939
|
+
*
|
|
86940
|
+
* @param {String} event The event
|
|
86941
|
+
* @param {Function} callback Callback fired on the event
|
|
86942
|
+
*/
|
|
86943
|
+
on(event, callback) {
|
|
86944
|
+
let subs = this._eventSubs[event];
|
|
86945
|
+
if (!subs) {
|
|
86946
|
+
subs = [];
|
|
86947
|
+
this._eventSubs[event] = subs;
|
|
86948
|
+
}
|
|
86949
|
+
subs.push(callback);
|
|
86950
|
+
}
|
|
86951
|
+
|
|
86952
|
+
/**
|
|
86953
|
+
* Fires an event at this Viewer.
|
|
86954
|
+
*
|
|
86955
|
+
* @param {String} event Event name
|
|
86956
|
+
* @param {Object} value Event parameters
|
|
86957
|
+
*/
|
|
86958
|
+
fire(event, value) {
|
|
86959
|
+
const subs = this._eventSubs[event];
|
|
86960
|
+
if (subs) {
|
|
86961
|
+
for (let i = 0, len = subs.length; i < len; i++) {
|
|
86962
|
+
subs[i](value);
|
|
86963
|
+
}
|
|
86964
|
+
}
|
|
86965
|
+
}
|
|
86966
|
+
|
|
86967
|
+
/**
|
|
86968
|
+
* Unsubscribes from an event fired at this Viewer.
|
|
86969
|
+
* @param event
|
|
86970
|
+
*/
|
|
86971
|
+
off(event) { // TODO
|
|
86972
|
+
|
|
86973
|
+
}
|
|
86974
|
+
|
|
86975
|
+
/**
|
|
86976
|
+
* Creates a {@link MetaModel} in this MetaScene.
|
|
86977
|
+
*
|
|
86978
|
+
* The MetaModel will contain a hierarchy of {@link MetaObject}s, created from the
|
|
86979
|
+
* meta objects in ````metaModelData````.
|
|
86980
|
+
*
|
|
86981
|
+
* The meta object hierarchy in ````metaModelData```` is expected to be non-cyclic, with a single root. If the meta
|
|
86982
|
+
* objects are cyclic, then this method will log an error and attempt to recover by creating a dummy root MetaObject
|
|
86983
|
+
* of type "Model" and connecting all other MetaObjects as its direct children. If the meta objects contain multiple
|
|
86984
|
+
* roots, then this method similarly attempts to recover by creating a dummy root MetaObject of type "Model" and
|
|
86985
|
+
* connecting all the root MetaObjects as its children.
|
|
86986
|
+
*
|
|
86987
|
+
* @param {String} modelId ID for the new {@link MetaModel}, which will have {@link MetaModel#id} set to this value.
|
|
86988
|
+
* @param {Object} metaModelData Data for the {@link MetaModel}.
|
|
86989
|
+
* @param {Object} [options] Options for creating the {@link MetaModel}.
|
|
86990
|
+
* @param {Object} [options.includeTypes] When provided, only create {@link MetaObject}s with types in this list.
|
|
86991
|
+
* @param {Object} [options.excludeTypes] When provided, never create {@link MetaObject}s with types in this list.
|
|
86992
|
+
* @param {Boolean} [options.globalizeObjectIds=false] Whether to globalize each {@link MetaObject#id}. Set this ````true```` when you need to load multiple instances of the same meta model, to avoid ID clashes between the meta objects in the different instances.
|
|
86993
|
+
* @returns {MetaModel} The new MetaModel.
|
|
86994
|
+
*/
|
|
86995
|
+
createMetaModel(modelId, metaModelData, options = {}) {
|
|
86996
|
+
|
|
86997
|
+
const projectId = metaModelData.projectId || "none";
|
|
86998
|
+
const revisionId = metaModelData.revisionId || "none";
|
|
86999
|
+
const newPropertySets = metaModelData.propertySets || [];
|
|
87000
|
+
const newObjects = metaModelData.metaObjects || [];
|
|
87001
|
+
const author = metaModelData.author;
|
|
87002
|
+
const createdAt = metaModelData.createdAt;
|
|
87003
|
+
const creatingApplication = metaModelData.creatingApplication;
|
|
87004
|
+
const schema = metaModelData.schema;
|
|
87005
|
+
// if (options.excludeTypes) {
|
|
87006
|
+
// excludeTypes = {};
|
|
87007
|
+
// for (let i = 0, len = options.excludeTypes.length; i < len; i++) {
|
|
87008
|
+
// includeTypes[options.excludeTypes[i]] = true;
|
|
87009
|
+
// }
|
|
87010
|
+
// }
|
|
87011
|
+
|
|
87012
|
+
const metaModel = new MetaModel(this, modelId, projectId, revisionId, author, createdAt, creatingApplication, schema, [], null);
|
|
87013
|
+
|
|
87014
|
+
this.metaModels[modelId] = metaModel;
|
|
87015
|
+
|
|
87016
|
+
for (let i = 0, len = newPropertySets.length; i < len; i++) {
|
|
87017
|
+
const propertySetCfg = newPropertySets[i];
|
|
87018
|
+
const propertySetId = propertySetCfg.id;
|
|
87019
|
+
const propertySet = new PropertySet(propertySetId, propertySetCfg.originalSystemId, propertySetCfg.name, propertySetCfg.type, propertySetCfg.properties);
|
|
87020
|
+
metaModel.propertySets[propertySetId] = propertySet;
|
|
87021
|
+
this.propertySets[propertySetId] = propertySet;
|
|
87022
|
+
}
|
|
87023
|
+
|
|
87024
|
+
const filteredObjectsParams = []; // Params for each new metaobject that passes our filters
|
|
87025
|
+
const existingObjects = []; // List of our metaobjects that are already existing, to which we'll also append new metaobjects we'll create
|
|
87026
|
+
const createObjectsParams = []; // List of params for metaobjects we'll create
|
|
87027
|
+
|
|
87028
|
+
|
|
87029
|
+
// Filter out the parameters we'll create
|
|
87030
|
+
|
|
87031
|
+
for (let i = 0, len = newObjects.length; i < len; i++) {
|
|
87032
|
+
const newObject = newObjects[i];
|
|
87033
|
+
newObject.type;
|
|
87034
|
+
filteredObjectsParams.push(newObject);
|
|
87035
|
+
}
|
|
87036
|
+
|
|
87037
|
+
// Build list of params for metaobjects we'll create
|
|
87038
|
+
|
|
87039
|
+
for (let i = 0, len = filteredObjectsParams.length; i < len; i++) {
|
|
87040
|
+
let filteredObject = filteredObjectsParams[i];
|
|
87041
|
+
const existingObject = this.metaObjects[filteredObject.id];
|
|
87042
|
+
if (existingObject) {
|
|
87043
|
+
existingObject.metaModels.push(metaModel);
|
|
87044
|
+
existingObjects.push(existingObject);
|
|
87045
|
+
continue;
|
|
87046
|
+
}
|
|
87047
|
+
createObjectsParams.push(filteredObject);
|
|
87048
|
+
}
|
|
87049
|
+
|
|
87050
|
+
// Create metaobjects in the creation list, add them to list of existing metaobjects
|
|
87051
|
+
|
|
87052
|
+
for (let i = 0, len = createObjectsParams.length; i < len; i++) {
|
|
87053
|
+
const createObject = createObjectsParams[i];
|
|
87054
|
+
const type = createObject.type;
|
|
87055
|
+
const objectId = createObject.id;
|
|
87056
|
+
const originalSystemId = createObject.id;
|
|
87057
|
+
const name = createObject.name;
|
|
87058
|
+
const propertySets = [];
|
|
87059
|
+
if (createObject.propertySetIds && createObject.propertySetIds.length > 0) {
|
|
87060
|
+
for (let j = 0, lenj = createObject.propertySetIds.length; j < lenj; j++) {
|
|
87061
|
+
const propertySetId = createObject.propertySetIds[j];
|
|
87062
|
+
const propertySet = metaModel.propertySets[propertySetId];
|
|
87063
|
+
if (propertySet) {
|
|
87064
|
+
propertySets.push(propertySet);
|
|
87065
|
+
}
|
|
87066
|
+
}
|
|
87067
|
+
}
|
|
87068
|
+
const parent = null;
|
|
87069
|
+
const children = null;
|
|
87070
|
+
const external = createObject.external;
|
|
87071
|
+
const metaObject = new MetaObject(metaModel, objectId, originalSystemId, name, type, propertySets, parent, children, external);
|
|
87072
|
+
metaObject._parentId = createObject.parent;
|
|
87073
|
+
this.metaObjects[objectId] = metaObject;
|
|
87074
|
+
(this.metaObjectsByType[type] || (this.metaObjectsByType[type] = {}))[objectId] = metaObject;
|
|
87075
|
+
if (this._typeCounts[type] === undefined) {
|
|
87076
|
+
this._typeCounts[type] = 1;
|
|
87077
|
+
} else {
|
|
87078
|
+
this._typeCounts[type]++;
|
|
87079
|
+
}
|
|
87080
|
+
existingObjects.push(metaObject);
|
|
87081
|
+
if (createObject.parent === undefined || createObject.parent === null) ;
|
|
87082
|
+
}
|
|
87083
|
+
|
|
87084
|
+
// Ensure that metaobjects in the existing metaobject list are all attached to their parents,
|
|
87085
|
+
// or registered as root metaobjects
|
|
87086
|
+
|
|
87087
|
+
for (let i = 0, len = existingObjects.length; i < len; i++) {
|
|
87088
|
+
const existingObject = existingObjects[i];
|
|
87089
|
+
const objectId = existingObject.id;
|
|
87090
|
+
if ((existingObject._parentId === undefined || existingObject._parentId === null) && !existingObject.parent) {
|
|
87091
|
+
metaModel.rootMetaObject = existingObject; // Deprecated, and won't work for federated models
|
|
87092
|
+
metaModel.rootMetaObjects[objectId] = existingObject;
|
|
87093
|
+
this.rootMetaObjects[objectId] = existingObject;
|
|
87094
|
+
} else if (existingObject._parentId) {
|
|
87095
|
+
const parentId = existingObject._parentId;
|
|
87096
|
+
existingObject._parentId = null;
|
|
87097
|
+
let parentMetaObject = this.metaObjects[parentId];
|
|
87098
|
+
if (parentMetaObject) {
|
|
87099
|
+
existingObject.parent = parentMetaObject;
|
|
87100
|
+
parentMetaObject.children = parentMetaObject.children || [];
|
|
87101
|
+
parentMetaObject.children.push(existingObject);
|
|
87102
|
+
}
|
|
87103
|
+
}
|
|
87104
|
+
}
|
|
87105
|
+
|
|
87106
|
+
this.fire("metaModelCreated", modelId);
|
|
87107
|
+
return metaModel;
|
|
87108
|
+
}
|
|
87109
|
+
|
|
87110
|
+
/**
|
|
87111
|
+
* Removes a {@link MetaModel} from this MetaScene.
|
|
87112
|
+
*
|
|
87113
|
+
* Fires a "metaModelDestroyed" event with the value of the {@link MetaModel#id}.
|
|
87114
|
+
*
|
|
87115
|
+
* @param {String} id ID of the target {@link MetaModel}.
|
|
87116
|
+
*/
|
|
87117
|
+
destroyMetaModel(id) {
|
|
87118
|
+
const metaModel = this.metaModels[id];
|
|
87119
|
+
if (!metaModel) {
|
|
87120
|
+
return;
|
|
87121
|
+
}
|
|
87122
|
+
this._removeMetaModel(metaModel);
|
|
87123
|
+
this.fire("metaModelDestroyed", id);
|
|
87124
|
+
}
|
|
87125
|
+
|
|
87126
|
+
_removeMetaModel(metaModel) {
|
|
87127
|
+
const metaObjects = this.metaObjects;
|
|
87128
|
+
const metaObjectsByType = this.metaObjectsByType;
|
|
87129
|
+
let visit = (metaObject) => {
|
|
87130
|
+
delete metaObjects[metaObject.id];
|
|
87131
|
+
const types = metaObjectsByType[metaObject.type];
|
|
87132
|
+
if (types && types[metaObject.id]) {
|
|
87133
|
+
delete types[metaObject.id];
|
|
87134
|
+
if (--this._typeCounts[metaObject.type] === 0) {
|
|
87135
|
+
delete this._typeCounts[metaObject.type];
|
|
87136
|
+
delete metaObjectsByType[metaObject.type];
|
|
87137
|
+
}
|
|
87138
|
+
}
|
|
87139
|
+
const children = metaObject.children;
|
|
87140
|
+
if (children) {
|
|
87141
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
87142
|
+
const childMetaObject = children[i];
|
|
87143
|
+
visit(childMetaObject);
|
|
87144
|
+
}
|
|
87145
|
+
}
|
|
87146
|
+
};
|
|
87147
|
+
visit(metaModel.rootMetaObject);
|
|
87148
|
+
for (let propertySetId in metaModel.propertySets) {
|
|
87149
|
+
if (metaModel.propertySets.hasOwnProperty(propertySetId)) {
|
|
87150
|
+
delete this.propertySets[propertySetId];
|
|
87151
|
+
}
|
|
87152
|
+
}
|
|
87153
|
+
delete this.metaModels[metaModel.id];
|
|
87154
|
+
}
|
|
87155
|
+
|
|
87156
|
+
/**
|
|
87157
|
+
* Gets the {@link MetaObject#id}s of the {@link MetaObject}s that have the given {@link MetaObject#type}.
|
|
87158
|
+
*
|
|
87159
|
+
* @param {String} type The type.
|
|
87160
|
+
* @returns {String[]} Array of {@link MetaObject#id}s.
|
|
87161
|
+
*/
|
|
87162
|
+
getObjectIDsByType(type) {
|
|
87163
|
+
const metaObjects = this.metaObjectsByType[type];
|
|
87164
|
+
return metaObjects ? Object.keys(metaObjects) : [];
|
|
87165
|
+
}
|
|
87166
|
+
|
|
87167
|
+
/**
|
|
87168
|
+
* Gets the {@link MetaObject#id}s of the {@link MetaObject}s within the given subtree.
|
|
87169
|
+
*
|
|
87170
|
+
* @param {String} id ID of the root {@link MetaObject} of the given subtree.
|
|
87171
|
+
* @param {String[]} [includeTypes] Optional list of types to include.
|
|
87172
|
+
* @param {String[]} [excludeTypes] Optional list of types to exclude.
|
|
87173
|
+
* @returns {String[]} Array of {@link MetaObject#id}s.
|
|
87174
|
+
*/
|
|
87175
|
+
getObjectIDsInSubtree(id, includeTypes, excludeTypes) {
|
|
87176
|
+
const list = [];
|
|
87177
|
+
const metaObject = this.metaObjects[id];
|
|
87178
|
+
const includeMask = (includeTypes && includeTypes.length > 0) ? arrayToMap(includeTypes) : null;
|
|
87179
|
+
const excludeMask = (excludeTypes && excludeTypes.length > 0) ? arrayToMap(excludeTypes) : null;
|
|
87180
|
+
|
|
87181
|
+
function visit(metaObject) {
|
|
87182
|
+
if (!metaObject) {
|
|
87183
|
+
return;
|
|
87184
|
+
}
|
|
87185
|
+
var include = true;
|
|
87186
|
+
if (excludeMask && excludeMask[metaObject.type]) {
|
|
87187
|
+
include = false;
|
|
87188
|
+
} else if (includeMask && (!includeMask[metaObject.type])) {
|
|
87189
|
+
include = false;
|
|
87190
|
+
}
|
|
87191
|
+
if (include) {
|
|
87192
|
+
list.push(metaObject.id);
|
|
87193
|
+
}
|
|
87194
|
+
const children = metaObject.children;
|
|
87195
|
+
if (children) {
|
|
87196
|
+
for (var i = 0, len = children.length; i < len; i++) {
|
|
87197
|
+
visit(children[i]);
|
|
87198
|
+
}
|
|
87199
|
+
}
|
|
87200
|
+
}
|
|
87201
|
+
|
|
87202
|
+
visit(metaObject);
|
|
87203
|
+
return list;
|
|
87204
|
+
}
|
|
87205
|
+
|
|
87206
|
+
/**
|
|
87207
|
+
* Iterates over the {@link MetaObject}s within the subtree.
|
|
87208
|
+
*
|
|
87209
|
+
* @param {String} id ID of root {@link MetaObject}.
|
|
87210
|
+
* @param {Function} callback Callback fired at each {@link MetaObject}.
|
|
87211
|
+
*/
|
|
87212
|
+
withMetaObjectsInSubtree(id, callback) {
|
|
87213
|
+
const metaObject = this.metaObjects[id];
|
|
87214
|
+
if (!metaObject) {
|
|
87215
|
+
return;
|
|
87216
|
+
}
|
|
87217
|
+
metaObject.withMetaObjectsInSubtree(callback);
|
|
87218
|
+
}
|
|
87219
|
+
}
|
|
87220
|
+
|
|
87221
|
+
function arrayToMap(array) {
|
|
87222
|
+
const map = {};
|
|
87223
|
+
for (var i = 0, len = array.length; i < len; i++) {
|
|
87224
|
+
map[array[i]] = true;
|
|
87225
|
+
}
|
|
87226
|
+
return map;
|
|
87227
|
+
}
|
|
87228
|
+
|
|
87229
|
+
/**
|
|
87230
|
+
* The 3D Viewer at the heart of the xeokit SDK.
|
|
87231
|
+
*
|
|
87232
|
+
* * A Viewer wraps a single {@link Scene}
|
|
87233
|
+
* * Add {@link Plugin}s to a Viewer to extend its functionality.
|
|
87234
|
+
* * {@link Viewer#metaScene} holds metadata about models in the
|
|
87235
|
+
* Viewer's {@link MetaScene}.
|
|
87236
|
+
* * Use {@link Viewer#cameraFlight} to fly or jump the {@link Scene}'s
|
|
87237
|
+
* {@link Camera} to target positions, boundaries or {@link Entity}s.
|
|
87238
|
+
*
|
|
87239
|
+
* @public
|
|
87240
|
+
*/
|
|
87241
|
+
class Viewer {
|
|
87242
|
+
|
|
87243
|
+
/**
|
|
87244
|
+
* @constructor
|
|
87245
|
+
* @param {Object} cfg Viewer configuration.
|
|
87246
|
+
* @param {String} [cfg.id] Optional ID for this Viewer, defaults to the ID of {@link Viewer#scene}, which xeokit automatically generates.
|
|
87247
|
+
* @param {String} [cfg.canvasId] ID of an existing HTML canvas for the {@link Viewer#scene} - either this or canvasElement is mandatory. When both values are given, the element reference is always preferred to the ID.
|
|
87248
|
+
* @param {HTMLCanvasElement} [cfg.canvasElement] Reference of an existing HTML canvas for the {@link Viewer#scene} - either this or canvasId is mandatory. When both values are given, the element reference is always preferred to the ID.
|
|
87249
|
+
* @param {HTMLElement} [cfg.keyboardEventsElement] Optional reference to HTML element on which key events should be handled. Defaults to the HTML Document.
|
|
87250
|
+
* @param {String} [cfg.spinnerElementId] ID of existing HTML element to show the {@link Spinner} - internally creates a default element automatically if this is omitted.
|
|
87251
|
+
* @param {Number} [cfg.passes=1] The number of times the {@link Viewer#scene} renders per frame.
|
|
87252
|
+
* @param {Boolean} [cfg.clearEachPass=false] When doing multiple passes per frame, specifies if to clear the canvas before each pass (true) or just before the first pass (false).
|
|
87253
|
+
* @param {Boolean} [cfg.preserveDrawingBuffer=true] Whether or not to preserve the WebGL drawing buffer. This needs to be ````true```` for {@link Viewer#getSnapshot} to work.
|
|
87254
|
+
* @param {Boolean} [cfg.transparent=true] Whether or not the canvas is transparent.
|
|
87255
|
+
* @param {Boolean} [cfg.premultipliedAlpha=false] Whether or not you want alpha composition with premultiplied alpha. Highlighting and selection works best when this is ````false````.
|
|
87256
|
+
* @param {Boolean} [cfg.gammaInput=true] When true, expects that all textures and colors are premultiplied gamma.
|
|
87257
|
+
* @param {Boolean} [cfg.gammaOutput=false] Whether or not to render with pre-multiplied gama.
|
|
87258
|
+
* @param {Number} [cfg.gammaFactor=2.2] The gamma factor to use when rendering with pre-multiplied gamma.
|
|
87259
|
+
* @param {Number[]} [cfg.backgroundColor=[1,1,1]] Sets the canvas background color to use when ````transparent```` is false.
|
|
87260
|
+
* @param {Boolean} [cfg.backgroundColorFromAmbientLight=true] When ````transparent```` is false, set this ````true````
|
|
87261
|
+
* to derive the canvas background color from {@link AmbientLight#color}, or ````false```` to set the canvas background to ````backgroundColor````.
|
|
87262
|
+
* @param {String} [cfg.units="meters"] The measurement unit type. Accepted values are ````"meters"````, ````"metres"````, , ````"centimeters"````, ````"centimetres"````, ````"millimeters"````, ````"millimetres"````, ````"yards"````, ````"feet"```` and ````"inches"````.
|
|
87263
|
+
* @param {Number} [cfg.scale=1] The number of Real-space units in each World-space coordinate system unit.
|
|
87264
|
+
* @param {Number[]} [cfg.origin=[0,0,0]] The Real-space 3D origin, in current measurement units, at which the World-space coordinate origin ````[0,0,0]```` sits.
|
|
87265
|
+
* @param {Boolean} [cfg.saoEnabled=false] Whether to enable Scalable Ambient Obscurance (SAO) effect. See {@link SAO} for more info.
|
|
87266
|
+
* @param {Boolean} [cfg.antialias=true] Whether to enable anti-aliasing.
|
|
87267
|
+
* @throws {String} Throws an exception when both canvasId or canvasElement are missing or they aren't pointing to a valid HTMLCanvasElement.
|
|
87268
|
+
* @param {Boolean} [cfg.alphaDepthMask=true] Whether writing into the depth buffer is enabled or disabled when rendering transparent objects.
|
|
87269
|
+
* @param {Boolean} [cfg.entityOffsetsEnabled=false] Whether to enable {@link Entity#offset}. For best performance, only set this ````true```` when you need to use {@link Entity#offset}.
|
|
87270
|
+
* @param {Boolean} [cfg.pickSurfacePrecisionEnabled=false] Whether to enable full-precision accuracy when surface picking with {@link Scene#pick}. Note that when ````true````, this configuration will increase the amount of browser memory used by the Viewer. The ````pickSurfacePrecision```` option for ````Scene#pick```` only works if this is set ````true````.
|
|
87271
|
+
* @param {Boolean} [cfg.logarithmicDepthBufferEnabled=false] Whether to enable logarithmic depth buffer. When this is true,
|
|
87272
|
+
* you can set huge values for {@link Perspective#far} and {@link Ortho#far}, to push the far clipping plane back so
|
|
87273
|
+
* that it does not clip huge models.
|
|
87274
|
+
* @param {Boolean} [cfg.colorTextureEnabled=true] Whether to enable base color texture rendering.
|
|
87275
|
+
* @param {Boolean} [cfg.pbrEnabled=false] Whether to enable physically-based rendering.
|
|
87276
|
+
* @param {LocaleService} [cfg.localeService=null] Optional locale-based translation service.
|
|
87277
|
+
*/
|
|
87278
|
+
constructor(cfg) {
|
|
87279
|
+
|
|
87280
|
+
/**
|
|
87281
|
+
* The Viewer's current language setting.
|
|
87282
|
+
* @property language
|
|
87283
|
+
* @deprecated
|
|
87284
|
+
* @type {String}
|
|
87285
|
+
*/
|
|
87286
|
+
this.language = "en";
|
|
87287
|
+
|
|
87288
|
+
/**
|
|
87289
|
+
* The viewer's locale service.
|
|
87290
|
+
*
|
|
87291
|
+
* This is configured via the Viewer's constructor.
|
|
87292
|
+
*
|
|
87293
|
+
* By default, this service will be an instance of {@link LocaleService}, which will just return
|
|
87294
|
+
* null translations for all given strings and phrases.
|
|
87295
|
+
*
|
|
87296
|
+
* @property localeService
|
|
87297
|
+
* @type {LocaleService}
|
|
87298
|
+
* @since 2.0
|
|
87299
|
+
*/
|
|
87300
|
+
this.localeService = cfg.localeService || new LocaleService();
|
|
87301
|
+
|
|
87302
|
+
/**
|
|
87303
|
+
* The Viewer's {@link Scene}.
|
|
87304
|
+
* @property scene
|
|
87305
|
+
* @type {Scene}
|
|
87306
|
+
*/
|
|
87307
|
+
this.scene = new Scene(this, {
|
|
87308
|
+
canvasId: cfg.canvasId,
|
|
87309
|
+
canvasElement: cfg.canvasElement,
|
|
87310
|
+
keyboardEventsElement: cfg.keyboardEventsElement,
|
|
87311
|
+
contextAttr: {
|
|
87312
|
+
preserveDrawingBuffer: cfg.preserveDrawingBuffer !== false,
|
|
87313
|
+
premultipliedAlpha: (!!cfg.premultipliedAlpha),
|
|
87314
|
+
antialias: (cfg.antialias !== false)
|
|
87315
|
+
},
|
|
87316
|
+
spinnerElementId: cfg.spinnerElementId,
|
|
87317
|
+
transparent: (cfg.transparent !== false),
|
|
87318
|
+
gammaInput: true,
|
|
87319
|
+
gammaOutput: false,
|
|
87320
|
+
backgroundColor: cfg.backgroundColor,
|
|
87321
|
+
backgroundColorFromAmbientLight: cfg.backgroundColorFromAmbientLight,
|
|
87322
|
+
ticksPerRender: 1,
|
|
87323
|
+
ticksPerOcclusionTest: 20,
|
|
87324
|
+
units: cfg.units,
|
|
87325
|
+
scale: cfg.scale,
|
|
87326
|
+
origin: cfg.origin,
|
|
87327
|
+
saoEnabled: cfg.saoEnabled,
|
|
87328
|
+
alphaDepthMask: (cfg.alphaDepthMask !== false),
|
|
87329
|
+
entityOffsetsEnabled: (!!cfg.entityOffsetsEnabled),
|
|
87330
|
+
pickSurfacePrecisionEnabled: (!!cfg.pickSurfacePrecisionEnabled),
|
|
87331
|
+
logarithmicDepthBufferEnabled: (!!cfg.logarithmicDepthBufferEnabled),
|
|
87332
|
+
pbrEnabled: (!!cfg.pbrEnabled),
|
|
87333
|
+
colorTextureEnabled: (cfg.colorTextureEnabled !== false)
|
|
87334
|
+
});
|
|
87335
|
+
|
|
87336
|
+
/**
|
|
87337
|
+
* Metadata about the {@link Scene} and the models and objects within it.
|
|
87338
|
+
* @property metaScene
|
|
87339
|
+
* @type {MetaScene}
|
|
87340
|
+
* @readonly
|
|
87341
|
+
*/
|
|
87342
|
+
this.metaScene = new MetaScene(this, this.scene);
|
|
87343
|
+
|
|
87344
|
+
/**
|
|
87345
|
+
* The Viewer's ID.
|
|
87346
|
+
* @property id
|
|
87347
|
+
*
|
|
87348
|
+
* @type {String|Number}
|
|
87349
|
+
*/
|
|
87350
|
+
this.id = cfg.id || this.scene.id;
|
|
87351
|
+
|
|
87352
|
+
/**
|
|
87353
|
+
* The Viewer's {@link Camera}. This is also found on {@link Scene#camera}.
|
|
87354
|
+
* @property camera
|
|
87355
|
+
* @type {Camera}
|
|
87356
|
+
*/
|
|
87357
|
+
this.camera = this.scene.camera;
|
|
87358
|
+
|
|
87359
|
+
/**
|
|
87360
|
+
* The Viewer's {@link CameraFlightAnimation}, which
|
|
87361
|
+
* is used to fly the {@link Scene}'s {@link Camera} to given targets.
|
|
87362
|
+
* @property cameraFlight
|
|
87363
|
+
* @type {CameraFlightAnimation}
|
|
87364
|
+
*/
|
|
87365
|
+
this.cameraFlight = new CameraFlightAnimation(this.scene, {
|
|
87366
|
+
duration: 0.5
|
|
87367
|
+
});
|
|
87368
|
+
|
|
87369
|
+
/**
|
|
87370
|
+
* The Viewer's {@link CameraControl}, which
|
|
87371
|
+
* controls the {@link Scene}'s {@link Camera} with mouse, touch and keyboard input.
|
|
87372
|
+
* @property cameraControl
|
|
87373
|
+
* @type {CameraControl}
|
|
87374
|
+
*/
|
|
87375
|
+
this.cameraControl = new CameraControl(this.scene, {
|
|
87376
|
+
// panToPointer: true,
|
|
87377
|
+
doublePickFlyTo: true
|
|
87378
|
+
});
|
|
87379
|
+
|
|
87380
|
+
this._plugins = [];
|
|
87381
|
+
|
|
87382
|
+
/**
|
|
87383
|
+
* Subscriptions to events sent with {@link fire}.
|
|
87384
|
+
* @private
|
|
87385
|
+
*/
|
|
87386
|
+
this._eventSubs = {};
|
|
87387
|
+
}
|
|
87388
|
+
|
|
87389
|
+
/**
|
|
87390
|
+
* Returns the capabilities of this Viewer.
|
|
87391
|
+
*
|
|
87392
|
+
* @returns {{astcSupported: boolean, etc1Supported: boolean, pvrtcSupported: boolean, etc2Supported: boolean, dxtSupported: boolean, bptcSupported: boolean}}
|
|
87393
|
+
*/
|
|
87394
|
+
get capabilities() {
|
|
87395
|
+
return this.scene.capabilities;
|
|
87396
|
+
}
|
|
87397
|
+
|
|
87377
87398
|
/**
|
|
87378
87399
|
* Subscribes to an event fired at this Viewer.
|
|
87379
87400
|
*
|
|
@@ -103170,142 +103191,398 @@ class StoreyViewsPlugin extends Plugin {
|
|
|
103170
103191
|
}
|
|
103171
103192
|
|
|
103172
103193
|
/**
|
|
103173
|
-
*
|
|
103194
|
+
* @desc A {@link Viewer} plugin that provides an HTML tree view to navigate the IFC elements in models.
|
|
103195
|
+
* <br>
|
|
103174
103196
|
*
|
|
103175
|
-
*
|
|
103176
|
-
* @param {String[]} errors Accumulates messages for validation errors.
|
|
103177
|
-
* @return {boolean} Returns ````true```` if no errors found, else ````false````.
|
|
103178
|
-
*/
|
|
103179
|
-
function validateMetaModelForTreeViewTypesHierarchy(metaModel, errors) {
|
|
103180
|
-
const rootMetaObject = metaModel.rootMetaObject;
|
|
103181
|
-
if (!rootMetaObject) {
|
|
103182
|
-
errors.push("Can't build types hierarchy: model is empty");
|
|
103183
|
-
return false;
|
|
103184
|
-
}
|
|
103185
|
-
return true;
|
|
103186
|
-
}
|
|
103187
|
-
|
|
103188
|
-
/**
|
|
103189
|
-
* Tests if {@link TreeViewPlugin} would be able to create a "storeys" hierarchy for the given {@link MetaModel}.
|
|
103197
|
+
* <a href="https://xeokit.github.io/xeokit-sdk/examples/#BIMOffline_XKT_WestRiverSideHospital" style="border: 1px solid black;"><img src="http://xeokit.io/img/docs/TreeViewPlugin/TreeViewPlugin.png"></a>
|
|
103190
103198
|
*
|
|
103191
|
-
*
|
|
103192
|
-
* @param {String[]} errors Accumulates messages for validation errors.
|
|
103193
|
-
* @return {boolean} Returns ````true```` if no errors found, else ````false````.
|
|
103194
|
-
*/
|
|
103195
|
-
function validateMetaModelForTreeViewStoreysHierarchy(metaModel, errors) {
|
|
103196
|
-
const rootMetaObject = metaModel.rootMetaObject;
|
|
103197
|
-
if (!rootMetaObject) {
|
|
103198
|
-
errors.push("Can't build storeys hierarchy: model is empty");
|
|
103199
|
-
return false;
|
|
103200
|
-
}
|
|
103201
|
-
return _validateMetaModelForStoreysHierarchy(rootMetaObject, errors);
|
|
103202
|
-
}
|
|
103203
|
-
|
|
103204
|
-
/**
|
|
103205
|
-
* Tests if {@link TreeViewPlugin} would be able to create a "containment" hierarchy for the given {@link MetaModel}.
|
|
103199
|
+
* [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/#BIMOffline_XKT_WestRiverSideHospital)]
|
|
103206
103200
|
*
|
|
103207
|
-
*
|
|
103208
|
-
*
|
|
103209
|
-
*
|
|
103210
|
-
|
|
103211
|
-
|
|
103212
|
-
|
|
103213
|
-
|
|
103214
|
-
|
|
103215
|
-
|
|
103216
|
-
|
|
103217
|
-
|
|
103218
|
-
|
|
103219
|
-
|
|
103220
|
-
|
|
103221
|
-
*
|
|
103222
|
-
|
|
103223
|
-
|
|
103224
|
-
|
|
103225
|
-
|
|
103226
|
-
|
|
103227
|
-
|
|
103228
|
-
|
|
103229
|
-
|
|
103230
|
-
|
|
103231
|
-
|
|
103232
|
-
|
|
103233
|
-
|
|
103234
|
-
|
|
103235
|
-
|
|
103236
|
-
|
|
103237
|
-
|
|
103238
|
-
|
|
103239
|
-
|
|
103240
|
-
|
|
103241
|
-
|
|
103242
|
-
|
|
103243
|
-
|
|
103244
|
-
|
|
103245
|
-
|
|
103246
|
-
|
|
103247
|
-
|
|
103248
|
-
|
|
103249
|
-
|
|
103250
|
-
|
|
103251
|
-
|
|
103252
|
-
|
|
103253
|
-
|
|
103254
|
-
|
|
103255
|
-
*
|
|
103201
|
+
* ## Overview
|
|
103202
|
+
*
|
|
103203
|
+
* * A fast HTML tree view, with zero external dependencies, that works with huge numbers of objects.
|
|
103204
|
+
* * Each tree node has a checkbox to control the visibility of its object.
|
|
103205
|
+
* * Has three hierarchy modes: "containment", "types" and "storeys".
|
|
103206
|
+
* * Automatically contains all models (that have metadata) that are currently in the {@link Scene}.
|
|
103207
|
+
* * Sorts tree nodes by default - spatially, from top-to-bottom for ````IfcBuildingStorey```` nodes, and alphanumerically for other nodes.
|
|
103208
|
+
* * Allows custom CSS styling.
|
|
103209
|
+
* * Use {@link ContextMenu} to create a context menu for the tree nodes.
|
|
103210
|
+
*
|
|
103211
|
+
* ## Credits
|
|
103212
|
+
*
|
|
103213
|
+
* TreeViewPlugin is based on techniques described in [*Super Fast Tree View in JavaScript*](https://chrissmith.xyz/super-fast-tree-view-in-javascript/) by [Chris Smith](https://twitter.com/chris22smith).
|
|
103214
|
+
*
|
|
103215
|
+
* ## Usage
|
|
103216
|
+
*
|
|
103217
|
+
* In the example below, we'll add a TreeViewPlugin which, by default, will automatically show the structural
|
|
103218
|
+
* hierarchy of the IFC elements in each model we load.
|
|
103219
|
+
*
|
|
103220
|
+
* Then we'll use an {@link XKTLoaderPlugin} to load the Schependomlaan model from an
|
|
103221
|
+
* [.xkt file](https://github.com/xeokit/xeokit-sdk/tree/master/examples/models/xkt/schependomlaan).
|
|
103222
|
+
*
|
|
103223
|
+
* [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/#BIMOffline_XKT_Schependomlaan)]
|
|
103224
|
+
*
|
|
103225
|
+
* ````javascript
|
|
103226
|
+
* import {Viewer, XKTLoaderPlugin, TreeViewPlugin} from "xeokit-sdk.es.js";
|
|
103227
|
+
*
|
|
103228
|
+
* const viewer = new Viewer({
|
|
103229
|
+
* canvasId: "myCanvas",
|
|
103230
|
+
* transparent: true
|
|
103231
|
+
* });
|
|
103232
|
+
*
|
|
103233
|
+
* viewer.camera.eye = [-2.56, 8.38, 8.27];
|
|
103234
|
+
* viewer.camera.look = [13.44, 3.31, -14.83];
|
|
103235
|
+
* viewer.camera.up = [0.10, 0.98, -0.14];
|
|
103236
|
+
*
|
|
103237
|
+
* const treeView = new TreeViewPlugin(viewer, {
|
|
103238
|
+
* containerElement: document.getElementById("myTreeViewContainer")
|
|
103239
|
+
* });
|
|
103240
|
+
*
|
|
103241
|
+
* const xktLoader = new XKTLoaderPlugin(viewer);
|
|
103242
|
+
*
|
|
103243
|
+
* const model = xktLoader.load({
|
|
103244
|
+
* id: "myModel",
|
|
103245
|
+
* src: "./models/xkt/Schependomlaan.xkt",
|
|
103246
|
+
* edges: true
|
|
103247
|
+
* });
|
|
103248
|
+
* ````
|
|
103249
|
+
*
|
|
103250
|
+
* ## Manually Adding Models
|
|
103251
|
+
*
|
|
103252
|
+
* Instead of adding models automatically, we can control which models appear in our TreeViewPlugin by adding them manually.
|
|
103253
|
+
*
|
|
103254
|
+
* In the next example, we'll configure the TreeViewPlugin to not add models automatically. Then, once the model
|
|
103255
|
+
* has loaded, we'll add it manually using {@link TreeViewPlugin#addModel}.
|
|
103256
|
+
*
|
|
103257
|
+
* ````javascript
|
|
103258
|
+
* const treeView = new TreeViewPlugin(viewer, {
|
|
103259
|
+
* containerElement: document.getElementById("myTreeViewContainer"),
|
|
103260
|
+
* autoAddModels: false // <<---------------- Don't auto-add models
|
|
103261
|
+
* });
|
|
103262
|
+
*
|
|
103263
|
+
* const xktLoader = new XKTLoaderPlugin(viewer);
|
|
103264
|
+
*
|
|
103265
|
+
* const model = xktLoader.load({
|
|
103266
|
+
* id: "myModel",
|
|
103267
|
+
* src: "./models/xkt/Schependomlaan.xkt",
|
|
103268
|
+
* edges: true
|
|
103269
|
+
* });
|
|
103270
|
+
*
|
|
103271
|
+
* model.on("loaded", () => {
|
|
103272
|
+
* treeView.addModel(model.id);
|
|
103273
|
+
* });
|
|
103274
|
+
* ````
|
|
103275
|
+
*
|
|
103276
|
+
* Adding models manually also allows us to set some options for the model. For example, the ````rootName```` option allows us to provide a custom name for
|
|
103277
|
+
* the root node, which is sometimes desirable when the model's "IfcProject" element's name is not suitable:
|
|
103278
|
+
*
|
|
103279
|
+
* ````javascript
|
|
103280
|
+
* model.on("loaded", () => {
|
|
103281
|
+
* treeView.addModel(model.id, {
|
|
103282
|
+
* rootName: "Schependomlaan Model"
|
|
103283
|
+
* });
|
|
103284
|
+
* });
|
|
103285
|
+
* ````
|
|
103286
|
+
*
|
|
103287
|
+
* ## Initially Expanding the Hierarchy
|
|
103288
|
+
*
|
|
103289
|
+
* We can also configure TreeViewPlugin to initially expand each model's nodes to a given depth.
|
|
103290
|
+
*
|
|
103291
|
+
* Let's automatically expand the first three nodes from the root, for every model added:
|
|
103292
|
+
*
|
|
103293
|
+
* ````javascript
|
|
103294
|
+
* const treeView = new TreeViewPlugin(viewer, {
|
|
103295
|
+
* containerElement: document.getElementById("myTreeViewContainer"),
|
|
103296
|
+
* autoExpandDepth: 3
|
|
103297
|
+
* });
|
|
103298
|
+
* ````
|
|
103299
|
+
*
|
|
103300
|
+
* ## Showing a Node by ID
|
|
103301
|
+
*
|
|
103302
|
+
* We can show a given node using its ID. This causes the TreeViewPlugin to collapse, then expand and scroll the node into view, then highlight the node.
|
|
103303
|
+
*
|
|
103304
|
+
* See the documentation for the {@link TreeViewPlugin#showNode} method for more information, including how to define a custom highlighted appearance for the node using CSS.
|
|
103305
|
+
*
|
|
103306
|
+
* Let's make the TreeViewPlugin show the node corresponding to whatever object {@link Entity} that we pick:
|
|
103307
|
+
*
|
|
103308
|
+
* ````javascript
|
|
103309
|
+
* viewer.cameraControl.on("picked", function (e) {
|
|
103310
|
+
* var objectId = e.entity.id;
|
|
103311
|
+
* treeView.showNode(objectId);
|
|
103312
|
+
* });
|
|
103313
|
+
* ````
|
|
103314
|
+
*
|
|
103315
|
+
* This will de-highlight any node that was previously shown by this method.
|
|
103316
|
+
*
|
|
103317
|
+
* Note that this method only works if the picked {@link Entity} is an object that belongs to a model that's represented in the TreeViewPlugin.
|
|
103318
|
+
*
|
|
103319
|
+
* ## Customizing Appearance
|
|
103320
|
+
*
|
|
103321
|
+
* We can customize the appearance of our TreeViewPlugin by defining custom CSS for its HTML
|
|
103322
|
+
* elements. See our example's [source code](https://github.com/xeokit/xeokit-sdk/blob/master/examples/BIMOffline_XKT_Schependomlaan.html)
|
|
103323
|
+
* for an example of custom CSS rules.
|
|
103324
|
+
*
|
|
103325
|
+
* ## Model Hierarchies
|
|
103326
|
+
*
|
|
103327
|
+
* TreeViewPlugin has three hierarchies for organizing its nodes:
|
|
103328
|
+
*
|
|
103329
|
+
* * "containment" - organizes the tree nodes to indicate the containment hierarchy of the {@link MetaObject}s.
|
|
103330
|
+
* * "types" - groups nodes by their IFC types.
|
|
103331
|
+
* * "storeys" - groups nodes within their ````IfcBuildingStoreys````, and sub-groups them by their IFC types.
|
|
103332
|
+
*
|
|
103333
|
+
* <br>
|
|
103334
|
+
* The table below shows what the hierarchies look like:
|
|
103335
|
+
* <br>
|
|
103336
|
+
*
|
|
103337
|
+
* | 1. Containment Hierarchy | 2. Types Hierarchy | 3. Storeys Hierarchy |
|
|
103338
|
+
* |---|---|---|
|
|
103339
|
+
* | <img src="http://xeokit.io/img/docs/TreeViewPlugin/structureMode.png"> | <img src="http://xeokit.io/img/docs/TreeViewPlugin/typesMode.png"> | <img src="http://xeokit.io/img/docs/TreeViewPlugin/storeysMode.png"> |
|
|
103340
|
+
* <br>
|
|
103341
|
+
*
|
|
103342
|
+
* Let's create a TreeViewPlugin that groups nodes by their building stories and IFC types:
|
|
103343
|
+
*
|
|
103344
|
+
* ````javascript
|
|
103345
|
+
* const treeView = new TreeViewPlugin(viewer, {
|
|
103346
|
+
* containerElement: document.getElementById("myTreeViewContainer"),
|
|
103347
|
+
* hierarchy: "stories"
|
|
103348
|
+
* });
|
|
103349
|
+
* ````
|
|
103350
|
+
*
|
|
103351
|
+
* ## Sorting Nodes
|
|
103352
|
+
*
|
|
103353
|
+
* TreeViewPlugin sorts its tree nodes by default. For a "storeys" hierarchy, it orders ````IfcBuildingStorey```` nodes
|
|
103354
|
+
* spatially, with the node for the highest story at the top, down to the lowest at the bottom.
|
|
103355
|
+
*
|
|
103356
|
+
* For all the hierarchy types ("containment", "classes" and "storeys"), TreeViewPlugin sorts the other node types
|
|
103357
|
+
* alphanumerically on their titles.
|
|
103358
|
+
*
|
|
103359
|
+
* If for some reason you need to prevent sorting, create your TreeViewPlugin with the option disabled, like so:
|
|
103360
|
+
*
|
|
103361
|
+
* ````javascript
|
|
103362
|
+
* const treeView = new TreeViewPlugin(viewer, {
|
|
103363
|
+
* containerElement: document.getElementById("myTreeViewContainer"),
|
|
103364
|
+
* hierarchy: "stories",
|
|
103365
|
+
* sortNodes: false // <<------ Disable node sorting
|
|
103366
|
+
* });
|
|
103367
|
+
* ````
|
|
103368
|
+
*
|
|
103369
|
+
* Note that, for all hierarchy modes, node sorting is only done for each model at the time that it is added to the TreeViewPlugin, and will not
|
|
103370
|
+
* update dynamically if we later transform the {@link Entity}s corresponding to the nodes.
|
|
103371
|
+
*
|
|
103372
|
+
* ## Pruning empty nodes
|
|
103373
|
+
*
|
|
103374
|
+
* Sometimes a model contains subtrees of objects that don't have any geometry. These are models whose
|
|
103375
|
+
* {@link MetaModel} contains trees of {@link MetaObject}s that don't have any {@link Entity}s in the {@link Scene}.
|
|
103376
|
+
*
|
|
103377
|
+
* For these models, the tree view would contain nodes that don't do anything in the Scene when we interact with them,
|
|
103378
|
+
* which is undesirable.
|
|
103379
|
+
*
|
|
103380
|
+
* By default, TreeViewPlugin will not create nodes for those objects. However, we can override that behaviour if we want
|
|
103381
|
+
* to have nodes for those objects (perhaps for debugging the model):
|
|
103382
|
+
*
|
|
103383
|
+
* ````javascript
|
|
103384
|
+
* const treeView = new TreeViewPlugin(viewer, {
|
|
103385
|
+
* containerElement: document.getElementById("myTreeViewContainer"),
|
|
103386
|
+
* hierarchy: "stories",
|
|
103387
|
+
* pruneEmptyNodes: false // <<------ Create nodes for object subtrees without geometry
|
|
103388
|
+
* });
|
|
103389
|
+
* ````
|
|
103390
|
+
*
|
|
103391
|
+
* ## Context Menu
|
|
103392
|
+
*
|
|
103393
|
+
* TreeViewPlugin fires a "contextmenu" event whenever we right-click on a tree node.
|
|
103394
|
+
*
|
|
103395
|
+
* The event contains:
|
|
103396
|
+
*
|
|
103397
|
+
* * ````event```` - the original [contextmenu](https://developer.mozilla.org/en-US/docs/Web/API/Element/contextmenu_event) [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent)
|
|
103398
|
+
* * ````viewer```` - the {@link Viewer}
|
|
103399
|
+
* * ````treeViewPlugin```` - the TreeViewPlugin
|
|
103400
|
+
* * ````treeViewNode```` - the {@link TreeViewNode} representing the tree node
|
|
103401
|
+
*<br><br>
|
|
103402
|
+
*
|
|
103403
|
+
* Let's use {@link ContextMenu} to show a simple context menu for the node we clicked.
|
|
103404
|
+
*
|
|
103405
|
+
* [[Run an example](https://xeokit.github.io/xeokit-sdk/examples/#ContextMenu_Canvas_TreeViewPlugin_Custom)]
|
|
103406
|
+
*
|
|
103407
|
+
* ````javascript
|
|
103408
|
+
* import {ContextMenu} from "../src/extras/ContextMenu/ContextMenu.js";
|
|
103409
|
+
*
|
|
103410
|
+
* const treeViewContextMenu = new ContextMenu({
|
|
103411
|
+
* items: [
|
|
103412
|
+
* [
|
|
103413
|
+
* [
|
|
103414
|
+
* {
|
|
103415
|
+
* title: "Hide",
|
|
103416
|
+
* doAction: function (context) {
|
|
103417
|
+
* context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
|
|
103418
|
+
* if (treeViewNode.objectId) {
|
|
103419
|
+
* const entity = context.viewer.scene.objects[treeViewNode.objectId];
|
|
103420
|
+
* if (entity) {
|
|
103421
|
+
* entity.visible = false;
|
|
103422
|
+
* }
|
|
103423
|
+
* }
|
|
103424
|
+
* });
|
|
103425
|
+
* }
|
|
103426
|
+
* },
|
|
103427
|
+
* {
|
|
103428
|
+
* title: "Hide all",
|
|
103429
|
+
* doAction: function (context) {
|
|
103430
|
+
* context.viewer.scene.setObjectsVisible(context.viewer.scene.visibleObjectIds, false);
|
|
103431
|
+
* }
|
|
103432
|
+
* }
|
|
103433
|
+
* ],
|
|
103434
|
+
* [
|
|
103435
|
+
* {
|
|
103436
|
+
* title: "Show",
|
|
103437
|
+
* doAction: function (context) {
|
|
103438
|
+
* context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
|
|
103439
|
+
* if (treeViewNode.objectId) {
|
|
103440
|
+
* const entity = context.viewer.scene.objects[treeViewNode.objectId];
|
|
103441
|
+
* if (entity) {
|
|
103442
|
+
* entity.visible = true;
|
|
103443
|
+
* entity.xrayed = false;
|
|
103444
|
+
* entity.selected = false;
|
|
103445
|
+
* }
|
|
103446
|
+
* }
|
|
103447
|
+
* });
|
|
103448
|
+
* }
|
|
103449
|
+
* },
|
|
103450
|
+
* {
|
|
103451
|
+
* title: "Show all",
|
|
103452
|
+
* doAction: function (context) {
|
|
103453
|
+
* const scene = context.viewer.scene;
|
|
103454
|
+
* scene.setObjectsVisible(scene.objectIds, true);
|
|
103455
|
+
* scene.setObjectsXRayed(scene.xrayedObjectIds, false);
|
|
103456
|
+
* scene.setObjectsSelected(scene.selectedObjectIds, false);
|
|
103457
|
+
* }
|
|
103458
|
+
* }
|
|
103459
|
+
* ]
|
|
103460
|
+
* ]
|
|
103461
|
+
* ]
|
|
103462
|
+
* });
|
|
103463
|
+
*
|
|
103464
|
+
* treeView.on("contextmenu", (e) => {
|
|
103465
|
+
*
|
|
103466
|
+
* const event = e.event; // MouseEvent
|
|
103467
|
+
* const viewer = e.viewer; // Viewer
|
|
103468
|
+
* const treeViewPlugin = e.treeViewPlugin; // TreeViewPlugin
|
|
103469
|
+
* const treeViewNode = e.treeViewNode; // TreeViewNode
|
|
103470
|
+
*
|
|
103471
|
+
* treeViewContextMenu.show(e.event.pageX, e.event.pageY);
|
|
103472
|
+
*
|
|
103473
|
+
* treeViewContextMenu.context = {
|
|
103474
|
+
* viewer: e.viewer,
|
|
103475
|
+
* treeViewPlugin: e.treeViewPlugin,
|
|
103476
|
+
* treeViewNode: e.treeViewNode
|
|
103477
|
+
* };
|
|
103478
|
+
* });
|
|
103479
|
+
* ````
|
|
103480
|
+
*
|
|
103481
|
+
* ## Clicking Node Titles
|
|
103482
|
+
*
|
|
103483
|
+
* TreeViewPlugin fires a "nodeTitleClicked" event whenever we left-click on a tree node.
|
|
103484
|
+
*
|
|
103485
|
+
* Like the "contextmenu" event, this event contains:
|
|
103486
|
+
*
|
|
103487
|
+
* * ````event```` - the original [click](https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event) [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent)
|
|
103488
|
+
* * ````viewer```` - the {@link Viewer}
|
|
103489
|
+
* * ````treeViewPlugin```` - the TreeViewPlugin
|
|
103490
|
+
* * ````treeViewNode```` - the {@link TreeViewNode} representing the tree node
|
|
103491
|
+
*<br><br>
|
|
103492
|
+
*
|
|
103493
|
+
* Let's register a callback to isolate and fit-to-view the {@link Entity}(s) represented by the node. This callback is
|
|
103494
|
+
* going to X-ray all the other Entitys, fly the camera to fit the Entity(s) for the clicked node, then hide the other Entitys.
|
|
103495
|
+
*
|
|
103496
|
+
* [[Run an example](https://xeokit.github.io/xeokit-sdk/examples/#ContextMenu_Canvas_TreeViewPlugin_Custom)]
|
|
103497
|
+
*
|
|
103498
|
+
* ````javascript
|
|
103499
|
+
* treeView.on("nodeTitleClicked", (e) => {
|
|
103500
|
+
* const scene = viewer.scene;
|
|
103501
|
+
* const objectIds = [];
|
|
103502
|
+
* e.treeViewPlugin.withNodeTree(e.treeViewNode, (treeViewNode) => {
|
|
103503
|
+
* if (treeViewNode.objectId) {
|
|
103504
|
+
* objectIds.push(treeViewNode.objectId);
|
|
103505
|
+
* }
|
|
103506
|
+
* });
|
|
103507
|
+
* scene.setObjectsXRayed(scene.objectIds, true);
|
|
103508
|
+
* scene.setObjectsVisible(scene.objectIds, true);
|
|
103509
|
+
* scene.setObjectsXRayed(objectIds, false);
|
|
103510
|
+
* viewer.cameraFlight.flyTo({
|
|
103511
|
+
* aabb: scene.getAABB(objectIds),
|
|
103512
|
+
* duration: 0.5
|
|
103513
|
+
* }, () => {
|
|
103514
|
+
* setTimeout(function () {
|
|
103515
|
+
* scene.setObjectsVisible(scene.xrayedObjectIds, false);
|
|
103516
|
+
* scene.setObjectsXRayed(scene.xrayedObjectIds, false);
|
|
103517
|
+
* }, 500);
|
|
103518
|
+
* });
|
|
103519
|
+
* });
|
|
103520
|
+
* ````
|
|
103521
|
+
*
|
|
103522
|
+
* To make the cursor change to a pointer when we hover over the node titles, and also to make the titles change to blue, we'll also define this CSS for the ````<span>```` elements
|
|
103523
|
+
* that represent the titles of our TreeViewPlugin nodes:
|
|
103524
|
+
*
|
|
103525
|
+
* ````css
|
|
103526
|
+
* #treeViewContainer ul li span:hover {
|
|
103527
|
+
* color: blue;
|
|
103528
|
+
* cursor: pointer;
|
|
103529
|
+
* }
|
|
103530
|
+
* ````
|
|
103256
103531
|
*
|
|
103257
|
-
*
|
|
103258
|
-
* * Created by each call to {@link TreeViewPlugin#addModel}.
|
|
103532
|
+
* @class TreeViewPlugin
|
|
103259
103533
|
*/
|
|
103260
|
-
class
|
|
103534
|
+
class TreeViewPlugin extends Plugin {
|
|
103261
103535
|
|
|
103262
103536
|
/**
|
|
103263
|
-
* @
|
|
103537
|
+
* @constructor
|
|
103538
|
+
*
|
|
103539
|
+
* @param {Viewer} viewer The Viewer.
|
|
103540
|
+
* @param {*} cfg Plugin configuration.
|
|
103541
|
+
* @param {HTMLElement} cfg.containerElement DOM element to contain the TreeViewPlugin.
|
|
103542
|
+
* @param {Boolean} [cfg.autoAddModels=true] When ````true```` (default), will automatically add each model as it's created. Set this ````false```` if you want to manually add models using {@link TreeViewPlugin#addModel} instead.
|
|
103543
|
+
* @param {Number} [cfg.autoExpandDepth] Optional depth to which to initially expand the tree.
|
|
103544
|
+
* @param {String} [cfg.hierarchy="containment"] How to organize the tree nodes: "containment", "storeys" or "types". See the class documentation for details.
|
|
103545
|
+
* @param {Boolean} [cfg.sortNodes=true] When true, will sort the children of each node. For a "storeys" hierarchy, the
|
|
103546
|
+
* ````IfcBuildingStorey```` nodes will be ordered spatially, from the highest storey down to the lowest, on the
|
|
103547
|
+
* vertical World axis. For all hierarchy types, other node types will be ordered in the ascending alphanumeric order of their titles.
|
|
103548
|
+
* @param {Boolean} [cfg.pruneEmptyNodes=true] When true, will not contain nodes that don't have content in the {@link Scene}. These are nodes whose {@link MetaObject}s don't have {@link Entity}s.
|
|
103264
103549
|
*/
|
|
103265
|
-
constructor(viewer,
|
|
103266
|
-
|
|
103267
|
-
if (!cfg.containerElement) {
|
|
103268
|
-
throw "Config expected: containerElement";
|
|
103269
|
-
}
|
|
103550
|
+
constructor(viewer, cfg = {}) {
|
|
103270
103551
|
|
|
103271
|
-
|
|
103272
|
-
if (!rootMetaObject) {
|
|
103273
|
-
return;
|
|
103274
|
-
}
|
|
103552
|
+
super("TreeViewPlugin", viewer);
|
|
103275
103553
|
|
|
103276
103554
|
/**
|
|
103277
|
-
* Contains messages for any errors found
|
|
103555
|
+
* Contains messages for any errors found while last rebuilding this TreeView.
|
|
103278
103556
|
* @type {String[]}
|
|
103279
103557
|
*/
|
|
103280
103558
|
this.errors = [];
|
|
103281
103559
|
|
|
103282
103560
|
/**
|
|
103283
|
-
* True if errors were found
|
|
103561
|
+
* True if errors were found generating this TreeView.
|
|
103284
103562
|
* @type {boolean}
|
|
103285
103563
|
*/
|
|
103286
103564
|
this.valid = true;
|
|
103287
103565
|
|
|
103288
|
-
|
|
103289
|
-
|
|
103290
|
-
|
|
103291
|
-
|
|
103292
|
-
this.metaModel = metaModel;
|
|
103566
|
+
if (!cfg.containerElement) {
|
|
103567
|
+
this.error("Config expected: containerElement");
|
|
103568
|
+
return;
|
|
103569
|
+
}
|
|
103293
103570
|
|
|
103294
|
-
this._id = idMap.addItem();
|
|
103295
|
-
this._baseId = "" + this._id;
|
|
103296
|
-
this._viewer = viewer;
|
|
103297
|
-
this._treeViewPlugin = treeViewPlugin;
|
|
103298
|
-
this._rootMetaObject = rootMetaObject;
|
|
103299
103571
|
this._containerElement = cfg.containerElement;
|
|
103572
|
+
this._metaModels = {};
|
|
103573
|
+
this._autoAddModels = (cfg.autoAddModels !== false);
|
|
103574
|
+
this._autoExpandDepth = (cfg.autoExpandDepth || 0);
|
|
103575
|
+
this._sortNodes = (cfg.sortNodes !== false);
|
|
103576
|
+
this._pruneEmptyNodes = (cfg.pruneEmptyNodes !== false);
|
|
103577
|
+
this._viewer = viewer;
|
|
103300
103578
|
this._rootElement = null;
|
|
103301
103579
|
this._muteSceneEvents = false;
|
|
103302
103580
|
this._muteTreeEvents = false;
|
|
103303
103581
|
this._rootNodes = [];
|
|
103304
|
-
this._objectNodes = {};
|
|
103582
|
+
this._objectNodes = {}; // Object ID -> Node
|
|
103305
103583
|
this._rootName = cfg.rootName;
|
|
103306
103584
|
this._sortNodes = cfg.sortNodes;
|
|
103307
103585
|
this._pruneEmptyNodes = cfg.pruneEmptyNodes;
|
|
103308
|
-
|
|
103309
103586
|
this._showListItemElementId = null;
|
|
103310
103587
|
|
|
103311
103588
|
this._containerElement.oncontextmenu = (e) => {
|
|
@@ -103358,43 +103635,41 @@ class ModelTreeView {
|
|
|
103358
103635
|
});
|
|
103359
103636
|
|
|
103360
103637
|
this._onObjectXrayed = this._viewer.scene.on('objectXRayed', (entity) => {
|
|
103361
|
-
|
|
103362
|
-
|
|
103363
|
-
}
|
|
103364
|
-
const objectId = entity.id;
|
|
103365
|
-
const node = this._objectNodes[objectId];
|
|
103366
|
-
if (!node) {
|
|
103367
|
-
return; // Not in this tree
|
|
103368
|
-
}
|
|
103369
|
-
|
|
103370
|
-
this._muteTreeEvents = true;
|
|
103371
|
-
const xrayed = entity.xrayed;
|
|
103372
|
-
const updated = (xrayed !== node.xrayed);
|
|
103373
|
-
if (!updated) {
|
|
103374
|
-
return;
|
|
103375
|
-
}
|
|
103376
|
-
node.xrayed = xrayed;
|
|
103377
|
-
const listItemElementId = 'node-' + node.nodeId;
|
|
103378
|
-
const listItemElement = document.getElementById(listItemElementId);
|
|
103379
|
-
if (listItemElement !== null) {
|
|
103380
|
-
if (xrayed) {
|
|
103381
|
-
listItemElement.classList.add('xrayed-node');
|
|
103382
|
-
} else {
|
|
103383
|
-
listItemElement.classList.remove('xrayed-node');
|
|
103638
|
+
if (this._muteSceneEvents) {
|
|
103639
|
+
return;
|
|
103384
103640
|
}
|
|
103385
|
-
|
|
103386
|
-
|
|
103387
|
-
|
|
103641
|
+
const objectId = entity.id;
|
|
103642
|
+
const node = this._objectNodes[objectId];
|
|
103643
|
+
if (!node) {
|
|
103644
|
+
return; // Not in this tree
|
|
103645
|
+
}
|
|
103646
|
+
this._muteTreeEvents = true;
|
|
103647
|
+
const xrayed = entity.xrayed;
|
|
103648
|
+
const updated = (xrayed !== node.xrayed);
|
|
103649
|
+
if (!updated) {
|
|
103650
|
+
return;
|
|
103651
|
+
}
|
|
103652
|
+
node.xrayed = xrayed;
|
|
103653
|
+
const listItemElementId = 'node-' + node.nodeId;
|
|
103654
|
+
const listItemElement = document.getElementById(listItemElementId);
|
|
103655
|
+
if (listItemElement !== null) {
|
|
103656
|
+
if (xrayed) {
|
|
103657
|
+
listItemElement.classList.add('xrayed-node');
|
|
103658
|
+
} else {
|
|
103659
|
+
listItemElement.classList.remove('xrayed-node');
|
|
103660
|
+
}
|
|
103661
|
+
}
|
|
103662
|
+
this._muteTreeEvents = false;
|
|
103388
103663
|
});
|
|
103389
103664
|
|
|
103390
|
-
this.
|
|
103665
|
+
this._switchExpandHandler = (event) => {
|
|
103391
103666
|
event.preventDefault();
|
|
103392
103667
|
event.stopPropagation();
|
|
103393
103668
|
const switchElement = event.target;
|
|
103394
103669
|
this._expandSwitchElement(switchElement);
|
|
103395
103670
|
};
|
|
103396
103671
|
|
|
103397
|
-
this.
|
|
103672
|
+
this._switchCollapseHandler = (event) => {
|
|
103398
103673
|
event.preventDefault();
|
|
103399
103674
|
event.stopPropagation();
|
|
103400
103675
|
const switchElement = event.target;
|
|
@@ -103409,7 +103684,7 @@ class ModelTreeView {
|
|
|
103409
103684
|
const checkbox = event.target;
|
|
103410
103685
|
const visible = checkbox.checked;
|
|
103411
103686
|
const nodeId = checkbox.id;
|
|
103412
|
-
const checkedObjectId =
|
|
103687
|
+
const checkedObjectId = nodeId;
|
|
103413
103688
|
const checkedNode = this._objectNodes[checkedObjectId];
|
|
103414
103689
|
const objects = this._viewer.scene.objects;
|
|
103415
103690
|
let numUpdated = 0;
|
|
@@ -103452,30 +103727,44 @@ class ModelTreeView {
|
|
|
103452
103727
|
this._hierarchy = cfg.hierarchy || "containment";
|
|
103453
103728
|
this._autoExpandDepth = cfg.autoExpandDepth || 0;
|
|
103454
103729
|
|
|
103455
|
-
this.
|
|
103456
|
-
|
|
103457
|
-
|
|
103458
|
-
|
|
103459
|
-
|
|
103460
|
-
|
|
103461
|
-
|
|
103462
|
-
|
|
103463
|
-
|
|
103464
|
-
|
|
103730
|
+
if (this._autoAddModels) {
|
|
103731
|
+
const modelIds = Object.keys(this.viewer.metaScene.metaModels);
|
|
103732
|
+
for (let i = 0, len = modelIds.length; i < len; i++) {
|
|
103733
|
+
const modelId = modelIds[i];
|
|
103734
|
+
this.addModel(modelId);
|
|
103735
|
+
}
|
|
103736
|
+
this.viewer.scene.on("modelLoaded", (modelId) => {
|
|
103737
|
+
if (this.viewer.metaScene.metaModels[modelId]) {
|
|
103738
|
+
this.addModel(modelId);
|
|
103739
|
+
}
|
|
103740
|
+
});
|
|
103741
|
+
}
|
|
103465
103742
|
|
|
103466
|
-
|
|
103467
|
-
* @private
|
|
103468
|
-
* @param depth
|
|
103469
|
-
*/
|
|
103470
|
-
setAutoExpandDepth(depth = 0) {
|
|
103471
|
-
this._autoExpandDepth = depth;
|
|
103743
|
+
this.hierarchy = cfg.hierarchy;
|
|
103472
103744
|
}
|
|
103473
103745
|
|
|
103474
103746
|
/**
|
|
103475
|
-
*
|
|
103476
|
-
*
|
|
103747
|
+
* Sets how the nodes are organized within this tree view.
|
|
103748
|
+
*
|
|
103749
|
+
* Accepted values are:
|
|
103750
|
+
*
|
|
103751
|
+
* * "containment" - organizes the nodes to indicate the containment hierarchy of the IFC objects.
|
|
103752
|
+
* * "types" - groups the nodes within their IFC types.
|
|
103753
|
+
* * "storeys" - groups the nodes within ````IfcBuildingStoreys```` and sub-groups them by their IFC types.
|
|
103754
|
+
*
|
|
103755
|
+
* <br>
|
|
103756
|
+
* This can be updated dynamically.
|
|
103757
|
+
*
|
|
103758
|
+
* Default value is "containment".
|
|
103759
|
+
*
|
|
103760
|
+
* @type {String}
|
|
103477
103761
|
*/
|
|
103478
|
-
|
|
103762
|
+
set hierarchy(hierarchy) {
|
|
103763
|
+
hierarchy = hierarchy || "containment";
|
|
103764
|
+
if (hierarchy !== "containment" && hierarchy !== "storeys" && hierarchy !== "types") {
|
|
103765
|
+
this.error("Unsupported value for `hierarchy' - defaulting to 'containment'");
|
|
103766
|
+
hierarchy = "containment";
|
|
103767
|
+
}
|
|
103479
103768
|
if (this._hierarchy === hierarchy) {
|
|
103480
103769
|
return;
|
|
103481
103770
|
}
|
|
@@ -103483,38 +103772,287 @@ class ModelTreeView {
|
|
|
103483
103772
|
this._createNodes();
|
|
103484
103773
|
}
|
|
103485
103774
|
|
|
103486
|
-
|
|
103487
|
-
|
|
103488
|
-
|
|
103489
|
-
|
|
103490
|
-
|
|
103491
|
-
|
|
103492
|
-
this.
|
|
103493
|
-
this._validate();
|
|
103494
|
-
if (this.valid || (this._hierarchy !== "storeys")) {
|
|
103495
|
-
this._createEnabledNodes();
|
|
103496
|
-
} else {
|
|
103497
|
-
this._createDisabledNodes();
|
|
103498
|
-
}
|
|
103775
|
+
/**
|
|
103776
|
+
* Gets how the nodes are organized within this tree view.
|
|
103777
|
+
*
|
|
103778
|
+
* @type {String}
|
|
103779
|
+
*/
|
|
103780
|
+
get hierarchy() {
|
|
103781
|
+
return this._hierarchy;
|
|
103499
103782
|
}
|
|
103500
103783
|
|
|
103501
|
-
|
|
103502
|
-
|
|
103503
|
-
|
|
103504
|
-
|
|
103505
|
-
|
|
103506
|
-
|
|
103507
|
-
|
|
103508
|
-
|
|
103509
|
-
|
|
103510
|
-
|
|
103511
|
-
|
|
103512
|
-
|
|
103784
|
+
/**
|
|
103785
|
+
* Adds a model to this tree view.
|
|
103786
|
+
*
|
|
103787
|
+
* The model will be automatically removed when destroyed.
|
|
103788
|
+
*
|
|
103789
|
+
* To automatically add each model as it's created, instead of manually calling this method each time,
|
|
103790
|
+
* provide a ````autoAddModels: true```` to the TreeViewPlugin constructor.
|
|
103791
|
+
*
|
|
103792
|
+
* @param {String} modelId ID of a model {@link Entity} in {@link Scene#models}.
|
|
103793
|
+
* @param {Object} [options] Options for model in the tree view.
|
|
103794
|
+
* @param {String} [options.rootName] Optional display name for the root node. Ordinary, for "containment"
|
|
103795
|
+
* and "storeys" hierarchy types, the tree would derive the root node name from the model's "IfcProject" element
|
|
103796
|
+
* name. This option allows to override that name when it is not suitable as a display name.
|
|
103797
|
+
*/
|
|
103798
|
+
addModel(modelId, options = {}) {
|
|
103799
|
+
if (!this._containerElement) {
|
|
103800
|
+
return;
|
|
103801
|
+
}
|
|
103802
|
+
const model = this.viewer.scene.models[modelId];
|
|
103803
|
+
if (!model) {
|
|
103804
|
+
throw "Model not found: " + modelId;
|
|
103805
|
+
}
|
|
103806
|
+
const metaModel = this.viewer.metaScene.metaModels[modelId];
|
|
103807
|
+
if (!metaModel) {
|
|
103808
|
+
this.error("MetaModel not found: " + modelId);
|
|
103809
|
+
return;
|
|
103810
|
+
}
|
|
103811
|
+
if (this._metaModels[modelId]) {
|
|
103812
|
+
this.warn("Model already added: " + modelId);
|
|
103813
|
+
return;
|
|
103814
|
+
}
|
|
103815
|
+
this._metaModels[modelId] = metaModel;
|
|
103816
|
+
model.on("destroyed", () => {
|
|
103817
|
+
this.removeModel(model.id);
|
|
103818
|
+
});
|
|
103819
|
+
this._createNodes();
|
|
103820
|
+
}
|
|
103821
|
+
|
|
103822
|
+
/**
|
|
103823
|
+
* Removes a model from this tree view.
|
|
103824
|
+
*
|
|
103825
|
+
* Does nothing if model not currently in tree view.
|
|
103826
|
+
*
|
|
103827
|
+
* @param {String} modelId ID of a model {@link Entity} in {@link Scene#models}.
|
|
103828
|
+
*/
|
|
103829
|
+
removeModel(modelId) {
|
|
103830
|
+
if (!this._containerElement) {
|
|
103831
|
+
return;
|
|
103832
|
+
}
|
|
103833
|
+
const metaModel = this._metaModels[modelId];
|
|
103834
|
+
if (!metaModel) {
|
|
103835
|
+
return;
|
|
103836
|
+
}
|
|
103837
|
+
delete this._metaModels[modelId];
|
|
103838
|
+
this._createNodes();
|
|
103839
|
+
}
|
|
103840
|
+
|
|
103841
|
+
/**
|
|
103842
|
+
* Highlights the tree view node that represents the given object {@link Entity}.
|
|
103843
|
+
*
|
|
103844
|
+
* This causes the tree view to collapse, then expand to reveal the node, then highlight the node.
|
|
103845
|
+
*
|
|
103846
|
+
* If a node is previously highlighted, de-highlights that node and collapses the tree first.
|
|
103847
|
+
*
|
|
103848
|
+
* Note that if the TreeViewPlugin was configured with ````pruneEmptyNodes: true```` (default configuration), then the
|
|
103849
|
+
* node won't exist in the tree if it has no Entitys in the {@link Scene}. in that case, nothing will happen.
|
|
103850
|
+
*
|
|
103851
|
+
* Within the DOM, the node is represented by an ````<li>```` element. This method will add a ````.highlighted-node```` class to
|
|
103852
|
+
* the element to make it appear highlighted, removing that class when de-highlighting it again. See the CSS rules
|
|
103853
|
+
* in the TreeViewPlugin examples for an example of that class.
|
|
103854
|
+
*
|
|
103855
|
+
* @param {String} objectId ID of the {@link Entity}.
|
|
103856
|
+
*/
|
|
103857
|
+
showNode(objectId) {
|
|
103858
|
+
if (this._showListItemElementId) {
|
|
103859
|
+
this.unShowNode();
|
|
103860
|
+
}
|
|
103861
|
+
const node = this._objectNodes[objectId];
|
|
103862
|
+
if (!node) {
|
|
103863
|
+
return; // Node may not exist for the given object if (this._pruneEmptyNodes == true)
|
|
103864
|
+
}
|
|
103865
|
+
const nodeId = node.nodeId;
|
|
103866
|
+
const switchElementId = "switch-" + nodeId;
|
|
103867
|
+
const switchElement = document.getElementById(switchElementId);
|
|
103868
|
+
if (switchElement) {
|
|
103869
|
+
this._expandSwitchElement(switchElement);
|
|
103870
|
+
switchElement.scrollIntoView();
|
|
103871
|
+
return;
|
|
103872
|
+
}
|
|
103873
|
+
const path = [];
|
|
103874
|
+
path.unshift(node);
|
|
103875
|
+
let parent = node.parent;
|
|
103876
|
+
while (parent) {
|
|
103877
|
+
path.unshift(parent);
|
|
103878
|
+
parent = parent.parent;
|
|
103879
|
+
}
|
|
103880
|
+
for (let i = 0, len = path.length; i < len; i++) {
|
|
103881
|
+
const node = path[i];
|
|
103882
|
+
const nodeId = node.nodeId;
|
|
103883
|
+
const switchElementId = "switch-" + nodeId;
|
|
103884
|
+
const switchElement = document.getElementById(switchElementId);
|
|
103885
|
+
if (switchElement) {
|
|
103886
|
+
this._expandSwitchElement(switchElement);
|
|
103887
|
+
}
|
|
103888
|
+
}
|
|
103889
|
+
const listItemElementId = 'node-' + nodeId;
|
|
103890
|
+
const listItemElement = document.getElementById(listItemElementId);
|
|
103891
|
+
listItemElement.scrollIntoView({block: "center"});
|
|
103892
|
+
listItemElement.classList.add("highlighted-node");
|
|
103893
|
+
this._showListItemElementId = listItemElementId;
|
|
103894
|
+
}
|
|
103895
|
+
|
|
103896
|
+
/**
|
|
103897
|
+
* De-highlights the node previously shown with {@link TreeViewPlugin#showNode}.
|
|
103898
|
+
*
|
|
103899
|
+
* Does nothing if no node is currently shown.
|
|
103900
|
+
*
|
|
103901
|
+
* If the node is currently scrolled into view, keeps the node in view.
|
|
103902
|
+
*/
|
|
103903
|
+
unShowNode() {
|
|
103904
|
+
if (!this._showListItemElementId) {
|
|
103905
|
+
return;
|
|
103906
|
+
}
|
|
103907
|
+
const listItemElement = document.getElementById(this._showListItemElementId);
|
|
103908
|
+
if (!listItemElement) {
|
|
103909
|
+
this._showListItemElementId = null;
|
|
103910
|
+
return;
|
|
103911
|
+
}
|
|
103912
|
+
listItemElement.classList.remove("highlighted-node");
|
|
103913
|
+
this._showListItemElementId = null;
|
|
103914
|
+
}
|
|
103915
|
+
|
|
103916
|
+
/**
|
|
103917
|
+
* Expands the tree to the given depth.
|
|
103918
|
+
*
|
|
103919
|
+
* Collapses the tree first.
|
|
103920
|
+
*
|
|
103921
|
+
* @param {Number} depth Depth to expand to.
|
|
103922
|
+
*/
|
|
103923
|
+
expandToDepth(depth) {
|
|
103924
|
+
this.collapse();
|
|
103925
|
+
const expand = (node, countDepth) => {
|
|
103926
|
+
if (countDepth === depth) {
|
|
103927
|
+
return;
|
|
103928
|
+
}
|
|
103929
|
+
const nodeId = node.nodeId;
|
|
103930
|
+
const switchElementId = "switch-" + nodeId;
|
|
103931
|
+
const switchElement = document.getElementById(switchElementId);
|
|
103932
|
+
if (switchElement) {
|
|
103933
|
+
this._expandSwitchElement(switchElement);
|
|
103934
|
+
const childNodes = node.children;
|
|
103935
|
+
for (var i = 0, len = childNodes.length; i < len; i++) {
|
|
103936
|
+
const childNode = childNodes[i];
|
|
103937
|
+
expand(childNode, countDepth + 1);
|
|
103938
|
+
}
|
|
103939
|
+
}
|
|
103940
|
+
};
|
|
103941
|
+
for (let i = 0, len = this._rootNodes.length; i < len; i++) {
|
|
103942
|
+
const rootNode = this._rootNodes[i];
|
|
103943
|
+
expand(rootNode, 0);
|
|
103944
|
+
}
|
|
103945
|
+
}
|
|
103946
|
+
|
|
103947
|
+
/**
|
|
103948
|
+
* Closes all the nodes in the tree.
|
|
103949
|
+
*/
|
|
103950
|
+
collapse() {
|
|
103951
|
+
for (let i = 0, len = this._rootNodes.length; i < len; i++) {
|
|
103952
|
+
const rootNode = this._rootNodes[i];
|
|
103953
|
+
const objectId = rootNode.objectId;
|
|
103954
|
+
this._collapseNode(objectId);
|
|
103955
|
+
}
|
|
103956
|
+
}
|
|
103957
|
+
|
|
103958
|
+
/**
|
|
103959
|
+
* Iterates over a subtree of the tree view's {@link TreeViewNode}s, calling the given callback for each
|
|
103960
|
+
* node in depth-first pre-order.
|
|
103961
|
+
*
|
|
103962
|
+
* @param {TreeViewNode} node Root of the subtree.
|
|
103963
|
+
* @param {Function} callback Callback called at each {@link TreeViewNode}, with the TreeViewNode given as the argument.
|
|
103964
|
+
*/
|
|
103965
|
+
withNodeTree(node, callback) {
|
|
103966
|
+
callback(node);
|
|
103967
|
+
const children = node.children;
|
|
103968
|
+
if (!children) {
|
|
103969
|
+
return;
|
|
103970
|
+
}
|
|
103971
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
103972
|
+
this.withNodeTree(children[i], callback);
|
|
103973
|
+
}
|
|
103974
|
+
}
|
|
103975
|
+
|
|
103976
|
+
/**
|
|
103977
|
+
* Destroys this TreeViewPlugin.
|
|
103978
|
+
*/
|
|
103979
|
+
destroy() {
|
|
103980
|
+
if (!this._containerElement) {
|
|
103981
|
+
return;
|
|
103982
|
+
}
|
|
103983
|
+
this._metaModels = {};
|
|
103984
|
+
if (this._rootElement && !this._destroyed) {
|
|
103985
|
+
this._rootElement.parentNode.removeChild(this._rootElement);
|
|
103986
|
+
this._viewer.scene.off(this._onObjectVisibility);
|
|
103987
|
+
this._destroyed = true;
|
|
103988
|
+
}
|
|
103989
|
+
super.destroy();
|
|
103990
|
+
}
|
|
103991
|
+
|
|
103992
|
+
_createNodes() {
|
|
103993
|
+
if (this._rootElement) {
|
|
103994
|
+
this._rootElement.parentNode.removeChild(this._rootElement);
|
|
103995
|
+
this._rootElement = null;
|
|
103996
|
+
}
|
|
103997
|
+
|
|
103998
|
+
this._rootNodes = [];
|
|
103999
|
+
this._objectNodes = {};
|
|
104000
|
+
this._validate();
|
|
104001
|
+
if (this.valid || (this._hierarchy !== "storeys")) {
|
|
104002
|
+
this._createEnabledNodes();
|
|
104003
|
+
} else {
|
|
104004
|
+
this._createDisabledNodes();
|
|
104005
|
+
}
|
|
104006
|
+
}
|
|
104007
|
+
|
|
104008
|
+
_validate() {
|
|
104009
|
+
this.errors = [];
|
|
104010
|
+
switch (this._hierarchy) {
|
|
104011
|
+
case "storeys":
|
|
104012
|
+
this.valid = this._validateMetaModelForStoreysHierarchy();
|
|
104013
|
+
break;
|
|
104014
|
+
case "types":
|
|
104015
|
+
this.valid = (this._rootNodes.length > 0);
|
|
104016
|
+
break;
|
|
104017
|
+
case "containment":
|
|
104018
|
+
default:
|
|
104019
|
+
this.valid = (this._rootNodes.length > 0);
|
|
103513
104020
|
break;
|
|
103514
104021
|
}
|
|
103515
104022
|
return this.valid;
|
|
103516
104023
|
}
|
|
103517
104024
|
|
|
104025
|
+
_validateMetaModelForStoreysHierarchy(level = 0, ctx, buildingNode) {
|
|
104026
|
+
// ctx = ctx || {
|
|
104027
|
+
// foundIFCBuildingStoreys: false
|
|
104028
|
+
// };
|
|
104029
|
+
// const metaObjectType = metaObject.type;
|
|
104030
|
+
// const children = metaObject.children;
|
|
104031
|
+
// if (metaObjectType === "IfcBuilding") {
|
|
104032
|
+
// buildingNode = true;
|
|
104033
|
+
// } else if (metaObjectType === "IfcBuildingStorey") {
|
|
104034
|
+
// if (!buildingNode) {
|
|
104035
|
+
// errors.push("Can't build storeys hierarchy: IfcBuildingStorey found without parent IfcBuilding");
|
|
104036
|
+
// return false;
|
|
104037
|
+
// }
|
|
104038
|
+
// ctx.foundIFCBuildingStoreys = true;
|
|
104039
|
+
// }
|
|
104040
|
+
// if (children) {
|
|
104041
|
+
// for (let i = 0, len = children.length; i < len; i++) {
|
|
104042
|
+
// const childMetaObject = children[i];
|
|
104043
|
+
// if (!this._validateMetaModelForStoreysHierarchy(childMetaObject, errors, level + 1, ctx, buildingNode)) {
|
|
104044
|
+
// return false;
|
|
104045
|
+
// }
|
|
104046
|
+
// }
|
|
104047
|
+
// }
|
|
104048
|
+
// if (level === 0) {
|
|
104049
|
+
// if (!ctx.foundIFCBuildingStoreys) {
|
|
104050
|
+
// // errors.push("Can't build storeys hierarchy: no IfcBuildingStoreys found");
|
|
104051
|
+
// }
|
|
104052
|
+
// }
|
|
104053
|
+
return true;
|
|
104054
|
+
}
|
|
104055
|
+
|
|
103518
104056
|
_createEnabledNodes() {
|
|
103519
104057
|
if (this._pruneEmptyNodes) {
|
|
103520
104058
|
this._findEmptyNodes();
|
|
@@ -103523,7 +104061,7 @@ class ModelTreeView {
|
|
|
103523
104061
|
case "storeys":
|
|
103524
104062
|
this._createStoreysNodes();
|
|
103525
104063
|
if (this._rootNodes.length === 0) {
|
|
103526
|
-
this.
|
|
104064
|
+
this.error("Failed to build storeys hierarchy");
|
|
103527
104065
|
}
|
|
103528
104066
|
break;
|
|
103529
104067
|
case "types":
|
|
@@ -103543,32 +104081,42 @@ class ModelTreeView {
|
|
|
103543
104081
|
|
|
103544
104082
|
_createDisabledNodes() {
|
|
103545
104083
|
|
|
103546
|
-
const metaObject = this._rootMetaObject;
|
|
103547
|
-
const metaObjectType = metaObject.type;
|
|
103548
|
-
const metaObjectName = metaObject.name;
|
|
103549
|
-
|
|
103550
|
-
const rootName = ((metaObjectName && metaObjectName !== "" && metaObjectName !== "Undefined" && metaObjectName !== "Default") ? metaObjectName : metaObjectType);
|
|
103551
|
-
|
|
103552
104084
|
const ul = document.createElement('ul');
|
|
103553
|
-
const li = document.createElement('li');
|
|
103554
|
-
ul.appendChild(li);
|
|
103555
|
-
this._containerElement.appendChild(ul);
|
|
103556
104085
|
this._rootElement = ul;
|
|
104086
|
+
this._containerElement.appendChild(ul);
|
|
103557
104087
|
|
|
103558
|
-
const
|
|
103559
|
-
|
|
103560
|
-
|
|
103561
|
-
|
|
103562
|
-
|
|
103563
|
-
|
|
104088
|
+
const rootMetaObjects = this._viewer.metaScene.rootMetaObjects;
|
|
104089
|
+
for (let i = 0, len = rootMetaObjects.length; i < len; i++) {
|
|
104090
|
+
const rootMetaObject = rootMetaObjects[i];
|
|
104091
|
+
const metaObjectType = rootMetaObject.type;
|
|
104092
|
+
const metaObjectName = rootMetaObject.name;
|
|
104093
|
+
const rootName = ((metaObjectName && metaObjectName !== ""
|
|
104094
|
+
&& metaObjectName !== "Undefined"
|
|
104095
|
+
&& metaObjectName !== "Default") ? metaObjectName : metaObjectType);
|
|
104096
|
+
const li = document.createElement('li');
|
|
104097
|
+
ul.appendChild(li);
|
|
104098
|
+
const switchElement = document.createElement('a');
|
|
104099
|
+
switchElement.href = '#';
|
|
104100
|
+
switchElement.textContent = '!';
|
|
104101
|
+
switchElement.classList.add('warn');
|
|
104102
|
+
switchElement.classList.add('warning');
|
|
104103
|
+
li.appendChild(switchElement);
|
|
104104
|
+
const span = document.createElement('span');
|
|
104105
|
+
span.textContent = rootName;
|
|
104106
|
+
li.appendChild(span);
|
|
104107
|
+
}
|
|
104108
|
+
}
|
|
103564
104109
|
|
|
103565
|
-
|
|
103566
|
-
|
|
103567
|
-
|
|
104110
|
+
|
|
104111
|
+
_findEmptyNodes() {
|
|
104112
|
+
const rootMetaObjects = this._viewer.metaScene.rootMetaObjects;
|
|
104113
|
+
for (let i = 0, len = rootMetaObjects.length; i < len; i++) {
|
|
104114
|
+
this._findEmptyNodes2(rootMetaObjects[i]);
|
|
104115
|
+
}
|
|
103568
104116
|
}
|
|
103569
104117
|
|
|
103570
|
-
|
|
103571
|
-
const viewer = this.
|
|
104118
|
+
_findEmptyNodes2(metaObject, countEntities = 0) {
|
|
104119
|
+
const viewer = this.viewer;
|
|
103572
104120
|
const scene = viewer.scene;
|
|
103573
104121
|
const children = metaObject.children;
|
|
103574
104122
|
const objectId = metaObject.id;
|
|
@@ -103580,18 +104128,21 @@ class ModelTreeView {
|
|
|
103580
104128
|
if (children) {
|
|
103581
104129
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
103582
104130
|
const childMetaObject = children[i];
|
|
103583
|
-
childMetaObject._countEntities = this.
|
|
104131
|
+
childMetaObject._countEntities = this._findEmptyNodes2(childMetaObject);
|
|
103584
104132
|
metaObject._countEntities += childMetaObject._countEntities;
|
|
103585
104133
|
}
|
|
103586
104134
|
}
|
|
103587
104135
|
return metaObject._countEntities;
|
|
103588
104136
|
}
|
|
103589
104137
|
|
|
103590
|
-
_createStoreysNodes(
|
|
103591
|
-
|
|
103592
|
-
|
|
103593
|
-
|
|
103594
|
-
|
|
104138
|
+
_createStoreysNodes() {
|
|
104139
|
+
const rootMetaObjects = this._viewer.metaScene.rootMetaObjects;
|
|
104140
|
+
for (let id in rootMetaObjects) {
|
|
104141
|
+
this._createStoreysNodes2(rootMetaObjects[id], null, null, null);
|
|
104142
|
+
}
|
|
104143
|
+
}
|
|
104144
|
+
|
|
104145
|
+
_createStoreysNodes2(metaObject, buildingNode, storeyNode, typeNodes) {
|
|
103595
104146
|
if (this._pruneEmptyNodes && (metaObject._countEntities === 0)) {
|
|
103596
104147
|
return;
|
|
103597
104148
|
}
|
|
@@ -103601,7 +104152,7 @@ class ModelTreeView {
|
|
|
103601
104152
|
const objectId = metaObject.id;
|
|
103602
104153
|
if (metaObjectType === "IfcBuilding") {
|
|
103603
104154
|
buildingNode = {
|
|
103604
|
-
nodeId:
|
|
104155
|
+
nodeId: objectId,
|
|
103605
104156
|
objectId: objectId,
|
|
103606
104157
|
title: this._rootName || ((metaObjectName && metaObjectName !== "" && metaObjectName !== "Undefined" && metaObjectName !== "Default") ? metaObjectName : metaObjectType),
|
|
103607
104158
|
type: metaObjectType,
|
|
@@ -103616,11 +104167,11 @@ class ModelTreeView {
|
|
|
103616
104167
|
this._objectNodes[buildingNode.objectId] = buildingNode;
|
|
103617
104168
|
} else if (metaObjectType === "IfcBuildingStorey") {
|
|
103618
104169
|
if (!buildingNode) {
|
|
103619
|
-
this.
|
|
104170
|
+
this.error("Failed to build storeys hierarchy for model '" + this.metaModel.id + "' - model does not have an IfcBuilding object, or is not an IFC model");
|
|
103620
104171
|
return;
|
|
103621
104172
|
}
|
|
103622
104173
|
storeyNode = {
|
|
103623
|
-
nodeId:
|
|
104174
|
+
nodeId: objectId,
|
|
103624
104175
|
objectId: objectId,
|
|
103625
104176
|
title: (metaObjectName && metaObjectName !== "" && metaObjectName !== "Undefined" && metaObjectName !== "Default") ? metaObjectName : metaObjectType,
|
|
103626
104177
|
type: metaObjectType,
|
|
@@ -103643,7 +104194,7 @@ class ModelTreeView {
|
|
|
103643
104194
|
let typeNode = typeNodes[metaObjectType];
|
|
103644
104195
|
if (!typeNode) {
|
|
103645
104196
|
const typeNodeObjectId = storeyNode.objectId + "." + metaObjectType;
|
|
103646
|
-
const typeNodeNodeId =
|
|
104197
|
+
const typeNodeNodeId = typeNodeObjectId;
|
|
103647
104198
|
typeNode = {
|
|
103648
104199
|
nodeId: typeNodeNodeId,
|
|
103649
104200
|
objectId: typeNodeObjectId,
|
|
@@ -103661,7 +104212,7 @@ class ModelTreeView {
|
|
|
103661
104212
|
typeNodes[metaObjectType] = typeNode;
|
|
103662
104213
|
}
|
|
103663
104214
|
const node = {
|
|
103664
|
-
nodeId:
|
|
104215
|
+
nodeId: objectId,
|
|
103665
104216
|
objectId: objectId,
|
|
103666
104217
|
title: (metaObjectName && metaObjectName !== "" && metaObjectName !== "Undefined" && metaObjectName !== "Default") ? metaObjectName : metaObjectType,
|
|
103667
104218
|
type: metaObjectType,
|
|
@@ -103680,12 +104231,19 @@ class ModelTreeView {
|
|
|
103680
104231
|
if (children) {
|
|
103681
104232
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
103682
104233
|
const childMetaObject = children[i];
|
|
103683
|
-
this.
|
|
104234
|
+
this._createStoreysNodes2(childMetaObject, buildingNode, storeyNode, typeNodes);
|
|
103684
104235
|
}
|
|
103685
104236
|
}
|
|
103686
104237
|
}
|
|
103687
104238
|
|
|
103688
|
-
_createTypesNodes(
|
|
104239
|
+
_createTypesNodes() {
|
|
104240
|
+
const rootMetaObjects = this._viewer.metaScene.rootMetaObjects;
|
|
104241
|
+
for (let id in rootMetaObjects) {
|
|
104242
|
+
this._createTypesNodes2(rootMetaObjects[id], null, null);
|
|
104243
|
+
}
|
|
104244
|
+
}
|
|
104245
|
+
|
|
104246
|
+
_createTypesNodes2(metaObject, rootNode, typeNodes) {
|
|
103689
104247
|
if (this._pruneEmptyNodes && (metaObject._countEntities === 0)) {
|
|
103690
104248
|
return;
|
|
103691
104249
|
}
|
|
@@ -103693,9 +104251,9 @@ class ModelTreeView {
|
|
|
103693
104251
|
const metaObjectName = metaObject.name;
|
|
103694
104252
|
const children = metaObject.children;
|
|
103695
104253
|
const objectId = metaObject.id;
|
|
103696
|
-
if (metaObject.
|
|
104254
|
+
if (!metaObject.parent) {
|
|
103697
104255
|
rootNode = {
|
|
103698
|
-
nodeId:
|
|
104256
|
+
nodeId: objectId,
|
|
103699
104257
|
objectId: objectId,
|
|
103700
104258
|
title: this._rootName || ((metaObjectName && metaObjectName !== "" && metaObjectName !== "Undefined" && metaObjectName !== "Default") ? metaObjectName : metaObjectType),
|
|
103701
104259
|
type: metaObjectType,
|
|
@@ -103717,7 +104275,7 @@ class ModelTreeView {
|
|
|
103717
104275
|
let typeNode = typeNodes[metaObjectType];
|
|
103718
104276
|
if (!typeNode) {
|
|
103719
104277
|
typeNode = {
|
|
103720
|
-
nodeId:
|
|
104278
|
+
nodeId: rootNode.objectId + "." + metaObjectType,
|
|
103721
104279
|
objectId: rootNode.objectId + "." + metaObjectType,
|
|
103722
104280
|
title: metaObjectType,
|
|
103723
104281
|
type: metaObjectType,
|
|
@@ -103733,7 +104291,7 @@ class ModelTreeView {
|
|
|
103733
104291
|
typeNodes[metaObjectType] = typeNode;
|
|
103734
104292
|
}
|
|
103735
104293
|
const node = {
|
|
103736
|
-
nodeId:
|
|
104294
|
+
nodeId: objectId,
|
|
103737
104295
|
objectId: objectId,
|
|
103738
104296
|
title: (metaObjectName && metaObjectName !== "" && metaObjectName !== "Default") ? metaObjectName : metaObjectType,
|
|
103739
104297
|
type: metaObjectType,
|
|
@@ -103752,12 +104310,19 @@ class ModelTreeView {
|
|
|
103752
104310
|
if (children) {
|
|
103753
104311
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
103754
104312
|
const childMetaObject = children[i];
|
|
103755
|
-
this.
|
|
104313
|
+
this._createTypesNodes2(childMetaObject, rootNode, typeNodes);
|
|
103756
104314
|
}
|
|
103757
104315
|
}
|
|
103758
104316
|
}
|
|
103759
104317
|
|
|
103760
|
-
_createContainmentNodes(
|
|
104318
|
+
_createContainmentNodes() {
|
|
104319
|
+
const rootMetaObjects = this._viewer.metaScene.rootMetaObjects;
|
|
104320
|
+
for (let id in rootMetaObjects) {
|
|
104321
|
+
this._createContainmentNodes2(rootMetaObjects[id], null);
|
|
104322
|
+
}
|
|
104323
|
+
}
|
|
104324
|
+
|
|
104325
|
+
_createContainmentNodes2(metaObject, parent) {
|
|
103761
104326
|
if (this._pruneEmptyNodes && (metaObject._countEntities === 0)) {
|
|
103762
104327
|
return;
|
|
103763
104328
|
}
|
|
@@ -103766,7 +104331,7 @@ class ModelTreeView {
|
|
|
103766
104331
|
const children = metaObject.children;
|
|
103767
104332
|
const objectId = metaObject.id;
|
|
103768
104333
|
const node = {
|
|
103769
|
-
nodeId:
|
|
104334
|
+
nodeId: objectId,
|
|
103770
104335
|
objectId: objectId,
|
|
103771
104336
|
title: (!parent) ? (this._rootName || metaObjectName) : (metaObjectName && metaObjectName !== "" && metaObjectName !== "Undefined" && metaObjectName !== "Default") ? metaObjectName : metaObjectType,
|
|
103772
104337
|
type: metaObjectType,
|
|
@@ -103787,7 +104352,7 @@ class ModelTreeView {
|
|
|
103787
104352
|
if (children) {
|
|
103788
104353
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
103789
104354
|
const childMetaObject = children[i];
|
|
103790
|
-
this.
|
|
104355
|
+
this._createContainmentNodes2(childMetaObject, node);
|
|
103791
104356
|
}
|
|
103792
104357
|
}
|
|
103793
104358
|
}
|
|
@@ -103817,7 +104382,7 @@ class ModelTreeView {
|
|
|
103817
104382
|
}
|
|
103818
104383
|
|
|
103819
104384
|
_getSpatialSortFunc() { // Creates cached sort func with Viewer in scope
|
|
103820
|
-
const viewer = this.
|
|
104385
|
+
const viewer = this.viewer;
|
|
103821
104386
|
const scene = viewer.scene;
|
|
103822
104387
|
const camera = scene.camera;
|
|
103823
104388
|
const metaScene = viewer.metaScene;
|
|
@@ -103862,8 +104427,7 @@ class ModelTreeView {
|
|
|
103862
104427
|
}
|
|
103863
104428
|
|
|
103864
104429
|
_synchNodesToEntities() {
|
|
103865
|
-
const
|
|
103866
|
-
const objectIds = rootMetaObject.getObjectIDsInSubtree();
|
|
104430
|
+
const objectIds = Object.keys(this.viewer.metaScene.metaObjects);
|
|
103867
104431
|
const metaObjects = this._viewer.metaScene.metaObjects;
|
|
103868
104432
|
const objects = this._viewer.scene.objects;
|
|
103869
104433
|
for (let i = 0, len = objectIds.length; i < len; i++) {
|
|
@@ -103930,7 +104494,7 @@ class ModelTreeView {
|
|
|
103930
104494
|
//const nodeId = this._objectToNodeID(node.objectId);
|
|
103931
104495
|
const nodeId = node.nodeId;
|
|
103932
104496
|
if (node.xrayed) {
|
|
103933
|
-
|
|
104497
|
+
nodeElement.classList.add('xrayed-node');
|
|
103934
104498
|
}
|
|
103935
104499
|
nodeElement.id = 'node-' + nodeId;
|
|
103936
104500
|
if (node.children.length > 0) {
|
|
@@ -103940,7 +104504,7 @@ class ModelTreeView {
|
|
|
103940
104504
|
switchElement.id = switchElementId;
|
|
103941
104505
|
switchElement.textContent = '+';
|
|
103942
104506
|
switchElement.classList.add('plus');
|
|
103943
|
-
switchElement.addEventListener('click', this.
|
|
104507
|
+
switchElement.addEventListener('click', this._switchExpandHandler);
|
|
103944
104508
|
nodeElement.appendChild(switchElement);
|
|
103945
104509
|
}
|
|
103946
104510
|
const checkbox = document.createElement('input');
|
|
@@ -103954,19 +104518,19 @@ class ModelTreeView {
|
|
|
103954
104518
|
span.textContent = node.title;
|
|
103955
104519
|
nodeElement.appendChild(span);
|
|
103956
104520
|
span.oncontextmenu = (e) => {
|
|
103957
|
-
this.
|
|
104521
|
+
this.fire("contextmenu", {
|
|
103958
104522
|
event: e,
|
|
103959
104523
|
viewer: this._viewer,
|
|
103960
|
-
treeViewPlugin: this
|
|
104524
|
+
treeViewPlugin: this,
|
|
103961
104525
|
treeViewNode: node
|
|
103962
104526
|
});
|
|
103963
104527
|
e.preventDefault();
|
|
103964
104528
|
};
|
|
103965
104529
|
span.onclick = (e) => {
|
|
103966
|
-
this.
|
|
104530
|
+
this.fire("nodeTitleClicked", {
|
|
103967
104531
|
event: e,
|
|
103968
104532
|
viewer: this._viewer,
|
|
103969
|
-
treeViewPlugin: this
|
|
104533
|
+
treeViewPlugin: this,
|
|
103970
104534
|
treeViewNode: node
|
|
103971
104535
|
});
|
|
103972
104536
|
e.preventDefault();
|
|
@@ -103974,103 +104538,6 @@ class ModelTreeView {
|
|
|
103974
104538
|
return nodeElement;
|
|
103975
104539
|
}
|
|
103976
104540
|
|
|
103977
|
-
/**
|
|
103978
|
-
* @private
|
|
103979
|
-
* @param depth
|
|
103980
|
-
*/
|
|
103981
|
-
expandToDepth(depth) {
|
|
103982
|
-
const expand = (node, countDepth) => {
|
|
103983
|
-
if (countDepth === depth) {
|
|
103984
|
-
return;
|
|
103985
|
-
}
|
|
103986
|
-
const nodeId = node.nodeId;
|
|
103987
|
-
const switchElementId = "switch-" + nodeId;
|
|
103988
|
-
const switchElement = document.getElementById(switchElementId);
|
|
103989
|
-
if (switchElement) {
|
|
103990
|
-
this._expandSwitchElement(switchElement);
|
|
103991
|
-
const childNodes = node.children;
|
|
103992
|
-
for (var i = 0, len = childNodes.length; i < len; i++) {
|
|
103993
|
-
const childNode = childNodes[i];
|
|
103994
|
-
expand(childNode, countDepth + 1);
|
|
103995
|
-
}
|
|
103996
|
-
}
|
|
103997
|
-
};
|
|
103998
|
-
for (let i = 0, len = this._rootNodes.length; i < len; i++) {
|
|
103999
|
-
const rootNode = this._rootNodes[i];
|
|
104000
|
-
expand(rootNode, 0);
|
|
104001
|
-
}
|
|
104002
|
-
}
|
|
104003
|
-
|
|
104004
|
-
/**
|
|
104005
|
-
* @private
|
|
104006
|
-
*/
|
|
104007
|
-
collapse() {
|
|
104008
|
-
for (let i = 0, len = this._rootNodes.length; i < len; i++) {
|
|
104009
|
-
const rootNode = this._rootNodes[i];
|
|
104010
|
-
const objectId = rootNode.objectId;
|
|
104011
|
-
this._collapseNode(objectId);
|
|
104012
|
-
}
|
|
104013
|
-
}
|
|
104014
|
-
|
|
104015
|
-
/**
|
|
104016
|
-
* @private
|
|
104017
|
-
* @param objectId
|
|
104018
|
-
*/
|
|
104019
|
-
showNode(objectId) {
|
|
104020
|
-
if (this._showListItemElementId) {
|
|
104021
|
-
this.unShowNode();
|
|
104022
|
-
}
|
|
104023
|
-
const node = this._objectNodes[objectId];
|
|
104024
|
-
if (!node) {
|
|
104025
|
-
return; // Node may not exist for the given object if (this._pruneEmptyNodes == true)
|
|
104026
|
-
}
|
|
104027
|
-
const nodeId = node.nodeId;
|
|
104028
|
-
const switchElementId = "switch-" + nodeId;
|
|
104029
|
-
const switchElement = document.getElementById(switchElementId);
|
|
104030
|
-
if (switchElement) {
|
|
104031
|
-
this._expandSwitchElement(switchElement);
|
|
104032
|
-
switchElement.scrollIntoView();
|
|
104033
|
-
return;
|
|
104034
|
-
}
|
|
104035
|
-
const path = [];
|
|
104036
|
-
path.unshift(node);
|
|
104037
|
-
let parent = node.parent;
|
|
104038
|
-
while (parent) {
|
|
104039
|
-
path.unshift(parent);
|
|
104040
|
-
parent = parent.parent;
|
|
104041
|
-
}
|
|
104042
|
-
for (let i = 0, len = path.length; i < len; i++) {
|
|
104043
|
-
const node = path[i];
|
|
104044
|
-
const nodeId = node.nodeId;
|
|
104045
|
-
const switchElementId = "switch-" + nodeId;
|
|
104046
|
-
const switchElement = document.getElementById(switchElementId);
|
|
104047
|
-
if (switchElement) {
|
|
104048
|
-
this._expandSwitchElement(switchElement);
|
|
104049
|
-
}
|
|
104050
|
-
}
|
|
104051
|
-
const listItemElementId = 'node-' + nodeId;
|
|
104052
|
-
const listItemElement = document.getElementById(listItemElementId);
|
|
104053
|
-
listItemElement.scrollIntoView({block: "center"});
|
|
104054
|
-
listItemElement.classList.add("highlighted-node");
|
|
104055
|
-
this._showListItemElementId = listItemElementId;
|
|
104056
|
-
}
|
|
104057
|
-
|
|
104058
|
-
/**
|
|
104059
|
-
* @private
|
|
104060
|
-
*/
|
|
104061
|
-
unShowNode() {
|
|
104062
|
-
if (!this._showListItemElementId) {
|
|
104063
|
-
return;
|
|
104064
|
-
}
|
|
104065
|
-
const listItemElement = document.getElementById(this._showListItemElementId);
|
|
104066
|
-
if (!listItemElement) {
|
|
104067
|
-
this._showListItemElementId = null;
|
|
104068
|
-
return;
|
|
104069
|
-
}
|
|
104070
|
-
listItemElement.classList.remove("highlighted-node");
|
|
104071
|
-
this._showListItemElementId = null;
|
|
104072
|
-
}
|
|
104073
|
-
|
|
104074
104541
|
_expandSwitchElement(switchElement) {
|
|
104075
104542
|
const parentElement = switchElement.parentElement;
|
|
104076
104543
|
const expanded = parentElement.getElementsByTagName('li')[0];
|
|
@@ -104078,7 +104545,7 @@ class ModelTreeView {
|
|
|
104078
104545
|
return;
|
|
104079
104546
|
}
|
|
104080
104547
|
const nodeId = parentElement.id.replace('node-', '');
|
|
104081
|
-
const objectId =
|
|
104548
|
+
const objectId = nodeId;
|
|
104082
104549
|
const switchNode = this._objectNodes[objectId];
|
|
104083
104550
|
const childNodes = switchNode.children;
|
|
104084
104551
|
const nodeElements = childNodes.map((node) => {
|
|
@@ -104092,12 +104559,12 @@ class ModelTreeView {
|
|
|
104092
104559
|
switchElement.classList.remove('plus');
|
|
104093
104560
|
switchElement.classList.add('minus');
|
|
104094
104561
|
switchElement.textContent = '-';
|
|
104095
|
-
switchElement.removeEventListener('click', this.
|
|
104096
|
-
switchElement.addEventListener('click', this.
|
|
104562
|
+
switchElement.removeEventListener('click', this._switchExpandHandler);
|
|
104563
|
+
switchElement.addEventListener('click', this._switchCollapseHandler);
|
|
104097
104564
|
}
|
|
104098
104565
|
|
|
104099
104566
|
_collapseNode(objectId) {
|
|
104100
|
-
const nodeId =
|
|
104567
|
+
const nodeId = objectId;
|
|
104101
104568
|
const switchElementId = "switch-" + nodeId;
|
|
104102
104569
|
const switchElement = document.getElementById(switchElementId);
|
|
104103
104570
|
this._collapseSwitchElement(switchElement);
|
|
@@ -104119,641 +104586,8 @@ class ModelTreeView {
|
|
|
104119
104586
|
switchElement.classList.remove('minus');
|
|
104120
104587
|
switchElement.classList.add('plus');
|
|
104121
104588
|
switchElement.textContent = '+';
|
|
104122
|
-
switchElement.removeEventListener('click', this.
|
|
104123
|
-
switchElement.addEventListener('click', this.
|
|
104124
|
-
}
|
|
104125
|
-
|
|
104126
|
-
/**
|
|
104127
|
-
* Destroys this ModelTreeView.
|
|
104128
|
-
* @private
|
|
104129
|
-
*/
|
|
104130
|
-
destroy() {
|
|
104131
|
-
if (this._rootElement && !this._destroyed) {
|
|
104132
|
-
this._rootElement.parentNode.removeChild(this._rootElement);
|
|
104133
|
-
this._viewer.scene.off(this._onObjectVisibility);
|
|
104134
|
-
this._destroyed = true;
|
|
104135
|
-
idMap.removeItem(this._id);
|
|
104136
|
-
}
|
|
104137
|
-
}
|
|
104138
|
-
}
|
|
104139
|
-
|
|
104140
|
-
/**
|
|
104141
|
-
* @desc A {@link Viewer} plugin that provides an HTML tree view to navigate the IFC elements in models.
|
|
104142
|
-
* <br>
|
|
104143
|
-
*
|
|
104144
|
-
* <a href="https://xeokit.github.io/xeokit-sdk/examples/#BIMOffline_XKT_WestRiverSideHospital" style="border: 1px solid black;"><img src="http://xeokit.io/img/docs/TreeViewPlugin/TreeViewPlugin.png"></a>
|
|
104145
|
-
*
|
|
104146
|
-
* [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/#BIMOffline_XKT_WestRiverSideHospital)]
|
|
104147
|
-
*
|
|
104148
|
-
* ## Overview
|
|
104149
|
-
*
|
|
104150
|
-
* * A fast HTML tree view, with zero external dependencies, that works with huge numbers of objects.
|
|
104151
|
-
* * Each tree node has a checkbox to control the visibility of its object.
|
|
104152
|
-
* * Has three hierarchy modes: "containment", "types" and "storeys".
|
|
104153
|
-
* * Automatically contains all models (that have metadata) that are currently in the {@link Scene}.
|
|
104154
|
-
* * Sorts tree nodes by default - spatially, from top-to-bottom for ````IfcBuildingStorey```` nodes, and alphanumerically for other nodes.
|
|
104155
|
-
* * Allows custom CSS styling.
|
|
104156
|
-
* * Use {@link ContextMenu} to create a context menu for the tree nodes.
|
|
104157
|
-
*
|
|
104158
|
-
* ## Credits
|
|
104159
|
-
*
|
|
104160
|
-
* TreeViewPlugin is based on techniques described in [*Super Fast Tree View in JavaScript*](https://chrissmith.xyz/super-fast-tree-view-in-javascript/) by [Chris Smith](https://twitter.com/chris22smith).
|
|
104161
|
-
*
|
|
104162
|
-
* ## Usage
|
|
104163
|
-
*
|
|
104164
|
-
* In the example below, we'll add a TreeViewPlugin which, by default, will automatically show the structural
|
|
104165
|
-
* hierarchy of the IFC elements in each model we load.
|
|
104166
|
-
*
|
|
104167
|
-
* Then we'll use an {@link XKTLoaderPlugin} to load the Schependomlaan model from an
|
|
104168
|
-
* [.xkt file](https://github.com/xeokit/xeokit-sdk/tree/master/examples/models/xkt/schependomlaan).
|
|
104169
|
-
*
|
|
104170
|
-
* [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/#BIMOffline_XKT_Schependomlaan)]
|
|
104171
|
-
*
|
|
104172
|
-
* ````javascript
|
|
104173
|
-
* import {Viewer, XKTLoaderPlugin, TreeViewPlugin} from "xeokit-sdk.es.js";
|
|
104174
|
-
*
|
|
104175
|
-
* const viewer = new Viewer({
|
|
104176
|
-
* canvasId: "myCanvas",
|
|
104177
|
-
* transparent: true
|
|
104178
|
-
* });
|
|
104179
|
-
*
|
|
104180
|
-
* viewer.camera.eye = [-2.56, 8.38, 8.27];
|
|
104181
|
-
* viewer.camera.look = [13.44, 3.31, -14.83];
|
|
104182
|
-
* viewer.camera.up = [0.10, 0.98, -0.14];
|
|
104183
|
-
*
|
|
104184
|
-
* const treeView = new TreeViewPlugin(viewer, {
|
|
104185
|
-
* containerElement: document.getElementById("myTreeViewContainer")
|
|
104186
|
-
* });
|
|
104187
|
-
*
|
|
104188
|
-
* const xktLoader = new XKTLoaderPlugin(viewer);
|
|
104189
|
-
*
|
|
104190
|
-
* const model = xktLoader.load({
|
|
104191
|
-
* id: "myModel",
|
|
104192
|
-
* src: "./models/xkt/Schependomlaan.xkt",
|
|
104193
|
-
* edges: true
|
|
104194
|
-
* });
|
|
104195
|
-
* ````
|
|
104196
|
-
*
|
|
104197
|
-
* ## Manually Adding Models
|
|
104198
|
-
*
|
|
104199
|
-
* Instead of adding models automatically, we can control which models appear in our TreeViewPlugin by adding them manually.
|
|
104200
|
-
*
|
|
104201
|
-
* In the next example, we'll configure the TreeViewPlugin to not add models automatically. Then, once the model
|
|
104202
|
-
* has loaded, we'll add it manually using {@link TreeViewPlugin#addModel}.
|
|
104203
|
-
*
|
|
104204
|
-
* ````javascript
|
|
104205
|
-
* const treeView = new TreeViewPlugin(viewer, {
|
|
104206
|
-
* containerElement: document.getElementById("myTreeViewContainer"),
|
|
104207
|
-
* autoAddModels: false // <<---------------- Don't auto-add models
|
|
104208
|
-
* });
|
|
104209
|
-
*
|
|
104210
|
-
* const xktLoader = new XKTLoaderPlugin(viewer);
|
|
104211
|
-
*
|
|
104212
|
-
* const model = xktLoader.load({
|
|
104213
|
-
* id: "myModel",
|
|
104214
|
-
* src: "./models/xkt/Schependomlaan.xkt",
|
|
104215
|
-
* edges: true
|
|
104216
|
-
* });
|
|
104217
|
-
*
|
|
104218
|
-
* model.on("loaded", () => {
|
|
104219
|
-
* treeView.addModel(model.id);
|
|
104220
|
-
* });
|
|
104221
|
-
* ````
|
|
104222
|
-
*
|
|
104223
|
-
* Adding models manually also allows us to set some options for the model. For example, the ````rootName```` option allows us to provide a custom name for
|
|
104224
|
-
* the root node, which is sometimes desirable when the model's "IfcProject" element's name is not suitable:
|
|
104225
|
-
*
|
|
104226
|
-
* ````javascript
|
|
104227
|
-
* model.on("loaded", () => {
|
|
104228
|
-
* treeView.addModel(model.id, {
|
|
104229
|
-
* rootName: "Schependomlaan Model"
|
|
104230
|
-
* });
|
|
104231
|
-
* });
|
|
104232
|
-
* ````
|
|
104233
|
-
*
|
|
104234
|
-
* ## Initially Expanding the Hierarchy
|
|
104235
|
-
*
|
|
104236
|
-
* We can also configure TreeViewPlugin to initially expand each model's nodes to a given depth.
|
|
104237
|
-
*
|
|
104238
|
-
* Let's automatically expand the first three nodes from the root, for every model added:
|
|
104239
|
-
*
|
|
104240
|
-
* ````javascript
|
|
104241
|
-
* const treeView = new TreeViewPlugin(viewer, {
|
|
104242
|
-
* containerElement: document.getElementById("myTreeViewContainer"),
|
|
104243
|
-
* autoExpandDepth: 3
|
|
104244
|
-
* });
|
|
104245
|
-
* ````
|
|
104246
|
-
*
|
|
104247
|
-
* ## Showing a Node by ID
|
|
104248
|
-
*
|
|
104249
|
-
* We can show a given node using its ID. This causes the TreeViewPlugin to collapse, then expand and scroll the node into view, then highlight the node.
|
|
104250
|
-
*
|
|
104251
|
-
* See the documentation for the {@link TreeViewPlugin#showNode} method for more information, including how to define a custom highlighted appearance for the node using CSS.
|
|
104252
|
-
*
|
|
104253
|
-
* Let's make the TreeViewPlugin show the node corresponding to whatever object {@link Entity} that we pick:
|
|
104254
|
-
*
|
|
104255
|
-
* ````javascript
|
|
104256
|
-
* viewer.cameraControl.on("picked", function (e) {
|
|
104257
|
-
* var objectId = e.entity.id;
|
|
104258
|
-
* treeView.showNode(objectId);
|
|
104259
|
-
* });
|
|
104260
|
-
* ````
|
|
104261
|
-
*
|
|
104262
|
-
* This will de-highlight any node that was previously shown by this method.
|
|
104263
|
-
*
|
|
104264
|
-
* Note that this method only works if the picked {@link Entity} is an object that belongs to a model that's represented in the TreeViewPlugin.
|
|
104265
|
-
*
|
|
104266
|
-
* ## Customizing Appearance
|
|
104267
|
-
*
|
|
104268
|
-
* We can customize the appearance of our TreeViewPlugin by defining custom CSS for its HTML
|
|
104269
|
-
* elements. See our example's [source code](https://github.com/xeokit/xeokit-sdk/blob/master/examples/BIMOffline_XKT_Schependomlaan.html)
|
|
104270
|
-
* for an example of custom CSS rules.
|
|
104271
|
-
*
|
|
104272
|
-
* ## Model Hierarchies
|
|
104273
|
-
*
|
|
104274
|
-
* TreeViewPlugin has three hierarchies for organizing its nodes:
|
|
104275
|
-
*
|
|
104276
|
-
* * "containment" - organizes the tree nodes to indicate the containment hierarchy of the {@link MetaObject}s.
|
|
104277
|
-
* * "types" - groups nodes by their IFC types.
|
|
104278
|
-
* * "storeys" - groups nodes within their ````IfcBuildingStoreys````, and sub-groups them by their IFC types.
|
|
104279
|
-
*
|
|
104280
|
-
* <br>
|
|
104281
|
-
* The table below shows what the hierarchies look like:
|
|
104282
|
-
* <br>
|
|
104283
|
-
*
|
|
104284
|
-
* | 1. Containment Hierarchy | 2. Types Hierarchy | 3. Storeys Hierarchy |
|
|
104285
|
-
* |---|---|---|
|
|
104286
|
-
* | <img src="http://xeokit.io/img/docs/TreeViewPlugin/structureMode.png"> | <img src="http://xeokit.io/img/docs/TreeViewPlugin/typesMode.png"> | <img src="http://xeokit.io/img/docs/TreeViewPlugin/storeysMode.png"> |
|
|
104287
|
-
* <br>
|
|
104288
|
-
*
|
|
104289
|
-
* Let's create a TreeViewPlugin that groups nodes by their building stories and IFC types:
|
|
104290
|
-
*
|
|
104291
|
-
* ````javascript
|
|
104292
|
-
* const treeView = new TreeViewPlugin(viewer, {
|
|
104293
|
-
* containerElement: document.getElementById("myTreeViewContainer"),
|
|
104294
|
-
* hierarchy: "stories"
|
|
104295
|
-
* });
|
|
104296
|
-
* ````
|
|
104297
|
-
*
|
|
104298
|
-
* ## Sorting Nodes
|
|
104299
|
-
*
|
|
104300
|
-
* TreeViewPlugin sorts its tree nodes by default. For a "storeys" hierarchy, it orders ````IfcBuildingStorey```` nodes
|
|
104301
|
-
* spatially, with the node for the highest story at the top, down to the lowest at the bottom.
|
|
104302
|
-
*
|
|
104303
|
-
* For all the hierarchy types ("containment", "classes" and "storeys"), TreeViewPlugin sorts the other node types
|
|
104304
|
-
* alphanumerically on their titles.
|
|
104305
|
-
*
|
|
104306
|
-
* If for some reason you need to prevent sorting, create your TreeViewPlugin with the option disabled, like so:
|
|
104307
|
-
*
|
|
104308
|
-
* ````javascript
|
|
104309
|
-
* const treeView = new TreeViewPlugin(viewer, {
|
|
104310
|
-
* containerElement: document.getElementById("myTreeViewContainer"),
|
|
104311
|
-
* hierarchy: "stories",
|
|
104312
|
-
* sortNodes: false // <<------ Disable node sorting
|
|
104313
|
-
* });
|
|
104314
|
-
* ````
|
|
104315
|
-
*
|
|
104316
|
-
* Note that, for all hierarchy modes, node sorting is only done for each model at the time that it is added to the TreeViewPlugin, and will not
|
|
104317
|
-
* update dynamically if we later transform the {@link Entity}s corresponding to the nodes.
|
|
104318
|
-
*
|
|
104319
|
-
* ## Pruning empty nodes
|
|
104320
|
-
*
|
|
104321
|
-
* Sometimes a model contains subtrees of objects that don't have any geometry. These are models whose
|
|
104322
|
-
* {@link MetaModel} contains trees of {@link MetaObject}s that don't have any {@link Entity}s in the {@link Scene}.
|
|
104323
|
-
*
|
|
104324
|
-
* For these models, the tree view would contain nodes that don't do anything in the Scene when we interact with them,
|
|
104325
|
-
* which is undesirable.
|
|
104326
|
-
*
|
|
104327
|
-
* By default, TreeViewPlugin will not create nodes for those objects. However, we can override that behaviour if we want
|
|
104328
|
-
* to have nodes for those objects (perhaps for debugging the model):
|
|
104329
|
-
*
|
|
104330
|
-
* ````javascript
|
|
104331
|
-
* const treeView = new TreeViewPlugin(viewer, {
|
|
104332
|
-
* containerElement: document.getElementById("myTreeViewContainer"),
|
|
104333
|
-
* hierarchy: "stories",
|
|
104334
|
-
* pruneEmptyNodes: false // <<------ Create nodes for object subtrees without geometry
|
|
104335
|
-
* });
|
|
104336
|
-
* ````
|
|
104337
|
-
*
|
|
104338
|
-
* ## Context Menu
|
|
104339
|
-
*
|
|
104340
|
-
* TreeViewPlugin fires a "contextmenu" event whenever we right-click on a tree node.
|
|
104341
|
-
*
|
|
104342
|
-
* The event contains:
|
|
104343
|
-
*
|
|
104344
|
-
* * ````event```` - the original [contextmenu](https://developer.mozilla.org/en-US/docs/Web/API/Element/contextmenu_event) [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent)
|
|
104345
|
-
* * ````viewer```` - the {@link Viewer}
|
|
104346
|
-
* * ````treeViewPlugin```` - the TreeViewPlugin
|
|
104347
|
-
* * ````treeViewNode```` - the {@link TreeViewNode} representing the tree node
|
|
104348
|
-
*<br><br>
|
|
104349
|
-
*
|
|
104350
|
-
* Let's use {@link ContextMenu} to show a simple context menu for the node we clicked.
|
|
104351
|
-
*
|
|
104352
|
-
* [[Run an example](https://xeokit.github.io/xeokit-sdk/examples/#ContextMenu_Canvas_TreeViewPlugin_Custom)]
|
|
104353
|
-
*
|
|
104354
|
-
* ````javascript
|
|
104355
|
-
* import {ContextMenu} from "../src/extras/ContextMenu/ContextMenu.js";
|
|
104356
|
-
*
|
|
104357
|
-
* const treeViewContextMenu = new ContextMenu({
|
|
104358
|
-
* items: [
|
|
104359
|
-
* [
|
|
104360
|
-
* [
|
|
104361
|
-
* {
|
|
104362
|
-
* title: "Hide",
|
|
104363
|
-
* doAction: function (context) {
|
|
104364
|
-
* context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
|
|
104365
|
-
* if (treeViewNode.objectId) {
|
|
104366
|
-
* const entity = context.viewer.scene.objects[treeViewNode.objectId];
|
|
104367
|
-
* if (entity) {
|
|
104368
|
-
* entity.visible = false;
|
|
104369
|
-
* }
|
|
104370
|
-
* }
|
|
104371
|
-
* });
|
|
104372
|
-
* }
|
|
104373
|
-
* },
|
|
104374
|
-
* {
|
|
104375
|
-
* title: "Hide all",
|
|
104376
|
-
* doAction: function (context) {
|
|
104377
|
-
* context.viewer.scene.setObjectsVisible(context.viewer.scene.visibleObjectIds, false);
|
|
104378
|
-
* }
|
|
104379
|
-
* }
|
|
104380
|
-
* ],
|
|
104381
|
-
* [
|
|
104382
|
-
* {
|
|
104383
|
-
* title: "Show",
|
|
104384
|
-
* doAction: function (context) {
|
|
104385
|
-
* context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
|
|
104386
|
-
* if (treeViewNode.objectId) {
|
|
104387
|
-
* const entity = context.viewer.scene.objects[treeViewNode.objectId];
|
|
104388
|
-
* if (entity) {
|
|
104389
|
-
* entity.visible = true;
|
|
104390
|
-
* entity.xrayed = false;
|
|
104391
|
-
* entity.selected = false;
|
|
104392
|
-
* }
|
|
104393
|
-
* }
|
|
104394
|
-
* });
|
|
104395
|
-
* }
|
|
104396
|
-
* },
|
|
104397
|
-
* {
|
|
104398
|
-
* title: "Show all",
|
|
104399
|
-
* doAction: function (context) {
|
|
104400
|
-
* const scene = context.viewer.scene;
|
|
104401
|
-
* scene.setObjectsVisible(scene.objectIds, true);
|
|
104402
|
-
* scene.setObjectsXRayed(scene.xrayedObjectIds, false);
|
|
104403
|
-
* scene.setObjectsSelected(scene.selectedObjectIds, false);
|
|
104404
|
-
* }
|
|
104405
|
-
* }
|
|
104406
|
-
* ]
|
|
104407
|
-
* ]
|
|
104408
|
-
* ]
|
|
104409
|
-
* });
|
|
104410
|
-
*
|
|
104411
|
-
* treeView.on("contextmenu", (e) => {
|
|
104412
|
-
*
|
|
104413
|
-
* const event = e.event; // MouseEvent
|
|
104414
|
-
* const viewer = e.viewer; // Viewer
|
|
104415
|
-
* const treeViewPlugin = e.treeViewPlugin; // TreeViewPlugin
|
|
104416
|
-
* const treeViewNode = e.treeViewNode; // TreeViewNode
|
|
104417
|
-
*
|
|
104418
|
-
* treeViewContextMenu.show(e.event.pageX, e.event.pageY);
|
|
104419
|
-
*
|
|
104420
|
-
* treeViewContextMenu.context = {
|
|
104421
|
-
* viewer: e.viewer,
|
|
104422
|
-
* treeViewPlugin: e.treeViewPlugin,
|
|
104423
|
-
* treeViewNode: e.treeViewNode
|
|
104424
|
-
* };
|
|
104425
|
-
* });
|
|
104426
|
-
* ````
|
|
104427
|
-
*
|
|
104428
|
-
* ## Clicking Node Titles
|
|
104429
|
-
*
|
|
104430
|
-
* TreeViewPlugin fires a "nodeTitleClicked" event whenever we left-click on a tree node.
|
|
104431
|
-
*
|
|
104432
|
-
* Like the "contextmenu" event, this event contains:
|
|
104433
|
-
*
|
|
104434
|
-
* * ````event```` - the original [click](https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event) [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent)
|
|
104435
|
-
* * ````viewer```` - the {@link Viewer}
|
|
104436
|
-
* * ````treeViewPlugin```` - the TreeViewPlugin
|
|
104437
|
-
* * ````treeViewNode```` - the {@link TreeViewNode} representing the tree node
|
|
104438
|
-
*<br><br>
|
|
104439
|
-
*
|
|
104440
|
-
* Let's register a callback to isolate and fit-to-view the {@link Entity}(s) represented by the node. This callback is
|
|
104441
|
-
* going to X-ray all the other Entitys, fly the camera to fit the Entity(s) for the clicked node, then hide the other Entitys.
|
|
104442
|
-
*
|
|
104443
|
-
* [[Run an example](https://xeokit.github.io/xeokit-sdk/examples/#ContextMenu_Canvas_TreeViewPlugin_Custom)]
|
|
104444
|
-
*
|
|
104445
|
-
* ````javascript
|
|
104446
|
-
* treeView.on("nodeTitleClicked", (e) => {
|
|
104447
|
-
* const scene = viewer.scene;
|
|
104448
|
-
* const objectIds = [];
|
|
104449
|
-
* e.treeViewPlugin.withNodeTree(e.treeViewNode, (treeViewNode) => {
|
|
104450
|
-
* if (treeViewNode.objectId) {
|
|
104451
|
-
* objectIds.push(treeViewNode.objectId);
|
|
104452
|
-
* }
|
|
104453
|
-
* });
|
|
104454
|
-
* scene.setObjectsXRayed(scene.objectIds, true);
|
|
104455
|
-
* scene.setObjectsVisible(scene.objectIds, true);
|
|
104456
|
-
* scene.setObjectsXRayed(objectIds, false);
|
|
104457
|
-
* viewer.cameraFlight.flyTo({
|
|
104458
|
-
* aabb: scene.getAABB(objectIds),
|
|
104459
|
-
* duration: 0.5
|
|
104460
|
-
* }, () => {
|
|
104461
|
-
* setTimeout(function () {
|
|
104462
|
-
* scene.setObjectsVisible(scene.xrayedObjectIds, false);
|
|
104463
|
-
* scene.setObjectsXRayed(scene.xrayedObjectIds, false);
|
|
104464
|
-
* }, 500);
|
|
104465
|
-
* });
|
|
104466
|
-
* });
|
|
104467
|
-
* ````
|
|
104468
|
-
*
|
|
104469
|
-
* To make the cursor change to a pointer when we hover over the node titles, and also to make the titles change to blue, we'll also define this CSS for the ````<span>```` elements
|
|
104470
|
-
* that represent the titles of our TreeViewPlugin nodes:
|
|
104471
|
-
*
|
|
104472
|
-
* ````css
|
|
104473
|
-
* #treeViewContainer ul li span:hover {
|
|
104474
|
-
* color: blue;
|
|
104475
|
-
* cursor: pointer;
|
|
104476
|
-
* }
|
|
104477
|
-
* ````
|
|
104478
|
-
*
|
|
104479
|
-
* @class TreeViewPlugin
|
|
104480
|
-
*/
|
|
104481
|
-
class TreeViewPlugin extends Plugin {
|
|
104482
|
-
|
|
104483
|
-
/**
|
|
104484
|
-
* @constructor
|
|
104485
|
-
*
|
|
104486
|
-
* @param {Viewer} viewer The Viewer.
|
|
104487
|
-
* @param {*} cfg Plugin configuration.
|
|
104488
|
-
* @param {HTMLElement} cfg.containerElement DOM element to contain the TreeViewPlugin.
|
|
104489
|
-
* @param {Boolean} [cfg.autoAddModels=true] When ````true```` (default), will automatically add each model as it's created. Set this ````false```` if you want to manually add models using {@link TreeViewPlugin#addModel} instead.
|
|
104490
|
-
* @param {Number} [cfg.autoExpandDepth] Optional depth to which to initially expand the tree.
|
|
104491
|
-
* @param {String} [cfg.hierarchy="containment"] How to organize the tree nodes: "containment", "storeys" or "types". See the class documentation for details.
|
|
104492
|
-
* @param {Boolean} [cfg.sortNodes=true] When true, will sort the children of each node. For a "storeys" hierarchy, the
|
|
104493
|
-
* ````IfcBuildingStorey```` nodes will be ordered spatially, from the highest storey down to the lowest, on the
|
|
104494
|
-
* vertical World axis. For all hierarchy types, other node types will be ordered in the ascending alphanumeric order of their titles.
|
|
104495
|
-
* @param {Boolean} [cfg.pruneEmptyNodes=true] When true, will not contain nodes that don't have content in the {@link Scene}. These are nodes whose {@link MetaObject}s don't have {@link Entity}s.
|
|
104496
|
-
*/
|
|
104497
|
-
constructor(viewer, cfg = {}) {
|
|
104498
|
-
|
|
104499
|
-
super("TreeViewPlugin", viewer);
|
|
104500
|
-
|
|
104501
|
-
if (!cfg.containerElement) {
|
|
104502
|
-
this.error("Config expected: containerElement");
|
|
104503
|
-
return;
|
|
104504
|
-
}
|
|
104505
|
-
|
|
104506
|
-
this._containerElement = cfg.containerElement;
|
|
104507
|
-
this._modelTreeViews = {};
|
|
104508
|
-
this._autoAddModels = (cfg.autoAddModels !== false);
|
|
104509
|
-
this._autoExpandDepth = (cfg.autoExpandDepth || 0);
|
|
104510
|
-
this._sortNodes = (cfg.sortNodes !== false);
|
|
104511
|
-
this._pruneEmptyNodes = (cfg.pruneEmptyNodes !== false);
|
|
104512
|
-
|
|
104513
|
-
if (this._autoAddModels) {
|
|
104514
|
-
const modelIds = Object.keys(this.viewer.metaScene.metaModels);
|
|
104515
|
-
for (let i = 0, len = modelIds.length; i < len; i++) {
|
|
104516
|
-
const modelId = modelIds[i];
|
|
104517
|
-
this.addModel(modelId);
|
|
104518
|
-
}
|
|
104519
|
-
this.viewer.scene.on("modelLoaded", (modelId) => {
|
|
104520
|
-
if (this.viewer.metaScene.metaModels[modelId]) {
|
|
104521
|
-
this.addModel(modelId);
|
|
104522
|
-
}
|
|
104523
|
-
});
|
|
104524
|
-
}
|
|
104525
|
-
|
|
104526
|
-
this.hierarchy = cfg.hierarchy;
|
|
104527
|
-
}
|
|
104528
|
-
|
|
104529
|
-
/**
|
|
104530
|
-
* Returns the map of {@link ModelTreeView}s.
|
|
104531
|
-
*
|
|
104532
|
-
* Each ModelTreeView is mapped to the ID of its model.
|
|
104533
|
-
*
|
|
104534
|
-
* @return {*|{}}
|
|
104535
|
-
*/
|
|
104536
|
-
get modelTreeViews() {
|
|
104537
|
-
return this._modelTreeViews;
|
|
104538
|
-
}
|
|
104539
|
-
|
|
104540
|
-
/**
|
|
104541
|
-
* Sets how the nodes are organized within this tree view.
|
|
104542
|
-
*
|
|
104543
|
-
* Accepted values are:
|
|
104544
|
-
*
|
|
104545
|
-
* * "containment" - organizes the nodes to indicate the containment hierarchy of the IFC objects.
|
|
104546
|
-
* * "types" - groups the nodes within their IFC types.
|
|
104547
|
-
* * "storeys" - groups the nodes within ````IfcBuildingStoreys```` and sub-groups them by their IFC types.
|
|
104548
|
-
*
|
|
104549
|
-
* <br>
|
|
104550
|
-
* This can be updated dynamically.
|
|
104551
|
-
*
|
|
104552
|
-
* Default value is "containment".
|
|
104553
|
-
*
|
|
104554
|
-
* @type {String}
|
|
104555
|
-
*/
|
|
104556
|
-
set hierarchy(hierarchy) {
|
|
104557
|
-
hierarchy = hierarchy || "containment";
|
|
104558
|
-
if (hierarchy !== "containment" && hierarchy !== "storeys" && hierarchy !== "types") {
|
|
104559
|
-
this.error("Unsupported value for `hierarchy' - defaulting to 'containment'");
|
|
104560
|
-
hierarchy = "containment";
|
|
104561
|
-
}
|
|
104562
|
-
this._hierarchy = hierarchy;
|
|
104563
|
-
for (let modelId in this._modelTreeViews) {
|
|
104564
|
-
if (this._modelTreeViews.hasOwnProperty(modelId)) {
|
|
104565
|
-
this._modelTreeViews[modelId].setHierarchy(this._hierarchy);
|
|
104566
|
-
}
|
|
104567
|
-
}
|
|
104568
|
-
}
|
|
104569
|
-
|
|
104570
|
-
/**
|
|
104571
|
-
* Gets how the nodes are organized within this tree view.
|
|
104572
|
-
*
|
|
104573
|
-
* @type {String}
|
|
104574
|
-
*/
|
|
104575
|
-
get hierarchy() {
|
|
104576
|
-
return this._hierarchy;
|
|
104577
|
-
}
|
|
104578
|
-
|
|
104579
|
-
/**
|
|
104580
|
-
* Adds a model to this tree view.
|
|
104581
|
-
*
|
|
104582
|
-
* The model will be automatically removed when destroyed.
|
|
104583
|
-
*
|
|
104584
|
-
* To automatically add each model as it's created, instead of manually calling this method each time,
|
|
104585
|
-
* provide a ````autoAddModels: true```` to the TreeViewPlugin constructor.
|
|
104586
|
-
*
|
|
104587
|
-
* @param {String} modelId ID of a model {@link Entity} in {@link Scene#models}.
|
|
104588
|
-
* @param {Object} [options] Options for model in the tree view.
|
|
104589
|
-
* @param {String} [options.rootName] Optional display name for the root node. Ordinary, for "containment"
|
|
104590
|
-
* and "storeys" hierarchy types, the tree would derive the root node name from the model's "IfcProject" element
|
|
104591
|
-
* name. This option allows to override that name when it is not suitable as a display name.
|
|
104592
|
-
* @returns {ModelTreeView} ModelTreeView for the newly-added model. If this method succeeded in adding the model,
|
|
104593
|
-
* then {@link ModelTreeView#valid} will equal ````true````. Otherwise, that property will be ````false````
|
|
104594
|
-
* and {@link ModelTreeView#errors} will contain error messages.
|
|
104595
|
-
*/
|
|
104596
|
-
addModel(modelId, options = {}) {
|
|
104597
|
-
if (!this._containerElement) {
|
|
104598
|
-
return;
|
|
104599
|
-
}
|
|
104600
|
-
const model = this.viewer.scene.models[modelId];
|
|
104601
|
-
if (!model) {
|
|
104602
|
-
throw "Model not found: " + modelId;
|
|
104603
|
-
}
|
|
104604
|
-
const metaModel = this.viewer.metaScene.metaModels[modelId];
|
|
104605
|
-
if (!metaModel) {
|
|
104606
|
-
this.error("MetaModel not found: " + modelId);
|
|
104607
|
-
return;
|
|
104608
|
-
}
|
|
104609
|
-
if (this._modelTreeViews[modelId]) {
|
|
104610
|
-
this.warn("Model already added: " + modelId);
|
|
104611
|
-
return;
|
|
104612
|
-
}
|
|
104613
|
-
const modelTreeView = new ModelTreeView(this.viewer, this, model, metaModel, {
|
|
104614
|
-
containerElement: this._containerElement,
|
|
104615
|
-
autoExpandDepth: this._autoExpandDepth,
|
|
104616
|
-
hierarchy: this._hierarchy,
|
|
104617
|
-
sortNodes: this._sortNodes,
|
|
104618
|
-
pruneEmptyNodes: this._pruneEmptyNodes,
|
|
104619
|
-
rootName: options.rootName
|
|
104620
|
-
});
|
|
104621
|
-
this._modelTreeViews[modelId] = modelTreeView;
|
|
104622
|
-
model.on("destroyed", () => {
|
|
104623
|
-
this.removeModel(model.id);
|
|
104624
|
-
});
|
|
104625
|
-
return modelTreeView;
|
|
104626
|
-
}
|
|
104627
|
-
|
|
104628
|
-
/**
|
|
104629
|
-
* Removes a model from this tree view.
|
|
104630
|
-
*
|
|
104631
|
-
* Does nothing if model not currently in tree view.
|
|
104632
|
-
*
|
|
104633
|
-
* @param {String} modelId ID of a model {@link Entity} in {@link Scene#models}.
|
|
104634
|
-
*/
|
|
104635
|
-
removeModel(modelId) {
|
|
104636
|
-
if (!this._containerElement) {
|
|
104637
|
-
return;
|
|
104638
|
-
}
|
|
104639
|
-
const modelTreeView = this._modelTreeViews[modelId];
|
|
104640
|
-
if (!modelTreeView) {
|
|
104641
|
-
return;
|
|
104642
|
-
}
|
|
104643
|
-
modelTreeView.destroy();
|
|
104644
|
-
delete this._modelTreeViews[modelId];
|
|
104645
|
-
}
|
|
104646
|
-
|
|
104647
|
-
/**
|
|
104648
|
-
* Collapses all trees within this tree view.
|
|
104649
|
-
*/
|
|
104650
|
-
collapse() {
|
|
104651
|
-
for (let modelId in this._modelTreeViews) {
|
|
104652
|
-
if (this._modelTreeViews.hasOwnProperty(modelId)) {
|
|
104653
|
-
const modelTreeView = this._modelTreeViews[modelId];
|
|
104654
|
-
modelTreeView.collapse();
|
|
104655
|
-
}
|
|
104656
|
-
}
|
|
104657
|
-
}
|
|
104658
|
-
|
|
104659
|
-
/**
|
|
104660
|
-
* Highlights the tree view node that represents the given object {@link Entity}.
|
|
104661
|
-
*
|
|
104662
|
-
* This causes the tree view to collapse, then expand to reveal the node, then highlight the node.
|
|
104663
|
-
*
|
|
104664
|
-
* If a node is previously highlighted, de-highlights that node and collapses the tree first.
|
|
104665
|
-
*
|
|
104666
|
-
* Note that if the TreeViewPlugin was configured with ````pruneEmptyNodes: true```` (default configuration), then the
|
|
104667
|
-
* node won't exist in the tree if it has no Entitys in the {@link Scene}. in that case, nothing will happen.
|
|
104668
|
-
*
|
|
104669
|
-
* Within the DOM, the node is represented by an ````<li>```` element. This method will add a ````.highlighted-node```` class to
|
|
104670
|
-
* the element to make it appear highlighted, removing that class when de-highlighting it again. See the CSS rules
|
|
104671
|
-
* in the TreeViewPlugin examples for an example of that class.
|
|
104672
|
-
*
|
|
104673
|
-
* @param {String} objectId ID of the {@link Entity}.
|
|
104674
|
-
*/
|
|
104675
|
-
showNode(objectId) {
|
|
104676
|
-
this.unShowNode();
|
|
104677
|
-
const metaObject = this.viewer.metaScene.metaObjects[objectId];
|
|
104678
|
-
if (!metaObject) {
|
|
104679
|
-
this.error("MetaObject not found: " + objectId);
|
|
104680
|
-
return;
|
|
104681
|
-
}
|
|
104682
|
-
const metaModel = metaObject.metaModel;
|
|
104683
|
-
const modelId = metaModel.id;
|
|
104684
|
-
const modelTreeView = this._modelTreeViews[modelId];
|
|
104685
|
-
if (!modelTreeView) {
|
|
104686
|
-
this.error("Object not in this TreeView: " + objectId);
|
|
104687
|
-
return;
|
|
104688
|
-
}
|
|
104689
|
-
modelTreeView.showNode(objectId);
|
|
104690
|
-
}
|
|
104691
|
-
|
|
104692
|
-
/**
|
|
104693
|
-
* De-highlights the node previously shown with {@link TreeViewPlugin#showNode}.
|
|
104694
|
-
*
|
|
104695
|
-
* Does nothing if no node is currently shown.
|
|
104696
|
-
*
|
|
104697
|
-
* If the node is currently scrolled into view, keeps the node in view.
|
|
104698
|
-
*/
|
|
104699
|
-
unShowNode() {
|
|
104700
|
-
for (let modelId in this._modelTreeViews) {
|
|
104701
|
-
if (this._modelTreeViews.hasOwnProperty(modelId)) {
|
|
104702
|
-
const modelTreeView = this._modelTreeViews[modelId];
|
|
104703
|
-
modelTreeView.unShowNode();
|
|
104704
|
-
}
|
|
104705
|
-
}
|
|
104706
|
-
}
|
|
104707
|
-
|
|
104708
|
-
/**
|
|
104709
|
-
* Expands the tree to the given depth.
|
|
104710
|
-
*
|
|
104711
|
-
* Collapses the tree first.
|
|
104712
|
-
*
|
|
104713
|
-
* @param {Number} depth Depth to expand to.
|
|
104714
|
-
*/
|
|
104715
|
-
expandToDepth(depth) {
|
|
104716
|
-
for (let modelId in this._modelTreeViews) {
|
|
104717
|
-
if (this._modelTreeViews.hasOwnProperty(modelId)) {
|
|
104718
|
-
const modelTreeView = this._modelTreeViews[modelId];
|
|
104719
|
-
modelTreeView.collapse();
|
|
104720
|
-
modelTreeView.expandToDepth(depth);
|
|
104721
|
-
}
|
|
104722
|
-
}
|
|
104723
|
-
}
|
|
104724
|
-
|
|
104725
|
-
/**
|
|
104726
|
-
* Iterates over a subtree of the tree view's {@link TreeViewNode}s, calling the given callback for each
|
|
104727
|
-
* node in depth-first pre-order.
|
|
104728
|
-
*
|
|
104729
|
-
* @param {TreeViewNode} node Root of the subtree.
|
|
104730
|
-
* @param {Function} callback Callback called at each {@link TreeViewNode}, with the TreeViewNode given as the argument.
|
|
104731
|
-
*/
|
|
104732
|
-
withNodeTree(node, callback) {
|
|
104733
|
-
callback(node);
|
|
104734
|
-
const children = node.children;
|
|
104735
|
-
if (!children) {
|
|
104736
|
-
return;
|
|
104737
|
-
}
|
|
104738
|
-
for (let i = 0, len = children.length; i < len; i++) {
|
|
104739
|
-
this.withNodeTree(children[i], callback);
|
|
104740
|
-
}
|
|
104741
|
-
}
|
|
104742
|
-
|
|
104743
|
-
/**
|
|
104744
|
-
* Destroys this TreeViewPlugin.
|
|
104745
|
-
*/
|
|
104746
|
-
destroy() {
|
|
104747
|
-
if (!this._containerElement) {
|
|
104748
|
-
return;
|
|
104749
|
-
}
|
|
104750
|
-
for (let modelId in this._modelTreeViews) {
|
|
104751
|
-
if (this._modelTreeViews.hasOwnProperty(modelId)) {
|
|
104752
|
-
this._modelTreeViews[modelId].destroy();
|
|
104753
|
-
}
|
|
104754
|
-
}
|
|
104755
|
-
this._modelTreeViews = {};
|
|
104756
|
-
super.destroy();
|
|
104589
|
+
switchElement.removeEventListener('click', this._switchCollapseHandler);
|
|
104590
|
+
switchElement.addEventListener('click', this._switchExpandHandler);
|
|
104757
104591
|
}
|
|
104758
104592
|
}
|
|
104759
104593
|
|
|
@@ -116456,7 +116290,7 @@ class XKTLoaderPlugin extends Plugin {
|
|
|
116456
116290
|
}
|
|
116457
116291
|
|
|
116458
116292
|
options.excludeUnclassifiedObjects = (params.excludeUnclassifiedObjects !== undefined) ? (!!params.excludeUnclassifiedObjects) : this._excludeUnclassifiedObjects;
|
|
116459
|
-
options.globalizeObjectIds = (params.globalizeObjectIds !== undefined) ? (!!params.globalizeObjectIds) : this._globalizeObjectIds;
|
|
116293
|
+
options.globalizeObjectIds = (params.globalizeObjectIds !== undefined && params.globalizeObjectIds !== null) ? (!!params.globalizeObjectIds) : this._globalizeObjectIds;
|
|
116460
116294
|
|
|
116461
116295
|
if (params.metaModelSrc || params.metaModelData) {
|
|
116462
116296
|
|
|
@@ -116465,7 +116299,7 @@ class XKTLoaderPlugin extends Plugin {
|
|
|
116465
116299
|
const metaModel = this.viewer.metaScene.createMetaModel(modelId, metaModelData, {
|
|
116466
116300
|
includeTypes: includeTypes,
|
|
116467
116301
|
excludeTypes: excludeTypes,
|
|
116468
|
-
globalizeObjectIds:
|
|
116302
|
+
globalizeObjectIds: options.globalizeObjectIds
|
|
116469
116303
|
});
|
|
116470
116304
|
|
|
116471
116305
|
if (!metaModel) {
|