@xeokit/xeokit-sdk 2.6.0-beta-1 → 2.6.0-beta-4

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.
@@ -7495,22 +7495,25 @@ const frame = function () {
7495
7495
  lastTime = time;
7496
7496
  };
7497
7497
 
7498
- class WorkerInterval {
7499
- worker = null;
7500
-
7501
- constructor(callback, interval) {
7502
- const blob = new Blob([`setInterval(() => postMessage(0), ${interval});`]);
7503
- const workerScript = URL.createObjectURL(blob);
7504
- this.worker = new Worker(workerScript);
7505
- this.worker.onmessage = callback;
7506
- }
7507
-
7508
- stop() {
7509
- this.worker.terminate();
7510
- }
7498
+ function customSetInterval(callback, interval) {
7499
+ let expected = Date.now() + interval;
7500
+ function loop() {
7501
+ const elapsed = Date.now() - expected;
7502
+ callback();
7503
+ expected += interval;
7504
+ setTimeout(loop, Math.max(0, interval - elapsed));
7505
+ }
7506
+ loop();
7507
+ return {
7508
+ cancel: function() {
7509
+ // No need to do anything, setTimeout cannot be directly cancelled
7510
+ }
7511
+ };
7511
7512
  }
7512
7513
 
7513
- new WorkerInterval(frame, 100);
7514
+ customSetInterval(() => {
7515
+ frame();
7516
+ }, 100);
7514
7517
 
7515
7518
  const renderFrame = function () {
7516
7519
  let time = Date.now();
@@ -10840,14 +10843,13 @@ class Dot {
10840
10843
  this._x = 0;
10841
10844
  this._y = 0;
10842
10845
 
10843
- this._visible = true;
10844
10846
  this._dot = document.createElement('div');
10845
10847
  this._dot.className += this._dot.className ? ' viewer-ruler-dot' : 'viewer-ruler-dot';
10846
10848
 
10847
10849
  this._dotClickable = document.createElement('div');
10848
10850
  this._dotClickable.className += this._dotClickable.className ? ' viewer-ruler-dot-clickable' : 'viewer-ruler-dot-clickable';
10849
10851
 
10850
- this._visible = true;
10852
+ this._visible = !!cfg.visible;
10851
10853
  this._culled = false;
10852
10854
 
10853
10855
  var dot = this._dot;
@@ -80721,6 +80723,8 @@ class SceneModel extends Component {
80721
80723
  this._vboBatchingLayers = {};
80722
80724
  this._dtxLayers = {};
80723
80725
 
80726
+ this._meshList = [];
80727
+
80724
80728
  this.layerList = []; // For GL state efficiency when drawing, InstancingLayers are in first part, BatchingLayers are in second
80725
80729
  this._entityList = [];
80726
80730
 
@@ -80730,11 +80734,9 @@ class SceneModel extends Component {
80730
80734
  this._textureSets = {};
80731
80735
  this._transforms = {};
80732
80736
  this._meshes = {};
80737
+ this._unusedMeshes = {};
80733
80738
  this._entities = {};
80734
80739
 
80735
- this._scheduledMeshes = {};
80736
- this._meshesCfgsBeforeMeshCreation = {};
80737
-
80738
80740
  /** @private **/
80739
80741
  this.renderFlags = new RenderFlags();
80740
80742
 
@@ -82303,7 +82305,7 @@ class SceneModel extends Component {
82303
82305
  * @param {Number} [cfg.opacity=1] Opacity in range ````[0..1]````. Overridden by texture set ````colorTexture````.
82304
82306
  * @param {Number} [cfg.metallic=0] Metallic factor in range ````[0..1]````. Overridden by texture set ````metallicRoughnessTexture````.
82305
82307
  * @param {Number} [cfg.roughness=1] Roughness factor in range ````[0..1]````. Overridden by texture set ````metallicRoughnessTexture````.
82306
- * @returns {Boolean} True = successfully mesh was created. False = error during creation of a mesh.
82308
+ * @returns {SceneModelMesh} The new mesh.
82307
82309
  */
82308
82310
  createMesh(cfg) {
82309
82311
 
@@ -82312,7 +82314,7 @@ class SceneModel extends Component {
82312
82314
  return false;
82313
82315
  }
82314
82316
 
82315
- if (this._scheduledMeshes[cfg.id]) {
82317
+ if (this._meshes[cfg.id]) {
82316
82318
  this.error(`[createMesh] SceneModel already has a mesh with this ID: ${cfg.id}`);
82317
82319
  return false;
82318
82320
  }
@@ -82632,17 +82634,7 @@ class SceneModel extends Component {
82632
82634
 
82633
82635
  cfg.numPrimitives = this._getNumPrimitives(cfg);
82634
82636
 
82635
- this._meshesCfgsBeforeMeshCreation[cfg.id] = cfg;
82636
-
82637
- return true;
82638
- }
82639
-
82640
- _createDefaultIndices(numIndices) {
82641
- const indices = [];
82642
- for (let i = 0; i < numIndices; i++) {
82643
- indices.push(i);
82644
- }
82645
- return indices;
82637
+ return this._createMesh(cfg);
82646
82638
  }
82647
82639
 
82648
82640
  _createMesh(cfg) {
@@ -82674,6 +82666,9 @@ class SceneModel extends Component {
82674
82666
  cfg.meshMatrix = cfg.transform.worldMatrix;
82675
82667
  }
82676
82668
  mesh.portionId = mesh.layer.createPortion(mesh, cfg);
82669
+ this._meshes[cfg.id] = mesh;
82670
+ this._unusedMeshes[cfg.id] = mesh;
82671
+ this._meshList.push(mesh);
82677
82672
  return mesh;
82678
82673
  }
82679
82674
 
@@ -83034,19 +83029,15 @@ class SceneModel extends Component {
83034
83029
  const meshId = cfg.meshIds[i];
83035
83030
  let mesh = this._meshes[meshId]; // Trying to get already created mesh
83036
83031
  if (!mesh) { // Checks if there is already created mesh for this meshId
83037
- let meshCfg = this._meshesCfgsBeforeMeshCreation[meshId]; // Trying to get already created cfg
83038
- if (!meshCfg) { // Checks if there is already created cfg for this meshId
83039
- this.error(`Mesh with this ID not found: "${meshId}" - ignoring this mesh`); // There is no such cfg
83040
- continue;
83041
- }
83042
- mesh = this._createMesh(meshCfg); // There is no such mesh yet, but there is already created cfg, so it creates this mesh
83043
- this._meshes[cfg.id] = mesh; // Now it will also add this mesh to dictionary of created meshes
83032
+ this.error(`Mesh with this ID not found: "${meshId}" - ignoring this mesh`); // There is no such cfg
83033
+ continue;
83044
83034
  }
83045
83035
  if (mesh.parent) {
83046
83036
  this.error(`Mesh with ID "${meshId}" already belongs to object with ID "${mesh.parent.id}" - ignoring this mesh`);
83047
83037
  continue;
83048
83038
  }
83049
83039
  meshes.push(mesh);
83040
+ delete this._unusedMeshes[meshId];
83050
83041
  }
83051
83042
  const lodCullable = true;
83052
83043
  const entity = new SceneModelEntity(
@@ -83070,6 +83061,7 @@ class SceneModel extends Component {
83070
83061
  if (this.destroyed) {
83071
83062
  return;
83072
83063
  }
83064
+ this._createDummyEntityForUnusedMeshes();
83073
83065
  for (let i = 0, len = this.layerList.length; i < len; i++) {
83074
83066
  const layer = this.layerList[i];
83075
83067
  layer.finalize();
@@ -83146,6 +83138,21 @@ class SceneModel extends Component {
83146
83138
  }
83147
83139
  }
83148
83140
 
83141
+ /** @private */
83142
+ _createDummyEntityForUnusedMeshes() {
83143
+ const unusedMeshIds = Object.keys(this._unusedMeshes);
83144
+ if (unusedMeshIds.length > 0) {
83145
+ const entityId = `${this.id}-dummyEntityForUnusedMeshes`;
83146
+ this.warn(`Creating dummy SceneModelEntity "${entityId}" for unused SceneMeshes: [${unusedMeshIds.join(",")}]`);
83147
+ this.createEntity({
83148
+ id: entityId,
83149
+ meshIds: unusedMeshIds,
83150
+ isObject: true
83151
+ });
83152
+ }
83153
+ this._unusedMeshes = {};
83154
+ }
83155
+
83149
83156
  _getActiveSectionPlanesForLayer(layer) {
83150
83157
  const renderFlags = this.renderFlags;
83151
83158
  const sectionPlanes = this.scene._sectionPlanesState.sectionPlanes;
@@ -7491,22 +7491,25 @@ const frame = function () {
7491
7491
  lastTime = time;
7492
7492
  };
7493
7493
 
7494
- class WorkerInterval {
7495
- worker = null;
7496
-
7497
- constructor(callback, interval) {
7498
- const blob = new Blob([`setInterval(() => postMessage(0), ${interval});`]);
7499
- const workerScript = URL.createObjectURL(blob);
7500
- this.worker = new Worker(workerScript);
7501
- this.worker.onmessage = callback;
7502
- }
7503
-
7504
- stop() {
7505
- this.worker.terminate();
7506
- }
7494
+ function customSetInterval(callback, interval) {
7495
+ let expected = Date.now() + interval;
7496
+ function loop() {
7497
+ const elapsed = Date.now() - expected;
7498
+ callback();
7499
+ expected += interval;
7500
+ setTimeout(loop, Math.max(0, interval - elapsed));
7501
+ }
7502
+ loop();
7503
+ return {
7504
+ cancel: function() {
7505
+ // No need to do anything, setTimeout cannot be directly cancelled
7506
+ }
7507
+ };
7507
7508
  }
7508
7509
 
7509
- new WorkerInterval(frame, 100);
7510
+ customSetInterval(() => {
7511
+ frame();
7512
+ }, 100);
7510
7513
 
7511
7514
  const renderFrame = function () {
7512
7515
  let time = Date.now();
@@ -10836,14 +10839,13 @@ class Dot {
10836
10839
  this._x = 0;
10837
10840
  this._y = 0;
10838
10841
 
10839
- this._visible = true;
10840
10842
  this._dot = document.createElement('div');
10841
10843
  this._dot.className += this._dot.className ? ' viewer-ruler-dot' : 'viewer-ruler-dot';
10842
10844
 
10843
10845
  this._dotClickable = document.createElement('div');
10844
10846
  this._dotClickable.className += this._dotClickable.className ? ' viewer-ruler-dot-clickable' : 'viewer-ruler-dot-clickable';
10845
10847
 
10846
- this._visible = true;
10848
+ this._visible = !!cfg.visible;
10847
10849
  this._culled = false;
10848
10850
 
10849
10851
  var dot = this._dot;
@@ -80717,6 +80719,8 @@ class SceneModel extends Component {
80717
80719
  this._vboBatchingLayers = {};
80718
80720
  this._dtxLayers = {};
80719
80721
 
80722
+ this._meshList = [];
80723
+
80720
80724
  this.layerList = []; // For GL state efficiency when drawing, InstancingLayers are in first part, BatchingLayers are in second
80721
80725
  this._entityList = [];
80722
80726
 
@@ -80726,11 +80730,9 @@ class SceneModel extends Component {
80726
80730
  this._textureSets = {};
80727
80731
  this._transforms = {};
80728
80732
  this._meshes = {};
80733
+ this._unusedMeshes = {};
80729
80734
  this._entities = {};
80730
80735
 
80731
- this._scheduledMeshes = {};
80732
- this._meshesCfgsBeforeMeshCreation = {};
80733
-
80734
80736
  /** @private **/
80735
80737
  this.renderFlags = new RenderFlags();
80736
80738
 
@@ -82299,7 +82301,7 @@ class SceneModel extends Component {
82299
82301
  * @param {Number} [cfg.opacity=1] Opacity in range ````[0..1]````. Overridden by texture set ````colorTexture````.
82300
82302
  * @param {Number} [cfg.metallic=0] Metallic factor in range ````[0..1]````. Overridden by texture set ````metallicRoughnessTexture````.
82301
82303
  * @param {Number} [cfg.roughness=1] Roughness factor in range ````[0..1]````. Overridden by texture set ````metallicRoughnessTexture````.
82302
- * @returns {Boolean} True = successfully mesh was created. False = error during creation of a mesh.
82304
+ * @returns {SceneModelMesh} The new mesh.
82303
82305
  */
82304
82306
  createMesh(cfg) {
82305
82307
 
@@ -82308,7 +82310,7 @@ class SceneModel extends Component {
82308
82310
  return false;
82309
82311
  }
82310
82312
 
82311
- if (this._scheduledMeshes[cfg.id]) {
82313
+ if (this._meshes[cfg.id]) {
82312
82314
  this.error(`[createMesh] SceneModel already has a mesh with this ID: ${cfg.id}`);
82313
82315
  return false;
82314
82316
  }
@@ -82628,17 +82630,7 @@ class SceneModel extends Component {
82628
82630
 
82629
82631
  cfg.numPrimitives = this._getNumPrimitives(cfg);
82630
82632
 
82631
- this._meshesCfgsBeforeMeshCreation[cfg.id] = cfg;
82632
-
82633
- return true;
82634
- }
82635
-
82636
- _createDefaultIndices(numIndices) {
82637
- const indices = [];
82638
- for (let i = 0; i < numIndices; i++) {
82639
- indices.push(i);
82640
- }
82641
- return indices;
82633
+ return this._createMesh(cfg);
82642
82634
  }
82643
82635
 
82644
82636
  _createMesh(cfg) {
@@ -82670,6 +82662,9 @@ class SceneModel extends Component {
82670
82662
  cfg.meshMatrix = cfg.transform.worldMatrix;
82671
82663
  }
82672
82664
  mesh.portionId = mesh.layer.createPortion(mesh, cfg);
82665
+ this._meshes[cfg.id] = mesh;
82666
+ this._unusedMeshes[cfg.id] = mesh;
82667
+ this._meshList.push(mesh);
82673
82668
  return mesh;
82674
82669
  }
82675
82670
 
@@ -83030,19 +83025,15 @@ class SceneModel extends Component {
83030
83025
  const meshId = cfg.meshIds[i];
83031
83026
  let mesh = this._meshes[meshId]; // Trying to get already created mesh
83032
83027
  if (!mesh) { // Checks if there is already created mesh for this meshId
83033
- let meshCfg = this._meshesCfgsBeforeMeshCreation[meshId]; // Trying to get already created cfg
83034
- if (!meshCfg) { // Checks if there is already created cfg for this meshId
83035
- this.error(`Mesh with this ID not found: "${meshId}" - ignoring this mesh`); // There is no such cfg
83036
- continue;
83037
- }
83038
- mesh = this._createMesh(meshCfg); // There is no such mesh yet, but there is already created cfg, so it creates this mesh
83039
- this._meshes[cfg.id] = mesh; // Now it will also add this mesh to dictionary of created meshes
83028
+ this.error(`Mesh with this ID not found: "${meshId}" - ignoring this mesh`); // There is no such cfg
83029
+ continue;
83040
83030
  }
83041
83031
  if (mesh.parent) {
83042
83032
  this.error(`Mesh with ID "${meshId}" already belongs to object with ID "${mesh.parent.id}" - ignoring this mesh`);
83043
83033
  continue;
83044
83034
  }
83045
83035
  meshes.push(mesh);
83036
+ delete this._unusedMeshes[meshId];
83046
83037
  }
83047
83038
  const lodCullable = true;
83048
83039
  const entity = new SceneModelEntity(
@@ -83066,6 +83057,7 @@ class SceneModel extends Component {
83066
83057
  if (this.destroyed) {
83067
83058
  return;
83068
83059
  }
83060
+ this._createDummyEntityForUnusedMeshes();
83069
83061
  for (let i = 0, len = this.layerList.length; i < len; i++) {
83070
83062
  const layer = this.layerList[i];
83071
83063
  layer.finalize();
@@ -83142,6 +83134,21 @@ class SceneModel extends Component {
83142
83134
  }
83143
83135
  }
83144
83136
 
83137
+ /** @private */
83138
+ _createDummyEntityForUnusedMeshes() {
83139
+ const unusedMeshIds = Object.keys(this._unusedMeshes);
83140
+ if (unusedMeshIds.length > 0) {
83141
+ const entityId = `${this.id}-dummyEntityForUnusedMeshes`;
83142
+ this.warn(`Creating dummy SceneModelEntity "${entityId}" for unused SceneMeshes: [${unusedMeshIds.join(",")}]`);
83143
+ this.createEntity({
83144
+ id: entityId,
83145
+ meshIds: unusedMeshIds,
83146
+ isObject: true
83147
+ });
83148
+ }
83149
+ this._unusedMeshes = {};
83150
+ }
83151
+
83145
83152
  _getActiveSectionPlanesForLayer(layer) {
83146
83153
  const renderFlags = this.renderFlags;
83147
83154
  const sectionPlanes = this.scene._sectionPlanesState.sectionPlanes;