@xeokit/xeokit-sdk 2.6.109 → 2.6.112

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/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@xeokit/xeokit-sdk",
3
- "version": "2.6.109",
3
+ "version": "2.6.112",
4
4
  "description": "3D BIM IFC Viewer SDK for AEC engineering applications. Open Source JavaScript Toolkit based on pure WebGL for top performance, real-world coordinates and full double precision",
5
5
  "module": "./dist/xeokit-sdk.es.js",
6
6
  "main": "./dist/xeokit-sdk.cjs.js",
7
7
  "types": "./types/index.d.ts",
8
8
  "scripts": {
9
- "build": "rollup --config rollup.config.js; rollup --config rollup.minified.config.js",
10
- "dev-build": "rollup --config rollup.dev.config.js",
11
- "test": "npx percy exec -- npx playwright test"
9
+ "build": "node -e \"console.error('WARNING: \\'npm run {build,dev-build,test}\\' scripts and \\'devDependencies\\' are soon going to be deprecated. Install a build tool and execute it directly.\\n');\"; rollup --config rollup.config.js; rollup --config rollup.minified.config.js",
10
+ "dev-build": "node -e \"console.error('WARNING: \\'npm run {build,dev-build,test}\\' scripts and \\'devDependencies\\' are soon going to be deprecated. Install a build tool and execute it directly.\\n');\"; rollup --config rollup.dev.config.js",
11
+ "test": "node -e \"console.error('WARNING: \\'npm run {build,dev-build,test}\\' scripts and \\'devDependencies\\' are soon going to be deprecated. Install a test tool and execute it directly.\\n');\"; npx percy exec -- npx playwright test"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
@@ -323,6 +323,9 @@ class GLTFLoaderPlugin extends Plugin {
323
323
  * @param {Boolean} [params.globalizeObjectIds=false] Indicates whether to globalize each {@link Entity#id} and {@link MetaObject#id}, in case you need to prevent ID clashes with other models.
324
324
  * @param {*} [params.parseOptions={}] Options to pass to loaders.gl parse method, eg. ````{ gltf: { excludeExtensions: { "KHR_texture_transform": false } } }````.
325
325
  * @param {Boolean} [params.entityPerMesh=false] Create an entity for each mesh, instead of grouping leaf meshes under their common entity.
326
+ * @param {*} [params.loadersGl={core,gltf}] Alternative user-provided loaders.gl library.
327
+ * This feature has been tested with loaders.gl 4.3.4 version.
328
+ * Because loaders.gl is supplied externally, xeokit cannot guarantee compatibility with all loaders.gl versions.
326
329
  * @returns {Entity} Entity representing the model, which will have {@link Entity#isModel} set ````true```` and will be registered by {@link Entity#id} in {@link Scene#models}
327
330
  */
328
331
  load(params = {}) {
@@ -108,11 +108,12 @@ function getBasePath(src) {
108
108
  function parseGLTF(plugin, src, gltf, metaModelJSON, options, sceneModel, ok, error) {
109
109
  const spinner = plugin.viewer.scene.canvas.spinner;
110
110
  spinner.processes++;
111
- parse(gltf, GLTFLoader, {
111
+ const loadersGl = options.loadersGl;
112
+ (loadersGl ? loadersGl.core.parse : parse)(gltf, loadersGl ? loadersGl.gltf.GLTFLoader : GLTFLoader, {
112
113
  ...(options.parseOptions || { }),
113
114
  baseUri: options.basePath
114
115
  }).then((gltfData) => {
115
- const processedGLTF = postProcessGLTF(gltfData);
116
+ const processedGLTF = (loadersGl ? loadersGl.gltf.postProcessGLTF : postProcessGLTF)(gltfData);
116
117
  const ctx = {
117
118
  src: src,
118
119
  entityId: options.entityId,
@@ -134,6 +134,9 @@ class ViewCullPlugin extends Plugin {
134
134
  if (cullDirty) {
135
135
  const kdNode = this._kdRoot;
136
136
  if (kdNode) {
137
+ for (let objectIdx = 0, len = this._objectCullStates.numObjects; objectIdx < len; objectIdx++) {
138
+ this._objectCullStates.setObjectViewCulled(objectIdx, false);
139
+ }
137
140
  this._visitKDNode(kdNode);
138
141
  }
139
142
  }
@@ -610,7 +610,7 @@ class XKTLoaderPlugin extends Plugin {
610
610
  * @param {String[]} [cfg.includeTypes] When loading metadata, only loads objects that have {@link MetaObject}s with {@link MetaObject#type} values in this list.
611
611
  * @param {String[]} [cfg.excludeTypes] When loading metadata, never loads objects that have {@link MetaObject}s with {@link MetaObject#type} values in this list.
612
612
  * @param {Boolean} [cfg.excludeUnclassifiedObjects=false] When loading metadata and this is ````true````, will only load {@link Entity}s that have {@link MetaObject}s (that are not excluded). This is useful when we don't want Entitys in the Scene that are not represented within IFC navigation components, such as {@link TreeViewPlugin}.
613
- * @param {Boolean} [cfg.reuseGeometries=true] Indicates whether to enable geometry reuse (````true```` by default) or whether to internally expand
613
+ * @param {Boolean|Function} [cfg.reuseGeometries=true] Indicates whether to enable geometry reuse (````true```` by default) or whether to internally expand, a function will be called with a `{ instanceCount: <number> }` argument.
614
614
  * all geometry instances into batches (````false````), and not use instancing to render them. Setting this ````false```` can significantly
615
615
  * improve Viewer performance for models that have a lot of geometry reuse, but may also increase the amount of
616
616
  * browser and GPU memory they require. See [#769](https://github.com/xeokit/xeokit-sdk/issues/769) for more info.
@@ -878,7 +878,7 @@ class XKTLoaderPlugin extends Plugin {
878
878
  * @type {Boolean}
879
879
  */
880
880
  set reuseGeometries(value) {
881
- this._reuseGeometries = value !== false;
881
+ this._reuseGeometries = value;
882
882
  }
883
883
 
884
884
  /**
@@ -896,6 +896,7 @@ class XKTLoaderPlugin extends Plugin {
896
896
  * @param {ArrayBuffer} [params.xkt] The *````.xkt````* file data, as an alternative to the ````src```` parameter.
897
897
  * @param {String} [params.metaModelSrc] Path or URL to an optional metadata file, as an alternative to the ````metaModelData```` parameter.
898
898
  * @param {*} [params.metaModelData] JSON model metadata, as an alternative to the ````metaModelSrc```` parameter.
899
+ * @param {Boolean} [params.loadIntoMetaScene=true] Whether to load metadata into MetaScene, otherwise expose as SceneModel::metadata.
899
900
  * @param {String} [params.manifestSrc] Path or URL to a JSON manifest file that provides paths to ````.xkt```` files to load as parts of the model. Use this option to load models that have been split into
900
901
  * multiple XKT files. See [tutorial](https://xeokit.io/blog/automatically-splitting-large-models-for-better-performance) for more info.
901
902
  * @param {Object} [params.manifest] A JSON manifest object (as an alternative to a path or URL) that provides paths to ````.xkt```` files to load as parts of the model. Use this option to load models that have been split into
@@ -919,9 +920,9 @@ class XKTLoaderPlugin extends Plugin {
919
920
  * Viewer will hide backfaces on watertight meshes, show backfaces on open meshes, and always show backfaces on meshes when we slice them open with {@link SectionPlane}s.
920
921
  * @param {Boolean} [params.excludeUnclassifiedObjects=false] When loading metadata and this is ````true````, will only load {@link Entity}s that have {@link MetaObject}s (that are not excluded). This is useful when we don't want Entitys in the Scene that are not represented within IFC navigation components, such as {@link TreeViewPlugin}.
921
922
  * @param {Boolean} [params.globalizeObjectIds=false] Indicates whether to globalize each {@link Entity#id} and {@link MetaObject#id}, in case you need to prevent ID clashes with other models. See {@link XKTLoaderPlugin#globalizeObjectIds} for more info.
922
- * @param {Boolean} [params.reuseGeometries=true] Indicates whether to enable geometry reuse (````true```` by default) or whether to expand
923
- * all geometry instances into batches (````false````), and not use instancing to render them. Setting this ````false```` can significantly
924
- * improve Viewer performance for models that have excessive geometry reuse, but may also increases the amount of
923
+ * @param {Boolean|Function} [params.reuseGeometries=true] Indicates whether to enable geometry reuse (````true```` by default) or whether to expand
924
+ * all geometry instances into batches (````false````), and not use instancing to render them. A function will be called with a `{ instanceCount: <number> }` argument. Setting this ````false```` can significantly
925
+ * improve Viewer performance for models that have excessive geometry reuse, but may also increase the amount of
925
926
  * browser and GPU memory used by the model. See [#769](https://github.com/xeokit/xeokit-sdk/issues/769) for more info.
926
927
  * @param {Boolean} [params.dtxEnabled=true] When ````true```` (default) use data textures (DTX), where appropriate, to
927
928
  * represent the returned model. Set false to always use vertex buffer objects (VBOs). Note that DTX is only applicable
@@ -948,7 +949,8 @@ class XKTLoaderPlugin extends Plugin {
948
949
  const includeIds = params.includeIds || this._includeIds;
949
950
  const objectDefaults = params.objectDefaults || this._objectDefaults;
950
951
 
951
- options.reuseGeometries = (params.reuseGeometries !== null && params.reuseGeometries !== undefined) ? params.reuseGeometries : (this._reuseGeometries !== false);
952
+ const reuseGeometries = params.reuseGeometries ?? this._reuseGeometries;
953
+ options.reuseGeometries = (typeof reuseGeometries !== "function") ? (() => reuseGeometries) : reuseGeometries;
952
954
 
953
955
  if (includeTypes) {
954
956
  options.includeTypesMap = {};
@@ -991,10 +993,30 @@ class XKTLoaderPlugin extends Plugin {
991
993
 
992
994
  const modelId = sceneModel.id; // In case ID was auto-generated
993
995
 
994
- const metaModel = new MetaModel({
995
- metaScene: this.viewer.metaScene,
996
- id: modelId
997
- });
996
+ const loadIntoMetaScene = (! ("loadIntoMetaScene" in params)) || params.loadIntoMetaScene;
997
+ const metaModel = (loadIntoMetaScene
998
+ ? new MetaModel({
999
+ id: modelId,
1000
+ metaScene: this.viewer.metaScene
1001
+ })
1002
+ : (function() {
1003
+ let firstMetadata = null;
1004
+ let modelMetadata = null;
1005
+ return {
1006
+ loadData: metadata => {
1007
+ if (! firstMetadata) {
1008
+ firstMetadata = metadata;
1009
+ } else {
1010
+ if (! modelMetadata) {
1011
+ modelMetadata = { };
1012
+ Object.entries(firstMetadata).forEach(([ k, v ]) => modelMetadata[k] = Array.isArray(v) ? v.slice(0) : v);
1013
+ }
1014
+ Object.entries(metadata).forEach(([ k, v ]) => { if (Array.isArray(v)) { v.forEach(e => modelMetadata[k].push(e)); } });
1015
+ }
1016
+ },
1017
+ finalize: () => sceneModel.metadata = modelMetadata || firstMetadata
1018
+ };
1019
+ })());
998
1020
 
999
1021
  this.viewer.scene.canvas.spinner.processes++;
1000
1022
 
@@ -1007,7 +1029,7 @@ class XKTLoaderPlugin extends Plugin {
1007
1029
  metaModel.finalize();
1008
1030
  this.viewer.scene.canvas.spinner.processes--;
1009
1031
  sceneModel.once("destroyed", () => {
1010
- this.viewer.metaScene.destroyMetaModel(metaModel.id);
1032
+ loadIntoMetaScene && this.viewer.metaScene.destroyMetaModel(metaModel.id);
1011
1033
  });
1012
1034
  this.scheduleTask(() => {
1013
1035
  if (sceneModel.destroyed) {
@@ -391,7 +391,7 @@ function load(viewer, options, inflatedData, sceneModel, metaModel, manifestCtx)
391
391
 
392
392
  if (!geometryArrays) {
393
393
  geometryArrays = {
394
- batchThisMesh: (!options.reuseGeometries)
394
+ batchThisMesh: (!options.reuseGeometries({ instanceCount: geometryReuseCount }))
395
395
  };
396
396
  const primitiveType = eachGeometryPrimitiveType[geometryIndex];
397
397
  let geometryValid = false;
@@ -384,7 +384,7 @@ function load(viewer, options, inflatedData, sceneModel, metaModel, manifestCtx)
384
384
 
385
385
  if (!geometryArrays) {
386
386
  geometryArrays = {
387
- batchThisMesh: (!options.reuseGeometries)
387
+ batchThisMesh: (!options.reuseGeometries({ instanceCount: geometryReuseCount }))
388
388
  };
389
389
  const primitiveType = eachGeometryPrimitiveType[geometryIndex];
390
390
  let geometryValid = false;
@@ -469,7 +469,7 @@ function load(viewer, options, inflatedData, sceneModel, metaModel, manifestCtx)
469
469
 
470
470
  if (!geometryArrays) {
471
471
  geometryArrays = {
472
- batchThisMesh: (!options.reuseGeometries)
472
+ batchThisMesh: (!options.reuseGeometries({ instanceCount: geometryReuseCount }))
473
473
  };
474
474
  const primitiveType = eachGeometryPrimitiveType[geometryIndex];
475
475
  const axisLabel = eachGeometryAxisLabel[geometryIndex];
@@ -341,7 +341,7 @@ function load(viewer, options, inflatedData, sceneModel, metaModel, manifestCtx)
341
341
  if (!geometryArrays) {
342
342
 
343
343
  geometryArrays = {
344
- batchThisMesh: (!options.reuseGeometries)
344
+ batchThisMesh: (!options.reuseGeometries({ instanceCount: geometryReuseCount }))
345
345
  };
346
346
 
347
347
  const primitiveType = eachGeometryPrimitiveType[geometryIndex];
@@ -297,7 +297,7 @@ function load(viewer, options, inflatedData, sceneModel, metaModel, manifestCtx)
297
297
 
298
298
  if (!geometryArrays) {
299
299
  geometryArrays = {
300
- batchThisMesh: (!options.reuseGeometries)
300
+ batchThisMesh: (!options.reuseGeometries({ instanceCount: geometryReuseCount }))
301
301
  };
302
302
  const primitiveType = eachGeometryPrimitiveType[geometryIndex];
303
303
  let geometryValid = false;